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