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