blob: 78bd2ff50276154f89d44d644ebbdd5ba88d45c1 [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
Samuel Fufaa579ddc2020-02-27 16:59:19 -080019import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
20
Winson Chung3d503fb2011-07-13 17:25:49 -070021import android.content.Context;
Tony Wickhamd6b40372015-09-23 18:37:57 -070022import android.graphics.Rect;
Winson Chung3d503fb2011-07-13 17:25:49 -070023import android.util.AttributeSet;
Sunny Goyal07b69292018-01-08 14:19:34 -080024import android.view.Gravity;
Sunny Goyald1580972019-04-09 11:52:49 -070025import android.view.MotionEvent;
Sunny Goyal4ffec482016-02-09 11:28:52 -080026import android.view.ViewDebug;
Sunny Goyal07b69292018-01-08 14:19:34 -080027import android.view.ViewGroup;
Winson Chung3d503fb2011-07-13 17:25:49 -070028import android.widget.FrameLayout;
29
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;
33
Samuel Fufaa579ddc2020-02-27 16:59:19 -080034import java.util.ArrayList;
35
Sunny Goyalc4d32012020-04-03 17:10:11 -070036public class Hotseat extends CellLayout implements LogContainerProvider, Insettable {
Winson Chung3d503fb2011-07-13 17:25:49 -070037
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);
Winson Chung3d503fb2011-07-13 17:25:49 -070051 }
52
Samuel Fufaaed008d2019-12-19 10:57:40 -080053 /**
54 * Returns orientation specific cell X given invariant order in the hotseat
55 */
56 public int getCellXFromOrder(int rank) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -070057 return mHasVerticalHotseat ? 0 : rank;
Winson Chung3d503fb2011-07-13 17:25:49 -070058 }
Hyunyoung Song31178b82015-02-24 14:12:51 -080059
Samuel Fufaaed008d2019-12-19 10:57:40 -080060 /**
61 * Returns orientation specific cell Y given invariant order in the hotseat
62 */
63 public int getCellYFromOrder(int rank) {
Sunny Goyal876e4622018-11-02 13:50:40 -070064 return mHasVerticalHotseat ? (getCountY() - (rank + 1)) : 0;
Winson Chung3d503fb2011-07-13 17:25:49 -070065 }
66
Sunny Goyalab770a12018-11-14 15:17:26 -080067 public void resetLayout(boolean hasVerticalHotseat) {
Sunny Goyal876e4622018-11-02 13:50:40 -070068 removeAllViewsInLayout();
Sunny Goyal11e96492018-03-23 17:06:00 -070069 mHasVerticalHotseat = hasVerticalHotseat;
Sunny Goyalab770a12018-11-14 15:17:26 -080070 InvariantDeviceProfile idp = mActivity.getDeviceProfile().inv;
Sunny Goyal11e96492018-03-23 17:06:00 -070071 if (hasVerticalHotseat) {
Sunny Goyal876e4622018-11-02 13:50:40 -070072 setGridSize(1, idp.numHotseatIcons);
Sunny Goyal11e96492018-03-23 17:06:00 -070073 } else {
Sunny Goyal876e4622018-11-02 13:50:40 -070074 setGridSize(idp.numHotseatIcons, 1);
Sunny Goyal11e96492018-03-23 17:06:00 -070075 }
Winson Chung3d503fb2011-07-13 17:25:49 -070076 }
Adam Cohene25af792013-06-06 23:08:25 -070077
Adam Cohena5f4e482013-10-11 12:10:28 -070078 @Override
Samuel Fufaa579ddc2020-02-27 16:59:19 -080079 public void fillInLogContainerData(ItemInfo childInfo, Target child,
80 ArrayList<Target> parents) {
81 child.rank = childInfo.rank;
82 child.gridX = childInfo.cellX;
83 child.gridY = childInfo.cellY;
84 parents.add(newContainerTarget(LauncherLogProto.ContainerType.HOTSEAT));
Winson Chung8f1eff72015-05-28 17:33:40 -070085 }
Sunny Goyal07b69292018-01-08 14:19:34 -080086
87 @Override
88 public void setInsets(Rect insets) {
89 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
Sunny Goyalc4d32012020-04-03 17:10:11 -070090 DeviceProfile grid = mActivity.getDeviceProfile();
Sunny Goyalae6e3182019-04-30 12:04:37 -070091 insets = grid.getInsets();
Sunny Goyal12069e62018-01-16 14:17:20 -080092
Sunny Goyal11e96492018-03-23 17:06:00 -070093 if (grid.isVerticalBarLayout()) {
Sunny Goyal07b69292018-01-08 14:19:34 -080094 lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -080095 if (grid.isSeascape()) {
Sunny Goyal07b69292018-01-08 14:19:34 -080096 lp.gravity = Gravity.LEFT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -070097 lp.width = grid.hotseatBarSizePx + insets.left;
Sunny Goyal07b69292018-01-08 14:19:34 -080098 } else {
99 lp.gravity = Gravity.RIGHT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700100 lp.width = grid.hotseatBarSizePx + insets.right;
Sunny Goyal07b69292018-01-08 14:19:34 -0800101 }
102 } else {
103 lp.gravity = Gravity.BOTTOM;
104 lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
105 lp.height = grid.hotseatBarSizePx + insets.bottom;
Sunny Goyal07b69292018-01-08 14:19:34 -0800106 }
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700107 Rect padding = grid.getHotseatLayoutPadding();
Sunny Goyal876e4622018-11-02 13:50:40 -0700108 setPadding(padding.left, padding.top, padding.right, padding.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700109
Sunny Goyal07b69292018-01-08 14:19:34 -0800110 setLayoutParams(lp);
111 InsettableFrameLayout.dispatchInsets(this, insets);
112 }
Sunny Goyald1580972019-04-09 11:52:49 -0700113
114 @Override
115 public boolean onTouchEvent(MotionEvent event) {
Samuel Fufaeacaf8a2019-09-17 11:31:11 -0700116 return event.getY() > getCellHeight();
Sunny Goyald1580972019-04-09 11:52:49 -0700117 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700118}