blob: deab13177dd560344b9f0627f9332149d1b15493 [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 {
30 static final String TAG = "Hotseat";
31
32 private Launcher mLauncher;
33 private CellLayout mContent;
34
35 private int mCellCountX;
36 private int mCellCountY;
37 private boolean mIsLandscape;
38
39 public Hotseat(Context context) {
40 this(context, null);
41 }
42
43 public Hotseat(Context context, AttributeSet attrs) {
44 this(context, attrs, 0);
45 }
46
47 public Hotseat(Context context, AttributeSet attrs, int defStyle) {
48 super(context, attrs, defStyle);
49
50 TypedArray a = context.obtainStyledAttributes(attrs,
51 R.styleable.Hotseat, defStyle, 0);
52 mCellCountX = a.getInt(R.styleable.Hotseat_cellCountX, -1);
53 mCellCountY = a.getInt(R.styleable.Hotseat_cellCountY, -1);
54 mIsLandscape = context.getResources().getConfiguration().orientation ==
55 Configuration.ORIENTATION_LANDSCAPE;
56 }
57
58 public void setup(Launcher launcher) {
59 mLauncher = launcher;
60 }
61
62 CellLayout getLayout() {
63 return mContent;
64 }
65
66 /* Get the orientation invariant order of the item in the hotseat for persistence. */
67 int getOrderInHotseat(int x, int y) {
68 return mIsLandscape ? (mContent.getCountY() - y - 1) : x;
69 }
70 /* Get the orientation specific coordinates given an invariant order in the hotseat. */
71 int getCellXFromOrder(int rank) {
72 return mIsLandscape ? 0 : rank;
73 }
74 int getCellYFromOrder(int rank) {
75 return mIsLandscape ? (mContent.getCountY() - (rank + 1)) : 0;
76 }
77
78 @Override
79 protected void onFinishInflate() {
80 super.onFinishInflate();
81 if (mCellCountX < 0) mCellCountX = LauncherModel.getCellCountX();
82 if (mCellCountY < 0) mCellCountY = LauncherModel.getCellCountY();
83 mContent = (CellLayout) findViewById(R.id.layout);
84 mContent.setGridSize(mCellCountX, mCellCountY);
85
86 resetLayout();
87 }
88
89 void resetLayout() {
90 mContent.removeAllViewsInLayout();
91
92 // Add the Apps button
93 Context context = getContext();
94 LayoutInflater inflater = LayoutInflater.from(context);
95 BubbleTextView allAppsButton = (BubbleTextView)
96 inflater.inflate(R.layout.application, mContent, false);
97 allAppsButton.setCompoundDrawablesWithIntrinsicBounds(null,
98 context.getResources().getDrawable(R.drawable.apps_hotseat_button), null, null);
99 // button.setText(context.getString(R.string.all_apps_button_label));
100 allAppsButton.setOnClickListener(new View.OnClickListener() {
101 @Override
102 public void onClick(android.view.View v) {
103 mLauncher.showAllApps(true);
104 }
105 });
106
107 // Note: We do this to ensure that the hotseat is always laid out in the orientation of
108 // the hotseat in order regardless of which orientation they were added
109 int x = getCellXFromOrder(0);
110 int y = getCellYFromOrder(0);
111 mContent.addViewToCellLayout(allAppsButton, -1, 0, new CellLayout.LayoutParams(x,y,1,1),
112 true);
113 }
114}