blob: c9ec481b53ec41b964dc32c4814fdfb6affa7999 [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 Sandler13522a22012-09-27 14:46:58 -040024import android.view.View;
25
Chet Haase4d179dc2012-08-22 07:14:42 -070026import com.android.systemui.R;
Daniel Sandler08d05e32012-08-08 16:39:54 -040027
28public class NotificationPanelView extends PanelView {
Chet Haase4d179dc2012-08-22 07:14:42 -070029
30 Drawable mHandleBar;
31 float mHandleBarHeight;
Daniel Sandler13522a22012-09-27 14:46:58 -040032 View mHandleView;
Chet Haase4d179dc2012-08-22 07:14:42 -070033
Daniel Sandler08d05e32012-08-08 16:39:54 -040034 public NotificationPanelView(Context context, AttributeSet attrs) {
35 super(context, attrs);
Daniel Sandler13522a22012-09-27 14:46:58 -040036 }
Chet Haase4d179dc2012-08-22 07:14:42 -070037
Daniel Sandler13522a22012-09-27 14:46:58 -040038 @Override
39 protected void onFinishInflate() {
40 super.onFinishInflate();
41
42 Resources resources = getContext().getResources();
Chet Haase4d179dc2012-08-22 07:14:42 -070043 mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
44 mHandleBarHeight = resources.getDimension(R.dimen.close_handle_height);
Daniel Sandler13522a22012-09-27 14:46:58 -040045 mHandleView = findViewById(R.id.handle);
Daniel Sandler08d05e32012-08-08 16:39:54 -040046 }
47
Daniel Sandler08d05e32012-08-08 16:39:54 -040048 @Override
49 public void fling(float vel, boolean always) {
50 ((PhoneStatusBarView) mBar).mBar.getGestureRecorder().tag(
51 "fling " + ((vel > 0) ? "open" : "closed"),
Daniel Sandlercf591db2012-08-15 16:11:55 -040052 "notifications,v=" + vel);
Daniel Sandler08d05e32012-08-08 16:39:54 -040053 super.fling(vel, always);
54 }
Chet Haase4d179dc2012-08-22 07:14:42 -070055
Daniel Sandler13522a22012-09-27 14:46:58 -040056 // We draw the handle ourselves so that it's always glued to the bottom of the window.
Chet Haase4d179dc2012-08-22 07:14:42 -070057 @Override
58 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
59 super.onLayout(changed, left, top, right, bottom);
60 if (changed) {
Daniel Sandler13522a22012-09-27 14:46:58 -040061 final int pl = getPaddingLeft();
62 final int pr = getPaddingRight();
63 mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
Chet Haase4d179dc2012-08-22 07:14:42 -070064 }
65 }
66
67 @Override
68 public void draw(Canvas canvas) {
69 super.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040070 final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
71 canvas.translate(0, off);
72 mHandleBar.setState(mHandleView.getDrawableState());
Chet Haase4d179dc2012-08-22 07:14:42 -070073 mHandleBar.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040074 canvas.translate(0, -off);
Chet Haase4d179dc2012-08-22 07:14:42 -070075 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040076}