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 android.view.cts; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.view.KeyEvent; 22 23 public class LongPressBackActivity extends Activity { 24 25 private boolean mWasPaused; 26 private boolean mWasStopped; 27 private boolean mSawBackDown; 28 private boolean mSawBackUp; 29 private boolean mSawOnBackPressed; 30 31 @Override 32 protected void onCreate(Bundle savedInstanceState) { 33 super.onCreate(savedInstanceState); 34 } 35 36 @Override 37 protected void onPause() { 38 mWasPaused = true; 39 super.onPause(); 40 } 41 42 @Override 43 protected void onStop() { 44 mWasStopped = true; 45 super.onStop(); 46 } 47 48 @Override 49 public boolean onKeyDown(int keyCode, KeyEvent event) { 50 if (keyCode == KeyEvent.KEYCODE_BACK && !event.isCanceled()) { 51 mSawBackDown = true; 52 } 53 return super.onKeyDown(keyCode, event); 54 } 55 56 @Override 57 public boolean onKeyUp(int keyCode, KeyEvent event) { 58 if (keyCode == KeyEvent.KEYCODE_BACK) { 59 mSawBackUp = true; 60 } 61 return super.onKeyUp(keyCode, event); 62 } 63 64 @Override 65 public void onBackPressed() { 66 mSawOnBackPressed = true; 67 super.onBackPressed(); 68 } 69 70 public boolean wasPaused() { 71 return mWasPaused; 72 } 73 74 public boolean wasStopped() { 75 return mWasStopped; 76 } 77 78 public boolean sawBackDown() { 79 return mSawBackDown; 80 } 81 82 public boolean sawBackUp() { 83 return mSawBackUp; 84 } 85 86 public boolean sawOnBackPressed() { 87 return mSawOnBackPressed; 88 } 89 }