• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.surfacecontrol.cts;
18 
19 import static android.view.WindowInsets.Type.displayCutout;
20 import static android.view.WindowInsets.Type.systemBars;
21 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
22 
23 import android.animation.Animator;
24 import android.animation.AnimatorListenerAdapter;
25 import android.animation.ValueAnimator;
26 import android.app.Activity;
27 import android.graphics.Color;
28 import android.os.Bundle;
29 import android.view.View;
30 import android.view.WindowInsetsController;
31 import android.view.WindowManager;
32 import android.widget.FrameLayout;
33 
34 import androidx.annotation.Nullable;
35 
36 import java.util.concurrent.CountDownLatch;
37 
38 public class TestActivity extends Activity {
39     private static final int sTypeMask = systemBars() | displayCutout();
40     private FrameLayout mParentLayout;
41 
42     @Override
onCreate(@ullable Bundle savedInstanceState)43     protected void onCreate(@Nullable Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45 
46         mParentLayout = new FrameLayout(this);
47         mParentLayout.setBackgroundColor(Color.YELLOW);
48         FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
49                 FrameLayout.LayoutParams.MATCH_PARENT,
50                 FrameLayout.LayoutParams.MATCH_PARENT);
51         setContentView(mParentLayout, layoutParams);
52 
53         WindowInsetsController windowInsetsController = getWindow().getInsetsController();
54         windowInsetsController.hide(sTypeMask);
55         WindowManager.LayoutParams params = getWindow().getAttributes();
56         params.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
57         params.flags |= WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
58         getWindow().setAttributes(params);
59         getWindow().setDecorFitsSystemWindows(false);
60     }
61 
getParentLayout()62     public FrameLayout getParentLayout() {
63         return mParentLayout;
64     }
65 
66     /** Run a short, but janky animation. */
startJankyAnimation(final CountDownLatch onEnd)67     public void startJankyAnimation(final CountDownLatch onEnd) {
68         final View view = new View(this);
69         view.setBackgroundColor(Color.BLUE);
70         FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100, 100);
71         getParentLayout().addView(view, layoutParams);
72 
73         ValueAnimator anim = ValueAnimator.ofFloat(0, 1);
74         boolean[] causedJank = new boolean[] { false };
75         anim.addUpdateListener($ -> {
76             float progress = anim.getAnimatedFraction();
77             if (progress > 0.5 && !causedJank[0]) {
78                 causedJank[0] = true;
79                 // Let's miss a deadline!
80                 android.os.SystemClock.sleep(50);
81             }
82             view.setTranslationX(progress * 100);
83             view.invalidate();
84         });
85         anim.addListener(new AnimatorListenerAdapter() {
86             @Override
87             public void onAnimationEnd(Animator anim) {
88                 getParentLayout().removeView(view);
89                 onEnd.countDown();
90             }
91         });
92         anim.start();
93     }
94 }
95