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.animation.LayoutTransition;
20import android.content.Context;
21import android.content.Intent;
22import android.content.res.Resources;
23import android.graphics.Canvas;
24import android.graphics.drawable.Drawable;
25import android.util.AttributeSet;
26import android.view.LayoutInflater;
27import android.view.View;
28import android.view.ViewGroup;
29
30import com.android.systemui.R;
31import com.android.systemui.statusbar.BaseStatusBar;
32import com.android.systemui.statusbar.GestureRecorder;
33import com.android.systemui.statusbar.policy.BatteryController;
34import com.android.systemui.statusbar.policy.BluetoothController;
35import com.android.systemui.statusbar.policy.LocationController;
36import com.android.systemui.statusbar.policy.NetworkController;
37
38public class SettingsPanelView extends PanelView {
39
40    private QuickSettings mQS;
41    private QuickSettingsContainerView mQSContainer;
42
43    Drawable mHandleBar;
44    float mHandleBarHeight;
45    View mHandleView;
46
47    public SettingsPanelView(Context context, AttributeSet attrs) {
48        super(context, attrs);
49    }
50
51    @Override
52    protected void onFinishInflate() {
53        super.onFinishInflate();
54
55        mQSContainer = (QuickSettingsContainerView) findViewById(R.id.quick_settings_container);
56
57        Resources resources = getContext().getResources();
58        mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
59        mHandleBarHeight = resources.getDimension(R.dimen.close_handle_height);
60        mHandleView = findViewById(R.id.handle);
61
62        setContentDescription(resources.getString(R.string.accessibility_desc_quick_settings));
63    }
64
65    public void setQuickSettings(QuickSettings qs) {
66        mQS = qs;
67    }
68
69    @Override
70    public void setBar(PanelBar panelBar) {
71        super.setBar(panelBar);
72
73        if (mQS != null) {
74            mQS.setBar(panelBar);
75        }
76    }
77
78    public void setImeWindowStatus(boolean visible) {
79        if (mQS != null) {
80            mQS.setImeWindowStatus(visible);
81        }
82    }
83
84    public void setup(NetworkController networkController, BluetoothController bluetoothController,
85            BatteryController batteryController, LocationController locationController) {
86        if (mQS != null) {
87            mQS.setup(networkController, bluetoothController, batteryController,
88                    locationController);
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    // We draw the handle ourselves so that it's always glued to the bottom of the window.
120    @Override
121    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
122        super.onLayout(changed, left, top, right, bottom);
123        if (changed) {
124            final int pl = getPaddingLeft();
125            final int pr = getPaddingRight();
126            mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
127        }
128    }
129
130    @Override
131    public void draw(Canvas canvas) {
132        super.draw(canvas);
133        final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
134        canvas.translate(0, off);
135        mHandleBar.setState(mHandleView.getDrawableState());
136        mHandleBar.draw(canvas);
137        canvas.translate(0, -off);
138    }
139}
140