blob: 8c4ae197d3b7e0621d70241e6e9c404b0705897d [file] [log] [blame]
Daniel Sandler3b0543a2011-06-14 11:30:28 -04001/*
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;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070025import android.view.MotionEvent;
Daniel Sandler3b0543a2011-06-14 11:30:28 -040026import android.view.View;
27import android.widget.FrameLayout;
28import android.widget.ImageView;
29import android.widget.RadioButton;
30import android.widget.RadioGroup;
31
32import com.android.systemui.R;
33
34public class CompatModePanel extends FrameLayout implements StatusBarPanel,
35 View.OnClickListener {
36 private static final boolean DEBUG = TabletStatusBar.DEBUG;
37 private static final String TAG = "CompatModePanel";
38
39 private ActivityManager mAM;
40
41 private boolean mAttached = false;
42 private Context mContext;
43 private RadioButton mOnButton, mOffButton;
44
45 private View mTrigger;
46// private InputMethodButton mInputMethodSwitchButton;
47
48 public CompatModePanel(Context context, AttributeSet attrs) {
49 super(context, attrs);
50 mContext = context;
51 mAM = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
52 }
53
54 @Override
55 public void onFinishInflate() {
56 mOnButton = (RadioButton) findViewById(R.id.compat_mode_on_radio);
57 mOffButton = (RadioButton) findViewById(R.id.compat_mode_off_radio);
58 mOnButton.setOnClickListener(this);
59 mOffButton.setOnClickListener(this);
60
61 refresh();
62 }
63
64 @Override
65 protected void onDetachedFromWindow() {
66 super.onDetachedFromWindow();
67 if (mAttached) {
68 mAttached = false;
69 }
70 }
71
72 @Override
73 protected void onAttachedToWindow() {
74 super.onAttachedToWindow();
75 if (!mAttached) {
76 mAttached = true;
77 }
78 }
79
80 @Override
81 public void onClick(View v) {
82 if (v == mOnButton) {
83 mAM.setFrontActivityScreenCompatMode(ActivityManager.COMPAT_MODE_ENABLED);
84 } else if (v == mOffButton) {
85 mAM.setFrontActivityScreenCompatMode(ActivityManager.COMPAT_MODE_DISABLED);
86 }
87 }
88
89 @Override
90 public boolean isInContentArea(int x, int y) {
91 return false;
92 }
93
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070094 @Override
95 public boolean dispatchHoverEvent(MotionEvent event) {
96 // Ignore hover events outside of this panel bounds since such events
97 // generate spurious accessibility events with the panel content when
98 // tapping outside of it, thus confusing the user.
99 final int x = (int) event.getX();
100 final int y = (int) event.getY();
101 if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
102 return super.dispatchHoverEvent(event);
103 }
104 return true;
105 }
106
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400107 public void setTrigger(View v) {
108 mTrigger = v;
109 }
110
111 public void openPanel() {
112 setVisibility(View.VISIBLE);
113 if (mTrigger != null) mTrigger.setSelected(true);
114 refresh();
115 }
116
117 public void closePanel() {
118 setVisibility(View.GONE);
119 if (mTrigger != null) mTrigger.setSelected(false);
120 }
121
122 private void refresh() {
123 int mode = mAM.getFrontActivityScreenCompatMode();
Dianne Hackborned31bbf2011-06-15 11:16:06 -0700124 if (mode == ActivityManager.COMPAT_MODE_ALWAYS
125 || mode == ActivityManager.COMPAT_MODE_NEVER) {
126 // No longer have something to switch.
127 closePanel();
128 return;
129 }
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400130 final boolean on = (mode == ActivityManager.COMPAT_MODE_ENABLED);
131 mOnButton.setChecked(on);
132 mOffButton.setChecked(!on);
133 }
Daniel Sandler3b0543a2011-06-14 11:30:28 -0400134}