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.systemui.stackdivider; 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.systemui.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 public class ForcedResizableInfoActivity extends Activity implements OnTouchListener { 39 40 public static final String EXTRA_FORCED_RESIZEABLE_REASON = "extra_forced_resizeable_reason"; 41 42 private static final long DISMISS_DELAY = 2500; 43 44 private final Runnable mFinishRunnable = new Runnable() { 45 @Override 46 public void run() { 47 finish(); 48 } 49 }; 50 51 @Override 52 protected void onCreate(@Nullable Bundle savedInstanceState) { 53 super.onCreate(savedInstanceState); 54 setContentView(R.layout.forced_resizable_activity); 55 TextView tv = (TextView) findViewById(com.android.internal.R.id.message); 56 int reason = getIntent().getIntExtra(EXTRA_FORCED_RESIZEABLE_REASON, -1); 57 String text; 58 switch (reason) { 59 case FORCED_RESIZEABLE_REASON_SPLIT_SCREEN: 60 text = getString(R.string.dock_forced_resizable); 61 break; 62 case FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY: 63 text = getString(R.string.forced_resizable_secondary_display); 64 break; 65 default: 66 throw new IllegalArgumentException("Unexpected forced resizeable reason: " 67 + reason); 68 } 69 tv.setText(text); 70 getWindow().setTitle(text); 71 getWindow().getDecorView().setOnTouchListener(this); 72 } 73 74 @Override 75 protected void onStart() { 76 super.onStart(); 77 getWindow().getDecorView().postDelayed(mFinishRunnable, DISMISS_DELAY); 78 } 79 80 @Override 81 protected void onStop() { 82 super.onStop(); 83 finish(); 84 } 85 86 @Override 87 public boolean onTouch(View v, MotionEvent event) { 88 finish(); 89 return true; 90 } 91 92 @Override 93 public boolean onKeyDown(int keyCode, KeyEvent event) { 94 finish(); 95 return true; 96 } 97 98 @Override 99 public void finish() { 100 super.finish(); 101 overridePendingTransition(0, R.anim.forced_resizable_exit); 102 } 103 104 @Override 105 public void setTaskDescription(ActivityManager.TaskDescription taskDescription) { 106 // Do nothing 107 } 108 } 109