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 static com.android.systemui.Flags.centralizedStatusBarHeightFix; 21 22 import android.content.Context; 23 import android.content.res.Configuration; 24 import android.content.res.Resources; 25 import android.util.AttributeSet; 26 import android.view.MotionEvent; 27 import android.view.View; 28 import android.view.ViewGroup; 29 import android.widget.FrameLayout; 30 31 import com.android.systemui.res.R; 32 import com.android.systemui.shade.LargeScreenHeaderHelper; 33 import com.android.systemui.util.LargeScreenUtils; 34 35 /** 36 * View that contains the top-most bits of the QS panel (primarily the status bar with date, time, 37 * battery, carrier info and privacy icons) and also contains the {@link QuickQSPanel}. 38 */ 39 public class QuickStatusBarHeader extends FrameLayout { 40 41 private boolean mExpanded; 42 private boolean mQsDisabled; 43 44 protected QuickQSPanel mHeaderQsPanel; 45 46 private boolean mSceneContainerEnabled; 47 QuickStatusBarHeader(Context context, AttributeSet attrs)48 public QuickStatusBarHeader(Context context, AttributeSet attrs) { 49 super(context, attrs); 50 } 51 52 @Override onFinishInflate()53 protected void onFinishInflate() { 54 super.onFinishInflate(); 55 mHeaderQsPanel = findViewById(R.id.quick_qs_panel); 56 57 updateResources(); 58 } 59 setSceneContainerEnabled(boolean enabled)60 void setSceneContainerEnabled(boolean enabled) { 61 mSceneContainerEnabled = enabled; 62 if (mSceneContainerEnabled) { 63 updateResources(); 64 } 65 } 66 67 @Override onConfigurationChanged(Configuration newConfig)68 protected void onConfigurationChanged(Configuration newConfig) { 69 super.onConfigurationChanged(newConfig); 70 updateResources(); 71 } 72 73 @Override onTouchEvent(MotionEvent event)74 public boolean onTouchEvent(MotionEvent event) { 75 // Only react to touches inside QuickQSPanel 76 if (event.getY() > mHeaderQsPanel.getTop()) { 77 return super.onTouchEvent(event); 78 } else { 79 return false; 80 } 81 } 82 updateResources()83 void updateResources() { 84 Resources resources = mContext.getResources(); 85 boolean largeScreenHeaderActive = 86 LargeScreenUtils.shouldUseLargeScreenShadeHeader(resources); 87 88 ViewGroup.LayoutParams lp = getLayoutParams(); 89 if (mQsDisabled) { 90 lp.height = 0; 91 } else { 92 lp.height = WRAP_CONTENT; 93 } 94 setLayoutParams(lp); 95 96 MarginLayoutParams qqsLP = (MarginLayoutParams) mHeaderQsPanel.getLayoutParams(); 97 if (mSceneContainerEnabled) { 98 qqsLP.topMargin = 0; 99 } else if (largeScreenHeaderActive) { 100 qqsLP.topMargin = mContext.getResources() 101 .getDimensionPixelSize(R.dimen.qqs_layout_margin_top); 102 } else { 103 qqsLP.topMargin = centralizedStatusBarHeightFix() 104 ? LargeScreenHeaderHelper.getLargeScreenHeaderHeight(mContext) 105 : mContext.getResources() 106 .getDimensionPixelSize(R.dimen.large_screen_shade_header_min_height); 107 } 108 mHeaderQsPanel.setLayoutParams(qqsLP); 109 } 110 setExpanded(boolean expanded, QuickQSPanelController quickQSPanelController)111 public void setExpanded(boolean expanded, QuickQSPanelController quickQSPanelController) { 112 if (mExpanded == expanded) return; 113 mExpanded = expanded; 114 quickQSPanelController.setExpanded(expanded); 115 } 116 disable(int state1, int state2, boolean animate)117 public void disable(int state1, int state2, boolean animate) { 118 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; 119 if (disabled == mQsDisabled) return; 120 mQsDisabled = disabled; 121 mHeaderQsPanel.setDisabledByPolicy(disabled); 122 updateResources(); 123 } 124 setContentMargins(View view, int marginStart, int marginEnd)125 private void setContentMargins(View view, int marginStart, int marginEnd) { 126 MarginLayoutParams lp = (MarginLayoutParams) view.getLayoutParams(); 127 lp.setMarginStart(marginStart); 128 lp.setMarginEnd(marginEnd); 129 view.setLayoutParams(lp); 130 } 131 } 132