1 /* 2 * Copyright (C) 2021 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.wm.shell.compatui; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.View; 22 import android.widget.ImageButton; 23 import android.widget.LinearLayout; 24 import android.widget.TextView; 25 26 import com.android.wm.shell.R; 27 28 /** 29 * Container for compat UI controls. 30 */ 31 public class CompatUILayout extends LinearLayout { 32 33 private CompatUIWindowManager mWindowManager; 34 CompatUILayout(Context context)35 public CompatUILayout(Context context) { 36 this(context, null); 37 } 38 CompatUILayout(Context context, AttributeSet attrs)39 public CompatUILayout(Context context, AttributeSet attrs) { 40 this(context, attrs, 0); 41 } 42 CompatUILayout(Context context, AttributeSet attrs, int defStyleAttr)43 public CompatUILayout(Context context, AttributeSet attrs, int defStyleAttr) { 44 this(context, attrs, defStyleAttr, 0); 45 } 46 CompatUILayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)47 public CompatUILayout(Context context, AttributeSet attrs, int defStyleAttr, 48 int defStyleRes) { 49 super(context, attrs, defStyleAttr, defStyleRes); 50 } 51 inject(CompatUIWindowManager windowManager)52 void inject(CompatUIWindowManager windowManager) { 53 mWindowManager = windowManager; 54 } 55 56 @Override onLayout(boolean changed, int left, int top, int right, int bottom)57 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 58 super.onLayout(changed, left, top, right, bottom); 59 // Need to relayout after changes like hiding / showing a hint since they affect size. 60 // Doing this directly in setSizeCompatHintVisibility can result in flaky animation. 61 mWindowManager.relayout(); 62 } 63 setSizeCompatHintVisibility(boolean show)64 void setSizeCompatHintVisibility(boolean show) { 65 final LinearLayout sizeCompatHint = findViewById(R.id.size_compat_hint); 66 int visibility = show ? View.VISIBLE : View.GONE; 67 if (sizeCompatHint.getVisibility() == visibility) { 68 return; 69 } 70 sizeCompatHint.setVisibility(visibility); 71 } 72 73 @Override onFinishInflate()74 protected void onFinishInflate() { 75 super.onFinishInflate(); 76 77 final ImageButton restartButton = findViewById(R.id.size_compat_restart_button); 78 restartButton.setOnClickListener(view -> mWindowManager.onRestartButtonClicked()); 79 restartButton.setOnLongClickListener(view -> { 80 mWindowManager.onRestartButtonLongClicked(); 81 return true; 82 }); 83 84 final LinearLayout sizeCompatHint = findViewById(R.id.size_compat_hint); 85 ((TextView) sizeCompatHint.findViewById(R.id.compat_mode_hint_text)) 86 .setText(R.string.restart_button_description); 87 sizeCompatHint.setOnClickListener(view -> setSizeCompatHintVisibility(/* show= */ false)); 88 } 89 } 90