CompatModePanel.java revision 3b0543acf11ac4638ec5452acc4c1c6716c26880
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.systemui.statusbar.tablet;
18
19import android.app.ActivityManager;
20import android.content.Context;
21import android.content.res.TypedArray;
22import android.os.RemoteException;
23import android.util.AttributeSet;
24import android.util.Slog;
25import android.view.View;
26import android.widget.FrameLayout;
27import android.widget.ImageView;
28import android.widget.RadioButton;
29import android.widget.RadioGroup;
30
31import com.android.systemui.R;
32
33public class CompatModePanel extends FrameLayout implements StatusBarPanel,
34        View.OnClickListener {
35    private static final boolean DEBUG = TabletStatusBar.DEBUG;
36    private static final String TAG = "CompatModePanel";
37
38    private ActivityManager mAM;
39
40    private boolean mAttached = false;
41    private Context mContext;
42    private RadioButton mOnButton, mOffButton;
43
44    private View mTrigger;
45//    private InputMethodButton mInputMethodSwitchButton;
46
47    public CompatModePanel(Context context, AttributeSet attrs) {
48        super(context, attrs);
49        mContext = context;
50        mAM = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
51    }
52
53    @Override
54    public void onFinishInflate() {
55        mOnButton  = (RadioButton) findViewById(R.id.compat_mode_on_radio);
56        mOffButton = (RadioButton) findViewById(R.id.compat_mode_off_radio);
57        mOnButton.setOnClickListener(this);
58        mOffButton.setOnClickListener(this);
59
60        refresh();
61    }
62
63    @Override
64    protected void onDetachedFromWindow() {
65        super.onDetachedFromWindow();
66        if (mAttached) {
67            mAttached = false;
68        }
69    }
70
71    @Override
72    protected void onAttachedToWindow() {
73        super.onAttachedToWindow();
74        if (!mAttached) {
75            mAttached = true;
76        }
77    }
78
79    @Override
80    public void onClick(View v) {
81        if (v == mOnButton) {
82            mAM.setFrontActivityScreenCompatMode(ActivityManager.COMPAT_MODE_ENABLED);
83        } else if (v == mOffButton) {
84            mAM.setFrontActivityScreenCompatMode(ActivityManager.COMPAT_MODE_DISABLED);
85        }
86    }
87
88    @Override
89    public boolean isInContentArea(int x, int y) {
90        return false;
91    }
92
93    public void setTrigger(View v) {
94        mTrigger = v;
95    }
96
97    public void openPanel() {
98        setVisibility(View.VISIBLE);
99        if (mTrigger != null) mTrigger.setSelected(true);
100        refresh();
101    }
102
103    public void closePanel() {
104        setVisibility(View.GONE);
105        if (mTrigger != null) mTrigger.setSelected(false);
106    }
107
108    private void refresh() {
109        int mode = mAM.getFrontActivityScreenCompatMode();
110        final boolean on = (mode == ActivityManager.COMPAT_MODE_ENABLED);
111        mOnButton.setChecked(on);
112        mOffButton.setChecked(!on);
113    }
114
115}
116