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.util.AttributeSet;
     21 import android.util.EventLog;
     22 import android.view.MotionEvent;
     23 import android.view.View;
     24 import android.view.ViewGroup;
     25 import android.view.accessibility.AccessibilityEvent;
     26 
     27 import com.android.systemui.DejankUtils;
     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 = false;
     35 
     36     PhoneStatusBar mBar;
     37 
     38     boolean mIsFullyOpenedPanel = false;
     39     private final PhoneStatusBarTransitions mBarTransitions;
     40     private ScrimController mScrimController;
     41     private float mMinFraction;
     42     private float mPanelFraction;
     43     private Runnable mHideExpandedRunnable = new Runnable() {
     44         @Override
     45         public void run() {
     46             if (mPanelFraction == 0.0f) {
     47                 mBar.makeExpandedInvisible();
     48             }
     49         }
     50     };
     51 
     52     public PhoneStatusBarView(Context context, AttributeSet attrs) {
     53         super(context, attrs);
     54 
     55         mBarTransitions = new PhoneStatusBarTransitions(this);
     56     }
     57 
     58     public BarTransitions getBarTransitions() {
     59         return mBarTransitions;
     60     }
     61 
     62     public void setBar(PhoneStatusBar bar) {
     63         mBar = bar;
     64     }
     65 
     66     public void setScrimController(ScrimController scrimController) {
     67         mScrimController = scrimController;
     68     }
     69 
     70     @Override
     71     public void onFinishInflate() {
     72         mBarTransitions.init();
     73     }
     74 
     75     @Override
     76     public boolean panelEnabled() {
     77         return mBar.panelsEnabled();
     78     }
     79 
     80     @Override
     81     public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
     82         if (super.onRequestSendAccessibilityEventInternal(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 void onPanelPeeked() {
     97         super.onPanelPeeked();
     98         mBar.makeExpandedVisible(false);
     99     }
    100 
    101     @Override
    102     public void onPanelCollapsed() {
    103         super.onPanelCollapsed();
    104         // Close the status bar in the next frame so we can show the end of the animation.
    105         DejankUtils.postAfterTraversal(mHideExpandedRunnable);
    106         mIsFullyOpenedPanel = false;
    107     }
    108 
    109     public void removePendingHideExpandedRunnables() {
    110         DejankUtils.removeCallbacks(mHideExpandedRunnable);
    111     }
    112 
    113     @Override
    114     public void onPanelFullyOpened() {
    115         super.onPanelFullyOpened();
    116         if (!mIsFullyOpenedPanel) {
    117             mPanel.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    118         }
    119         mIsFullyOpenedPanel = true;
    120     }
    121 
    122     @Override
    123     public boolean onTouchEvent(MotionEvent event) {
    124         boolean barConsumedEvent = mBar.interceptTouchEvent(event);
    125 
    126         if (DEBUG_GESTURES) {
    127             if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
    128                 EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH,
    129                         event.getActionMasked(), (int) event.getX(), (int) event.getY(),
    130                         barConsumedEvent ? 1 : 0);
    131             }
    132         }
    133 
    134         return barConsumedEvent || super.onTouchEvent(event);
    135     }
    136 
    137     @Override
    138     public void onTrackingStarted() {
    139         super.onTrackingStarted();
    140         mBar.onTrackingStarted();
    141         mScrimController.onTrackingStarted();
    142         removePendingHideExpandedRunnables();
    143     }
    144 
    145     @Override
    146     public void onClosingFinished() {
    147         super.onClosingFinished();
    148         mBar.onClosingFinished();
    149     }
    150 
    151     @Override
    152     public void onTrackingStopped(boolean expand) {
    153         super.onTrackingStopped(expand);
    154         mBar.onTrackingStopped(expand);
    155     }
    156 
    157     @Override
    158     public void onExpandingFinished() {
    159         super.onExpandingFinished();
    160         mScrimController.onExpandingFinished();
    161     }
    162 
    163     @Override
    164     public boolean onInterceptTouchEvent(MotionEvent event) {
    165         return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event);
    166     }
    167 
    168     @Override
    169     public void panelScrimMinFractionChanged(float minFraction) {
    170         if (mMinFraction != minFraction) {
    171             mMinFraction = minFraction;
    172             if (minFraction != 0.0f) {
    173                 mScrimController.animateNextChange();
    174             }
    175             updateScrimFraction();
    176         }
    177     }
    178 
    179     @Override
    180     public void panelExpansionChanged(float frac, boolean expanded) {
    181         super.panelExpansionChanged(frac, expanded);
    182         mPanelFraction = frac;
    183         updateScrimFraction();
    184     }
    185 
    186     private void updateScrimFraction() {
    187         float scrimFraction = Math.max(mPanelFraction, mMinFraction);
    188         mScrimController.setPanelExpansion(scrimFraction);
    189     }
    190 
    191     public void onDensityOrFontScaleChanged() {
    192         ViewGroup.LayoutParams layoutParams = getLayoutParams();
    193         layoutParams.height = getResources().getDimensionPixelSize(
    194                 R.dimen.status_bar_height);
    195         setLayoutParams(layoutParams);
    196     }
    197 }
    198