1 /* 2 * Copyright (C) 2014 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.systemui.recents; 18 19 import android.app.ActivityManager; 20 import android.content.Context; 21 import android.content.res.Configuration; 22 import android.content.res.Resources; 23 24 import android.os.SystemProperties; 25 26 import com.android.systemui.R; 27 import com.android.systemui.recents.misc.SystemServicesProxy; 28 import com.android.systemui.recents.views.DockState; 29 import com.android.systemui.shared.recents.model.TaskStack; 30 31 /** 32 * Represents the dock regions for each orientation. 33 */ 34 class DockRegion { 35 public static DockState[] PHONE_LANDSCAPE = { 36 // We only allow docking to the left in landscape for now on small devices 37 DockState.LEFT 38 }; 39 public static DockState[] PHONE_PORTRAIT = { 40 // We only allow docking to the top for now on small devices 41 DockState.TOP 42 }; 43 public static DockState[] TABLET_LANDSCAPE = { 44 DockState.LEFT, 45 DockState.RIGHT 46 }; 47 public static DockState[] TABLET_PORTRAIT = PHONE_PORTRAIT; 48 } 49 50 /** 51 * Application resources that can be retrieved from the application context and are not specifically 52 * tied to the current activity. 53 */ 54 public class RecentsConfiguration { 55 56 private static final int LARGE_SCREEN_MIN_DP = 600; 57 private static final int XLARGE_SCREEN_MIN_DP = 720; 58 59 // Launch states 60 public RecentsActivityLaunchState mLaunchState = new RecentsActivityLaunchState(); 61 62 // Since the positions in Recents has to be calculated globally (before the RecentsActivity 63 // starts), we need to calculate some resource values ourselves, instead of relying on framework 64 // resources. 65 public final boolean isLargeScreen; 66 public final boolean isXLargeScreen; 67 public final int smallestWidth; 68 69 /** Misc **/ 70 public boolean fakeShadows; 71 public int svelteLevel; 72 73 // Whether this product supports Grid-based Recents. If this is field is set to true, then 74 // Recents will layout task views in a grid mode when there's enough space in the screen. 75 public boolean isGridEnabled; 76 77 // Support for Android Recents for low ram devices. If this field is set to true, then Recents 78 // will use the alternative layout. 79 public boolean isLowRamDevice; 80 81 // Enable drag and drop split from Recents. Disabled for low ram devices. 82 public boolean dragToSplitEnabled; 83 84 private final Context mAppContext; 85 RecentsConfiguration(Context context)86 public RecentsConfiguration(Context context) { 87 // Load only resources that can not change after the first load either through developer 88 // settings or via multi window 89 SystemServicesProxy ssp = Recents.getSystemServices(); 90 mAppContext = context.getApplicationContext(); 91 Resources res = mAppContext.getResources(); 92 fakeShadows = res.getBoolean(R.bool.config_recents_fake_shadows); 93 svelteLevel = res.getInteger(R.integer.recents_svelte_level); 94 isGridEnabled = SystemProperties.getBoolean("ro.recents.grid", false); 95 isLowRamDevice = ActivityManager.isLowRamDeviceStatic(); 96 dragToSplitEnabled = !isLowRamDevice; 97 98 float screenDensity = context.getResources().getDisplayMetrics().density; 99 smallestWidth = ssp.getDeviceSmallestWidth(); 100 isLargeScreen = smallestWidth >= (int) (screenDensity * LARGE_SCREEN_MIN_DP); 101 isXLargeScreen = smallestWidth >= (int) (screenDensity * XLARGE_SCREEN_MIN_DP); 102 } 103 104 /** 105 * Returns the activity launch state. 106 * TODO: This will be refactored out of RecentsConfiguration. 107 */ getLaunchState()108 public RecentsActivityLaunchState getLaunchState() { 109 return mLaunchState; 110 } 111 112 /** 113 * Returns the preferred dock states for the current orientation. 114 * @return a list of dock states for device and its orientation 115 */ getDockStatesForCurrentOrientation()116 public DockState[] getDockStatesForCurrentOrientation() { 117 boolean isLandscape = mAppContext.getResources().getConfiguration().orientation == 118 Configuration.ORIENTATION_LANDSCAPE; 119 RecentsConfiguration config = Recents.getConfiguration(); 120 if (config.isLargeScreen) { 121 return isLandscape ? DockRegion.TABLET_LANDSCAPE : DockRegion.TABLET_PORTRAIT; 122 } else { 123 return isLandscape ? DockRegion.PHONE_LANDSCAPE : DockRegion.PHONE_PORTRAIT; 124 } 125 } 126 127 } 128