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 17 package com.android.systemui.statusbar.phone; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 import android.graphics.Canvas; 22 import android.graphics.drawable.Drawable; 23 import android.util.AttributeSet; 24 import android.util.EventLog; 25 import android.util.Slog; 26 import android.view.MotionEvent; 27 import android.view.View; 28 import android.view.accessibility.AccessibilityEvent; 29 30 import com.android.systemui.EventLogTags; 31 import com.android.systemui.R; 32 import com.android.systemui.statusbar.GestureRecorder; 33 34 public class NotificationPanelView extends PanelView { 35 public static final boolean DEBUG_GESTURES = true; 36 37 Drawable mHandleBar; 38 int mHandleBarHeight; 39 View mHandleView; 40 int mFingers; 41 PhoneStatusBar mStatusBar; 42 boolean mOkToFlip; 43 44 public NotificationPanelView(Context context, AttributeSet attrs) { 45 super(context, attrs); 46 } 47 48 public void setStatusBar(PhoneStatusBar bar) { 49 mStatusBar = bar; 50 } 51 52 @Override 53 protected void onFinishInflate() { 54 super.onFinishInflate(); 55 56 Resources resources = getContext().getResources(); 57 mHandleBar = resources.getDrawable(R.drawable.status_bar_close); 58 mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height); 59 mHandleView = findViewById(R.id.handle); 60 } 61 62 @Override 63 public void fling(float vel, boolean always) { 64 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder(); 65 if (gr != null) { 66 gr.tag( 67 "fling " + ((vel > 0) ? "open" : "closed"), 68 "notifications,v=" + vel); 69 } 70 super.fling(vel, always); 71 } 72 73 @Override 74 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { 75 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { 76 event.getText() 77 .add(getContext().getString(R.string.accessibility_desc_notification_shade)); 78 return true; 79 } 80 81 return super.dispatchPopulateAccessibilityEvent(event); 82 } 83 84 // We draw the handle ourselves so that it's always glued to the bottom of the window. 85 @Override 86 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 87 super.onLayout(changed, left, top, right, bottom); 88 if (changed) { 89 final int pl = getPaddingLeft(); 90 final int pr = getPaddingRight(); 91 mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight); 92 } 93 } 94 95 @Override 96 public void draw(Canvas canvas) { 97 super.draw(canvas); 98 final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom()); 99 canvas.translate(0, off); 100 mHandleBar.setState(mHandleView.getDrawableState()); 101 mHandleBar.draw(canvas); 102 canvas.translate(0, -off); 103 } 104 105 @Override 106 public boolean onTouchEvent(MotionEvent event) { 107 if (DEBUG_GESTURES) { 108 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) { 109 EventLog.writeEvent(EventLogTags.SYSUI_NOTIFICATIONPANEL_TOUCH, 110 event.getActionMasked(), (int) event.getX(), (int) event.getY()); 111 } 112 } 113 if (PhoneStatusBar.SETTINGS_DRAG_SHORTCUT && mStatusBar.mHasFlipSettings) { 114 switch (event.getActionMasked()) { 115 case MotionEvent.ACTION_DOWN: 116 mOkToFlip = getExpandedHeight() == 0; 117 break; 118 case MotionEvent.ACTION_POINTER_DOWN: 119 if (mOkToFlip) { 120 float miny = event.getY(0); 121 float maxy = miny; 122 for (int i=1; i<event.getPointerCount(); i++) { 123 final float y = event.getY(i); 124 if (y < miny) miny = y; 125 if (y > maxy) maxy = y; 126 } 127 if (maxy - miny < mHandleBarHeight) { 128 if (getMeasuredHeight() < mHandleBarHeight) { 129 mStatusBar.switchToSettings(); 130 } else { 131 mStatusBar.flipToSettings(); 132 } 133 mOkToFlip = false; 134 } 135 } 136 break; 137 } 138 } 139 return mHandleView.dispatchTouchEvent(event); 140 } 141 } 142