blob: c53a74377aa89e12233d6074fc99bdf10213736e [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
17package com.android.launcher2;
18
19import android.content.Context;
20import android.content.res.Configuration;
21import android.content.res.TypedArray;
22import android.util.AttributeSet;
23import android.view.LayoutInflater;
24import android.view.View;
25import android.widget.FrameLayout;
26
27import com.android.launcher.R;
28
29public class Hotseat extends FrameLayout {
Winson Chungf30ad5f2011-08-08 10:55:42 -070030 private static final String TAG = "Hotseat";
31 private static final int sAllAppsButtonRank = 2; // In the middle of the dock
Winson Chung3d503fb2011-07-13 17:25:49 -070032
33 private Launcher mLauncher;
34 private CellLayout mContent;
35
36 private int mCellCountX;
37 private int mCellCountY;
38 private boolean mIsLandscape;
39
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);
50
51 TypedArray a = context.obtainStyledAttributes(attrs,
52 R.styleable.Hotseat, defStyle, 0);
53 mCellCountX = a.getInt(R.styleable.Hotseat_cellCountX, -1);
54 mCellCountY = a.getInt(R.styleable.Hotseat_cellCountY, -1);
55 mIsLandscape = context.getResources().getConfiguration().orientation ==
56 Configuration.ORIENTATION_LANDSCAPE;
57 }
58
59 public void setup(Launcher launcher) {
60 mLauncher = launcher;
Winson Chung4d279d92011-07-21 11:46:32 -070061 setOnKeyListener(new HotseatBubbleTextViewKeyEventListener());
Winson Chung3d503fb2011-07-13 17:25:49 -070062 }
63
64 CellLayout getLayout() {
65 return mContent;
66 }
67
68 /* Get the orientation invariant order of the item in the hotseat for persistence. */
69 int getOrderInHotseat(int x, int y) {
70 return mIsLandscape ? (mContent.getCountY() - y - 1) : x;
71 }
72 /* Get the orientation specific coordinates given an invariant order in the hotseat. */
73 int getCellXFromOrder(int rank) {
74 return mIsLandscape ? 0 : rank;
75 }
76 int getCellYFromOrder(int rank) {
77 return mIsLandscape ? (mContent.getCountY() - (rank + 1)) : 0;
78 }
Winson Chungf30ad5f2011-08-08 10:55:42 -070079 public static boolean isAllAppsButtonRank(int rank) {
80 return rank == sAllAppsButtonRank;
81 }
Winson Chung3d503fb2011-07-13 17:25:49 -070082
83 @Override
84 protected void onFinishInflate() {
85 super.onFinishInflate();
86 if (mCellCountX < 0) mCellCountX = LauncherModel.getCellCountX();
87 if (mCellCountY < 0) mCellCountY = LauncherModel.getCellCountY();
88 mContent = (CellLayout) findViewById(R.id.layout);
89 mContent.setGridSize(mCellCountX, mCellCountY);
90
91 resetLayout();
92 }
93
94 void resetLayout() {
95 mContent.removeAllViewsInLayout();
96
97 // Add the Apps button
98 Context context = getContext();
99 LayoutInflater inflater = LayoutInflater.from(context);
100 BubbleTextView allAppsButton = (BubbleTextView)
101 inflater.inflate(R.layout.application, mContent, false);
102 allAppsButton.setCompoundDrawablesWithIntrinsicBounds(null,
103 context.getResources().getDrawable(R.drawable.apps_hotseat_button), null, null);
Winson Chung4d279d92011-07-21 11:46:32 -0700104 // allAppsButton.setText(context.getString(R.string.all_apps_button_label));
105 allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
Winson Chung3d503fb2011-07-13 17:25:49 -0700106 allAppsButton.setOnClickListener(new View.OnClickListener() {
107 @Override
108 public void onClick(android.view.View v) {
Winson Chung4d279d92011-07-21 11:46:32 -0700109 if (mLauncher != null) {
110 mLauncher.showAllApps(true);
111 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700112 }
113 });
114
115 // Note: We do this to ensure that the hotseat is always laid out in the orientation of
116 // the hotseat in order regardless of which orientation they were added
Winson Chungf30ad5f2011-08-08 10:55:42 -0700117 int x = getCellXFromOrder(sAllAppsButtonRank);
118 int y = getCellYFromOrder(sAllAppsButtonRank);
Winson Chung3d503fb2011-07-13 17:25:49 -0700119 mContent.addViewToCellLayout(allAppsButton, -1, 0, new CellLayout.LayoutParams(x,y,1,1),
120 true);
121 }
122}