blob: ff364853bead5964853be3cc905eaed2805761b2 [file] [log] [blame]
Daniel Sandler08d05e32012-08-08 16:39:54 -04001/*
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;
Chet Haase4d179dc2012-08-22 07:14:42 -070020import android.content.res.Resources;
21import android.graphics.Canvas;
22import android.graphics.drawable.Drawable;
Daniel Sandler08d05e32012-08-08 16:39:54 -040023import android.util.AttributeSet;
Chris Wren64161cc2012-12-17 16:49:30 -050024import android.util.EventLog;
Daniel Sandler040c2e42012-10-17 00:56:33 -040025import android.util.Slog;
26import android.view.MotionEvent;
Daniel Sandler13522a22012-09-27 14:46:58 -040027import android.view.View;
28
Chris Wren64161cc2012-12-17 16:49:30 -050029import com.android.systemui.EventLogTags;
Chet Haase4d179dc2012-08-22 07:14:42 -070030import com.android.systemui.R;
Daniel Sandler151f00d2012-10-02 22:33:08 -040031import com.android.systemui.statusbar.GestureRecorder;
Daniel Sandler08d05e32012-08-08 16:39:54 -040032
33public class NotificationPanelView extends PanelView {
Chris Wren64161cc2012-12-17 16:49:30 -050034 public static final boolean DEBUG_GESTURES = true;
Chet Haase4d179dc2012-08-22 07:14:42 -070035
36 Drawable mHandleBar;
Daniel Sandler076324ae2012-11-30 16:14:21 -050037 int mHandleBarHeight;
Daniel Sandler13522a22012-09-27 14:46:58 -040038 View mHandleView;
Daniel Sandler040c2e42012-10-17 00:56:33 -040039 int mFingers;
40 PhoneStatusBar mStatusBar;
Daniel Sandler2017a052012-10-17 15:39:28 -040041 boolean mOkToFlip;
Chet Haase4d179dc2012-08-22 07:14:42 -070042
Daniel Sandler08d05e32012-08-08 16:39:54 -040043 public NotificationPanelView(Context context, AttributeSet attrs) {
44 super(context, attrs);
Daniel Sandler13522a22012-09-27 14:46:58 -040045 }
Chet Haase4d179dc2012-08-22 07:14:42 -070046
Daniel Sandler040c2e42012-10-17 00:56:33 -040047 public void setStatusBar(PhoneStatusBar bar) {
48 mStatusBar = bar;
49 }
50
Daniel Sandler13522a22012-09-27 14:46:58 -040051 @Override
52 protected void onFinishInflate() {
53 super.onFinishInflate();
54
55 Resources resources = getContext().getResources();
Chet Haase4d179dc2012-08-22 07:14:42 -070056 mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
Daniel Sandler076324ae2012-11-30 16:14:21 -050057 mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height);
Daniel Sandler13522a22012-09-27 14:46:58 -040058 mHandleView = findViewById(R.id.handle);
Casey Burkhardtbac221f2012-10-03 18:13:58 -070059
60 setContentDescription(resources.getString(R.string.accessibility_desc_notification_shade));
Daniel Sandler08d05e32012-08-08 16:39:54 -040061 }
62
Daniel Sandler08d05e32012-08-08 16:39:54 -040063 @Override
64 public void fling(float vel, boolean always) {
Daniel Sandler151f00d2012-10-02 22:33:08 -040065 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 Sandler08d05e32012-08-08 16:39:54 -040071 super.fling(vel, always);
72 }
Chet Haase4d179dc2012-08-22 07:14:42 -070073
Daniel Sandler13522a22012-09-27 14:46:58 -040074 // We draw the handle ourselves so that it's always glued to the bottom of the window.
Chet Haase4d179dc2012-08-22 07:14:42 -070075 @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 Sandler13522a22012-09-27 14:46:58 -040079 final int pl = getPaddingLeft();
80 final int pr = getPaddingRight();
81 mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
Chet Haase4d179dc2012-08-22 07:14:42 -070082 }
83 }
84
85 @Override
86 public void draw(Canvas canvas) {
87 super.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040088 final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
89 canvas.translate(0, off);
90 mHandleBar.setState(mHandleView.getDrawableState());
Chet Haase4d179dc2012-08-22 07:14:42 -070091 mHandleBar.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040092 canvas.translate(0, -off);
Chet Haase4d179dc2012-08-22 07:14:42 -070093 }
Daniel Sandler040c2e42012-10-17 00:56:33 -040094
95 @Override
96 public boolean onTouchEvent(MotionEvent event) {
Chris Wren64161cc2012-12-17 16:49:30 -050097 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 Sandler040c2e42012-10-17 00:56:33 -0400103 if (PhoneStatusBar.SETTINGS_DRAG_SHORTCUT && mStatusBar.mHasFlipSettings) {
104 switch (event.getActionMasked()) {
105 case MotionEvent.ACTION_DOWN:
Daniel Sandler2017a052012-10-17 15:39:28 -0400106 mOkToFlip = getExpandedHeight() == 0;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400107 break;
108 case MotionEvent.ACTION_POINTER_DOWN:
Daniel Sandler2017a052012-10-17 15:39:28 -0400109 if (mOkToFlip) {
Daniel Sandler040c2e42012-10-17 00:56:33 -0400110 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 Sandler2017a052012-10-17 15:39:28 -0400123 mOkToFlip = false;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400124 }
125 }
126 break;
127 }
128 }
129 return mHandleView.dispatchTouchEvent(event);
130 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400131}