Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.camera.ui;
     18 
     19 import com.android.camera.CameraPreference.OnPreferenceChangedListener;
     20 import com.android.camera.ListPreference;
     21 import com.android.camera.R;
     22 
     23 import android.content.Context;
     24 import android.hardware.Camera.CameraInfo;
     25 import android.view.View;
     26 
     27 /**
     28  * A view for switching the front/back camera.
     29  */
     30 public class CameraPicker extends RotateImageView implements View.OnClickListener {
     31     private static int mImageResource;
     32 
     33     private OnPreferenceChangedListener mListener;
     34     private ListPreference mPreference;
     35     private CharSequence[] mCameras;
     36 
     37     public CameraPicker(Context context) {
     38         super(context);
     39         setImageResource(mImageResource);
     40         setContentDescription(getResources().getString(
     41                 R.string.accessibility_camera_picker));
     42     }
     43 
     44     public static void setImageResourceId(int imageResource) {
     45         mImageResource = imageResource;
     46     }
     47 
     48     public void setListener(OnPreferenceChangedListener listener) {
     49         mListener = listener;
     50     }
     51 
     52     public void initialize(ListPreference pref) {
     53         mPreference = pref;
     54         mCameras = pref.getEntryValues();
     55         if (mCameras == null) return;
     56         setOnClickListener(this);
     57         setVisibility(View.VISIBLE);
     58     }
     59 
     60     @Override
     61     public void onClick(View v) {
     62         if (mCameras == null) return;
     63         int index = mPreference.findIndexOfValue(mPreference.getValue());
     64         CharSequence[] values = mPreference.getEntryValues();
     65         index = (index + 1) % values.length;
     66         mPreference.setValue((String) mCameras[index]);
     67         mListener.onSharedPreferenceChanged();
     68     }
     69 }
     70