NotificationPanelView.java revision 151f00d8f06e207038125f227b42f06a25d5e0a0
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
17package com.android.systemui.statusbar.phone;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.graphics.Canvas;
22import android.graphics.drawable.Drawable;
23import android.util.AttributeSet;
24import android.view.View;
25
26import com.android.systemui.R;
27import com.android.systemui.statusbar.GestureRecorder;
28
29public class NotificationPanelView extends PanelView {
30
31    Drawable mHandleBar;
32    float mHandleBarHeight;
33    View mHandleView;
34
35    public NotificationPanelView(Context context, AttributeSet attrs) {
36        super(context, attrs);
37    }
38
39    @Override
40    protected void onFinishInflate() {
41        super.onFinishInflate();
42
43        Resources resources = getContext().getResources();
44        mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
45        mHandleBarHeight = resources.getDimension(R.dimen.close_handle_height);
46        mHandleView = findViewById(R.id.handle);
47    }
48
49    @Override
50    public void fling(float vel, boolean always) {
51        GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
52        if (gr != null) {
53            gr.tag(
54                "fling " + ((vel > 0) ? "open" : "closed"),
55                "notifications,v=" + vel);
56        }
57        super.fling(vel, always);
58    }
59
60    // We draw the handle ourselves so that it's always glued to the bottom of the window.
61    @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) {
65            final int pl = getPaddingLeft();
66            final int pr = getPaddingRight();
67            mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
68        }
69    }
70
71    @Override
72    public void draw(Canvas canvas) {
73        super.draw(canvas);
74        final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
75        canvas.translate(0, off);
76        mHandleBar.setState(mHandleView.getDrawableState());
77        mHandleBar.draw(canvas);
78        canvas.translate(0, -off);
79    }
80}
81