InLineSettingItem.java revision a8b55a9628fa7c073d4f9c97c9a198275194f76a
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.R; 20import com.android.camera.ListPreference; 21 22import android.content.Context; 23import android.util.AttributeSet; 24import android.view.View; 25import android.widget.LinearLayout; 26import android.widget.TextView; 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 */ 38public abstract class InLineSettingItem extends LinearLayout { 39 protected Context mContext; 40 private Listener mListener; 41 protected ListPreference mPreference; 42 protected int mIndex; 43 // Scene mode can override the original preference value. 44 protected String mOverrideValue; 45 46 static public interface Listener { 47 public void onSettingChanged(); 48 } 49 50 public InLineSettingItem(Context context, AttributeSet attrs) { 51 super(context, attrs); 52 mContext = context; 53 } 54 55 protected void setTitle(ListPreference preference) { 56 ((TextView) findViewById(R.id.title)).setText(preference.getTitle()); 57 } 58 59 public void initialize(ListPreference preference) { 60 setTitle(preference); 61 if (preference == null) return; 62 mPreference = preference; 63 reloadPreference(); 64 } 65 66 protected abstract void updateView(); 67 68 protected boolean changeIndex(int index) { 69 mIndex = index; 70 mPreference.setValueIndex(mIndex); 71 if (mListener != null) { 72 mListener.onSettingChanged(); 73 } 74 updateView(); 75 return true; 76 } 77 78 // The value of the preference may have changed. Update the UI. 79 public void reloadPreference() { 80 mIndex = mPreference.findIndexOfValue(mPreference.getValue()); 81 updateView(); 82 } 83 84 public void setSettingChangedListener(Listener listener) { 85 mListener = listener; 86 } 87 88 public void overrideSettings(String value) { 89 mOverrideValue = value; 90 updateView(); 91 } 92} 93