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