blob: 32b7c68466b6c947b84ccd5f501db9c8eacd3939 [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 Sandler151f00d2012-10-02 22:33:08 -040027import com.android.systemui.statusbar.GestureRecorder;
Daniel Sandler08d05e32012-08-08 16:39:54 -040028
29public class NotificationPanelView extends PanelView {
Chet Haase4d179dc2012-08-22 07:14:42 -070030
31 Drawable mHandleBar;
32 float mHandleBarHeight;
Daniel Sandler13522a22012-09-27 14:46:58 -040033 View mHandleView;
Chet Haase4d179dc2012-08-22 07:14:42 -070034
Daniel Sandler08d05e32012-08-08 16:39:54 -040035 public NotificationPanelView(Context context, AttributeSet attrs) {
36 super(context, attrs);
Daniel Sandler13522a22012-09-27 14:46:58 -040037 }
Chet Haase4d179dc2012-08-22 07:14:42 -070038
Daniel Sandler13522a22012-09-27 14:46:58 -040039 @Override
40 protected void onFinishInflate() {
41 super.onFinishInflate();
42
43 Resources resources = getContext().getResources();
Chet Haase4d179dc2012-08-22 07:14:42 -070044 mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
45 mHandleBarHeight = resources.getDimension(R.dimen.close_handle_height);
Daniel Sandler13522a22012-09-27 14:46:58 -040046 mHandleView = findViewById(R.id.handle);
Daniel Sandler08d05e32012-08-08 16:39:54 -040047 }
48
Daniel Sandler08d05e32012-08-08 16:39:54 -040049 @Override
50 public void fling(float vel, boolean always) {
Daniel Sandler151f00d2012-10-02 22:33:08 -040051 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
52 if (gr != null) {
53 gr.tag(
54 "fling " + ((vel > 0) ? "open" : "closed"),
55 "notifications,v=" + vel);
56 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040057 super.fling(vel, always);
58 }
Chet Haase4d179dc2012-08-22 07:14:42 -070059
Daniel Sandler13522a22012-09-27 14:46:58 -040060 // We draw the handle ourselves so that it's always glued to the bottom of the window.
Chet Haase4d179dc2012-08-22 07:14:42 -070061 @Override
62 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
63 super.onLayout(changed, left, top, right, bottom);
64 if (changed) {
Daniel Sandler13522a22012-09-27 14:46:58 -040065 final int pl = getPaddingLeft();
66 final int pr = getPaddingRight();
67 mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
Chet Haase4d179dc2012-08-22 07:14:42 -070068 }
69 }
70
71 @Override
72 public void draw(Canvas canvas) {
73 super.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040074 final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
75 canvas.translate(0, off);
76 mHandleBar.setState(mHandleView.getDrawableState());
Chet Haase4d179dc2012-08-22 07:14:42 -070077 mHandleBar.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040078 canvas.translate(0, -off);
Chet Haase4d179dc2012-08-22 07:14:42 -070079 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040080}