Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 18 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 19 | import android.content.ComponentName; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.res.Configuration; |
Winson Chung | 0e721a4 | 2012-08-02 17:40:30 -0700 | [diff] [blame] | 22 | import android.content.res.Resources; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 23 | import android.util.AttributeSet; |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 24 | import android.util.Log; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 25 | import android.view.View; |
| 26 | import android.widget.FrameLayout; |
| 27 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 28 | import java.util.ArrayList; |
| 29 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 30 | public class Hotseat extends FrameLayout { |
Winson Chung | f30ad5f | 2011-08-08 10:55:42 -0700 | [diff] [blame] | 31 | private static final String TAG = "Hotseat"; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 32 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 33 | private CellLayout mContent; |
| 34 | |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 35 | private int mAllAppsButtonRank; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 36 | |
Winson Chung | 0e721a4 | 2012-08-02 17:40:30 -0700 | [diff] [blame] | 37 | private boolean mTransposeLayoutWithOrientation; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 38 | private boolean mIsLandscape; |
| 39 | |
| 40 | public Hotseat(Context context) { |
| 41 | this(context, null); |
| 42 | } |
| 43 | |
| 44 | public Hotseat(Context context, AttributeSet attrs) { |
| 45 | this(context, attrs, 0); |
| 46 | } |
| 47 | |
| 48 | public Hotseat(Context context, AttributeSet attrs, int defStyle) { |
| 49 | super(context, attrs, defStyle); |
| 50 | |
Winson Chung | 0e721a4 | 2012-08-02 17:40:30 -0700 | [diff] [blame] | 51 | Resources r = context.getResources(); |
Winson Chung | 0e721a4 | 2012-08-02 17:40:30 -0700 | [diff] [blame] | 52 | mTransposeLayoutWithOrientation = |
| 53 | r.getBoolean(R.bool.hotseat_transpose_layout_with_orientation); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 54 | mIsLandscape = context.getResources().getConfiguration().orientation == |
| 55 | Configuration.ORIENTATION_LANDSCAPE; |
| 56 | } |
| 57 | |
| 58 | public void setup(Launcher launcher) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 59 | setOnKeyListener(new HotseatIconKeyEventListener()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | CellLayout getLayout() { |
| 63 | return mContent; |
| 64 | } |
Winson Chung | 0e721a4 | 2012-08-02 17:40:30 -0700 | [diff] [blame] | 65 | |
| 66 | private boolean hasVerticalHotseat() { |
| 67 | return (mIsLandscape && mTransposeLayoutWithOrientation); |
| 68 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 69 | |
| 70 | /* Get the orientation invariant order of the item in the hotseat for persistence. */ |
| 71 | int getOrderInHotseat(int x, int y) { |
Winson Chung | 0e721a4 | 2012-08-02 17:40:30 -0700 | [diff] [blame] | 72 | return hasVerticalHotseat() ? (mContent.getCountY() - y - 1) : x; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 73 | } |
| 74 | /* Get the orientation specific coordinates given an invariant order in the hotseat. */ |
| 75 | int getCellXFromOrder(int rank) { |
Winson Chung | 0e721a4 | 2012-08-02 17:40:30 -0700 | [diff] [blame] | 76 | return hasVerticalHotseat() ? 0 : rank; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 77 | } |
| 78 | int getCellYFromOrder(int rank) { |
Winson Chung | 0e721a4 | 2012-08-02 17:40:30 -0700 | [diff] [blame] | 79 | return hasVerticalHotseat() ? (mContent.getCountY() - (rank + 1)) : 0; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 80 | } |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 81 | public boolean isAllAppsButtonRank(int rank) { |
Adam Cohen | 947dc54 | 2013-06-06 22:43:33 -0700 | [diff] [blame] | 82 | return false; |
Winson Chung | f30ad5f | 2011-08-08 10:55:42 -0700 | [diff] [blame] | 83 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 84 | |
| 85 | @Override |
| 86 | protected void onFinishInflate() { |
| 87 | super.onFinishInflate(); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 88 | LauncherAppState app = LauncherAppState.getInstance(); |
| 89 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 90 | |
| 91 | mAllAppsButtonRank = (int) (grid.numHotseatIcons / 2); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 92 | mContent = (CellLayout) findViewById(R.id.layout); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 93 | if (grid.isLandscape && !grid.isLargeTablet()) { |
| 94 | mContent.setGridSize(1, (int) grid.numHotseatIcons); |
| 95 | } else { |
| 96 | mContent.setGridSize((int) grid.numHotseatIcons, 1); |
| 97 | } |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 98 | mContent.setIsHotseat(true); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 99 | |
| 100 | resetLayout(); |
| 101 | } |
| 102 | |
| 103 | void resetLayout() { |
| 104 | mContent.removeAllViewsInLayout(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 105 | } |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 106 | |
Winson Chung | 156ab5b | 2013-07-12 14:14:16 -0700 | [diff] [blame] | 107 | void addAllAppsFolder(IconCache iconCache, |
| 108 | ArrayList<ApplicationInfo> allApps, ArrayList<ComponentName> onWorkspace, |
| 109 | Launcher launcher, Workspace workspace) { |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 110 | FolderInfo fi = new FolderInfo(); |
| 111 | |
| 112 | fi.cellX = getCellXFromOrder(mAllAppsButtonRank); |
| 113 | fi.cellY = getCellYFromOrder(mAllAppsButtonRank); |
| 114 | fi.spanX = 1; |
| 115 | fi.spanY = 1; |
| 116 | fi.container = LauncherSettings.Favorites.CONTAINER_HOTSEAT; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 117 | fi.screenId = mAllAppsButtonRank; |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 118 | fi.itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER; |
Daniel Sandler | dd3204b | 2013-08-15 15:47:41 -0700 | [diff] [blame] | 119 | fi.title = "More Apps"; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 120 | LauncherModel.addItemToDatabase(launcher, fi, fi.container, fi.screenId, fi.cellX, |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 121 | fi.cellY, false); |
| 122 | FolderIcon folder = FolderIcon.fromXml(R.layout.folder_icon, launcher, |
| 123 | getLayout(), fi, iconCache); |
Winson Chung | 156ab5b | 2013-07-12 14:14:16 -0700 | [diff] [blame] | 124 | workspace.addInScreen(folder, fi.container, fi.screenId, fi.cellX, fi.cellY, |
| 125 | fi.spanX, fi.spanY); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 126 | |
| 127 | for (ApplicationInfo info: allApps) { |
| 128 | ComponentName cn = info.intent.getComponent(); |
| 129 | if (!onWorkspace.contains(cn)) { |
Daniel Sandler | dd3204b | 2013-08-15 15:47:41 -0700 | [diff] [blame] | 130 | Log.d(TAG, "Adding to 'more apps': " + info.intent); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 131 | ShortcutInfo si = info.makeShortcut(); |
| 132 | fi.add(si); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | void addAppsToAllAppsFolder(ArrayList<ApplicationInfo> apps) { |
| 138 | View v = mContent.getChildAt(getCellXFromOrder(mAllAppsButtonRank), getCellYFromOrder(mAllAppsButtonRank)); |
| 139 | FolderIcon fi = null; |
| 140 | |
| 141 | if (v instanceof FolderIcon) { |
| 142 | fi = (FolderIcon) v; |
| 143 | } else { |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | FolderInfo info = fi.getFolderInfo(); |
| 148 | for (ApplicationInfo a: apps) { |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 149 | ShortcutInfo si = a.makeShortcut(); |
| 150 | info.add(si); |
| 151 | } |
| 152 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 153 | } |