• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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.quickstep.views;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.util.FloatProperty;
22 import android.view.ViewGroup;
23 import android.widget.FrameLayout;
24 
25 import androidx.annotation.Nullable;
26 import androidx.appcompat.widget.AppCompatTextView;
27 
28 import com.android.launcher3.R;
29 import com.android.launcher3.statemanager.StatefulActivity;
30 
31 /**
32  * A rounded rectangular component containing a single TextView.
33  * Appears when a split is in progress, and tells the user to select a second app to initiate
34  * splitscreen.
35  *
36  * Appears and disappears concurrently with a FloatingTaskView.
37  */
38 public class SplitInstructionsView extends FrameLayout {
39     private final StatefulActivity mLauncher;
40     private AppCompatTextView mTextView;
41 
42     public static final FloatProperty<SplitInstructionsView> UNFOLD =
43             new FloatProperty<SplitInstructionsView>("SplitInstructionsUnfold") {
44                 @Override
45                 public void setValue(SplitInstructionsView splitInstructionsView, float v) {
46                     splitInstructionsView.setScaleY(v);
47                 }
48 
49                 @Override
50                 public Float get(SplitInstructionsView splitInstructionsView) {
51                     return splitInstructionsView.getScaleY();
52                 }
53             };
54 
SplitInstructionsView(Context context)55     public SplitInstructionsView(Context context) {
56         this(context, null);
57     }
58 
SplitInstructionsView(Context context, @Nullable AttributeSet attrs)59     public SplitInstructionsView(Context context, @Nullable AttributeSet attrs) {
60         this(context, attrs, 0);
61     }
62 
SplitInstructionsView(Context context, AttributeSet attrs, int defStyleAttr)63     public SplitInstructionsView(Context context, AttributeSet attrs, int defStyleAttr) {
64         super(context, attrs, defStyleAttr);
65         mLauncher = (StatefulActivity) context;
66     }
67 
getSplitInstructionsView(StatefulActivity launcher)68     static SplitInstructionsView getSplitInstructionsView(StatefulActivity launcher) {
69         ViewGroup dragLayer = launcher.getDragLayer();
70         final SplitInstructionsView splitInstructionsView =
71                 (SplitInstructionsView) launcher.getLayoutInflater().inflate(
72                         R.layout.split_instructions_view,
73                         dragLayer,
74                         false
75                 );
76 
77         splitInstructionsView.mTextView = splitInstructionsView.findViewById(
78                 R.id.split_instructions_text);
79 
80         // Since textview overlays base view, and we sometimes manipulate the alpha of each
81         // simultaneously, force overlapping rendering to false prevents redrawing of pixels,
82         // improving performance at the cost of some accuracy.
83         splitInstructionsView.forceHasOverlappingRendering(false);
84 
85         dragLayer.addView(splitInstructionsView);
86         return splitInstructionsView;
87     }
88 
89     @Override
onMeasure(int widthMeasureSpec, int heightMeasureSpec)90     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
91         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
92         ensureProperRotation();
93     }
94 
ensureProperRotation()95     void ensureProperRotation() {
96         ((RecentsView) mLauncher.getOverviewPanel()).getPagedOrientationHandler()
97                 .setSplitInstructionsParams(
98                         this,
99                         mLauncher.getDeviceProfile(),
100                         getMeasuredHeight(),
101                         getMeasuredWidth()
102                 );
103     }
104 
getTextView()105     public AppCompatTextView getTextView() {
106         return mTextView;
107     }
108 }
109