• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.display.cts;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.view.Display;
22 import android.view.WindowManager;
23 
24 import androidx.annotation.Nullable;
25 
26 /**
27  * Test activity to exercise getting metrics for displays.
28  */
29 public class DisplayTestActivity extends Activity {
30 
31     private static final String PREFERRED_DISPLAY_MODE_ID = "preferred_display_mode_id";
32     private int mPreferredDisplayModeId = 0;
33 
34     @Override
onSaveInstanceState(Bundle outBundle)35     public void onSaveInstanceState(Bundle outBundle) {
36         super.onSaveInstanceState(outBundle);
37 
38         outBundle.putInt(PREFERRED_DISPLAY_MODE_ID, mPreferredDisplayModeId);
39     }
40 
41     @Override
onCreate(@ullable Bundle savedInstanceState)42     public void onCreate(@Nullable Bundle savedInstanceState) {
43         super.onCreate(savedInstanceState);
44 
45         if (savedInstanceState != null) {
46             mPreferredDisplayModeId = savedInstanceState.getInt(PREFERRED_DISPLAY_MODE_ID, 0);
47             resetLayoutParams();
48         }
49     }
50 
51     /** Set an override for the display mode. This is called directly from test instrumentation. */
setPreferredDisplayMode(Display.Mode mode)52     public void setPreferredDisplayMode(Display.Mode mode) {
53         mPreferredDisplayModeId = mode.getModeId();
54         resetLayoutParams();
55     }
56 
resetLayoutParams()57     private void resetLayoutParams() {
58         WindowManager.LayoutParams params = getWindow().getAttributes();
59         params.preferredDisplayModeId = mPreferredDisplayModeId;
60         getWindow().setAttributes(params);
61     }
62 }
63