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 android.content.Context;
     20 
     21 import com.android.camera.CameraSettings;
     22 import com.android.camera.IconListPreference;
     23 import com.android.camera.ListPreference;
     24 import com.android.camera.PreferenceGroup;
     25 
     26 public class CameraHeadUpDisplay extends HeadUpDisplay {
     27 
     28     private static final String TAG = "CamcoderHeadUpDisplay";
     29 
     30     private OtherSettingsIndicator mOtherSettings;
     31     private GpsIndicator mGpsIndicator;
     32     private ZoomIndicator mZoomIndicator;
     33     private Context mContext;
     34     private float[] mInitialZoomRatios;
     35     private int mInitialOrientation;
     36 
     37     public CameraHeadUpDisplay(Context context) {
     38         super(context);
     39         mContext = context;
     40     }
     41 
     42     public void initialize(Context context, PreferenceGroup group,
     43             float[] initialZoomRatios, int initialOrientation) {
     44         mInitialZoomRatios = initialZoomRatios;
     45         mInitialOrientation = initialOrientation;
     46         super.initialize(context, group);
     47     }
     48 
     49     @Override
     50     protected void initializeIndicatorBar(
     51             Context context, PreferenceGroup group) {
     52         super.initializeIndicatorBar(context, group);
     53 
     54         ListPreference prefs[] = getListPreferences(group,
     55                 CameraSettings.KEY_FOCUS_MODE,
     56                 CameraSettings.KEY_EXPOSURE,
     57                 CameraSettings.KEY_SCENE_MODE,
     58                 CameraSettings.KEY_PICTURE_SIZE,
     59                 CameraSettings.KEY_JPEG_QUALITY,
     60                 CameraSettings.KEY_COLOR_EFFECT);
     61 
     62         mOtherSettings = new OtherSettingsIndicator(context, prefs);
     63         mOtherSettings.setOnRestorePreferencesClickedRunner(new Runnable() {
     64             public void run() {
     65                 if (mListener != null) {
     66                     mListener.onRestorePreferencesClicked();
     67                 }
     68             }
     69         });
     70         mIndicatorBar.addComponent(mOtherSettings);
     71 
     72         mGpsIndicator = new GpsIndicator(
     73                 context, (IconListPreference)
     74                 group.findPreference(CameraSettings.KEY_RECORD_LOCATION));
     75         mIndicatorBar.addComponent(mGpsIndicator);
     76 
     77         addIndicator(context, group, CameraSettings.KEY_WHITE_BALANCE);
     78         addIndicator(context, group, CameraSettings.KEY_FLASH_MODE);
     79 
     80         if (mInitialZoomRatios != null) {
     81             mZoomIndicator = new ZoomIndicator(mContext);
     82             mZoomIndicator.setZoomRatios(mInitialZoomRatios);
     83             mIndicatorBar.addComponent(mZoomIndicator);
     84         } else {
     85             mZoomIndicator = null;
     86         }
     87 
     88         addIndicator(context, group, CameraSettings.KEY_CAMERA_ID);
     89 
     90         mIndicatorBar.setOrientation(mInitialOrientation);
     91     }
     92 
     93     public void setZoomListener(ZoomControllerListener listener) {
     94         // The rendering thread won't access listener variable, so we don't
     95         // need to do concurrency protection here
     96         mZoomIndicator.setZoomListener(listener);
     97     }
     98 
     99     public void setZoomIndex(int index) {
    100         GLRootView root = getGLRootView();
    101         if (root != null) {
    102             synchronized (root) {
    103                 mZoomIndicator.setZoomIndex(index);
    104             }
    105         } else {
    106             mZoomIndicator.setZoomIndex(index);
    107         }
    108     }
    109 
    110     public void setGpsHasSignal(final boolean hasSignal) {
    111         GLRootView root = getGLRootView();
    112         if (root != null) {
    113             synchronized (root) {
    114                 mGpsIndicator.setHasSignal(hasSignal);
    115             }
    116         } else {
    117             mGpsIndicator.setHasSignal(hasSignal);
    118         }
    119     }
    120 
    121     /**
    122      * Sets the zoom rations the camera driver provides. This methods must be
    123      * called before <code>setZoomListener()</code> and
    124      * <code>setZoomIndex()</code>
    125      */
    126     public void setZoomRatios(float[] zoomRatios) {
    127         GLRootView root = getGLRootView();
    128         if (root != null) {
    129             synchronized(root) {
    130                 setZoomRatiosLocked(zoomRatios);
    131             }
    132         } else {
    133             setZoomRatiosLocked(zoomRatios);
    134         }
    135     }
    136 
    137     private void setZoomRatiosLocked(float[] zoomRatios) {
    138         mZoomIndicator.setZoomRatios(zoomRatios);
    139     }
    140 }
    141