1 /* 2 * Copyright (C) 2008 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 android.server.wm.window; 18 19 import android.app.Activity; 20 import android.graphics.Insets; 21 import android.os.Bundle; 22 import android.server.wm.cts.R; 23 import android.view.KeyEvent; 24 import android.view.Menu; 25 import android.view.View; 26 import android.view.Window; 27 import android.view.WindowInsets; 28 29 public class WindowCtsActivity extends Activity { 30 31 private static boolean mIsOnCreateOptionsMenuCalled; 32 private static boolean mIsOnOptionsMenuClosedCalled; 33 private static boolean mIsOnKeyDownCalled; 34 35 private WindowInsets mLastInsets; 36 37 @Override onCreate(Bundle savedInstanceState)38 protected void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 getWindow().requestFeature(Window.FEATURE_LEFT_ICON); 41 getWindow().setDecorFitsSystemWindows(true); 42 setContentView(R.layout.windowstub_layout); 43 getContentView().setOnApplyWindowInsetsListener((v, insets) -> { 44 mLastInsets = insets; 45 return insets; 46 }); 47 } 48 49 @Override onCreateOptionsMenu(Menu menu)50 public boolean onCreateOptionsMenu(Menu menu) { 51 menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "Quit").setShortcut('1', 'q'); 52 menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "Action").setShortcut('2', 'a'); 53 mIsOnCreateOptionsMenuCalled = true; 54 return super.onCreateOptionsMenu(menu); 55 } 56 57 @Override onOptionsMenuClosed(Menu menu)58 public void onOptionsMenuClosed(Menu menu) { 59 super.onOptionsMenuClosed(menu); 60 mIsOnOptionsMenuClosedCalled = true; 61 } 62 63 @Override onKeyDown(int keyCode, KeyEvent event)64 public boolean onKeyDown(int keyCode, KeyEvent event) { 65 mIsOnKeyDownCalled = true; 66 return super.onKeyDown(keyCode, event); 67 } 68 getContentView()69 public View getContentView() { 70 return findViewById(R.id.listview_window); 71 } 72 getAppliedInsets()73 public Insets getAppliedInsets() { 74 View view = (View) getContentView().getParent(); 75 int[] location = new int[2]; 76 view.getLocationInWindow(location); 77 View decorView = getWindow().getDecorView(); 78 return Insets.of(location[0], location[1], 79 decorView.getWidth() - (location[0] + view.getWidth()), 80 decorView.getHeight() - (location[1] + view.getHeight())); 81 } 82 getLastInsets()83 public WindowInsets getLastInsets() { 84 return mLastInsets; 85 } 86 isOnCreateOptionsMenuCalled()87 public boolean isOnCreateOptionsMenuCalled() { 88 return mIsOnCreateOptionsMenuCalled; 89 } 90 isOnOptionsMenuClosedCalled()91 public boolean isOnOptionsMenuClosedCalled() { 92 return mIsOnOptionsMenuClosedCalled; 93 } 94 isOnKeyDownCalled()95 public boolean isOnKeyDownCalled() { 96 return mIsOnKeyDownCalled; 97 } 98 setFlagFalse()99 public void setFlagFalse() { 100 mIsOnCreateOptionsMenuCalled = false; 101 mIsOnOptionsMenuClosedCalled = false; 102 } 103 } 104