1 /* 2 * Copyright (C) 2016 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.legacysplitscreen; 18 19 import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY; 20 import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; 21 22 import android.annotation.Nullable; 23 import android.app.Activity; 24 import android.app.ActivityManager; 25 import android.os.Bundle; 26 import android.view.KeyEvent; 27 import android.view.MotionEvent; 28 import android.view.View; 29 import android.view.View.OnTouchListener; 30 import android.widget.TextView; 31 32 import com.android.wm.shell.R; 33 34 /** 35 * Translucent activity that gets started on top of a task in multi-window to inform the user that 36 * we forced the activity below to be resizable. 37 * 38 * Note: This activity runs on the main thread of the process hosting the Shell lib. 39 */ 40 public class ForcedResizableInfoActivity extends Activity implements OnTouchListener { 41 42 public static final String EXTRA_FORCED_RESIZEABLE_REASON = "extra_forced_resizeable_reason"; 43 44 private static final long DISMISS_DELAY = 2500; 45 46 private final Runnable mFinishRunnable = new Runnable() { 47 @Override 48 public void run() { 49 finish(); 50 } 51 }; 52 53 @Override onCreate(@ullable Bundle savedInstanceState)54 protected void onCreate(@Nullable Bundle savedInstanceState) { 55 super.onCreate(savedInstanceState); 56 setContentView(R.layout.forced_resizable_activity); 57 TextView tv = findViewById(com.android.internal.R.id.message); 58 int reason = getIntent().getIntExtra(EXTRA_FORCED_RESIZEABLE_REASON, -1); 59 String text; 60 switch (reason) { 61 case FORCED_RESIZEABLE_REASON_SPLIT_SCREEN: 62 text = getString(R.string.dock_forced_resizable); 63 break; 64 case FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY: 65 text = getString(R.string.forced_resizable_secondary_display); 66 break; 67 default: 68 throw new IllegalArgumentException("Unexpected forced resizeable reason: " 69 + reason); 70 } 71 tv.setText(text); 72 getWindow().setTitle(text); 73 getWindow().getDecorView().setOnTouchListener(this); 74 } 75 76 @Override onStart()77 protected void onStart() { 78 super.onStart(); 79 getWindow().getDecorView().postDelayed(mFinishRunnable, DISMISS_DELAY); 80 } 81 82 @Override onStop()83 protected void onStop() { 84 super.onStop(); 85 finish(); 86 } 87 88 @Override onTouch(View v, MotionEvent event)89 public boolean onTouch(View v, MotionEvent event) { 90 finish(); 91 return true; 92 } 93 94 @Override onKeyDown(int keyCode, KeyEvent event)95 public boolean onKeyDown(int keyCode, KeyEvent event) { 96 finish(); 97 return true; 98 } 99 100 @Override finish()101 public void finish() { 102 super.finish(); 103 overridePendingTransition(0, R.anim.forced_resizable_exit); 104 } 105 106 @Override setTaskDescription(ActivityManager.TaskDescription taskDescription)107 public void setTaskDescription(ActivityManager.TaskDescription taskDescription) { 108 // Do nothing 109 } 110 } 111