• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 import android.util.AttributeSet;
21 import android.view.accessibility.AccessibilityEvent;
22 import android.widget.LinearLayout;
23 import android.widget.TextView;
24 
25 import com.android.camera.ListPreference;
26 import com.android.camera.R;
27 
28 /**
29  * A one-line camera setting could be one of three types: knob, switch or restore
30  * preference button. The setting includes a title for showing the preference
31  * title which is initialized in the SimpleAdapter. A knob also includes
32  * (ex: Picture size), a previous button, the current value (ex: 5MP),
33  * and a next button. A switch, i.e. the preference RecordLocationPreference,
34  * has only two values on and off which will be controlled in a switch button.
35  * Other setting popup window includes several InLineSettingItem items with
36  * different types if possible.
37  */
38 public abstract class InLineSettingItem extends LinearLayout {
39     private Listener mListener;
40     protected ListPreference mPreference;
41     protected int mIndex;
42     // Scene mode can override the original preference value.
43     protected String mOverrideValue;
44     protected TextView mTitle;
45 
46     static public interface Listener {
onSettingChanged(ListPreference pref)47         public void onSettingChanged(ListPreference pref);
48     }
49 
InLineSettingItem(Context context, AttributeSet attrs)50     public InLineSettingItem(Context context, AttributeSet attrs) {
51         super(context, attrs);
52     }
53 
setTitle(ListPreference preference)54     protected void setTitle(ListPreference preference) {
55         mTitle = ((TextView) findViewById(R.id.title));
56         mTitle.setText(preference.getTitle());
57     }
58 
initialize(ListPreference preference)59     public void initialize(ListPreference preference) {
60         setTitle(preference);
61         if (preference == null) return;
62         mPreference = preference;
63         reloadPreference();
64     }
65 
updateView()66     protected abstract void updateView();
67 
changeIndex(int index)68     protected boolean changeIndex(int index) {
69         if (index >= mPreference.getEntryValues().length || index < 0) return false;
70         mIndex = index;
71         mPreference.setValueIndex(mIndex);
72         if (mListener != null) {
73             mListener.onSettingChanged(mPreference);
74         }
75         updateView();
76         sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
77         return true;
78     }
79 
80     // The value of the preference may have changed. Update the UI.
reloadPreference()81     public void reloadPreference() {
82         mIndex = mPreference.findIndexOfValue(mPreference.getValue());
83         updateView();
84     }
85 
setSettingChangedListener(Listener listener)86     public void setSettingChangedListener(Listener listener) {
87         mListener = listener;
88     }
89 
overrideSettings(String value)90     public void overrideSettings(String value) {
91         mOverrideValue = value;
92         updateView();
93     }
94 }
95