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 import com.android.systemui.statusbar.policy.BatteryController;
     33 import com.android.systemui.statusbar.policy.BluetoothController;
     34 import com.android.systemui.statusbar.policy.LocationController;
     35 import com.android.systemui.statusbar.policy.NetworkController;
     36 import com.android.systemui.statusbar.policy.RotationLockController;
     37 
     38 public class SettingsPanelView extends PanelView {
     39     public static final boolean DEBUG_GESTURES = true;
     40 
     41     private QuickSettings mQS;
     42     private QuickSettingsContainerView mQSContainer;
     43 
     44     Drawable mHandleBar;
     45     int mHandleBarHeight;
     46     View mHandleView;
     47 
     48     public SettingsPanelView(Context context, AttributeSet attrs) {
     49         super(context, attrs);
     50     }
     51 
     52     @Override
     53     protected void onFinishInflate() {
     54         super.onFinishInflate();
     55 
     56         mQSContainer = (QuickSettingsContainerView) findViewById(R.id.quick_settings_container);
     57 
     58         Resources resources = getContext().getResources();
     59         mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
     60         mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height);
     61         mHandleView = findViewById(R.id.handle);
     62     }
     63 
     64     public void setQuickSettings(QuickSettings qs) {
     65         mQS = qs;
     66     }
     67 
     68     @Override
     69     public void setBar(PanelBar panelBar) {
     70         super.setBar(panelBar);
     71 
     72         if (mQS != null) {
     73             mQS.setBar(panelBar);
     74         }
     75     }
     76 
     77     public void setImeWindowStatus(boolean visible) {
     78         if (mQS != null) {
     79             mQS.setImeWindowStatus(visible);
     80         }
     81     }
     82 
     83     public void setup(NetworkController networkController, BluetoothController bluetoothController,
     84             BatteryController batteryController, LocationController locationController,
     85             RotationLockController rotationLockController) {
     86         if (mQS != null) {
     87             mQS.setup(networkController, bluetoothController, batteryController,
     88                     locationController, rotationLockController);
     89         }
     90     }
     91 
     92     void updateResources() {
     93         if (mQS != null) {
     94             mQS.updateResources();
     95         }
     96         if (mQSContainer != null) {
     97             mQSContainer.updateResources();
     98         }
     99         requestLayout();
    100     }
    101 
    102     @Override
    103     public void fling(float vel, boolean always) {
    104         GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
    105         if (gr != null) {
    106             gr.tag(
    107                 "fling " + ((vel > 0) ? "open" : "closed"),
    108                 "settings,v=" + vel);
    109         }
    110         super.fling(vel, always);
    111     }
    112 
    113     public void setService(PhoneStatusBar phoneStatusBar) {
    114         if (mQS != null) {
    115             mQS.setService(phoneStatusBar);
    116         }
    117     }
    118 
    119     @Override
    120     public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    121         if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
    122             event.getText()
    123                     .add(getContext().getString(R.string.accessibility_desc_quick_settings));
    124             return true;
    125         }
    126 
    127         return super.dispatchPopulateAccessibilityEvent(event);
    128     }
    129 
    130     // We draw the handle ourselves so that it's always glued to the bottom of the window.
    131     @Override
    132     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    133         super.onLayout(changed, left, top, right, bottom);
    134         if (changed) {
    135             final int pl = getPaddingLeft();
    136             final int pr = getPaddingRight();
    137             mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
    138         }
    139     }
    140 
    141     @Override
    142     public void draw(Canvas canvas) {
    143         super.draw(canvas);
    144         final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
    145         canvas.translate(0, off);
    146         mHandleBar.setState(mHandleView.getDrawableState());
    147         mHandleBar.draw(canvas);
    148         canvas.translate(0, -off);
    149     }
    150 
    151     @Override
    152     public boolean onTouchEvent(MotionEvent event) {
    153         if (DEBUG_GESTURES) {
    154             if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
    155                 EventLog.writeEvent(EventLogTags.SYSUI_QUICKPANEL_TOUCH,
    156                        event.getActionMasked(), (int) event.getX(), (int) event.getY());
    157             }
    158         }
    159         return super.onTouchEvent(event);
    160     }
    161 }
    162