1 /*
2  * Copyright (C) 2020 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 package com.android.quickstep.interaction;
17 
18 import static com.android.quickstep.interaction.TutorialFragment.KEY_TUTORIAL_TYPE;
19 
20 import android.graphics.Color;
21 import android.graphics.Rect;
22 import android.os.Bundle;
23 import android.util.DisplayMetrics;
24 import android.view.Display;
25 import android.view.View;
26 import android.view.Window;
27 
28 import androidx.fragment.app.FragmentActivity;
29 
30 import com.android.launcher3.R;
31 import com.android.quickstep.interaction.TutorialController.TutorialType;
32 
33 import java.util.List;
34 
35 /** Shows the gesture interactive sandbox in full screen mode. */
36 public class GestureSandboxActivity extends FragmentActivity {
37 
38     private static final String LOG_TAG = "GestureSandboxActivity";
39 
40     private TutorialFragment mFragment;
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         requestWindowFeature(Window.FEATURE_NO_TITLE);
46         setContentView(R.layout.gesture_tutorial_activity);
47 
48         mFragment = TutorialFragment.newInstance(getTutorialType(getIntent().getExtras()));
49         getSupportFragmentManager().beginTransaction()
50                 .add(R.id.gesture_tutorial_fragment_container, mFragment)
51                 .commit();
52     }
53 
54     @Override
onAttachedToWindow()55     public void onAttachedToWindow() {
56         super.onAttachedToWindow();
57         disableSystemGestures();
58         mFragment.onAttachedToWindow();
59     }
60 
61     @Override
onDetachedFromWindow()62     public void onDetachedFromWindow() {
63         super.onDetachedFromWindow();
64         mFragment.onDetachedFromWindow();
65     }
66 
67     @Override
onWindowFocusChanged(boolean hasFocus)68     public void onWindowFocusChanged(boolean hasFocus) {
69         super.onWindowFocusChanged(hasFocus);
70         if (hasFocus) {
71             hideSystemUI();
72         }
73     }
74 
getTutorialType(Bundle extras)75     private TutorialType getTutorialType(Bundle extras) {
76         TutorialType defaultType = TutorialType.RIGHT_EDGE_BACK_NAVIGATION;
77 
78         if (extras == null || !extras.containsKey(KEY_TUTORIAL_TYPE)) {
79             return defaultType;
80         }
81         try {
82             return TutorialType.valueOf(extras.getString(KEY_TUTORIAL_TYPE, ""));
83         } catch (IllegalArgumentException e) {
84             return defaultType;
85         }
86     }
87 
hideSystemUI()88     private void hideSystemUI() {
89         getWindow().getDecorView().setSystemUiVisibility(
90                 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
91                         | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
92                         | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
93                         | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
94                         | View.SYSTEM_UI_FLAG_FULLSCREEN);
95         getWindow().setNavigationBarColor(Color.TRANSPARENT);
96     }
97 
disableSystemGestures()98     private void disableSystemGestures() {
99         Display display = getDisplay();
100         if (display != null) {
101             DisplayMetrics metrics = new DisplayMetrics();
102             display.getMetrics(metrics);
103             getWindow().setSystemGestureExclusionRects(
104                     List.of(new Rect(0, 0, metrics.widthPixels, metrics.heightPixels)));
105         }
106     }
107 }
108