blob: d28e96f2de23d92d2c7d5dfc25bddb1635d01eb3 [file] [log] [blame]
Winson Chung3d503fb2011-07-13 17:25:49 -07001/*
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 Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Winson Chung3d503fb2011-07-13 17:25:49 -070018
Adam Cohene25af792013-06-06 23:08:25 -070019import android.content.ComponentName;
Winson Chung3d503fb2011-07-13 17:25:49 -070020import android.content.Context;
Adam Cohene25af792013-06-06 23:08:25 -070021import android.content.Intent;
Winson Chung3d503fb2011-07-13 17:25:49 -070022import android.content.res.Configuration;
Winson Chung0e721a42012-08-02 17:40:30 -070023import android.content.res.Resources;
Winson Chung3d503fb2011-07-13 17:25:49 -070024import android.content.res.TypedArray;
25import android.util.AttributeSet;
26import android.view.LayoutInflater;
Winson Chung64359a52013-07-08 17:17:08 -070027import android.util.Log;
Michael Jurka5130e402011-10-13 04:55:35 -070028import android.view.MotionEvent;
Winson Chung3d503fb2011-07-13 17:25:49 -070029import android.view.View;
30import android.widget.FrameLayout;
31
Daniel Sandler325dc232013-06-05 22:57:57 -040032import com.android.launcher3.R;
Winson Chung3d503fb2011-07-13 17:25:49 -070033
Adam Cohene25af792013-06-06 23:08:25 -070034import java.util.ArrayList;
35
Winson Chung3d503fb2011-07-13 17:25:49 -070036public class Hotseat extends FrameLayout {
Michael Jurka3a9fced2012-04-13 14:44:29 -070037 @SuppressWarnings("unused")
Winson Chungf30ad5f2011-08-08 10:55:42 -070038 private static final String TAG = "Hotseat";
Winson Chung3d503fb2011-07-13 17:25:49 -070039
Winson Chung3d503fb2011-07-13 17:25:49 -070040 private CellLayout mContent;
41
Andrew Flynn0dca1ec2012-02-29 13:33:22 -080042 private int mAllAppsButtonRank;
Adam Cohen307fe232012-08-16 17:55:58 -070043
Winson Chung0e721a42012-08-02 17:40:30 -070044 private boolean mTransposeLayoutWithOrientation;
Winson Chung3d503fb2011-07-13 17:25:49 -070045 private boolean mIsLandscape;
46
47 public Hotseat(Context context) {
48 this(context, null);
49 }
50
51 public Hotseat(Context context, AttributeSet attrs) {
52 this(context, attrs, 0);
53 }
54
55 public Hotseat(Context context, AttributeSet attrs, int defStyle) {
56 super(context, attrs, defStyle);
57
58 TypedArray a = context.obtainStyledAttributes(attrs,
59 R.styleable.Hotseat, defStyle, 0);
Winson Chung0e721a42012-08-02 17:40:30 -070060 Resources r = context.getResources();
Winson Chung0e721a42012-08-02 17:40:30 -070061 mTransposeLayoutWithOrientation =
62 r.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chung3d503fb2011-07-13 17:25:49 -070063 mIsLandscape = context.getResources().getConfiguration().orientation ==
64 Configuration.ORIENTATION_LANDSCAPE;
65 }
66
67 public void setup(Launcher launcher) {
Adam Cohenac56cff2011-09-28 20:45:37 -070068 setOnKeyListener(new HotseatIconKeyEventListener());
Winson Chung3d503fb2011-07-13 17:25:49 -070069 }
70
71 CellLayout getLayout() {
72 return mContent;
73 }
Winson Chung0e721a42012-08-02 17:40:30 -070074
75 private boolean hasVerticalHotseat() {
76 return (mIsLandscape && mTransposeLayoutWithOrientation);
77 }
Winson Chung3d503fb2011-07-13 17:25:49 -070078
79 /* Get the orientation invariant order of the item in the hotseat for persistence. */
80 int getOrderInHotseat(int x, int y) {
Winson Chung0e721a42012-08-02 17:40:30 -070081 return hasVerticalHotseat() ? (mContent.getCountY() - y - 1) : x;
Winson Chung3d503fb2011-07-13 17:25:49 -070082 }
83 /* Get the orientation specific coordinates given an invariant order in the hotseat. */
84 int getCellXFromOrder(int rank) {
Winson Chung0e721a42012-08-02 17:40:30 -070085 return hasVerticalHotseat() ? 0 : rank;
Winson Chung3d503fb2011-07-13 17:25:49 -070086 }
87 int getCellYFromOrder(int rank) {
Winson Chung0e721a42012-08-02 17:40:30 -070088 return hasVerticalHotseat() ? (mContent.getCountY() - (rank + 1)) : 0;
Winson Chung3d503fb2011-07-13 17:25:49 -070089 }
Andrew Flynn0dca1ec2012-02-29 13:33:22 -080090 public boolean isAllAppsButtonRank(int rank) {
Adam Cohen947dc542013-06-06 22:43:33 -070091 return false;
Winson Chungf30ad5f2011-08-08 10:55:42 -070092 }
Winson Chung3d503fb2011-07-13 17:25:49 -070093
94 @Override
95 protected void onFinishInflate() {
96 super.onFinishInflate();
Winson Chung5f8afe62013-08-12 16:19:28 -070097 LauncherAppState app = LauncherAppState.getInstance();
98 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
99
100 mAllAppsButtonRank = (int) (grid.numHotseatIcons / 2);
Winson Chung3d503fb2011-07-13 17:25:49 -0700101 mContent = (CellLayout) findViewById(R.id.layout);
Winson Chung5f8afe62013-08-12 16:19:28 -0700102 if (grid.isLandscape && !grid.isLargeTablet()) {
103 mContent.setGridSize(1, (int) grid.numHotseatIcons);
104 } else {
105 mContent.setGridSize((int) grid.numHotseatIcons, 1);
106 }
Andrew Flynn0dca1ec2012-02-29 13:33:22 -0800107 mContent.setIsHotseat(true);
Winson Chung3d503fb2011-07-13 17:25:49 -0700108
109 resetLayout();
110 }
111
112 void resetLayout() {
113 mContent.removeAllViewsInLayout();
Winson Chung3d503fb2011-07-13 17:25:49 -0700114 }
Adam Cohene25af792013-06-06 23:08:25 -0700115
Winson Chung156ab5b2013-07-12 14:14:16 -0700116 void addAllAppsFolder(IconCache iconCache,
117 ArrayList<ApplicationInfo> allApps, ArrayList<ComponentName> onWorkspace,
118 Launcher launcher, Workspace workspace) {
Adam Cohene25af792013-06-06 23:08:25 -0700119 FolderInfo fi = new FolderInfo();
120
121 fi.cellX = getCellXFromOrder(mAllAppsButtonRank);
122 fi.cellY = getCellYFromOrder(mAllAppsButtonRank);
123 fi.spanX = 1;
124 fi.spanY = 1;
125 fi.container = LauncherSettings.Favorites.CONTAINER_HOTSEAT;
Adam Cohendcd297f2013-06-18 13:13:40 -0700126 fi.screenId = mAllAppsButtonRank;
Adam Cohene25af792013-06-06 23:08:25 -0700127 fi.itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
Daniel Sandlerdd3204b2013-08-15 15:47:41 -0700128 fi.title = "More Apps";
Adam Cohendcd297f2013-06-18 13:13:40 -0700129 LauncherModel.addItemToDatabase(launcher, fi, fi.container, fi.screenId, fi.cellX,
Adam Cohene25af792013-06-06 23:08:25 -0700130 fi.cellY, false);
131 FolderIcon folder = FolderIcon.fromXml(R.layout.folder_icon, launcher,
132 getLayout(), fi, iconCache);
Winson Chung156ab5b2013-07-12 14:14:16 -0700133 workspace.addInScreen(folder, fi.container, fi.screenId, fi.cellX, fi.cellY,
134 fi.spanX, fi.spanY);
Adam Cohene25af792013-06-06 23:08:25 -0700135
136 for (ApplicationInfo info: allApps) {
137 ComponentName cn = info.intent.getComponent();
138 if (!onWorkspace.contains(cn)) {
Daniel Sandlerdd3204b2013-08-15 15:47:41 -0700139 Log.d(TAG, "Adding to 'more apps': " + info.intent);
Adam Cohene25af792013-06-06 23:08:25 -0700140 ShortcutInfo si = info.makeShortcut();
141 fi.add(si);
142 }
143 }
144 }
145
146 void addAppsToAllAppsFolder(ArrayList<ApplicationInfo> apps) {
147 View v = mContent.getChildAt(getCellXFromOrder(mAllAppsButtonRank), getCellYFromOrder(mAllAppsButtonRank));
148 FolderIcon fi = null;
149
150 if (v instanceof FolderIcon) {
151 fi = (FolderIcon) v;
152 } else {
153 return;
154 }
155
156 FolderInfo info = fi.getFolderInfo();
157 for (ApplicationInfo a: apps) {
158 ComponentName cn = a.intent.getComponent();
159 ShortcutInfo si = a.makeShortcut();
160 info.add(si);
161 }
162 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700163}