blob: 2e2eba4331a3130c5a4b71fec32e66b2a136d989 [file] [log] [blame]
Michael Kolb376b5412010-12-15 11:52:57 -08001/*
2 * Copyright (C) 2010 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.browser;
18
19import com.android.browser.view.PieMenu;
20
21import android.app.Activity;
22import android.view.View;
23import android.view.View.OnClickListener;
24import android.view.ViewGroup.LayoutParams;
25import android.webkit.WebView;
26import android.widget.FrameLayout;
27import android.widget.ImageView;
28
29import java.util.HashMap;
30import java.util.Map;
31
32/**
33 * controller for Quick Controls pie menu
34 */
35public class PieControl implements OnClickListener, PieMenu.PieController {
36
37 private Activity mActivity;
38 private UiController mUiController;
39 private XLargeUi mUi;
40 private PieMenu mPie;
41 private ImageView mBack;
42 private ImageView mForward;
43 private ImageView mRefresh;
44 private ImageView mUrl;
45 private ImageView mOptions;
46 private ImageView mBookmarks;
47 private ImageView mNewTab;
48 private ImageView mClose;
49
50 private Map<View,Tab> mTabItems;
51
52 boolean mNewTabMode = true;
53
54 public PieControl(Activity activity, UiController controller, XLargeUi ui) {
55 mActivity = activity;
56 mUiController = controller;
57 mUi = ui;
58 mTabItems = new HashMap<View, Tab>();
59 }
60
61 protected void attachToContainer(FrameLayout container) {
62 if (mPie == null) {
63 mPie = new PieMenu(mActivity);
64 LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
65 LayoutParams.MATCH_PARENT);
66 mPie.setLayoutParams(lp);
Michael Kolb2a56eca2011-02-25 09:45:06 -080067 mNewTab = makeMenuView(R.drawable.ic_pie_new_tab);
68 mPie.addItem(mNewTab);
Michael Kolb376b5412010-12-15 11:52:57 -080069 mBack = makeMenuView(R.drawable.ic_pie_back);
70 mPie.addItem(mBack);
Michael Kolb467af0a2011-01-11 13:09:49 -080071 mUrl = makeMenuView(R.drawable.ic_pie_web);
Michael Kolb376b5412010-12-15 11:52:57 -080072 mPie.addItem(mUrl);
73 mBookmarks = makeMenuView(R.drawable.ic_pie_bookmarks);
74 mPie.addItem(mBookmarks);
Michael Kolb376b5412010-12-15 11:52:57 -080075 mOptions = makeMenuView(R.drawable.ic_pie_more);
76 mPie.addItem(mOptions);
Michael Kolb2a56eca2011-02-25 09:45:06 -080077 setClickListener(mBack,
78 mUrl,
79 mOptions,
80 mBookmarks,
81 mNewTab
82 );
Michael Kolb376b5412010-12-15 11:52:57 -080083 mPie.setController(this);
84 }
85 container.addView(mPie);
86 }
87
88 protected void removeFromContainer(FrameLayout container) {
89 container.removeView(mPie);
90 }
91
92 private ImageView makeMenuView(int image) {
93 ImageView item = new ImageView(mActivity);
94 item.setImageResource(image);
95 LayoutParams lp = new LayoutParams(48, 48);
96 item.setLayoutParams(lp);
97 return item;
98 }
99
100 private void setClickListener(View... views) {
101 for (View view : views) {
102 view.setOnClickListener(this);
103 }
104 }
105
106 protected void forceToTop(FrameLayout container) {
107 if (mPie.getParent() != null) {
108 container.removeView(mPie);
109 container.addView(mPie);
110 }
111 }
112
113 @Override
114 public void onClick(View v) {
115 mPie.show(false);
116 Tab tab = mUiController.getTabControl().getCurrentTab();
117 WebView web = tab.getWebView();
118 if (mBack == v) {
119 web.goBack();
120 } else if (mForward == v) {
121 web.goForward();
122 } else if (mRefresh == v) {
123 if (tab.inPageLoad()) {
124 web.stopLoading();
125 } else {
126 web.reload();
127 }
128 } else if (mUrl == v) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800129 mUi.showTitleBarAndEdit();
Michael Kolb376b5412010-12-15 11:52:57 -0800130 } else if (mOptions == v) {
131 mActivity.openOptionsMenu();
132 } else if (mBookmarks == v) {
133 mUiController.bookmarksOrHistoryPicker(false);
134 } else if (mNewTab == v) {
135 mUiController.openTabToHomePage();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800136 mUi.showTitleBarAndEdit();
Michael Kolb376b5412010-12-15 11:52:57 -0800137 } else if (mClose == v) {
138 mUiController.closeCurrentTab();
139 } else {
140 Tab ntab = mTabItems.get(v);
141 if (ntab != null) {
142 mUiController.switchToTab(mUiController.getTabControl().getTabIndex(ntab));
143 }
144 }
145 }
146
147 @Override
148 public boolean onOpen() {
149 return true;
150 }
151
152}