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 | |
| 19 | import android.content.Context; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 20 | import android.graphics.Rect; |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 21 | import android.graphics.drawable.Drawable; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 22 | import android.util.AttributeSet; |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 23 | import android.view.LayoutInflater; |
Adam Cohen | a5f4e48 | 2013-10-11 12:10:28 -0700 | [diff] [blame] | 24 | import android.view.MotionEvent; |
Winson | a49b1f7 | 2015-10-16 14:57:24 -0700 | [diff] [blame] | 25 | import android.view.View; |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 26 | import android.view.ViewDebug; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 27 | import android.widget.FrameLayout; |
Adam Cohen | 61f560d | 2013-09-30 15:58:20 -0700 | [diff] [blame] | 28 | import android.widget.TextView; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 29 | |
Hyunyoung Song | ddec1c7 | 2016-04-12 18:32:04 -0700 | [diff] [blame^] | 30 | import com.android.launcher3.logging.UserEventLogger; |
| 31 | import com.android.launcher3.userevent.nano.LauncherLogProto; |
| 32 | import com.android.launcher3.userevent.nano.LauncherLogProto.Target; |
| 33 | |
Winson Chung | 8f1eff7 | 2015-05-28 17:33:40 -0700 | [diff] [blame] | 34 | public class Hotseat extends FrameLayout |
Hyunyoung Song | ddec1c7 | 2016-04-12 18:32:04 -0700 | [diff] [blame^] | 35 | implements UserEventLogger.LaunchSourceProvider{ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 36 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 37 | private CellLayout mContent; |
| 38 | |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 39 | private Launcher mLauncher; |
| 40 | |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 41 | @ViewDebug.ExportedProperty(category = "launcher") |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 42 | private int mAllAppsButtonRank; |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 43 | |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 44 | @ViewDebug.ExportedProperty(category = "launcher") |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 45 | private final boolean mHasVerticalHotseat; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 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); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 57 | mLauncher = (Launcher) context; |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 58 | mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Tony Wickham | 95cdb3a | 2016-02-18 14:37:07 -0800 | [diff] [blame] | 61 | public CellLayout getLayout() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 62 | return mContent; |
| 63 | } |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
Winson Chung | c393b07 | 2015-05-20 15:03:13 -0700 | [diff] [blame] | 66 | * Returns whether there are other icons than the all apps button in the hotseat. |
| 67 | */ |
| 68 | public boolean hasIcons() { |
| 69 | return mContent.getShortcutsAndWidgets().getChildCount() > 1; |
| 70 | } |
| 71 | |
| 72 | /** |
Winson Chung | 11a1a53 | 2013-09-13 11:14:45 -0700 | [diff] [blame] | 73 | * Registers the specified listener on the cell layout of the hotseat. |
| 74 | */ |
| 75 | @Override |
| 76 | public void setOnLongClickListener(OnLongClickListener l) { |
| 77 | mContent.setOnLongClickListener(l); |
| 78 | } |
Tony Wickham | 6cbd222 | 2015-11-09 17:51:08 -0800 | [diff] [blame] | 79 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 80 | /* Get the orientation invariant order of the item in the hotseat for persistence. */ |
| 81 | int getOrderInHotseat(int x, int y) { |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 82 | return mHasVerticalHotseat ? (mContent.getCountY() - y - 1) : x; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 83 | } |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 84 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 85 | /* Get the orientation specific coordinates given an invariant order in the hotseat. */ |
| 86 | int getCellXFromOrder(int rank) { |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 87 | return mHasVerticalHotseat ? 0 : rank; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 88 | } |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 89 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 90 | int getCellYFromOrder(int rank) { |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 91 | return mHasVerticalHotseat ? (mContent.getCountY() - (rank + 1)) : 0; |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 94 | public boolean isAllAppsButtonRank(int rank) { |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 95 | return rank == mAllAppsButtonRank; |
Winson Chung | f30ad5f | 2011-08-08 10:55:42 -0700 | [diff] [blame] | 96 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 97 | |
| 98 | @Override |
| 99 | protected void onFinishInflate() { |
| 100 | super.onFinishInflate(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 101 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 102 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 103 | mAllAppsButtonRank = grid.inv.hotseatAllAppsRank; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 104 | mContent = (CellLayout) findViewById(R.id.layout); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 105 | if (grid.isLandscape && !grid.isLargeTablet) { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 106 | mContent.setGridSize(1, (int) grid.inv.numHotseatIcons); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 107 | } else { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 108 | mContent.setGridSize((int) grid.inv.numHotseatIcons, 1); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 109 | } |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 110 | mContent.setIsHotseat(true); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 111 | |
| 112 | resetLayout(); |
| 113 | } |
| 114 | |
| 115 | void resetLayout() { |
| 116 | mContent.removeAllViewsInLayout(); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 117 | |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 118 | // Add the Apps button |
| 119 | Context context = getContext(); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 120 | |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 121 | LayoutInflater inflater = LayoutInflater.from(context); |
| 122 | TextView allAppsButton = (TextView) |
| 123 | inflater.inflate(R.layout.all_apps_button, mContent, false); |
| 124 | Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon); |
Adam Cohen | 71b0473 | 2014-06-11 10:36:14 -0700 | [diff] [blame] | 125 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 126 | mLauncher.resizeIconDrawable(d); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 127 | int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down); |
| 128 | Rect bounds = d.getBounds(); |
| 129 | d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx, |
| 130 | bounds.bottom - scaleDownPx / 2); |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 131 | allAppsButton.setCompoundDrawables(null, d, null, null); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 132 | |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 133 | allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label)); |
| 134 | allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener()); |
| 135 | if (mLauncher != null) { |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 136 | mLauncher.setAllAppsButton(allAppsButton); |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 137 | allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener()); |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 138 | allAppsButton.setOnClickListener(mLauncher); |
Winson Chung | 76648c5 | 2015-07-10 14:33:23 -0700 | [diff] [blame] | 139 | allAppsButton.setOnLongClickListener(mLauncher); |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 140 | allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 141 | } |
Sunny Goyal | c9acdd5 | 2015-02-26 12:34:42 -0800 | [diff] [blame] | 142 | |
| 143 | // Note: We do this to ensure that the hotseat is always laid out in the orientation of |
| 144 | // the hotseat in order regardless of which orientation they were added |
| 145 | int x = getCellXFromOrder(mAllAppsButtonRank); |
| 146 | int y = getCellYFromOrder(mAllAppsButtonRank); |
| 147 | CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x,y,1,1); |
| 148 | lp.canReorder = false; |
| 149 | mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 150 | } |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 151 | |
Adam Cohen | a5f4e48 | 2013-10-11 12:10:28 -0700 | [diff] [blame] | 152 | @Override |
| 153 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 154 | // We don't want any clicks to go through to the hotseat unless the workspace is in |
| 155 | // the normal state. |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 156 | if (mLauncher.getWorkspace().workspaceInModalState()) { |
Adam Cohen | a5f4e48 | 2013-10-11 12:10:28 -0700 | [diff] [blame] | 157 | return true; |
| 158 | } |
| 159 | return false; |
| 160 | } |
Winson Chung | 8f1eff7 | 2015-05-28 17:33:40 -0700 | [diff] [blame] | 161 | |
| 162 | @Override |
Hyunyoung Song | ddec1c7 | 2016-04-12 18:32:04 -0700 | [diff] [blame^] | 163 | public void fillInLaunchSourceData(View v, ItemInfo info, Target target, Target targetParent) { |
| 164 | target.itemType = LauncherLogProto.APP_ICON; |
| 165 | target.gridX = info.cellX; |
| 166 | target.gridY = info.cellY; |
| 167 | targetParent.containerType = LauncherLogProto.HOTSEAT; |
Winson Chung | 8f1eff7 | 2015-05-28 17:33:40 -0700 | [diff] [blame] | 168 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 169 | } |