Home | History | Annotate | Download | only in phone
      1 /*
      2  * Copyright (C) 2008 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.util.AttributeSet;
     22 import android.util.EventLog;
     23 import android.util.Log;
     24 import android.view.MotionEvent;
     25 import android.view.View;
     26 import android.view.accessibility.AccessibilityEvent;
     27 
     28 import com.android.systemui.EventLogTags;
     29 import com.android.systemui.R;
     30 
     31 public class PhoneStatusBarView extends PanelBar {
     32     private static final String TAG = "PhoneStatusBarView";
     33     private static final boolean DEBUG = PhoneStatusBar.DEBUG;
     34     private static final boolean DEBUG_GESTURES = true;
     35 
     36     PhoneStatusBar mBar;
     37 
     38     PanelView mLastFullyOpenedPanel = null;
     39     PanelView mNotificationPanel;
     40     private final PhoneStatusBarTransitions mBarTransitions;
     41     private ScrimController mScrimController;
     42 
     43     public PhoneStatusBarView(Context context, AttributeSet attrs) {
     44         super(context, attrs);
     45 
     46         Resources res = getContext().getResources();
     47         mBarTransitions = new PhoneStatusBarTransitions(this);
     48     }
     49 
     50     public BarTransitions getBarTransitions() {
     51         return mBarTransitions;
     52     }
     53 
     54     public void setBar(PhoneStatusBar bar) {
     55         mBar = bar;
     56     }
     57 
     58     public void setScrimController(ScrimController scrimController) {
     59         mScrimController = scrimController;
     60     }
     61 
     62     @Override
     63     public void onFinishInflate() {
     64         mBarTransitions.init();
     65     }
     66 
     67     @Override
     68     public void addPanel(PanelView pv) {
     69         super.addPanel(pv);
     70         if (pv.getId() == R.id.notification_panel) {
     71             mNotificationPanel = pv;
     72         }
     73     }
     74 
     75     @Override
     76     public boolean panelsEnabled() {
     77         return mBar.panelsEnabled();
     78     }
     79 
     80     @Override
     81     public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
     82         if (super.onRequestSendAccessibilityEvent(child, event)) {
     83             // The status bar is very small so augment the view that the user is touching
     84             // with the content of the status bar a whole. This way an accessibility service
     85             // may announce the current item as well as the entire content if appropriate.
     86             AccessibilityEvent record = AccessibilityEvent.obtain();
     87             onInitializeAccessibilityEvent(record);
     88             dispatchPopulateAccessibilityEvent(record);
     89             event.appendRecord(record);
     90             return true;
     91         }
     92         return false;
     93     }
     94 
     95     @Override
     96     public PanelView selectPanelForTouch(MotionEvent touch) {
     97         // No double swiping. If either panel is open, nothing else can be pulled down.
     98         return mNotificationPanel.getExpandedHeight() > 0
     99                 ? null
    100                 : mNotificationPanel;
    101     }
    102 
    103     @Override
    104     public void onPanelPeeked() {
    105         super.onPanelPeeked();
    106         mBar.makeExpandedVisible(false);
    107     }
    108 
    109     @Override
    110     public void onAllPanelsCollapsed() {
    111         super.onAllPanelsCollapsed();
    112 
    113         // Close the status bar in the next frame so we can show the end of the animation.
    114         postOnAnimation(new Runnable() {
    115             @Override
    116             public void run() {
    117                 mBar.makeExpandedInvisible();
    118             }
    119         });
    120         mLastFullyOpenedPanel = null;
    121     }
    122 
    123     @Override
    124     public void onPanelFullyOpened(PanelView openPanel) {
    125         super.onPanelFullyOpened(openPanel);
    126         if (openPanel != mLastFullyOpenedPanel) {
    127             openPanel.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    128         }
    129         mLastFullyOpenedPanel = openPanel;
    130     }
    131 
    132     @Override
    133     public boolean onTouchEvent(MotionEvent event) {
    134         boolean barConsumedEvent = mBar.interceptTouchEvent(event);
    135 
    136         if (DEBUG_GESTURES) {
    137             if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
    138                 EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH,
    139                         event.getActionMasked(), (int) event.getX(), (int) event.getY(),
    140                         barConsumedEvent ? 1 : 0);
    141             }
    142         }
    143 
    144         return barConsumedEvent || super.onTouchEvent(event);
    145     }
    146 
    147     @Override
    148     public void onTrackingStarted(PanelView panel) {
    149         super.onTrackingStarted(panel);
    150         mBar.onTrackingStarted();
    151         mScrimController.onTrackingStarted();
    152     }
    153 
    154     @Override
    155     public void onTrackingStopped(PanelView panel, boolean expand) {
    156         super.onTrackingStopped(panel, expand);
    157         mBar.onTrackingStopped(expand);
    158     }
    159 
    160     @Override
    161     public void onExpandingFinished() {
    162         super.onExpandingFinished();
    163         mScrimController.onExpandingFinished();
    164     }
    165 
    166     @Override
    167     public boolean onInterceptTouchEvent(MotionEvent event) {
    168         return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event);
    169     }
    170 
    171     @Override
    172     public void panelExpansionChanged(PanelView panel, float frac, boolean expanded) {
    173         super.panelExpansionChanged(panel, frac, expanded);
    174         mScrimController.setPanelExpansion(frac);
    175         mBar.updateCarrierLabelVisibility(false);
    176     }
    177 }
    178