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 17 package com.android.launcher3; 18 19 import android.content.Context; 20 import android.graphics.Rect; 21 import android.util.AttributeSet; 22 import android.view.Gravity; 23 import android.view.MotionEvent; 24 import android.view.View; 25 import android.view.ViewDebug; 26 import android.view.ViewGroup; 27 import android.widget.FrameLayout; 28 29 import com.android.launcher3.graphics.RotationMode; 30 import com.android.launcher3.logging.StatsLogUtils.LogContainerProvider; 31 import com.android.launcher3.userevent.nano.LauncherLogProto; 32 import com.android.launcher3.userevent.nano.LauncherLogProto.Target; 33 import com.android.launcher3.views.Transposable; 34 35 public class Hotseat extends CellLayout implements LogContainerProvider, Insettable, Transposable { 36 37 @ViewDebug.ExportedProperty(category = "launcher") 38 private boolean mHasVerticalHotseat; 39 Hotseat(Context context)40 public Hotseat(Context context) { 41 this(context, null); 42 } 43 Hotseat(Context context, AttributeSet attrs)44 public Hotseat(Context context, AttributeSet attrs) { 45 this(context, attrs, 0); 46 } 47 Hotseat(Context context, AttributeSet attrs, int defStyle)48 public Hotseat(Context context, AttributeSet attrs, int defStyle) { 49 super(context, attrs, defStyle); 50 } 51 52 /* Get the orientation specific coordinates given an invariant order in the hotseat. */ getCellXFromOrder(int rank)53 int getCellXFromOrder(int rank) { 54 return mHasVerticalHotseat ? 0 : rank; 55 } 56 getCellYFromOrder(int rank)57 int getCellYFromOrder(int rank) { 58 return mHasVerticalHotseat ? (getCountY() - (rank + 1)) : 0; 59 } 60 resetLayout(boolean hasVerticalHotseat)61 public void resetLayout(boolean hasVerticalHotseat) { 62 removeAllViewsInLayout(); 63 mHasVerticalHotseat = hasVerticalHotseat; 64 InvariantDeviceProfile idp = mActivity.getDeviceProfile().inv; 65 if (hasVerticalHotseat) { 66 setGridSize(1, idp.numHotseatIcons); 67 } else { 68 setGridSize(idp.numHotseatIcons, 1); 69 } 70 } 71 72 @Override fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent)73 public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) { 74 target.gridX = info.cellX; 75 target.gridY = info.cellY; 76 targetParent.containerType = LauncherLogProto.ContainerType.HOTSEAT; 77 } 78 79 @Override setInsets(Rect insets)80 public void setInsets(Rect insets) { 81 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); 82 DeviceProfile grid = mActivity.getWallpaperDeviceProfile(); 83 insets = grid.getInsets(); 84 85 if (grid.isVerticalBarLayout()) { 86 lp.height = ViewGroup.LayoutParams.MATCH_PARENT; 87 if (grid.isSeascape()) { 88 lp.gravity = Gravity.LEFT; 89 lp.width = grid.hotseatBarSizePx + insets.left; 90 } else { 91 lp.gravity = Gravity.RIGHT; 92 lp.width = grid.hotseatBarSizePx + insets.right; 93 } 94 } else { 95 lp.gravity = Gravity.BOTTOM; 96 lp.width = ViewGroup.LayoutParams.MATCH_PARENT; 97 lp.height = grid.hotseatBarSizePx + insets.bottom; 98 } 99 Rect padding = grid.getHotseatLayoutPadding(); 100 setPadding(padding.left, padding.top, padding.right, padding.bottom); 101 102 setLayoutParams(lp); 103 InsettableFrameLayout.dispatchInsets(this, insets); 104 } 105 106 @Override onTouchEvent(MotionEvent event)107 public boolean onTouchEvent(MotionEvent event) { 108 // Don't let if follow through to workspace 109 return true; 110 } 111 112 @Override getRotationMode()113 public RotationMode getRotationMode() { 114 return Launcher.getLauncher(getContext()).getRotationMode(); 115 } 116 } 117