• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.settings.activityembedding;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.util.DisplayMetrics;
22 import android.util.FeatureFlagUtils;
23 import android.util.Log;
24 import android.util.TypedValue;
25 
26 import androidx.window.embedding.SplitController;
27 
28 import com.android.settings.R;
29 
30 /** An util class collecting all common methods for the embedding activity features. */
31 public class ActivityEmbeddingUtils {
32     // The smallest value of current width of the window when the split should be used.
33     private static final int MIN_CURRENT_SCREEN_SPLIT_WIDTH_DP = 720;
34     // The smallest value of the smallest-width (sw) of the window in any rotation when
35     // the split should be used.
36     private static final int MIN_SMALLEST_SCREEN_SPLIT_WIDTH_DP = 600;
37     // The minimum width of the activity to show the regular homepage layout.
38     private static final float MIN_REGULAR_HOMEPAGE_LAYOUT_WIDTH_DP = 380f;
39     private static final String TAG = "ActivityEmbeddingUtils";
40 
41     /** Get the smallest width dp of the window when the split should be used. */
getMinCurrentScreenSplitWidthDp()42     public static int getMinCurrentScreenSplitWidthDp() {
43         return MIN_CURRENT_SCREEN_SPLIT_WIDTH_DP;
44     }
45 
46     /**
47      * Get the smallest dp value of the smallest-width (sw) of the window in any rotation when
48      * the split should be used.
49      */
getMinSmallestScreenSplitWidthDp()50     public static int getMinSmallestScreenSplitWidthDp() {
51         return MIN_SMALLEST_SCREEN_SPLIT_WIDTH_DP;
52     }
53 
54     /**
55      * Get the ratio to use when splitting windows. This should be a float which describes
56      * the percentage of the screen which the first window should occupy.
57      */
getSplitRatio(Context context)58     public static float getSplitRatio(Context context) {
59         return context.getResources().getFloat(R.dimen.config_activity_embed_split_ratio);
60     }
61 
62     /** Whether to support embedding activity feature. */
isEmbeddingActivityEnabled(Context context)63     public static boolean isEmbeddingActivityEnabled(Context context) {
64         final boolean isFlagEnabled = FeatureFlagUtils.isEnabled(context,
65                 FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN);
66         final boolean isSplitSupported = SplitController.getInstance(context).isSplitSupported();
67 
68         Log.d(TAG, "isFlagEnabled = " + isFlagEnabled);
69         Log.d(TAG, "isSplitSupported = " + isSplitSupported);
70 
71         return isFlagEnabled && isSplitSupported;
72     }
73 
74     /** Whether to show the regular or simplified homepage layout. */
isRegularHomepageLayout(Activity activity)75     public static boolean isRegularHomepageLayout(Activity activity) {
76         DisplayMetrics dm = activity.getResources().getDisplayMetrics();
77         return dm.widthPixels >= (int) TypedValue.applyDimension(
78                 TypedValue.COMPLEX_UNIT_DIP, MIN_REGULAR_HOMEPAGE_LAYOUT_WIDTH_DP, dm);
79     }
80 }
81