Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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.launcher3; |
| 18 | |
Winson Chung | f7d4585 | 2013-10-10 18:57:15 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 20 | import android.content.res.Resources; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 21 | import android.util.DisplayMetrics; |
| 22 | import android.util.TypedValue; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 23 | |
| 24 | import java.util.ArrayList; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 25 | |
| 26 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 27 | public class DynamicGrid { |
| 28 | @SuppressWarnings("unused") |
| 29 | private static final String TAG = "DynamicGrid"; |
| 30 | |
| 31 | private DeviceProfile mProfile; |
| 32 | private float mMinWidth; |
| 33 | private float mMinHeight; |
| 34 | |
Winson Chung | 67ca7e4 | 2013-10-31 16:53:19 -0700 | [diff] [blame] | 35 | // This is a static that we use for the default icon size on a 4/5-inch phone |
| 36 | static float DEFAULT_ICON_SIZE_DP = 60; |
| 37 | static float DEFAULT_ICON_SIZE_PX = 0; |
| 38 | |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 39 | public static float dpiFromPx(int size, DisplayMetrics metrics){ |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 40 | float densityRatio = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT; |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 41 | return (size / densityRatio); |
| 42 | } |
| 43 | public static int pxFromDp(float size, DisplayMetrics metrics) { |
| 44 | return (int) Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, |
| 45 | size, metrics)); |
| 46 | } |
| 47 | public static int pxFromSp(float size, DisplayMetrics metrics) { |
| 48 | return (int) Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, |
| 49 | size, metrics)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Winson Chung | f7d4585 | 2013-10-10 18:57:15 -0700 | [diff] [blame] | 52 | public DynamicGrid(Context context, Resources resources, |
| 53 | int minWidthPx, int minHeightPx, |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 54 | int widthPx, int heightPx, |
| 55 | int awPx, int ahPx) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 56 | DisplayMetrics dm = resources.getDisplayMetrics(); |
| 57 | ArrayList<DeviceProfile> deviceProfiles = |
| 58 | new ArrayList<DeviceProfile>(); |
Nilesh Agrawal | 16f3ea8 | 2014-01-09 17:14:01 -0800 | [diff] [blame] | 59 | boolean hasAA = !LauncherAppState.isDisableAllApps(); |
Winson Chung | 67ca7e4 | 2013-10-31 16:53:19 -0700 | [diff] [blame] | 60 | DEFAULT_ICON_SIZE_PX = pxFromDp(DEFAULT_ICON_SIZE_DP, dm); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 61 | // Our phone profiles include the bar sizes in each orientation |
| 62 | deviceProfiles.add(new DeviceProfile("Super Short Stubby", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 63 | 255, 300, 2, 3, 48, 13, (hasAA ? 3 : 5), 48, R.xml.default_workspace_4x4)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 64 | deviceProfiles.add(new DeviceProfile("Shorter Stubby", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 65 | 255, 400, 3, 3, 48, 13, (hasAA ? 3 : 5), 48, R.xml.default_workspace_4x4)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 66 | deviceProfiles.add(new DeviceProfile("Short Stubby", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 67 | 275, 420, 3, 4, 48, 13, (hasAA ? 5 : 5), 48, R.xml.default_workspace_4x4)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 68 | deviceProfiles.add(new DeviceProfile("Stubby", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 69 | 255, 450, 3, 4, 48, 13, (hasAA ? 5 : 5), 48, R.xml.default_workspace_4x4)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 70 | deviceProfiles.add(new DeviceProfile("Nexus S", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 71 | 296, 491.33f, 4, 4, 48, 13, (hasAA ? 5 : 5), 48, R.xml.default_workspace_4x4)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 72 | deviceProfiles.add(new DeviceProfile("Nexus 4", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 73 | 335, 567, 4, 4, DEFAULT_ICON_SIZE_DP, 13, (hasAA ? 5 : 5), 56, R.xml.default_workspace_4x4)); |
Winson Chung | 3abfd16 | 2014-01-17 14:43:02 -0800 | [diff] [blame] | 74 | deviceProfiles.add(new DeviceProfile("Nexus 5", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 75 | 359, 567, 4, 4, DEFAULT_ICON_SIZE_DP, 13, (hasAA ? 5 : 5), 56, R.xml.default_workspace_4x4)); |
Winson Chung | 6d11011 | 2014-01-16 14:03:55 -0800 | [diff] [blame] | 76 | deviceProfiles.add(new DeviceProfile("Large Phone", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 77 | 406, 694, 5, 5, 64, 14.4f, 5, 56, R.xml.default_workspace_5x5)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 78 | // The tablet profile is odd in that the landscape orientation |
| 79 | // also includes the nav bar on the side |
| 80 | deviceProfiles.add(new DeviceProfile("Nexus 7", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 81 | 575, 904, 5, 6, 72, 14.4f, 7, 60, R.xml.default_workspace_5x6)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 82 | // Larger tablet profiles always have system bars on the top & bottom |
| 83 | deviceProfiles.add(new DeviceProfile("Nexus 10", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 84 | 727, 1207, 5, 6, 76, 14.4f, 7, 64, R.xml.default_workspace_5x6)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 85 | deviceProfiles.add(new DeviceProfile("20-inch Tablet", |
Adam Cohen | cee8c66 | 2014-10-16 09:49:52 -0700 | [diff] [blame] | 86 | 1527, 2527, 7, 7, 100, 20, 7, 72, R.xml.default_workspace_4x4)); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 87 | mMinWidth = dpiFromPx(minWidthPx, dm); |
| 88 | mMinHeight = dpiFromPx(minHeightPx, dm); |
Winson Chung | f7d4585 | 2013-10-10 18:57:15 -0700 | [diff] [blame] | 89 | mProfile = new DeviceProfile(context, deviceProfiles, |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 90 | mMinWidth, mMinHeight, |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 91 | widthPx, heightPx, |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 92 | awPx, ahPx, |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 93 | resources); |
| 94 | } |
| 95 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 96 | public DeviceProfile getDeviceProfile() { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 97 | return mProfile; |
| 98 | } |
| 99 | |
| 100 | public String toString() { |
| 101 | return "-------- DYNAMIC GRID ------- \n" + |
| 102 | "Wd: " + mProfile.minWidthDps + ", Hd: " + mProfile.minHeightDps + |
| 103 | ", W: " + mProfile.widthPx + ", H: " + mProfile.heightPx + |
| 104 | " [r: " + mProfile.numRows + ", c: " + mProfile.numColumns + |
Winson Chung | 6e1c0d3 | 2013-10-25 15:24:24 -0700 | [diff] [blame] | 105 | ", is: " + mProfile.iconSizePx + ", its: " + mProfile.iconTextSizePx + |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 106 | ", cw: " + mProfile.cellWidthPx + ", ch: " + mProfile.cellHeightPx + |
| 107 | ", hc: " + mProfile.numHotseatIcons + ", his: " + mProfile.hotseatIconSizePx + "]"; |
| 108 | } |
| 109 | } |