Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 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.browser; |
| 18 | |
| 19 | import android.app.Activity; |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 20 | import android.view.Menu; |
| 21 | import android.view.MenuItem; |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 22 | import android.view.View; |
| 23 | import android.view.View.OnClickListener; |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 24 | import android.widget.PopupMenu; |
| 25 | import android.widget.PopupMenu.OnMenuItemClickListener; |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 26 | |
Michael Kolb | 59b4ff3 | 2011-11-22 16:13:43 -0800 | [diff] [blame] | 27 | import com.android.browser.UI.ComboViews; |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 28 | import com.android.browser.view.PieItem; |
| 29 | import com.android.browser.view.PieMenu.PieView.OnLayoutListener; |
| 30 | import com.android.browser.view.PieStackView; |
| 31 | |
| 32 | import java.util.List; |
| 33 | |
| 34 | /** |
| 35 | * controller for Quick Controls pie menu |
| 36 | */ |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 37 | public class PieControlPhone extends PieControlBase implements OnClickListener, |
| 38 | OnMenuItemClickListener { |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 39 | |
| 40 | private PhoneUi mUi; |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 41 | private PieItem mUrl; |
| 42 | private PieItem mShowTabs; |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 43 | private PieItem mOptions; |
Michael Kolb | 59b4ff3 | 2011-11-22 16:13:43 -0800 | [diff] [blame] | 44 | private PieItem mNewTab; |
| 45 | private PieItem mBookmarks; |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 46 | private TabAdapter mTabAdapter; |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 47 | private PopupMenu mPopup; |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 48 | |
| 49 | public PieControlPhone(Activity activity, UiController controller, PhoneUi ui) { |
| 50 | super(activity, controller); |
| 51 | mUi = ui; |
| 52 | } |
| 53 | |
| 54 | protected void populateMenu() { |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 55 | mUrl = makeItem(R.drawable.ic_web_holo_dark, 1); |
| 56 | View tabs = makeTabsView(); |
| 57 | mShowTabs = new PieItem(tabs, 1); |
| 58 | mTabAdapter = new TabAdapter(mActivity, mUiController); |
| 59 | PieStackView stack = new PieStackView(mActivity); |
| 60 | stack.setLayoutListener(new OnLayoutListener() { |
| 61 | @Override |
| 62 | public void onLayout(int ax, int ay, boolean left) { |
| 63 | buildTabs(); |
| 64 | } |
| 65 | }); |
| 66 | stack.setOnCurrentListener(mTabAdapter); |
| 67 | stack.setAdapter(mTabAdapter); |
| 68 | mShowTabs.setPieView(stack); |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 69 | mOptions = makeItem(com.android.internal.R.drawable.ic_menu_moreoverflow_normal_holo_dark, |
| 70 | 1); |
| 71 | |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 72 | // level 1 |
Michael Kolb | 59b4ff3 | 2011-11-22 16:13:43 -0800 | [diff] [blame] | 73 | mNewTab = makeItem(R.drawable.ic_new_window_holo_dark, 1); |
| 74 | mBookmarks = makeItem(R.drawable.ic_bookmarks_holo_dark, 1); |
| 75 | mPie.addItem(mNewTab); |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 76 | mPie.addItem(mShowTabs); |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 77 | mPie.addItem(mUrl); |
Michael Kolb | 59b4ff3 | 2011-11-22 16:13:43 -0800 | [diff] [blame] | 78 | mPie.addItem(mBookmarks); |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 79 | mPie.addItem(mOptions); |
Michael Kolb | 59b4ff3 | 2011-11-22 16:13:43 -0800 | [diff] [blame] | 80 | setClickListener(this, mUrl, mShowTabs, mOptions, mNewTab, mBookmarks); |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 81 | mPopup = new PopupMenu(mActivity, mUi.getTitleBar()); |
| 82 | Menu menu = mPopup.getMenu(); |
| 83 | mPopup.getMenuInflater().inflate(R.menu.browser, menu); |
| 84 | mPopup.setOnMenuItemClickListener(this); |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 87 | protected void showMenu() { |
| 88 | mUiController.updateMenuState(mUiController.getCurrentTab(), mPopup.getMenu()); |
| 89 | mPopup.show(); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public boolean onMenuItemClick(MenuItem item) { |
| 94 | return mUiController.onOptionsItemSelected(item); |
| 95 | } |
| 96 | |
| 97 | |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 98 | private void buildTabs() { |
| 99 | final List<Tab> tabs = mUiController.getTabs(); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 100 | mUi.getActiveTab().capture(); |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 101 | mTabAdapter.setTabs(tabs); |
| 102 | PieStackView sym = (PieStackView) mShowTabs.getPieView(); |
| 103 | sym.setCurrent(mUiController.getTabControl().getCurrentPosition()); |
| 104 | |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public void onClick(View v) { |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 109 | if (mUrl.getView() == v) { |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 110 | mUi.editUrl(false); |
| 111 | } else if (mShowTabs.getView() == v) { |
| 112 | mUi.showNavScreen(); |
Michael Kolb | 7167738 | 2011-09-27 13:37:28 -0700 | [diff] [blame] | 113 | } else if (mOptions.getView() == v) { |
| 114 | showMenu(); |
Michael Kolb | 59b4ff3 | 2011-11-22 16:13:43 -0800 | [diff] [blame] | 115 | } else if (mNewTab.getView() == v) { |
| 116 | mUiController.openTabToHomePage(); |
| 117 | mUi.editUrl(false); |
| 118 | } else if (mBookmarks.getView() == v) { |
| 119 | mUiController.bookmarksOrHistoryPicker(ComboViews.Bookmarks); |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 123 | } |