SettingsPanelView.java revision 6196cfdb528d662741c68126062dd34d78641a5b
1/* 2 * Copyright (C) 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 17package com.android.systemui.statusbar.phone; 18 19import android.animation.LayoutTransition; 20import android.content.Context; 21import android.content.Intent; 22import android.content.res.Resources; 23import android.graphics.Canvas; 24import android.graphics.drawable.Drawable; 25import android.util.AttributeSet; 26import android.util.EventLog; 27import android.view.LayoutInflater; 28import android.view.MotionEvent; 29import android.view.View; 30import android.view.ViewGroup; 31import android.view.accessibility.AccessibilityEvent; 32 33import com.android.systemui.EventLogTags; 34import com.android.systemui.R; 35import com.android.systemui.statusbar.BaseStatusBar; 36import com.android.systemui.statusbar.GestureRecorder; 37import com.android.systemui.statusbar.policy.BatteryController; 38import com.android.systemui.statusbar.policy.BluetoothController; 39import com.android.systemui.statusbar.policy.LocationController; 40import com.android.systemui.statusbar.policy.NetworkController; 41import com.android.systemui.statusbar.policy.RotationLockController; 42 43public class SettingsPanelView extends PanelView { 44 public static final boolean DEBUG_GESTURES = true; 45 46 private QuickSettings mQS; 47 private QuickSettingsContainerView mQSContainer; 48 49 Drawable mHandleBar; 50 int mHandleBarHeight; 51 View mHandleView; 52 53 public SettingsPanelView(Context context, AttributeSet attrs) { 54 super(context, attrs); 55 } 56 57 @Override 58 protected void onFinishInflate() { 59 super.onFinishInflate(); 60 61 mQSContainer = (QuickSettingsContainerView) findViewById(R.id.quick_settings_container); 62 63 Resources resources = getContext().getResources(); 64 mHandleBar = resources.getDrawable(R.drawable.status_bar_close); 65 mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height); 66 mHandleView = findViewById(R.id.handle); 67 } 68 69 public void setQuickSettings(QuickSettings qs) { 70 mQS = qs; 71 } 72 73 @Override 74 public void setBar(PanelBar panelBar) { 75 super.setBar(panelBar); 76 77 if (mQS != null) { 78 mQS.setBar(panelBar); 79 } 80 } 81 82 public void setImeWindowStatus(boolean visible) { 83 if (mQS != null) { 84 mQS.setImeWindowStatus(visible); 85 } 86 } 87 88 public void setup(NetworkController networkController, BluetoothController bluetoothController, 89 BatteryController batteryController, LocationController locationController, 90 RotationLockController rotationLockController) { 91 if (mQS != null) { 92 mQS.setup(networkController, bluetoothController, batteryController, 93 locationController, rotationLockController); 94 } 95 } 96 97 void updateResources() { 98 if (mQS != null) { 99 mQS.updateResources(); 100 } 101 if (mQSContainer != null) { 102 mQSContainer.updateResources(); 103 } 104 requestLayout(); 105 } 106 107 @Override 108 public void fling(float vel, boolean always) { 109 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder(); 110 if (gr != null) { 111 gr.tag( 112 "fling " + ((vel > 0) ? "open" : "closed"), 113 "settings,v=" + vel); 114 } 115 super.fling(vel, always); 116 } 117 118 public void setService(PhoneStatusBar phoneStatusBar) { 119 if (mQS != null) { 120 mQS.setService(phoneStatusBar); 121 } 122 } 123 124 @Override 125 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { 126 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { 127 event.getText() 128 .add(getContext().getString(R.string.accessibility_desc_quick_settings)); 129 return true; 130 } 131 132 return super.dispatchPopulateAccessibilityEvent(event); 133 } 134 135 // We draw the handle ourselves so that it's always glued to the bottom of the window. 136 @Override 137 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 138 super.onLayout(changed, left, top, right, bottom); 139 if (changed) { 140 final int pl = getPaddingLeft(); 141 final int pr = getPaddingRight(); 142 mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight); 143 } 144 } 145 146 @Override 147 public void draw(Canvas canvas) { 148 super.draw(canvas); 149 final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom()); 150 canvas.translate(0, off); 151 mHandleBar.setState(mHandleView.getDrawableState()); 152 mHandleBar.draw(canvas); 153 canvas.translate(0, -off); 154 } 155 156 @Override 157 public boolean onTouchEvent(MotionEvent event) { 158 if (DEBUG_GESTURES) { 159 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) { 160 EventLog.writeEvent(EventLogTags.SYSUI_QUICKPANEL_TOUCH, 161 event.getActionMasked(), (int) event.getX(), (int) event.getY()); 162 } 163 } 164 return super.onTouchEvent(event); 165 } 166} 167