| 1 |
/* |
| 2 |
* Copyright 2012 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.notificationstudio.editor; |
| 18 |
|
| 19 |
import android.view.View; |
| 20 |
import android.view.ViewStub; |
| 21 |
import android.widget.CompoundButton; |
| 22 |
import android.widget.CompoundButton.OnCheckedChangeListener; |
| 23 |
import android.widget.Switch; |
| 24 |
|
| 25 |
import com.android.notificationstudio.R; |
| 26 |
import com.android.notificationstudio.editor.Editors.Editor; |
| 27 |
import com.android.notificationstudio.model.EditableItem; |
| 28 |
|
| 29 |
public class BooleanEditor implements Editor { |
| 30 |
|
| 31 |
public Runnable bindEditor(View v, final EditableItem item, final Runnable afterChange) { |
| 32 |
final ViewStub booleanEditorStub = (ViewStub) v.findViewById(R.id.boolean_editor_stub); |
| 33 |
booleanEditorStub.setLayoutResource(R.layout.boolean_editor); |
| 34 |
final Switch booleanEditor = (Switch) booleanEditorStub.inflate(); |
| 35 |
Runnable updateSwitch = new Runnable() { |
| 36 |
public void run() { |
| 37 |
booleanEditor.setChecked(item.hasValue() && item.getValueBool()); |
| 38 |
}}; |
| 39 |
booleanEditor.setVisibility(View.VISIBLE); |
| 40 |
updateSwitch.run(); |
| 41 |
booleanEditor.setOnCheckedChangeListener(new OnCheckedChangeListener(){ |
| 42 |
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 43 |
item.setValue(isChecked); |
| 44 |
afterChange.run(); |
| 45 |
}}); |
| 46 |
return updateSwitch; |
| 47 |
} |
| 48 |
|
| 49 |
} |