Home | History | Annotate | Download | only in recents
      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 import android.graphics.Rect;
     24 
     25 import android.os.SystemProperties;
     26 
     27 import com.android.systemui.R;
     28 import com.android.systemui.recents.misc.SystemServicesProxy;
     29 import com.android.systemui.recents.model.TaskStack;
     30 
     31 /**
     32  * Represents the dock regions for each orientation.
     33  */
     34 class DockRegion {
     35     public static TaskStack.DockState[] PHONE_LANDSCAPE = {
     36             // We only allow docking to the left in landscape for now on small devices
     37             TaskStack.DockState.LEFT
     38     };
     39     public static TaskStack.DockState[] PHONE_PORTRAIT = {
     40             // We only allow docking to the top for now on small devices
     41             TaskStack.DockState.TOP
     42     };
     43     public static TaskStack.DockState[] TABLET_LANDSCAPE = {
     44             TaskStack.DockState.LEFT,
     45             TaskStack.DockState.RIGHT
     46     };
     47     public static TaskStack.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     /** Levels of svelte in increasing severity/austerity. */
     60     // No svelting.
     61     public static final int SVELTE_NONE = 0;
     62     // Limit thumbnail cache to number of visible thumbnails when Recents was loaded, disable
     63     // caching thumbnails as you scroll.
     64     public static final int SVELTE_LIMIT_CACHE = 1;
     65     // Disable the thumbnail cache, load thumbnails asynchronously when the activity loads and
     66     // evict all thumbnails when hidden.
     67     public static final int SVELTE_DISABLE_CACHE = 2;
     68     // Disable all thumbnail loading.
     69     public static final int SVELTE_DISABLE_LOADING = 3;
     70 
     71     // Launch states
     72     public RecentsActivityLaunchState mLaunchState = new RecentsActivityLaunchState();
     73 
     74     // Since the positions in Recents has to be calculated globally (before the RecentsActivity
     75     // starts), we need to calculate some resource values ourselves, instead of relying on framework
     76     // resources.
     77     public final boolean isLargeScreen;
     78     public final boolean isXLargeScreen;
     79     public final int smallestWidth;
     80 
     81     /** Misc **/
     82     public boolean fakeShadows;
     83     public int svelteLevel;
     84 
     85     // Whether this product supports Grid-based Recents. If this is field is set to true, then
     86     // Recents will layout task views in a grid mode when there's enough space in the screen.
     87     public boolean isGridEnabled;
     88 
     89     // Support for Android Recents for low ram devices. If this field is set to true, then Recents
     90     // will use the alternative layout.
     91     public boolean isLowRamDevice;
     92 
     93     // Enable drag and drop split from Recents. Disabled for low ram devices.
     94     public boolean dragToSplitEnabled;
     95 
     96     private final Context mAppContext;
     97 
     98     public RecentsConfiguration(Context context) {
     99         // Load only resources that can not change after the first load either through developer
    100         // settings or via multi window
    101         SystemServicesProxy ssp = Recents.getSystemServices();
    102         mAppContext = context.getApplicationContext();
    103         Resources res = mAppContext.getResources();
    104         fakeShadows = res.getBoolean(R.bool.config_recents_fake_shadows);
    105         svelteLevel = res.getInteger(R.integer.recents_svelte_level);
    106         isGridEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
    107         isLowRamDevice = ActivityManager.isLowRamDeviceStatic();
    108         dragToSplitEnabled = !isLowRamDevice;
    109 
    110         float screenDensity = context.getResources().getDisplayMetrics().density;
    111         smallestWidth = ssp.getDeviceSmallestWidth();
    112         isLargeScreen = smallestWidth >= (int) (screenDensity * LARGE_SCREEN_MIN_DP);
    113         isXLargeScreen = smallestWidth >= (int) (screenDensity * XLARGE_SCREEN_MIN_DP);
    114     }
    115 
    116     /**
    117      * Returns the activity launch state.
    118      * TODO: This will be refactored out of RecentsConfiguration.
    119      */
    120     public RecentsActivityLaunchState getLaunchState() {
    121         return mLaunchState;
    122     }
    123 
    124     /**
    125      * Returns the preferred dock states for the current orientation.
    126      * @return a list of dock states for device and its orientation
    127      */
    128     public TaskStack.DockState[] getDockStatesForCurrentOrientation() {
    129         boolean isLandscape = mAppContext.getResources().getConfiguration().orientation ==
    130                 Configuration.ORIENTATION_LANDSCAPE;
    131         RecentsConfiguration config = Recents.getConfiguration();
    132         if (config.isLargeScreen) {
    133             return isLandscape ? DockRegion.TABLET_LANDSCAPE : DockRegion.TABLET_PORTRAIT;
    134         } else {
    135             return isLandscape ? DockRegion.PHONE_LANDSCAPE : DockRegion.PHONE_PORTRAIT;
    136         }
    137     }
    138 
    139 }
    140