blob: a857eba9c064b09e8fc233602466477f1cdc8f1a [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;
Daniel Sandler040c2e42012-10-17 00:56:33 -040024import android.util.Slog;
25import android.view.MotionEvent;
Daniel Sandler13522a22012-09-27 14:46:58 -040026import android.view.View;
27
Chet Haase4d179dc2012-08-22 07:14:42 -070028import com.android.systemui.R;
Daniel Sandler151f00d2012-10-02 22:33:08 -040029import com.android.systemui.statusbar.GestureRecorder;
Daniel Sandler08d05e32012-08-08 16:39:54 -040030
31public class NotificationPanelView extends PanelView {
Chet Haase4d179dc2012-08-22 07:14:42 -070032
33 Drawable mHandleBar;
34 float mHandleBarHeight;
Daniel Sandler13522a22012-09-27 14:46:58 -040035 View mHandleView;
Daniel Sandler040c2e42012-10-17 00:56:33 -040036 int mFingers;
37 PhoneStatusBar mStatusBar;
38 private boolean mFlipped;
Chet Haase4d179dc2012-08-22 07:14:42 -070039
Daniel Sandler08d05e32012-08-08 16:39:54 -040040 public NotificationPanelView(Context context, AttributeSet attrs) {
41 super(context, attrs);
Daniel Sandler13522a22012-09-27 14:46:58 -040042 }
Chet Haase4d179dc2012-08-22 07:14:42 -070043
Daniel Sandler040c2e42012-10-17 00:56:33 -040044 public void setStatusBar(PhoneStatusBar bar) {
45 mStatusBar = bar;
46 }
47
Daniel Sandler13522a22012-09-27 14:46:58 -040048 @Override
49 protected void onFinishInflate() {
50 super.onFinishInflate();
51
52 Resources resources = getContext().getResources();
Chet Haase4d179dc2012-08-22 07:14:42 -070053 mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
54 mHandleBarHeight = resources.getDimension(R.dimen.close_handle_height);
Daniel Sandler13522a22012-09-27 14:46:58 -040055 mHandleView = findViewById(R.id.handle);
Casey Burkhardtbac221f2012-10-03 18:13:58 -070056
57 setContentDescription(resources.getString(R.string.accessibility_desc_notification_shade));
Daniel Sandler08d05e32012-08-08 16:39:54 -040058 }
59
Daniel Sandler08d05e32012-08-08 16:39:54 -040060 @Override
61 public void fling(float vel, boolean always) {
Daniel Sandler151f00d2012-10-02 22:33:08 -040062 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
63 if (gr != null) {
64 gr.tag(
65 "fling " + ((vel > 0) ? "open" : "closed"),
66 "notifications,v=" + vel);
67 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040068 super.fling(vel, always);
69 }
Chet Haase4d179dc2012-08-22 07:14:42 -070070
Daniel Sandler13522a22012-09-27 14:46:58 -040071 // We draw the handle ourselves so that it's always glued to the bottom of the window.
Chet Haase4d179dc2012-08-22 07:14:42 -070072 @Override
73 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
74 super.onLayout(changed, left, top, right, bottom);
75 if (changed) {
Daniel Sandler13522a22012-09-27 14:46:58 -040076 final int pl = getPaddingLeft();
77 final int pr = getPaddingRight();
78 mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
Chet Haase4d179dc2012-08-22 07:14:42 -070079 }
80 }
81
82 @Override
83 public void draw(Canvas canvas) {
84 super.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040085 final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
86 canvas.translate(0, off);
87 mHandleBar.setState(mHandleView.getDrawableState());
Chet Haase4d179dc2012-08-22 07:14:42 -070088 mHandleBar.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040089 canvas.translate(0, -off);
Chet Haase4d179dc2012-08-22 07:14:42 -070090 }
Daniel Sandler040c2e42012-10-17 00:56:33 -040091
92 @Override
93 public boolean onTouchEvent(MotionEvent event) {
94 if (PhoneStatusBar.SETTINGS_DRAG_SHORTCUT && mStatusBar.mHasFlipSettings) {
95 switch (event.getActionMasked()) {
96 case MotionEvent.ACTION_DOWN:
97 mFlipped = false;
98 break;
99 case MotionEvent.ACTION_POINTER_DOWN:
100 if (!mFlipped) {
101 float miny = event.getY(0);
102 float maxy = miny;
103 for (int i=1; i<event.getPointerCount(); i++) {
104 final float y = event.getY(i);
105 if (y < miny) miny = y;
106 if (y > maxy) maxy = y;
107 }
108 if (maxy - miny < mHandleBarHeight) {
109 if (getMeasuredHeight() < mHandleBarHeight) {
110 mStatusBar.switchToSettings();
111 } else {
112 mStatusBar.flipToSettings();
113 }
114 mFlipped = true;
115 }
116 }
117 break;
118 }
119 }
120 return mHandleView.dispatchTouchEvent(event);
121 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400122}