2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com.android.camera;
18 import android.content.Context;
19 import android.content.res.TypedArray;
20 import android.util.AttributeSet;
21 import android.view.View;
24 * A toggle button that supports two states with images rendererd on top for each state.
26 public class ToggleImageButton extends MultiToggleImageButton {
28 * Listener interface for button state changes.
30 public interface OnStateChangeListener {
32 * @param view the ToggleImageButton that received the touch event
33 * @param state the new state the button is in
35 public abstract void stateChanged(View view, boolean state);
38 private OnStateChangeListener mOnStateChangeListener;
39 public ToggleImageButton(Context context) {
43 public ToggleImageButton(Context context, AttributeSet attrs) {
44 super(context, attrs);
47 public ToggleImageButton(Context context, AttributeSet attrs, int defStyle) {
48 super(context, attrs, defStyle);
52 * Set the state change listener.
53 * @param onStateChangeListener the listener to set
55 public void setOnStateChangeListener(OnStateChangeListener onStateChangeListener) {
56 mOnStateChangeListener = onStateChangeListener;
60 * Set the current button state, thus causing the state change listener to get called.
61 * @param state the desired state
63 public void setState(boolean state) {
64 super.setState(state ? 1 : 0);
68 protected void init() {
70 super.setOnStateChangeListener(new MultiToggleImageButton.OnStateChangeListener() {
72 public void stateChanged(View v, int state) {
73 if (mOnStateChangeListener != null) {
74 mOnStateChangeListener.stateChanged(v, (state == 1));