Daniel Sandler | 3b0543a | 2011-06-14 11:30:28 -0400 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.statusbar.tablet; |
| 18 | |
| 19 | import android.app.ActivityManager; |
| 20 | import android.content.Context; |
| 21 | import android.content.res.TypedArray; |
| 22 | import android.os.RemoteException; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.util.Slog; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 25 | import android.view.MotionEvent; |
Daniel Sandler | 3b0543a | 2011-06-14 11:30:28 -0400 | [diff] [blame] | 26 | import android.view.View; |
| 27 | import android.widget.FrameLayout; |
| 28 | import android.widget.ImageView; |
| 29 | import android.widget.RadioButton; |
| 30 | import android.widget.RadioGroup; |
| 31 | |
| 32 | import com.android.systemui.R; |
| 33 | |
| 34 | public 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 Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 94 | @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 Sandler | 3b0543a | 2011-06-14 11:30:28 -0400 | [diff] [blame] | 107 | 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 Hackborn | ed31bbf | 2011-06-15 11:16:06 -0700 | [diff] [blame] | 124 | 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 Sandler | 3b0543a | 2011-06-14 11:30:28 -0400 | [diff] [blame] | 130 | final boolean on = (mode == ActivityManager.COMPAT_MODE_ENABLED); |
| 131 | mOnButton.setChecked(on); |
| 132 | mOffButton.setChecked(!on); |
| 133 | } |
Daniel Sandler | 3b0543a | 2011-06-14 11:30:28 -0400 | [diff] [blame] | 134 | } |