Home | History | Annotate | Download | only in phone
      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 
     17 package com.android.systemui.statusbar.phone;
     18 
     19 import android.content.Context;
     20 import android.content.res.Resources;
     21 import android.graphics.Canvas;
     22 import android.graphics.drawable.Drawable;
     23 import android.util.AttributeSet;
     24 import android.util.EventLog;
     25 import android.view.MotionEvent;
     26 import android.view.View;
     27 import android.view.accessibility.AccessibilityEvent;
     28 
     29 import com.android.systemui.EventLogTags;
     30 import com.android.systemui.R;
     31 import com.android.systemui.statusbar.GestureRecorder;
     32 
     33 public class NotificationPanelView extends PanelView {
     34     public static final boolean DEBUG_GESTURES = true;
     35 
     36     Drawable mHandleBar;
     37     int mHandleBarHeight;
     38     View mHandleView;
     39     int mFingers;
     40     PhoneStatusBar mStatusBar;
     41     boolean mOkToFlip;
     42 
     43     public NotificationPanelView(Context context, AttributeSet attrs) {
     44         super(context, attrs);
     45     }
     46 
     47     public void setStatusBar(PhoneStatusBar bar) {
     48         mStatusBar = bar;
     49     }
     50 
     51     @Override
     52     protected void onFinishInflate() {
     53         super.onFinishInflate();
     54 
     55         Resources resources = getContext().getResources();
     56         mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
     57         mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height);
     58         mHandleView = findViewById(R.id.handle);
     59     }
     60 
     61     @Override
     62     public void fling(float vel, boolean always) {
     63         GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
     64         if (gr != null) {
     65             gr.tag(
     66                 "fling " + ((vel > 0) ? "open" : "closed"),
     67                 "notifications,v=" + vel);
     68         }
     69         super.fling(vel, always);
     70     }
     71 
     72     @Override
     73     public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
     74         if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
     75             event.getText()
     76                     .add(getContext().getString(R.string.accessibility_desc_notification_shade));
     77             return true;
     78         }
     79 
     80         return super.dispatchPopulateAccessibilityEvent(event);
     81     }
     82 
     83     // We draw the handle ourselves so that it's always glued to the bottom of the window.
     84     @Override
     85     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
     86         super.onLayout(changed, left, top, right, bottom);
     87         if (changed) {
     88             final int pl = getPaddingLeft();
     89             final int pr = getPaddingRight();
     90             mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
     91         }
     92     }
     93 
     94     @Override
     95     public void draw(Canvas canvas) {
     96         super.draw(canvas);
     97         final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
     98         canvas.translate(0, off);
     99         mHandleBar.setState(mHandleView.getDrawableState());
    100         mHandleBar.draw(canvas);
    101         canvas.translate(0, -off);
    102     }
    103 
    104     @Override
    105     public boolean onTouchEvent(MotionEvent event) {
    106         if (DEBUG_GESTURES) {
    107             if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
    108                 EventLog.writeEvent(EventLogTags.SYSUI_NOTIFICATIONPANEL_TOUCH,
    109                        event.getActionMasked(), (int) event.getX(), (int) event.getY());
    110             }
    111         }
    112         if (PhoneStatusBar.SETTINGS_DRAG_SHORTCUT && mStatusBar.mHasFlipSettings) {
    113             switch (event.getActionMasked()) {
    114                 case MotionEvent.ACTION_DOWN:
    115                     mOkToFlip = getExpandedHeight() == 0;
    116                     break;
    117                 case MotionEvent.ACTION_POINTER_DOWN:
    118                     if (mOkToFlip) {
    119                         float miny = event.getY(0);
    120                         float maxy = miny;
    121                         for (int i=1; i<event.getPointerCount(); i++) {
    122                             final float y = event.getY(i);
    123                             if (y < miny) miny = y;
    124                             if (y > maxy) maxy = y;
    125                         }
    126                         if (maxy - miny < mHandleBarHeight) {
    127                             if (getMeasuredHeight() < mHandleBarHeight) {
    128                                 mStatusBar.switchToSettings();
    129                             } else {
    130                                 mStatusBar.flipToSettings();
    131                             }
    132                             mOkToFlip = false;
    133                         }
    134                     }
    135                     break;
    136             }
    137         }
    138         return mHandleView.dispatchTouchEvent(event);
    139     }
    140 }
    141