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