1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.systemui.qs; 16 17 import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS; 18 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; 19 20 import android.content.Context; 21 import android.content.res.Configuration; 22 import android.content.res.Resources; 23 import android.util.AttributeSet; 24 import android.view.MotionEvent; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.FrameLayout; 28 29 import com.android.systemui.res.R; 30 import com.android.systemui.shade.LargeScreenHeaderHelper; 31 import com.android.systemui.util.LargeScreenUtils; 32 33 /** 34 * View that contains the top-most bits of the QS panel (primarily the status bar with date, time, 35 * battery, carrier info and privacy icons) and also contains the {@link QuickQSPanel}. 36 */ 37 public class QuickStatusBarHeader extends FrameLayout { 38 39 private boolean mExpanded; 40 private boolean mQsDisabled; 41 42 protected QuickQSPanel mHeaderQsPanel; 43 44 private boolean mSceneContainerEnabled; 45 QuickStatusBarHeader(Context context, AttributeSet attrs)46 public QuickStatusBarHeader(Context context, AttributeSet attrs) { 47 super(context, attrs); 48 } 49 50 @Override onFinishInflate()51 protected void onFinishInflate() { 52 super.onFinishInflate(); 53 mHeaderQsPanel = findViewById(R.id.quick_qs_panel); 54 55 updateResources(); 56 } 57 setSceneContainerEnabled(boolean enabled)58 void setSceneContainerEnabled(boolean enabled) { 59 mSceneContainerEnabled = enabled; 60 if (mSceneContainerEnabled) { 61 updateResources(); 62 } 63 } 64 65 @Override onConfigurationChanged(Configuration newConfig)66 protected void onConfigurationChanged(Configuration newConfig) { 67 super.onConfigurationChanged(newConfig); 68 updateResources(); 69 } 70 71 @Override onTouchEvent(MotionEvent event)72 public boolean onTouchEvent(MotionEvent event) { 73 // Only react to touches inside QuickQSPanel 74 if (event.getY() > mHeaderQsPanel.getTop()) { 75 return super.onTouchEvent(event); 76 } else { 77 return false; 78 } 79 } 80 updateResources()81 void updateResources() { 82 Resources resources = mContext.getResources(); 83 boolean largeScreenHeaderActive = 84 LargeScreenUtils.shouldUseLargeScreenShadeHeader(resources); 85 86 ViewGroup.LayoutParams lp = getLayoutParams(); 87 if (mQsDisabled) { 88 lp.height = 0; 89 } else { 90 lp.height = WRAP_CONTENT; 91 } 92 setLayoutParams(lp); 93 94 MarginLayoutParams qqsLP = (MarginLayoutParams) mHeaderQsPanel.getLayoutParams(); 95 if (mSceneContainerEnabled) { 96 qqsLP.topMargin = 0; 97 } else if (largeScreenHeaderActive) { 98 qqsLP.topMargin = mContext.getResources() 99 .getDimensionPixelSize(R.dimen.qqs_layout_margin_top); 100 } else { 101 qqsLP.topMargin = LargeScreenHeaderHelper.getLargeScreenHeaderHeight(mContext); 102 } 103 mHeaderQsPanel.setLayoutParams(qqsLP); 104 } 105 setExpanded(boolean expanded, QuickQSPanelController quickQSPanelController)106 public void setExpanded(boolean expanded, QuickQSPanelController quickQSPanelController) { 107 if (mExpanded == expanded) return; 108 mExpanded = expanded; 109 quickQSPanelController.setExpanded(expanded); 110 } 111 disable(int state1, int state2, boolean animate)112 public void disable(int state1, int state2, boolean animate) { 113 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; 114 if (disabled == mQsDisabled) return; 115 mQsDisabled = disabled; 116 mHeaderQsPanel.setDisabledByPolicy(disabled); 117 updateResources(); 118 } 119 setContentMargins(View view, int marginStart, int marginEnd)120 private void setContentMargins(View view, int marginStart, int marginEnd) { 121 MarginLayoutParams lp = (MarginLayoutParams) view.getLayoutParams(); 122 lp.setMarginStart(marginStart); 123 lp.setMarginEnd(marginEnd); 124 view.setLayoutParams(lp); 125 } 126 127 /** 128 * @return height with the squishiness fraction applied. 129 */ getSquishedHeight()130 public int getSquishedHeight() { 131 return mHeaderQsPanel.getSquishedHeight(); 132 } 133 } 134