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