From 0241e7556501caae1f57d2bdf3677d7e4a619eb0 Mon Sep 17 00:00:00 2001 From: Michael Kolb Date: Thu, 7 Jul 2011 14:58:50 -0700 Subject: make QC work on phone Reduce options in QC menu on phone Avoid restart when enabling/disabling QC Bug: 3326929 Change-Id: I5119c4df99226dcb28f47a95471872fbf51be48e --- src/com/android/browser/BaseUi.java | 3 +- src/com/android/browser/BrowserSettings.java | 4 + src/com/android/browser/PhoneUi.java | 11 +- src/com/android/browser/PieControl.java | 359 --------------------- src/com/android/browser/PieControlBase.java | 187 +++++++++++ src/com/android/browser/PieControlPhone.java | 96 ++++++ src/com/android/browser/PieControlXLarge.java | 215 ++++++++++++ src/com/android/browser/UI.java | 3 + src/com/android/browser/XLargeUi.java | 12 +- .../preferences/LabPreferencesFragment.java | 35 +- 10 files changed, 529 insertions(+), 396 deletions(-) delete mode 100644 src/com/android/browser/PieControl.java create mode 100644 src/com/android/browser/PieControlBase.java create mode 100644 src/com/android/browser/PieControlPhone.java create mode 100644 src/com/android/browser/PieControlXLarge.java (limited to 'src/com/android') diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java index 8e24353..3638bbf 100644 --- a/src/com/android/browser/BaseUi.java +++ b/src/com/android/browser/BaseUi.java @@ -251,7 +251,8 @@ public abstract class BaseUi implements UI, OnTouchListener { getTitleBar().setIncognitoMode(incognito); updateAutoLogin(tab, false); if (web != null && web.getVisibleTitleHeight() - != getTitleBar().getEmbeddedHeight()) { + != getTitleBar().getEmbeddedHeight() + && !mUseQuickControls) { showTitleBarForDuration(); } } diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 22fc3c3..4d41426 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -276,6 +276,10 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, if (mController.getUi() != null) { mController.getUi().setFullscreen(useFullscreen()); } + } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) { + if (mController.getUi() != null) { + mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false)); + } } } diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java index 0c236af..20c90f6 100644 --- a/src/com/android/browser/PhoneUi.java +++ b/src/com/android/browser/PhoneUi.java @@ -36,7 +36,7 @@ public class PhoneUi extends BaseUi { private TitleBarPhone mTitleBar; private ActiveTabsPage mActiveTabsPage; - private PieControl mPieControl; + private PieControlPhone mPieControl; private NavScreen mNavScreen; boolean mExtendedMenuOpen; @@ -262,15 +262,18 @@ public class PhoneUi extends BaseUi { } } - private void setUseQuickControls(boolean useQuickControls) { + @Override + public void setUseQuickControls(boolean useQuickControls) { mUseQuickControls = useQuickControls; getTitleBar().setUseQuickControls(mUseQuickControls); if (useQuickControls) { - mPieControl = new PieControl(mActivity, mUiController, this); + mPieControl = new PieControlPhone(mActivity, mUiController, this); mPieControl.attachToContainer(mContentView); WebView web = getWebView(); if (web != null) { web.setEmbeddedTitleBar(null); + // don't show url bar on scrolling + web.setOnTouchListener(null); } } else { if (mPieControl != null) { @@ -279,6 +282,8 @@ public class PhoneUi extends BaseUi { WebView web = getWebView(); if (web != null) { web.setEmbeddedTitleBar(mTitleBar); + // show url bar on scrolling + web.setOnTouchListener(this); } setTitleGravity(Gravity.NO_GRAVITY); } diff --git a/src/com/android/browser/PieControl.java b/src/com/android/browser/PieControl.java deleted file mode 100644 index 8bcd972..0000000 --- a/src/com/android/browser/PieControl.java +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.browser; - -import com.android.browser.view.PieItem; -import com.android.browser.view.PieListView; -import com.android.browser.view.PieMenu; -import com.android.browser.view.PieMenu.PieView.OnLayoutListener; -import com.android.browser.view.PieStackView; -import com.android.browser.view.PieStackView.OnCurrentListener; - -import android.app.Activity; -import android.content.Context; -import android.graphics.Bitmap; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; -import android.webkit.WebView; -import android.widget.BaseAdapter; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.ImageView.ScaleType; -import android.widget.TextView; - -import java.util.ArrayList; -import java.util.List; - -/** - * controller for Quick Controls pie menu - */ -public class PieControl implements OnClickListener, PieMenu.PieController { - - private Activity mActivity; - private UiController mUiController; - private BaseUi mUi; - private PieMenu mPie; - private PieItem mBack; - private PieItem mForward; - private PieItem mRefresh; - private PieItem mUrl; - private PieItem mOptions; - private PieItem mBookmarks; - private PieItem mNewTab; - private PieItem mClose; - private MenuAdapter mMenuAdapter; - private PieItem mShowTabs; - private TabAdapter mTabAdapter; - private TextView mTabsCount; - private int mItemSize; - - public PieControl(Activity activity, UiController controller, BaseUi ui) { - mActivity = activity; - mUiController = controller; - mUi = ui; - mItemSize = (int) activity.getResources().getDimension(R.dimen.qc_item_size); - } - - protected void attachToContainer(FrameLayout container) { - if (mPie == null) { - mPie = new PieMenu(mActivity); - LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, - LayoutParams.MATCH_PARENT); - mPie.setLayoutParams(lp); - mBack = makeItem(R.drawable.ic_back_holo_dark, 1); - mUrl = makeItem(R.drawable.ic_web_holo_dark, 1); - mBookmarks = makeItem(R.drawable.ic_bookmarks_holo_dark, 1); - mRefresh = makeItem(R.drawable.ic_refresh_holo_dark, 2); - mForward = makeItem(R.drawable.ic_forward_holo_dark, 2); - mNewTab = makeItem(R.drawable.ic_new_window_holo_dark, 2); - mClose = makeItem(R.drawable.ic_close_window_holo_dark, 2); - View tabs = makeTabsView(); - mShowTabs = new PieItem(tabs, 2); - mOptions = makeItem( - com.android.internal.R.drawable.ic_menu_moreoverflow_normal_holo_dark, - 2); - mMenuAdapter = new MenuAdapter(mActivity, mUiController); - mTabAdapter = new TabAdapter(mActivity, mUiController); - PieStackView stack = new PieStackView(mActivity); - stack.setLayoutListener(new OnLayoutListener() { - @Override - public void onLayout(int ax, int ay, boolean left) { - buildTabs(); - } - }); - stack.setOnCurrentListener(mTabAdapter); - stack.setAdapter(mTabAdapter); - mShowTabs.setPieView(stack); - PieListView menuview = new PieListView(mActivity); - menuview.setLayoutListener(new OnLayoutListener() { - @Override - public void onLayout(int ax, int ay, boolean left) { - buildMenu(); - } - }); - - mOptions.setPieView(menuview); - menuview.setAdapter(mMenuAdapter); - setClickListener(mBack, - mRefresh, - mForward, - mUrl, - mBookmarks, - mNewTab, - mClose - ); - // level 1 - mPie.addItem(mBack); - mPie.addItem(mUrl); - mPie.addItem(mBookmarks); - // level 2 - mPie.addItem(mForward); - mPie.addItem(mRefresh); - mPie.addItem(mOptions); - mPie.addItem(mShowTabs); - mPie.addItem(mNewTab); - mPie.addItem(mClose); - mPie.setController(this); - } - container.addView(mPie); - } - - private void buildTabs() { - final List tabs = mUiController.getTabs(); - mUi.captureTab(mUi.getActiveTab()); - mTabAdapter.setTabs(tabs); - PieStackView sym = (PieStackView) mShowTabs.getPieView(); - sym.setCurrent(mUiController.getTabControl().getCurrentPosition()); - - } - - private void buildMenu() { - Menu menu = mUi.getMenu(); - menu.setGroupVisible(R.id.NAV_MENU, false); - mMenuAdapter.setMenu(menu); - } - - protected void removeFromContainer(FrameLayout container) { - container.removeView(mPie); - } - - private View makeTabsView() { - View v = mActivity.getLayoutInflater().inflate(R.layout.qc_tabs_view, null); - mTabsCount = (TextView) v.findViewById(R.id.label); - mTabsCount.setText("1"); - ImageView image = (ImageView) v.findViewById(R.id.icon); - image.setImageResource(R.drawable.ic_windows_holo_dark); - image.setScaleType(ScaleType.CENTER); - LayoutParams lp = new LayoutParams(mItemSize, mItemSize); - v.setLayoutParams(lp); - return v; - } - - private PieItem makeItem(int image, int l) { - ImageView view = new ImageView(mActivity); - view.setImageResource(image); - view.setMinimumWidth(mItemSize); - view.setMinimumHeight(mItemSize); - view.setScaleType(ScaleType.CENTER); - LayoutParams lp = new LayoutParams(mItemSize, mItemSize); - view.setLayoutParams(lp); - return new PieItem(view, l); - } - - private void setClickListener(PieItem... items) { - for (PieItem item : items) { - item.getView().setOnClickListener(this); - } - } - - protected void forceToTop(FrameLayout container) { - if (mPie.getParent() != null) { - container.removeView(mPie); - container.addView(mPie); - } - } - - @Override - public void onClick(View v) { - Tab tab = mUiController.getTabControl().getCurrentTab(); - WebView web = tab.getWebView(); - if (mBack.getView() == v) { - web.goBack(); - } else if (mForward.getView() == v) { - web.goForward(); - } else if (mRefresh.getView() == v) { - if (tab.inPageLoad()) { - web.stopLoading(); - } else { - web.reload(); - } - } else if (mUrl.getView() == v) { - mUi.editUrl(false); - } else if (mBookmarks.getView() == v) { - mUiController.bookmarksOrHistoryPicker(false); - } else if (mNewTab.getView() == v) { - mUiController.openTabToHomePage(); - mUi.editUrl(false); - } else if (mClose.getView() == v) { - mUiController.closeCurrentTab(); - } - } - - @Override - public boolean onOpen() { - int n = mUiController.getTabControl().getTabCount(); - mTabsCount.setText(Integer.toString(n)); - return true; - } - - private static class TabAdapter extends BaseAdapter implements OnCurrentListener { - - LayoutInflater mInflater; - UiController mUiController; - private List mTabs; - private int mCurrent; - - public TabAdapter(Context ctx, UiController ctl) { - mInflater = LayoutInflater.from(ctx); - mUiController = ctl; - mTabs = new ArrayList(); - mCurrent = -1; - } - - public void setTabs(List tabs) { - mTabs = tabs; - notifyDataSetChanged(); - } - - @Override - public int getCount() { - return mTabs.size(); - } - - @Override - public Tab getItem(int position) { - return mTabs.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - final Tab tab = mTabs.get(position); - View view = mInflater.inflate(R.layout.qc_tab, - null); - ImageView thumb = (ImageView) view.findViewById(R.id.thumb); - TextView title1 = (TextView) view.findViewById(R.id.title1); - TextView title2 = (TextView) view.findViewById(R.id.title2); - Bitmap b = tab.getScreenshot(); - if (b != null) { - thumb.setImageBitmap(b); - } - if (position > mCurrent) { - title1.setVisibility(View.GONE); - title2.setText(tab.getTitle()); - } else { - title2.setVisibility(View.GONE); - title1.setText(tab.getTitle()); - } - view.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - mUiController.switchToTab(tab); - } - }); - return view; - } - - @Override - public void onSetCurrent(int index) { - mCurrent = index; - } - - } - - private static class MenuAdapter extends BaseAdapter - implements OnClickListener { - - List mItems; - UiController mUiController; - LayoutInflater mInflater; - - public MenuAdapter(Context ctx, UiController ctl) { - mUiController = ctl; - mInflater = LayoutInflater.from(ctx); - mItems = new ArrayList(); - } - - public void setMenu(Menu menu) { - mItems.clear(); - for (int i = 0; i < menu.size(); i++) { - MenuItem item = menu.getItem(i); - if (item.isEnabled() && item.isVisible()) { - mItems.add(item); - } - } - notifyDataSetChanged(); - } - - @Override - public int getCount() { - return mItems.size(); - } - - @Override - public MenuItem getItem(int position) { - return mItems.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public void onClick(View v) { - if (v.getTag() != null) { - mUiController.onOptionsItemSelected((MenuItem) v.getTag()); - } - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - final MenuItem item = mItems.get(position); - View view = mInflater.inflate( - R.layout.qc_menu_item, null); - TextView label = - (TextView) view.findViewById(R.id.title); - label.setText(item.getTitle()); - label.setTag(item); - label.setOnClickListener(this); - label.setLayoutParams(new LayoutParams(240, 32)); - return label; - } - - } - -} diff --git a/src/com/android/browser/PieControlBase.java b/src/com/android/browser/PieControlBase.java new file mode 100644 index 0000000..830afea --- /dev/null +++ b/src/com/android/browser/PieControlBase.java @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.browser; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Bitmap; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; +import android.widget.BaseAdapter; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.ImageView.ScaleType; +import android.widget.TextView; + +import com.android.browser.view.PieItem; +import com.android.browser.view.PieMenu; +import com.android.browser.view.PieStackView.OnCurrentListener; + +import java.util.ArrayList; +import java.util.List; + +/** + * base controller for Quick Controls pie menu + */ +public abstract class PieControlBase implements PieMenu.PieController { + + protected Activity mActivity; + protected UiController mUiController; + protected PieMenu mPie; + protected int mItemSize; + protected TextView mTabsCount; + + public PieControlBase(Activity activity, UiController controller) { + mActivity = activity; + mUiController = controller; + mItemSize = (int) activity.getResources().getDimension(R.dimen.qc_item_size); + } + + protected void attachToContainer(FrameLayout container) { + if (mPie == null) { + mPie = new PieMenu(mActivity); + LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.MATCH_PARENT); + mPie.setLayoutParams(lp); + populateMenu(); + mPie.setController(this); + } + container.addView(mPie); + } + + protected void removeFromContainer(FrameLayout container) { + container.removeView(mPie); + } + + protected void forceToTop(FrameLayout container) { + if (mPie.getParent() != null) { + container.removeView(mPie); + container.addView(mPie); + } + } + + protected abstract void populateMenu(); + + protected void setClickListener(OnClickListener listener, PieItem... items) { + for (PieItem item : items) { + item.getView().setOnClickListener(listener); + } + } + + @Override + public boolean onOpen() { + int n = mUiController.getTabControl().getTabCount(); + mTabsCount.setText(Integer.toString(n)); + return true; + } + + protected PieItem makeItem(int image, int l) { + ImageView view = new ImageView(mActivity); + view.setImageResource(image); + view.setMinimumWidth(mItemSize); + view.setMinimumHeight(mItemSize); + view.setScaleType(ScaleType.CENTER); + LayoutParams lp = new LayoutParams(mItemSize, mItemSize); + view.setLayoutParams(lp); + return new PieItem(view, l); + } + + protected View makeTabsView() { + View v = mActivity.getLayoutInflater().inflate(R.layout.qc_tabs_view, null); + mTabsCount = (TextView) v.findViewById(R.id.label); + mTabsCount.setText("1"); + ImageView image = (ImageView) v.findViewById(R.id.icon); + image.setImageResource(R.drawable.ic_windows_holo_dark); + image.setScaleType(ScaleType.CENTER); + LayoutParams lp = new LayoutParams(mItemSize, mItemSize); + v.setLayoutParams(lp); + return v; + } + + static class TabAdapter extends BaseAdapter implements OnCurrentListener { + + LayoutInflater mInflater; + UiController mUiController; + private List mTabs; + private int mCurrent; + + public TabAdapter(Context ctx, UiController ctl) { + mInflater = LayoutInflater.from(ctx); + mUiController = ctl; + mTabs = new ArrayList(); + mCurrent = -1; + } + + public void setTabs(List tabs) { + mTabs = tabs; + notifyDataSetChanged(); + } + + @Override + public int getCount() { + return mTabs.size(); + } + + @Override + public Tab getItem(int position) { + return mTabs.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + final Tab tab = mTabs.get(position); + View view = mInflater.inflate(R.layout.qc_tab, + null); + ImageView thumb = (ImageView) view.findViewById(R.id.thumb); + TextView title1 = (TextView) view.findViewById(R.id.title1); + TextView title2 = (TextView) view.findViewById(R.id.title2); + Bitmap b = tab.getScreenshot(); + if (b != null) { + thumb.setImageBitmap(b); + } + if (position > mCurrent) { + title1.setVisibility(View.GONE); + title2.setText(tab.getTitle()); + } else { + title2.setVisibility(View.GONE); + title1.setText(tab.getTitle()); + } + view.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mUiController.switchToTab(tab); + } + }); + return view; + } + + @Override + public void onSetCurrent(int index) { + mCurrent = index; + } + + } + +} diff --git a/src/com/android/browser/PieControlPhone.java b/src/com/android/browser/PieControlPhone.java new file mode 100644 index 0000000..2b8d5d9 --- /dev/null +++ b/src/com/android/browser/PieControlPhone.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.browser; + +import android.app.Activity; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup.LayoutParams; +import android.webkit.WebView; +import android.widget.ImageView; +import android.widget.ImageView.ScaleType; +import android.widget.TextView; + +import com.android.browser.view.PieItem; +import com.android.browser.view.PieMenu.PieView.OnLayoutListener; +import com.android.browser.view.PieStackView; + +import java.util.List; + +/** + * controller for Quick Controls pie menu + */ +public class PieControlPhone extends PieControlBase implements OnClickListener { + + private PhoneUi mUi; + private PieItem mBack; + private PieItem mUrl; + private PieItem mShowTabs; + private TabAdapter mTabAdapter; + + public PieControlPhone(Activity activity, UiController controller, PhoneUi ui) { + super(activity, controller); + mUi = ui; + } + + protected void populateMenu() { + mBack = makeItem(R.drawable.ic_back_holo_dark, 1); + mUrl = makeItem(R.drawable.ic_web_holo_dark, 1); + View tabs = makeTabsView(); + mShowTabs = new PieItem(tabs, 1); + mTabAdapter = new TabAdapter(mActivity, mUiController); + PieStackView stack = new PieStackView(mActivity); + stack.setLayoutListener(new OnLayoutListener() { + @Override + public void onLayout(int ax, int ay, boolean left) { + buildTabs(); + } + }); + stack.setOnCurrentListener(mTabAdapter); + stack.setAdapter(mTabAdapter); + mShowTabs.setPieView(stack); + // level 1 + mPie.addItem(mBack); + mPie.addItem(mUrl); + mPie.addItem(mShowTabs); + setClickListener(this, mBack, mUrl, mShowTabs); + } + + private void buildTabs() { + final List tabs = mUiController.getTabs(); + mUi.captureTab(mUi.getActiveTab()); + mTabAdapter.setTabs(tabs); + PieStackView sym = (PieStackView) mShowTabs.getPieView(); + sym.setCurrent(mUiController.getTabControl().getCurrentPosition()); + + } + + @Override + public void onClick(View v) { + Tab tab = mUiController.getTabControl().getCurrentTab(); + WebView web = tab.getWebView(); + if (mBack.getView() == v) { + web.goBack(); + } else if (mUrl.getView() == v) { + mUi.editUrl(false); + } else if (mShowTabs.getView() == v) { + mUi.showNavScreen(); + } + } + + +} diff --git a/src/com/android/browser/PieControlXLarge.java b/src/com/android/browser/PieControlXLarge.java new file mode 100644 index 0000000..2c29fa1 --- /dev/null +++ b/src/com/android/browser/PieControlXLarge.java @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.browser; + +import android.app.Activity; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; +import android.webkit.WebView; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.android.browser.view.PieItem; +import com.android.browser.view.PieListView; +import com.android.browser.view.PieMenu.PieView.OnLayoutListener; +import com.android.browser.view.PieStackView; + +import java.util.ArrayList; +import java.util.List; + +/** + * controller for Quick Controls pie menu + */ +public class PieControlXLarge extends PieControlBase implements OnClickListener { + + private BaseUi mUi; + private PieItem mBack; + private PieItem mForward; + private PieItem mRefresh; + private PieItem mUrl; + private PieItem mOptions; + private PieItem mBookmarks; + private PieItem mNewTab; + private PieItem mClose; + private MenuAdapter mMenuAdapter; + private PieItem mShowTabs; + private TabAdapter mTabAdapter; + + public PieControlXLarge(Activity activity, UiController controller, BaseUi ui) { + super(activity, controller); + mUiController = controller; + mUi = ui; + } + + protected void populateMenu() { + mBack = makeItem(R.drawable.ic_back_holo_dark, 1); + mUrl = makeItem(R.drawable.ic_web_holo_dark, 1); + mBookmarks = makeItem(R.drawable.ic_bookmarks_holo_dark, 1); + mRefresh = makeItem(R.drawable.ic_refresh_holo_dark, 2); + mForward = makeItem(R.drawable.ic_forward_holo_dark, 2); + mNewTab = makeItem(R.drawable.ic_new_window_holo_dark, 2); + mClose = makeItem(R.drawable.ic_close_window_holo_dark, 2); + View tabs = makeTabsView(); + mShowTabs = new PieItem(tabs, 2); + mOptions = makeItem(com.android.internal.R.drawable.ic_menu_moreoverflow_normal_holo_dark, + 2); + mMenuAdapter = new MenuAdapter(mActivity, mUiController); + mTabAdapter = new TabAdapter(mActivity, mUiController); + PieStackView stack = new PieStackView(mActivity); + stack.setLayoutListener(new OnLayoutListener() { + @Override + public void onLayout(int ax, int ay, boolean left) { + buildTabs(); + } + }); + stack.setOnCurrentListener(mTabAdapter); + stack.setAdapter(mTabAdapter); + mShowTabs.setPieView(stack); + PieListView menuview = new PieListView(mActivity); + menuview.setLayoutListener(new OnLayoutListener() { + @Override + public void onLayout(int ax, int ay, boolean left) { + buildMenu(); + } + }); + + mOptions.setPieView(menuview); + menuview.setAdapter(mMenuAdapter); + setClickListener(this, mBack, mRefresh, mForward, mUrl, mBookmarks, mNewTab, + mClose); + // level 1 + mPie.addItem(mBack); + mPie.addItem(mUrl); + mPie.addItem(mBookmarks); + // level 2 + mPie.addItem(mForward); + mPie.addItem(mRefresh); + mPie.addItem(mOptions); + mPie.addItem(mShowTabs); + mPie.addItem(mNewTab); + mPie.addItem(mClose); + } + + private void buildTabs() { + final List tabs = mUiController.getTabs(); + mUi.captureTab(mUi.getActiveTab()); + mTabAdapter.setTabs(tabs); + PieStackView sym = (PieStackView) mShowTabs.getPieView(); + sym.setCurrent(mUiController.getTabControl().getCurrentPosition()); + } + + private void buildMenu() { + Menu menu = mUi.getMenu(); + menu.setGroupVisible(R.id.NAV_MENU, false); + mMenuAdapter.setMenu(menu); + } + + @Override + public void onClick(View v) { + Tab tab = mUiController.getTabControl().getCurrentTab(); + WebView web = tab.getWebView(); + if (mBack.getView() == v) { + web.goBack(); + } else if (mForward.getView() == v) { + web.goForward(); + } else if (mRefresh.getView() == v) { + if (tab.inPageLoad()) { + web.stopLoading(); + } else { + web.reload(); + } + } else if (mUrl.getView() == v) { + mUi.editUrl(false); + } else if (mBookmarks.getView() == v) { + mUiController.bookmarksOrHistoryPicker(false); + } else if (mNewTab.getView() == v) { + mUiController.openTabToHomePage(); + mUi.editUrl(false); + } else if (mClose.getView() == v) { + mUiController.closeCurrentTab(); + } + } + + private static class MenuAdapter extends BaseAdapter + implements OnClickListener { + + List mItems; + UiController mUiController; + LayoutInflater mInflater; + + public MenuAdapter(Context ctx, UiController ctl) { + mUiController = ctl; + mInflater = LayoutInflater.from(ctx); + mItems = new ArrayList(); + } + + public void setMenu(Menu menu) { + mItems.clear(); + for (int i = 0; i < menu.size(); i++) { + MenuItem item = menu.getItem(i); + if (item.isEnabled() && item.isVisible()) { + mItems.add(item); + } + } + notifyDataSetChanged(); + } + + @Override + public int getCount() { + return mItems.size(); + } + + @Override + public MenuItem getItem(int position) { + return mItems.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public void onClick(View v) { + if (v.getTag() != null) { + mUiController.onOptionsItemSelected((MenuItem) v.getTag()); + } + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + final MenuItem item = mItems.get(position); + View view = mInflater.inflate( + R.layout.qc_menu_item, null); + TextView label = + (TextView) view.findViewById(R.id.title); + label.setText(item.getTitle()); + label.setTag(item); + label.setOnClickListener(this); + label.setLayoutParams(new LayoutParams(240, 32)); + return label; + } + + } + +} diff --git a/src/com/android/browser/UI.java b/src/com/android/browser/UI.java index 93f6e63..fdd2b93 100644 --- a/src/com/android/browser/UI.java +++ b/src/com/android/browser/UI.java @@ -143,4 +143,7 @@ public interface UI { void hideAutoLogin(Tab tab); void setFullscreen(boolean enabled); + + void setUseQuickControls(boolean enabled); + } diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java index 6fcfab7..290bbf7 100644 --- a/src/com/android/browser/XLargeUi.java +++ b/src/com/android/browser/XLargeUi.java @@ -42,7 +42,7 @@ public class XLargeUi extends BaseUi { private TitleBarXLarge mTitleBar; - private PieControl mPieControl; + private PieControlXLarge mPieControl; private Handler mHandler; /** @@ -84,16 +84,20 @@ public class XLargeUi extends BaseUi { } } - private void setUseQuickControls(boolean useQuickControls) { + @Override + public void setUseQuickControls(boolean useQuickControls) { mUseQuickControls = useQuickControls; mTitleBar.setUseQuickControls(mUseQuickControls); if (useQuickControls) { checkTabCount(); - mPieControl = new PieControl(mActivity, mUiController, this); + mPieControl = new PieControlXLarge(mActivity, mUiController, this); mPieControl.attachToContainer(mContentView); WebView web = getWebView(); if (web != null) { web.setEmbeddedTitleBar(null); + // don't show url bar on scrolling + web.setOnTouchListener(null); + } } else { mActivity.getActionBar().show(); @@ -103,6 +107,8 @@ public class XLargeUi extends BaseUi { WebView web = getWebView(); if (web != null) { web.setEmbeddedTitleBar(mTitleBar); + // show url bar on scrolling + web.setOnTouchListener(this); } setTitleGravity(Gravity.NO_GRAVITY); } diff --git a/src/com/android/browser/preferences/LabPreferencesFragment.java b/src/com/android/browser/preferences/LabPreferencesFragment.java index 0dd8805..ca3a86a 100644 --- a/src/com/android/browser/preferences/LabPreferencesFragment.java +++ b/src/com/android/browser/preferences/LabPreferencesFragment.java @@ -16,23 +16,16 @@ package com.android.browser.preferences; -import com.android.browser.BrowserActivity; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.PreferenceFragment; + import com.android.browser.BrowserSettings; import com.android.browser.PreferenceKeys; import com.android.browser.R; import com.android.browser.search.SearchEngine; -import android.app.AlertDialog; -import android.content.Intent; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.Preference.OnPreferenceChangeListener; -import android.preference.PreferenceFragment; -import android.view.LayoutInflater; -import android.view.View; - -public class LabPreferencesFragment extends PreferenceFragment - implements OnPreferenceChangeListener { +public class LabPreferencesFragment extends PreferenceFragment { private BrowserSettings mBrowserSettings; private Preference useInstantPref; @@ -44,17 +37,9 @@ public class LabPreferencesFragment extends PreferenceFragment // Load the XML preferences file addPreferencesFromResource(R.xml.lab_preferences); - registerChangeListener(PreferenceKeys.PREF_ENABLE_QUICK_CONTROLS); useInstantPref = findPreference(PreferenceKeys.PREF_USE_INSTANT_SEARCH); } - private void registerChangeListener(String key) { - Preference e = findPreference(key); - if (e != null) { - e.setOnPreferenceChangeListener(this); - } - } - @Override public void onResume() { super.onResume(); @@ -72,14 +57,4 @@ public class LabPreferencesFragment extends PreferenceFragment } } - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - String key = preference.getKey(); - if (PreferenceKeys.PREF_ENABLE_QUICK_CONTROLS.equals(key)) { - // Attempt to restart - startActivity(new Intent(BrowserActivity.ACTION_RESTART, null, - getActivity(), BrowserActivity.class)); - } - return true; - } } -- cgit v1.1