blob: 6a625eb955652a270353236c6b23eb63b71a7fb7 [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;
20import android.content.res.Configuration;
Winson Chung0e721a42012-08-02 17:40:30 -070021import android.content.res.Resources;
Winson Chung3d503fb2011-07-13 17:25:49 -070022import android.content.res.TypedArray;
23import android.util.AttributeSet;
24import android.view.LayoutInflater;
Michael Jurka5130e402011-10-13 04:55:35 -070025import android.view.MotionEvent;
Winson Chung3d503fb2011-07-13 17:25:49 -070026import android.view.View;
27import android.widget.FrameLayout;
28
Daniel Sandler325dc232013-06-05 22:57:57 -040029import com.android.launcher3.R;
Winson Chung3d503fb2011-07-13 17:25:49 -070030
31public class Hotseat extends FrameLayout {
Michael Jurka3a9fced2012-04-13 14:44:29 -070032 @SuppressWarnings("unused")
Winson Chungf30ad5f2011-08-08 10:55:42 -070033 private static final String TAG = "Hotseat";
Winson Chung3d503fb2011-07-13 17:25:49 -070034
35 private Launcher mLauncher;
36 private CellLayout mContent;
37
38 private int mCellCountX;
39 private int mCellCountY;
Andrew Flynn0dca1ec2012-02-29 13:33:22 -080040 private int mAllAppsButtonRank;
Adam Cohen307fe232012-08-16 17:55:58 -070041
Winson Chung0e721a42012-08-02 17:40:30 -070042 private boolean mTransposeLayoutWithOrientation;
Winson Chung3d503fb2011-07-13 17:25:49 -070043 private boolean mIsLandscape;
44
45 public Hotseat(Context context) {
46 this(context, null);
47 }
48
49 public Hotseat(Context context, AttributeSet attrs) {
50 this(context, attrs, 0);
51 }
52
53 public Hotseat(Context context, AttributeSet attrs, int defStyle) {
54 super(context, attrs, defStyle);
55
56 TypedArray a = context.obtainStyledAttributes(attrs,
57 R.styleable.Hotseat, defStyle, 0);
Winson Chung0e721a42012-08-02 17:40:30 -070058 Resources r = context.getResources();
Winson Chung3d503fb2011-07-13 17:25:49 -070059 mCellCountX = a.getInt(R.styleable.Hotseat_cellCountX, -1);
60 mCellCountY = a.getInt(R.styleable.Hotseat_cellCountY, -1);
Winson Chung0e721a42012-08-02 17:40:30 -070061 mAllAppsButtonRank = r.getInteger(R.integer.hotseat_all_apps_index);
62 mTransposeLayoutWithOrientation =
63 r.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chung3d503fb2011-07-13 17:25:49 -070064 mIsLandscape = context.getResources().getConfiguration().orientation ==
65 Configuration.ORIENTATION_LANDSCAPE;
66 }
67
68 public void setup(Launcher launcher) {
69 mLauncher = launcher;
Adam Cohenac56cff2011-09-28 20:45:37 -070070 setOnKeyListener(new HotseatIconKeyEventListener());
Winson Chung3d503fb2011-07-13 17:25:49 -070071 }
72
73 CellLayout getLayout() {
74 return mContent;
75 }
Winson Chung0e721a42012-08-02 17:40:30 -070076
77 private boolean hasVerticalHotseat() {
78 return (mIsLandscape && mTransposeLayoutWithOrientation);
79 }
Winson Chung3d503fb2011-07-13 17:25:49 -070080
81 /* Get the orientation invariant order of the item in the hotseat for persistence. */
82 int getOrderInHotseat(int x, int y) {
Winson Chung0e721a42012-08-02 17:40:30 -070083 return hasVerticalHotseat() ? (mContent.getCountY() - y - 1) : x;
Winson Chung3d503fb2011-07-13 17:25:49 -070084 }
85 /* Get the orientation specific coordinates given an invariant order in the hotseat. */
86 int getCellXFromOrder(int rank) {
Winson Chung0e721a42012-08-02 17:40:30 -070087 return hasVerticalHotseat() ? 0 : rank;
Winson Chung3d503fb2011-07-13 17:25:49 -070088 }
89 int getCellYFromOrder(int rank) {
Winson Chung0e721a42012-08-02 17:40:30 -070090 return hasVerticalHotseat() ? (mContent.getCountY() - (rank + 1)) : 0;
Winson Chung3d503fb2011-07-13 17:25:49 -070091 }
Andrew Flynn0dca1ec2012-02-29 13:33:22 -080092 public boolean isAllAppsButtonRank(int rank) {
Adam Cohen947dc542013-06-06 22:43:33 -070093 return false;
Winson Chungf30ad5f2011-08-08 10:55:42 -070094 }
Winson Chung3d503fb2011-07-13 17:25:49 -070095
96 @Override
97 protected void onFinishInflate() {
98 super.onFinishInflate();
99 if (mCellCountX < 0) mCellCountX = LauncherModel.getCellCountX();
100 if (mCellCountY < 0) mCellCountY = LauncherModel.getCellCountY();
101 mContent = (CellLayout) findViewById(R.id.layout);
102 mContent.setGridSize(mCellCountX, mCellCountY);
Andrew Flynn0dca1ec2012-02-29 13:33:22 -0800103 mContent.setIsHotseat(true);
Winson Chung3d503fb2011-07-13 17:25:49 -0700104
105 resetLayout();
106 }
107
108 void resetLayout() {
109 mContent.removeAllViewsInLayout();
Winson Chung3d503fb2011-07-13 17:25:49 -0700110 }
111}