blob: b89e727207bc85fb8dd822c668afb23bb61e8e87 [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;
Sunny Goyald1580972019-04-09 11:52:49 -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
Sunny Goyalae6e3182019-04-30 12:04:37 -070029import com.android.launcher3.graphics.RotationMode;
Hyunyoung Songfc007472018-10-25 14:09:50 -070030import com.android.launcher3.logging.StatsLogUtils.LogContainerProvider;
Sunny Goyal876e4622018-11-02 13:50:40 -070031import com.android.launcher3.userevent.nano.LauncherLogProto;
Hyunyoung Songddec1c72016-04-12 18:32:04 -070032import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Sunny Goyalae6e3182019-04-30 12:04:37 -070033import com.android.launcher3.views.Transposable;
Hyunyoung Songddec1c72016-04-12 18:32:04 -070034
Sunny Goyalae6e3182019-04-30 12:04:37 -070035public class Hotseat extends CellLayout implements LogContainerProvider, Insettable, Transposable {
Winson Chung3d503fb2011-07-13 17:25:49 -070036
Sunny Goyal4ffec482016-02-09 11:28:52 -080037 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal12069e62018-01-16 14:17:20 -080038 private boolean mHasVerticalHotseat;
Winson Chung3d503fb2011-07-13 17:25:49 -070039
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);
Winson Chung3d503fb2011-07-13 17:25:49 -070050 }
51
Samuel Fufaaed008d2019-12-19 10:57:40 -080052 /**
53 * Returns orientation specific cell X given invariant order in the hotseat
54 */
55 public int getCellXFromOrder(int rank) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -070056 return mHasVerticalHotseat ? 0 : rank;
Winson Chung3d503fb2011-07-13 17:25:49 -070057 }
Hyunyoung Song31178b82015-02-24 14:12:51 -080058
Samuel Fufaaed008d2019-12-19 10:57:40 -080059 /**
60 * Returns orientation specific cell Y given invariant order in the hotseat
61 */
62 public int getCellYFromOrder(int rank) {
Sunny Goyal876e4622018-11-02 13:50:40 -070063 return mHasVerticalHotseat ? (getCountY() - (rank + 1)) : 0;
Winson Chung3d503fb2011-07-13 17:25:49 -070064 }
65
Sunny Goyalab770a12018-11-14 15:17:26 -080066 public void resetLayout(boolean hasVerticalHotseat) {
Sunny Goyal876e4622018-11-02 13:50:40 -070067 removeAllViewsInLayout();
Sunny Goyal11e96492018-03-23 17:06:00 -070068 mHasVerticalHotseat = hasVerticalHotseat;
Sunny Goyalab770a12018-11-14 15:17:26 -080069 InvariantDeviceProfile idp = mActivity.getDeviceProfile().inv;
Sunny Goyal11e96492018-03-23 17:06:00 -070070 if (hasVerticalHotseat) {
Sunny Goyal876e4622018-11-02 13:50:40 -070071 setGridSize(1, idp.numHotseatIcons);
Sunny Goyal11e96492018-03-23 17:06:00 -070072 } else {
Sunny Goyal876e4622018-11-02 13:50:40 -070073 setGridSize(idp.numHotseatIcons, 1);
Sunny Goyal11e96492018-03-23 17:06:00 -070074 }
Winson Chung3d503fb2011-07-13 17:25:49 -070075 }
Adam Cohene25af792013-06-06 23:08:25 -070076
Adam Cohena5f4e482013-10-11 12:10:28 -070077 @Override
Hyunyoung Songdf7ef682016-10-06 17:52:22 -070078 public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) {
Hyunyoung Songddec1c72016-04-12 18:32:04 -070079 target.gridX = info.cellX;
80 target.gridY = info.cellY;
Sunny Goyal876e4622018-11-02 13:50:40 -070081 targetParent.containerType = LauncherLogProto.ContainerType.HOTSEAT;
Winson Chung8f1eff72015-05-28 17:33:40 -070082 }
Sunny Goyal07b69292018-01-08 14:19:34 -080083
84 @Override
85 public void setInsets(Rect insets) {
86 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
Sunny Goyalae6e3182019-04-30 12:04:37 -070087 DeviceProfile grid = mActivity.getWallpaperDeviceProfile();
88 insets = grid.getInsets();
Sunny Goyal12069e62018-01-16 14:17:20 -080089
Sunny Goyal11e96492018-03-23 17:06:00 -070090 if (grid.isVerticalBarLayout()) {
Sunny Goyal07b69292018-01-08 14:19:34 -080091 lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -080092 if (grid.isSeascape()) {
Sunny Goyal07b69292018-01-08 14:19:34 -080093 lp.gravity = Gravity.LEFT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -070094 lp.width = grid.hotseatBarSizePx + insets.left;
Sunny Goyal07b69292018-01-08 14:19:34 -080095 } else {
96 lp.gravity = Gravity.RIGHT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -070097 lp.width = grid.hotseatBarSizePx + insets.right;
Sunny Goyal07b69292018-01-08 14:19:34 -080098 }
99 } else {
100 lp.gravity = Gravity.BOTTOM;
101 lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
102 lp.height = grid.hotseatBarSizePx + insets.bottom;
Sunny Goyal07b69292018-01-08 14:19:34 -0800103 }
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700104 Rect padding = grid.getHotseatLayoutPadding();
Sunny Goyal876e4622018-11-02 13:50:40 -0700105 setPadding(padding.left, padding.top, padding.right, padding.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700106
Sunny Goyal07b69292018-01-08 14:19:34 -0800107 setLayoutParams(lp);
108 InsettableFrameLayout.dispatchInsets(this, insets);
109 }
Sunny Goyald1580972019-04-09 11:52:49 -0700110
111 @Override
112 public boolean onTouchEvent(MotionEvent event) {
Samuel Fufaeacaf8a2019-09-17 11:31:11 -0700113 return event.getY() > getCellHeight();
Sunny Goyald1580972019-04-09 11:52:49 -0700114 }
Sunny Goyalae6e3182019-04-30 12:04:37 -0700115
116 @Override
117 public RotationMode getRotationMode() {
118 return Launcher.getLauncher(getContext()).getRotationMode();
119 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700120}