• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.providers.media.photopicker.espresso;
18 
19 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
20 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
21 import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
22 import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
23 
24 import static androidx.test.espresso.Espresso.onIdle;
25 
26 import static com.google.common.truth.Truth.assertThat;
27 
28 import androidx.test.core.app.ActivityScenario;
29 
30 class OrientationUtils {
setLandscapeOrientation(ActivityScenario<PhotoPickerTestActivity> scenario)31     public static void setLandscapeOrientation(ActivityScenario<PhotoPickerTestActivity> scenario) {
32         changeOrientation(scenario, SCREEN_ORIENTATION_LANDSCAPE, ORIENTATION_LANDSCAPE);
33     }
34 
setPortraitOrientation(ActivityScenario<PhotoPickerTestActivity> scenario)35     public static void setPortraitOrientation(ActivityScenario<PhotoPickerTestActivity> scenario) {
36         changeOrientation(scenario, SCREEN_ORIENTATION_PORTRAIT, ORIENTATION_PORTRAIT);
37     }
38 
changeOrientation( ActivityScenario<PhotoPickerTestActivity> scenario, int screenOrientation, int configOrientation)39     private static void changeOrientation(
40             ActivityScenario<PhotoPickerTestActivity> scenario,
41             int screenOrientation,
42             int configOrientation) {
43         scenario.onActivity(
44                 activity -> {
45                     activity.setRequestedOrientation(screenOrientation);
46                 });
47 
48         onIdle();
49 
50         scenario.onActivity(
51                 activity -> {
52                     assertThat(activity.getResources().getConfiguration().orientation)
53                             .isEqualTo(configOrientation);
54                 });
55     }
56 }
57