blob: cb354a6f1cbd61dfa98b140e39293d30d9eb68fd [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
19import android.content.Context;
Tony Wickhamd6b40372015-09-23 18:37:57 -070020import android.graphics.Rect;
Winson Chung3d503fb2011-07-13 17:25:49 -070021import android.util.AttributeSet;
Sunny Goyal07b69292018-01-08 14:19:34 -080022import android.view.Gravity;
Adam Cohena5f4e482013-10-11 12:10:28 -070023import android.view.MotionEvent;
Winsona49b1f72015-10-16 14:57:24 -070024import android.view.View;
Sunny Goyal4ffec482016-02-09 11:28:52 -080025import android.view.ViewDebug;
Sunny Goyal07b69292018-01-08 14:19:34 -080026import android.view.ViewGroup;
Winson Chung3d503fb2011-07-13 17:25:49 -070027import android.widget.FrameLayout;
28
Hyunyoung Songfc007472018-10-25 14:09:50 -070029import com.android.launcher3.logging.StatsLogUtils.LogContainerProvider;
Sunny Goyal6c46a6d2016-11-23 02:24:32 +053030import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
Hyunyoung Songddec1c72016-04-12 18:32:04 -070031import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
32
Sunny Goyal07b69292018-01-08 14:19:34 -080033public class Hotseat extends FrameLayout implements LogContainerProvider, Insettable {
Winson Chung3d503fb2011-07-13 17:25:49 -070034
Sunny Goyal07b69292018-01-08 14:19:34 -080035 private final Launcher mLauncher;
Winson Chung3d503fb2011-07-13 17:25:49 -070036 private CellLayout mContent;
37
Sunny Goyal4ffec482016-02-09 11:28:52 -080038 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal12069e62018-01-16 14:17:20 -080039 private boolean mHasVerticalHotseat;
Winson Chung3d503fb2011-07-13 17:25:49 -070040
41 public Hotseat(Context context) {
42 this(context, null);
43 }
44
45 public Hotseat(Context context, AttributeSet attrs) {
46 this(context, attrs, 0);
47 }
48
49 public Hotseat(Context context, AttributeSet attrs, int defStyle) {
50 super(context, attrs, defStyle);
Tony2fd02082016-10-07 12:50:01 -070051 mLauncher = Launcher.getLauncher(context);
Winson Chung3d503fb2011-07-13 17:25:49 -070052 }
53
Tony Wickham95cdb3a2016-02-18 14:37:07 -080054 public CellLayout getLayout() {
Winson Chung3d503fb2011-07-13 17:25:49 -070055 return mContent;
56 }
Winson Chung11a1a532013-09-13 11:14:45 -070057
Winson Chung3d503fb2011-07-13 17:25:49 -070058 /* Get the orientation invariant order of the item in the hotseat for persistence. */
59 int getOrderInHotseat(int x, int y) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -070060 return mHasVerticalHotseat ? (mContent.getCountY() - y - 1) : x;
Winson Chung3d503fb2011-07-13 17:25:49 -070061 }
Hyunyoung Song31178b82015-02-24 14:12:51 -080062
Winson Chung3d503fb2011-07-13 17:25:49 -070063 /* Get the orientation specific coordinates given an invariant order in the hotseat. */
64 int getCellXFromOrder(int rank) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -070065 return mHasVerticalHotseat ? 0 : rank;
Winson Chung3d503fb2011-07-13 17:25:49 -070066 }
Hyunyoung Song31178b82015-02-24 14:12:51 -080067
Winson Chung3d503fb2011-07-13 17:25:49 -070068 int getCellYFromOrder(int rank) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -070069 return mHasVerticalHotseat ? (mContent.getCountY() - (rank + 1)) : 0;
Hyunyoung Song31178b82015-02-24 14:12:51 -080070 }
71
Winson Chung3d503fb2011-07-13 17:25:49 -070072 @Override
73 protected void onFinishInflate() {
74 super.onFinishInflate();
Sunny Goyal12069e62018-01-16 14:17:20 -080075 mContent = findViewById(R.id.layout);
Winson Chung3d503fb2011-07-13 17:25:49 -070076 }
77
Sunny Goyal11e96492018-03-23 17:06:00 -070078 void resetLayout(boolean hasVerticalHotseat) {
Winson Chung3d503fb2011-07-13 17:25:49 -070079 mContent.removeAllViewsInLayout();
Sunny Goyal11e96492018-03-23 17:06:00 -070080 mHasVerticalHotseat = hasVerticalHotseat;
81 InvariantDeviceProfile idp = mLauncher.getDeviceProfile().inv;
82 if (hasVerticalHotseat) {
83 mContent.setGridSize(1, idp.numHotseatIcons);
84 } else {
85 mContent.setGridSize(idp.numHotseatIcons, 1);
86 }
Winson Chung3d503fb2011-07-13 17:25:49 -070087 }
Adam Cohene25af792013-06-06 23:08:25 -070088
Adam Cohena5f4e482013-10-11 12:10:28 -070089 @Override
90 public boolean onInterceptTouchEvent(MotionEvent ev) {
91 // We don't want any clicks to go through to the hotseat unless the workspace is in
Sunny Goyal4583d092016-08-17 11:11:48 -070092 // the normal state or an accessible drag is in progress.
Tony Wickham0c7852f2016-12-02 14:47:04 -080093 return !mLauncher.getWorkspace().workspaceIconsCanBeDragged() &&
Sunny Goyal4583d092016-08-17 11:11:48 -070094 !mLauncher.getAccessibilityDelegate().isInAccessibleDrag();
Adam Cohena5f4e482013-10-11 12:10:28 -070095 }
Winson Chung8f1eff72015-05-28 17:33:40 -070096
97 @Override
Hyunyoung Songdf7ef682016-10-06 17:52:22 -070098 public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) {
Hyunyoung Songddec1c72016-04-12 18:32:04 -070099 target.gridX = info.cellX;
100 target.gridY = info.cellY;
Sunny Goyal6c46a6d2016-11-23 02:24:32 +0530101 targetParent.containerType = ContainerType.HOTSEAT;
Winson Chung8f1eff72015-05-28 17:33:40 -0700102 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800103
104 @Override
105 public void setInsets(Rect insets) {
106 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
107 DeviceProfile grid = mLauncher.getDeviceProfile();
Sunny Goyal12069e62018-01-16 14:17:20 -0800108
Sunny Goyal11e96492018-03-23 17:06:00 -0700109 if (grid.isVerticalBarLayout()) {
Sunny Goyal07b69292018-01-08 14:19:34 -0800110 lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800111 if (grid.isSeascape()) {
Sunny Goyal07b69292018-01-08 14:19:34 -0800112 lp.gravity = Gravity.LEFT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700113 lp.width = grid.hotseatBarSizePx + insets.left;
Sunny Goyal07b69292018-01-08 14:19:34 -0800114 } else {
115 lp.gravity = Gravity.RIGHT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700116 lp.width = grid.hotseatBarSizePx + insets.right;
Sunny Goyal07b69292018-01-08 14:19:34 -0800117 }
118 } else {
119 lp.gravity = Gravity.BOTTOM;
120 lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
121 lp.height = grid.hotseatBarSizePx + insets.bottom;
Sunny Goyal07b69292018-01-08 14:19:34 -0800122 }
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700123 Rect padding = grid.getHotseatLayoutPadding();
124 getLayout().setPadding(padding.left, padding.top, padding.right, padding.bottom);
125
Sunny Goyal07b69292018-01-08 14:19:34 -0800126 setLayoutParams(lp);
127 InsettableFrameLayout.dispatchInsets(this, insets);
128 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700129}