InLineSettingSwitch.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; 20 21import android.content.Context; 22import android.util.AttributeSet; 23import android.view.View; 24import android.widget.Button; 25import android.widget.CompoundButton; 26import android.widget.CompoundButton.OnCheckedChangeListener; 27import android.widget.Switch; 28 29/* A switch setting control which turns on/off the setting. */ 30public class InLineSettingSwitch extends InLineSettingItem { 31 private Switch mSwitch; 32 33 OnCheckedChangeListener mCheckedChangeListener = new OnCheckedChangeListener() { 34 public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) { 35 changeIndex(desiredState ? 1 : 0); 36 } 37 }; 38 39 public InLineSettingSwitch(Context context, AttributeSet attrs) { 40 super(context, attrs); 41 } 42 43 @Override 44 protected void onFinishInflate() { 45 super.onFinishInflate(); 46 mSwitch = (Switch) findViewById(R.id.setting_switch); 47 mSwitch.setOnCheckedChangeListener(mCheckedChangeListener); 48 } 49 50 protected void updateView() { 51 if (mOverrideValue == null) { 52 mSwitch.setChecked(mIndex == 1); 53 } else { 54 int index = mPreference.findIndexOfValue(mOverrideValue); 55 mSwitch.setChecked(index == 1); 56 } 57 } 58} 59