summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-01-14 11:01:05 -0800
committerJohn Reck <jreck@google.com>2011-01-14 17:37:01 -0800
commitb3417f0a68a1efc64604ea354ae7f856ce79cb16 (patch)
tree455c87606f0f1a97c2c06c7338a5aa29715880e8 /src/com/android
parent231f751049febdb0877ead6364d33d130286cff1 (diff)
downloadpackages_apps_browser-b3417f0a68a1efc64604ea354ae7f856ce79cb16.zip
packages_apps_browser-b3417f0a68a1efc64604ea354ae7f856ce79cb16.tar.gz
packages_apps_browser-b3417f0a68a1efc64604ea354ae7f856ce79cb16.tar.bz2
Bookmark UI update
Change-Id: Ibdf7f93f7c5863d7108044dcd40d3866ff02518a
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/browser/BaseUi.java9
-rw-r--r--src/com/android/browser/BreadCrumbView.java30
-rw-r--r--src/com/android/browser/BrowserActivity.java2
-rw-r--r--src/com/android/browser/BrowserBookmarksAdapter.java19
-rw-r--r--src/com/android/browser/BrowserBookmarksPage.java64
-rw-r--r--src/com/android/browser/BrowserHistoryPage.java1
-rw-r--r--src/com/android/browser/CombinedBookmarkHistoryView.java183
-rw-r--r--src/com/android/browser/Controller.java32
-rw-r--r--src/com/android/browser/OptionsMenuHandler.java27
-rw-r--r--src/com/android/browser/UI.java3
-rw-r--r--src/com/android/browser/UiController.java3
-rw-r--r--src/com/android/browser/XLargeUi.java15
12 files changed, 272 insertions, 116 deletions
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index 7e0c5da..5ccfdda 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -30,7 +30,6 @@ import android.util.Log;
import android.view.Gravity;
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;
@@ -38,7 +37,6 @@ import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebChromeClient;
-import android.webkit.WebHistoryItem;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageButton;
@@ -455,6 +453,7 @@ public abstract class BaseUi implements UI, WebViewFactory {
if (mActiveTab != null) {
mActiveTab.putInForeground();
}
+ mActivity.invalidateOptionsMenu();
}
@Override
@@ -638,12 +637,6 @@ public abstract class BaseUi implements UI, WebViewFactory {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
- @Override
- public void onPrepareOptionsMenu(Menu menu) {
- final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
- newtab.setEnabled(mUiController.getTabControl().canCreateNewTab());
- }
-
// -------------------------------------------------------------------------
// Helper function for WebChromeClient
// -------------------------------------------------------------------------
diff --git a/src/com/android/browser/BreadCrumbView.java b/src/com/android/browser/BreadCrumbView.java
index 113d55b..b8409f0 100644
--- a/src/com/android/browser/BreadCrumbView.java
+++ b/src/com/android/browser/BreadCrumbView.java
@@ -17,6 +17,7 @@
package com.android.browser;
import android.content.Context;
+import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
@@ -37,6 +38,7 @@ import java.util.List;
* Use pushView, popView, clear, and getTopData to change/access the view stack
*/
public class BreadCrumbView extends LinearLayout implements OnClickListener {
+ private static final int DIVIDER_PADDING = 12; // dips
interface Controller {
public void onTop(int level, Object data);
@@ -47,6 +49,7 @@ public class BreadCrumbView extends LinearLayout implements OnClickListener {
private List<Crumb> mCrumbs;
private boolean mUseBackButton;
private Drawable mSeparatorDrawable;
+ private float mDividerPadding;
private int mMaxVisible = -1;
/**
@@ -79,8 +82,10 @@ public class BreadCrumbView extends LinearLayout implements OnClickListener {
private void init(Context ctx) {
mUseBackButton = false;
mCrumbs = new ArrayList<Crumb>();
- mSeparatorDrawable = ctx.getResources().getDrawable(
- R.drawable.crumb_divider);
+ TypedArray a = ctx.obtainStyledAttributes(com.android.internal.R.styleable.Theme);
+ mSeparatorDrawable = a.getDrawable(com.android.internal.R.styleable.Theme_dividerVertical);
+ a.recycle();
+ mDividerPadding = DIVIDER_PADDING * ctx.getResources().getDisplayMetrics().density;
addBackButton();
}
@@ -176,13 +181,26 @@ public class BreadCrumbView extends LinearLayout implements OnClickListener {
}
private void addSeparator() {
- ImageView sep = new ImageView(mContext);
- sep.setImageDrawable(mSeparatorDrawable);
- sep.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
- LayoutParams.MATCH_PARENT));
+ View sep = makeDividerView();
+ sep.setLayoutParams(makeDividerLayoutParams());
addView(sep);
}
+ private ImageView makeDividerView() {
+ ImageView result = new ImageView(mContext);
+ result.setImageDrawable(mSeparatorDrawable);
+ result.setScaleType(ImageView.ScaleType.FIT_XY);
+ return result;
+ }
+
+ private LayoutParams makeDividerLayoutParams() {
+ LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
+ LayoutParams.MATCH_PARENT);
+ params.topMargin = (int) mDividerPadding;
+ params.bottomMargin = (int) mDividerPadding;
+ return params;
+ }
+
private void pop(boolean notify) {
int n = mCrumbs.size();
if (n > 0) {
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 018744d..a67b4e6 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -252,7 +252,7 @@ public class BrowserActivity extends Activity {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
- return mController.prepareOptionsMenu(menu);
+ return mController.onPrepareOptionsMenu(menu);
}
@Override
diff --git a/src/com/android/browser/BrowserBookmarksAdapter.java b/src/com/android/browser/BrowserBookmarksAdapter.java
index c680a88..26ba62c 100644
--- a/src/com/android/browser/BrowserBookmarksAdapter.java
+++ b/src/com/android/browser/BrowserBookmarksAdapter.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.drawable.PaintDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -30,6 +31,7 @@ import android.widget.TextView;
class BrowserBookmarksAdapter extends CursorAdapter {
LayoutInflater mInflater;
int mCurrentView;
+ PaintDrawable mFaviconBackground;
/**
* Create a new BrowserBookmarksAdapter.
@@ -37,9 +39,16 @@ class BrowserBookmarksAdapter extends CursorAdapter {
public BrowserBookmarksAdapter(Context context, int defaultView) {
// Make sure to tell the CursorAdapter to avoid the observer and auto-requery
// since the Loader will do that for us.
- super(context, null);
+ super(context, null, 0);
mInflater = LayoutInflater.from(context);
selectView(defaultView);
+ float density = context.getResources().getDisplayMetrics().density;
+ mFaviconBackground = new PaintDrawable();
+ int padding = (int) (5 * density);
+ mFaviconBackground.setPadding(padding, padding, padding, padding);
+ mFaviconBackground.getPaint().setColor(context.getResources()
+ .getColor(R.color.bookmarkListFaviconBackground));
+ mFaviconBackground.setCornerRadius(3 * density);
}
@Override
@@ -58,7 +67,8 @@ class BrowserBookmarksAdapter extends CursorAdapter {
tv.setText(cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE));
if (cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0) {
// folder
- thumb.setImageResource(R.drawable.ic_folder);
+ thumb.setImageResource(R.drawable.thumb_bookmark_widget_folder_holo);
+ thumb.setBackgroundDrawable(null);
} else {
byte[] thumbData = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_THUMBNAIL);
Bitmap thumbBitmap = null;
@@ -71,6 +81,7 @@ class BrowserBookmarksAdapter extends CursorAdapter {
} else {
thumb.setImageBitmap(thumbBitmap);
}
+ thumb.setBackgroundResource(R.drawable.border_thumb_bookmarks_widget_holo);
}
}
@@ -82,6 +93,7 @@ class BrowserBookmarksAdapter extends CursorAdapter {
if (cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0) {
// folder
favicon.setImageResource(R.drawable.ic_folder_bookmark_widget_holo_dark);
+ favicon.setBackgroundDrawable(null);
} else {
byte[] faviconData = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_FAVICON);
Bitmap faviconBitmap = null;
@@ -94,6 +106,9 @@ class BrowserBookmarksAdapter extends CursorAdapter {
} else {
favicon.setImageBitmap(faviconBitmap);
}
+ //favicon.setBackgroundResource(R.drawable.bookmark_list_favicon_bg);
+ // TODO: Switch to above instead of below once b/3353813 is fixed
+ favicon.setBackgroundDrawable(mFaviconBackground);
}
}
diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java
index d5a5182..2df0561 100644
--- a/src/com/android/browser/BrowserBookmarksPage.java
+++ b/src/com/android/browser/BrowserBookmarksPage.java
@@ -33,6 +33,8 @@ import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
+import android.content.res.Configuration;
+import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -47,10 +49,10 @@ import android.text.TextUtils;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
+import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebIconDatabase.IconListener;
import android.widget.Adapter;
@@ -60,7 +62,6 @@ import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.PopupMenu.OnMenuItemClickListener;
-import android.widget.TextView;
import android.widget.Toast;
interface BookmarksPageCallbacks {
@@ -76,7 +77,7 @@ interface BookmarksPageCallbacks {
*/
public class BrowserBookmarksPage extends Fragment implements View.OnCreateContextMenuListener,
LoaderManager.LoaderCallbacks<Cursor>, OnItemClickListener, IconListener,
- OnItemSelectedListener, BreadCrumbView.Controller, OnClickListener, OnMenuItemClickListener {
+ OnItemSelectedListener, BreadCrumbView.Controller, OnMenuItemClickListener {
static final String LOGTAG = "browser";
@@ -108,7 +109,6 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
View mHeader;
ViewGroup mHeaderContainer;
BreadCrumbView mCrumbs;
- TextView mSelectBookmarkView;
int mCrumbVisibility = View.VISIBLE;
int mCrumbMaxVisible = -1;
boolean mCrumbBackButton = false;
@@ -339,6 +339,11 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
};
@Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.bookmark, menu);
+ }
+
+ @Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
Cursor cursor = mAdapter.getItem(info.position);
@@ -401,6 +406,8 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ setHasOptionsMenu(true);
+
Bundle args = getArguments();
mDisableNewWindow = args == null ? false : args.getBoolean(EXTRA_DISABLE_WINDOW, false);
}
@@ -438,19 +445,12 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
if (mCallbacks != null) {
mCallbacks.onFolderChanged(1, BrowserContract.Bookmarks.CONTENT_URI_DEFAULT_FOLDER);
}
- mSelectBookmarkView = (TextView) mHeader.findViewById(R.id.select_bookmark_view);
- mSelectBookmarkView.setOnClickListener(this);
// Start the loaders
LoaderManager lm = getLoaderManager();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
mCurrentView =
prefs.getInt(PREF_SELECTED_VIEW, BrowserBookmarksPage.VIEW_THUMBNAILS);
- if (mCurrentView == BrowserBookmarksPage.VIEW_THUMBNAILS) {
- mSelectBookmarkView.setText(R.string.bookmark_list_view);
- } else {
- mSelectBookmarkView.setText(R.string.bookmark_thumbnail_view);
- }
mAdapter = new BrowserBookmarksAdapter(getActivity(), mCurrentView);
String accountType = prefs.getString(PREF_ACCOUNT_TYPE, DEFAULT_ACCOUNT);
String accountName = prefs.getString(PREF_ACCOUNT_NAME, DEFAULT_ACCOUNT);
@@ -650,16 +650,39 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
cm.setPrimaryClip(ClipData.newRawUri(null, null, Uri.parse(text.toString())));
}
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.thumbnail_view:
+ selectView(VIEW_THUMBNAILS);
+ return true;
+ case R.id.list_view:
+ selectView(VIEW_LIST);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ Resources res = getActivity().getResources();
+ int horizontalSpacing = (int) res.getDimension(R.dimen.combo_horizontalSpacing);
+ mGrid.setHorizontalSpacing(horizontalSpacing);
+ }
+
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ menu.findItem(R.id.list_view).setVisible(mCurrentView != VIEW_LIST);
+ menu.findItem(R.id.thumbnail_view).setVisible(mCurrentView != VIEW_THUMBNAILS);
+ }
+
void selectView(int view) {
if (view == mCurrentView) {
return;
}
mCurrentView = view;
- if (mCurrentView == BrowserBookmarksPage.VIEW_THUMBNAILS) {
- mSelectBookmarkView.setText(R.string.bookmark_list_view);
- } else {
- mSelectBookmarkView.setText(R.string.bookmark_thumbnail_view);
- }
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
Editor edit = prefs.edit();
edit.putInt(PREF_SELECTED_VIEW, mCurrentView);
@@ -716,15 +739,6 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
}
@Override
- public void onClick(View view) {
- if (mSelectBookmarkView == view) {
- selectView(mCurrentView == BrowserBookmarksPage.VIEW_LIST
- ? BrowserBookmarksPage.VIEW_THUMBNAILS
- : BrowserBookmarksPage.VIEW_LIST);
- }
- }
-
- @Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.list_view:
diff --git a/src/com/android/browser/BrowserHistoryPage.java b/src/com/android/browser/BrowserHistoryPage.java
index 41d3749..87649d4 100644
--- a/src/com/android/browser/BrowserHistoryPage.java
+++ b/src/com/android/browser/BrowserHistoryPage.java
@@ -41,7 +41,6 @@ import android.preference.PreferenceManager;
import android.provider.Browser;
import android.provider.BrowserContract;
import android.provider.BrowserContract.Combined;
-import android.text.TextUtils;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
diff --git a/src/com/android/browser/CombinedBookmarkHistoryView.java b/src/com/android/browser/CombinedBookmarkHistoryView.java
index 0f12353..f4b2e9c 100644
--- a/src/com/android/browser/CombinedBookmarkHistoryView.java
+++ b/src/com/android/browser/CombinedBookmarkHistoryView.java
@@ -17,10 +17,13 @@
package com.android.browser;
+import android.app.ActionBar;
+import android.app.ActionBar.Tab;
+import android.app.ActionBar.TabListener;
import android.app.Activity;
-import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
@@ -28,16 +31,18 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Browser;
+import android.view.Gravity;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.webkit.WebIconDatabase;
import android.webkit.WebIconDatabase.IconListener;
+import android.widget.FrameLayout;
import android.widget.LinearLayout;
-import android.widget.TextView;
import java.util.HashMap;
import java.util.Vector;
@@ -48,7 +53,7 @@ interface BookmarksHistoryCallbacks {
}
public class CombinedBookmarkHistoryView extends LinearLayout
- implements OnClickListener, OnTouchListener {
+ implements OnTouchListener, TabListener, OptionsMenuHandler {
final static String STARTING_FRAGMENT = "fragment";
@@ -57,18 +62,15 @@ public class CombinedBookmarkHistoryView extends LinearLayout
private UiController mUiController;
private Activity mActivity;
+ private ActionBar mActionBar;
private Bundle mExtras;
- long mCurrentFragment;
+ int mCurrentFragment;
- View mTabs;
- TextView mTabBookmarks;
- TextView mTabHistory;
- TextView mAddBookmark;
- View mSeperateSelectAdd;
+ ActionBar.Tab mTabBookmarks;
+ ActionBar.Tab mTabHistory;
ViewGroup mBookmarksHeader;
- View mHome;
BrowserBookmarksPage mBookmarks;
BrowserHistoryPage mHistory;
@@ -116,27 +118,22 @@ public class CombinedBookmarkHistoryView extends LinearLayout
mUiController = controller;
mActivity = activity;
mExtras = extras;
+ mActionBar = mActivity.getActionBar();
+
View v = LayoutInflater.from(activity).inflate(R.layout.bookmarks_history, this);
v.setOnTouchListener(this);
Resources res = activity.getResources();
// setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
- mTabs = findViewById(R.id.tabs);
- mBookmarksHeader = (ViewGroup) findViewById(R.id.header_container);
-
- mTabBookmarks = (TextView) findViewById(R.id.bmtab);
- mTabHistory = (TextView) findViewById(R.id.historytab);
- mAddBookmark = (TextView) findViewById(R.id.addbm);
- mSeperateSelectAdd = findViewById(R.id.seperate_select_add);
- mHome = findViewById(R.id.home);
- mAddBookmark.setOnClickListener(this);
- mTabHistory.setOnClickListener(this);
- mTabBookmarks.setOnClickListener(this);
- mHome.setOnClickListener(this);
+ mBookmarksHeader = new FrameLayout(mActivity);
+ mBookmarksHeader.setLayoutParams(new FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.WRAP_CONTENT,
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ Gravity.CENTER_VERTICAL));
+
// Start up the default fragment
initFragments(mExtras);
- loadFragment(startingFragment, mExtras, false);
// XXX: Must do this before launching the AsyncTask to avoid a
// potential crash if the icon database has not been created.
@@ -153,6 +150,36 @@ public class CombinedBookmarkHistoryView extends LinearLayout
}
}).execute();
+ setupActionBar(startingFragment);
+ mUiController.registerOptionsMenuHandler(this);
+ }
+
+ void setupActionBar(int startingFragment) {
+ mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
+ | ActionBar.DISPLAY_USE_LOGO);
+ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+ mActionBar.removeAllTabs();
+ mTabBookmarks = mActionBar.newTab();
+ mTabBookmarks.setText(R.string.tab_bookmarks);
+ mTabBookmarks.setTabListener(this);
+ mActionBar.addTab(mTabBookmarks, FRAGMENT_ID_BOOKMARKS == startingFragment);
+ mTabHistory = mActionBar.newTab();
+ mTabHistory.setText(R.string.tab_history);
+ mTabHistory.setTabListener(this);
+ mActionBar.addTab(mTabHistory, FRAGMENT_ID_HISTORY == startingFragment);
+ mActionBar.setCustomView(mBookmarksHeader);
+
+ }
+
+ @Override
+ protected void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+
+ Resources res = mContext.getResources();
+ int paddingLeftRight = (int) res.getDimension(R.dimen.combo_paddingLeftRight);
+ int paddingTop = (int) res.getDimension(R.dimen.combo_paddingTop);
+ findViewById(R.id.fragment).setPadding(paddingLeftRight, paddingTop,
+ paddingLeftRight, 0);
}
private BookmarksPageCallbacks mBookmarkCallbackWrapper = new BookmarksPageCallbacks() {
@@ -173,13 +200,15 @@ public class CombinedBookmarkHistoryView extends LinearLayout
@Override
public void onFolderChanged(int level, Uri uri) {
+ final int toggleFlags = ActionBar.DISPLAY_SHOW_CUSTOM
+ | ActionBar.DISPLAY_HOME_AS_UP;
// 1 is "bookmarks" root folder
if (level <= 1) {
- mTabs.setVisibility(View.VISIBLE);
- mBookmarks.setBreadCrumbVisibility(View.INVISIBLE);
+ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+ mActionBar.setDisplayOptions(0, toggleFlags);
} else {
- mTabs.setVisibility(View.GONE);
- mBookmarks.setBreadCrumbVisibility(View.VISIBLE);
+ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+ mActionBar.setDisplayOptions(toggleFlags, toggleFlags);
}
}
};
@@ -188,39 +217,24 @@ public class CombinedBookmarkHistoryView extends LinearLayout
mBookmarks = BrowserBookmarksPage.newInstance(mBookmarkCallbackWrapper,
extras, mBookmarksHeader);
mBookmarks.setBreadCrumbMaxVisible(2);
- mBookmarks.setBreadCrumbUseBackButton(true);
+ mBookmarks.setBreadCrumbUseBackButton(false);
mHistory = BrowserHistoryPage.newInstance(mUiController, extras);
}
- private void loadFragment(int id, Bundle extras, boolean notify) {
- String fragmentClassName;
- Fragment fragment = null;
+ private void loadFragment(int id, FragmentTransaction ft) {
+ if (mCurrentFragment == id) return;
+
switch (id) {
case FRAGMENT_ID_BOOKMARKS:
- fragment = mBookmarks;
- mSeperateSelectAdd.setVisibility(View.VISIBLE);
- mBookmarksHeader.setVisibility(View.VISIBLE);
- mAddBookmark.setVisibility(View.VISIBLE);
- mTabBookmarks.setActivated(true);
- mTabHistory.setActivated(false);
+ ft.replace(R.id.fragment, mBookmarks);
break;
case FRAGMENT_ID_HISTORY:
- fragment = mHistory;
- mBookmarksHeader.setVisibility(View.INVISIBLE);
- mSeperateSelectAdd.setVisibility(View.INVISIBLE);
- mAddBookmark.setVisibility(View.INVISIBLE);
- mTabBookmarks.setActivated(false);
- mTabHistory.setActivated(true);
+ ft.replace(R.id.fragment, mHistory);
break;
default:
throw new IllegalArgumentException();
}
mCurrentFragment = id;
-
- FragmentManager fm = mActivity.getFragmentManager();
- FragmentTransaction transaction = fm.openTransaction();
- transaction.replace(R.id.fragment, fragment);
- transaction.commit();
}
@Override
@@ -234,22 +248,7 @@ public class CombinedBookmarkHistoryView extends LinearLayout
transaction.remove(mHistory);
}
transaction.commit();
- }
-
- @Override
- public void onClick(View view) {
- if ((mTabHistory == view) && (mCurrentFragment != FRAGMENT_ID_HISTORY)) {
- loadFragment(FRAGMENT_ID_HISTORY, mExtras, false);
- } else if (mTabBookmarks == view) {
- if (mCurrentFragment != FRAGMENT_ID_BOOKMARKS) {
- loadFragment(FRAGMENT_ID_BOOKMARKS, mExtras, true);
- }
- } else if (mAddBookmark == view) {
- mUiController.bookmarkCurrentPage(mBookmarks.getFolderId());
- } else if (mHome == view) {
- BrowserSettings settings = BrowserSettings.getInstance();
- mUiController.onUrlSelected(settings.getHomePage(), false);
- }
+ mUiController.unregisterOptionsMenuHandler(this);
}
/**
@@ -270,4 +269,58 @@ public class CombinedBookmarkHistoryView extends LinearLayout
public boolean onTouch(View v, MotionEvent event) {
return true;
}
+
+ @Override
+ public void onTabReselected(Tab tab, FragmentTransaction ft) {
+ // Ignore
+ }
+
+ @Override
+ public void onTabSelected(Tab tab, FragmentTransaction ft) {
+ if (tab == mTabBookmarks) {
+ loadFragment(FRAGMENT_ID_BOOKMARKS, ft);
+ } else if (tab == mTabHistory) {
+ loadFragment(FRAGMENT_ID_HISTORY, ft);
+ }
+ }
+
+ @Override
+ public void onTabUnselected(Tab tab, FragmentTransaction ft) {
+ // Ignore
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Handled by fragment
+ return false;
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ // Handled by fragment
+ return false;
+ }
+
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ mUiController.getUi().onBackKey();
+ return true;
+ case R.id.go_home:
+ BrowserSettings settings = BrowserSettings.getInstance();
+ mUiController.onUrlSelected(settings.getHomePage(), false);
+ return true;
+ case R.id.add_bookmark:
+ mUiController.bookmarkCurrentPage(mBookmarks.getFolderId());
+ return true;
+ }
+
+ switch (mCurrentFragment) {
+ case FRAGMENT_ID_BOOKMARKS:
+ return mBookmarks.onOptionsItemSelected(item);
+ case FRAGMENT_ID_HISTORY:
+ return mHistory.onOptionsItemSelected(item);
+ }
+ return false;
+ }
}
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index fe19927..6c6fe0b 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -137,6 +137,7 @@ public class Controller
private TabControl mTabControl;
private BrowserSettings mSettings;
private WebViewFactory mFactory;
+ private OptionsMenuHandler mOptionsMenuHandler = null;
private WakeLock mWakeLock;
@@ -1186,6 +1187,10 @@ public class Controller
// TODO: maybe put into separate handler
protected boolean onCreateOptionsMenu(Menu menu) {
+ if (mOptionsMenuHandler != null) {
+ return mOptionsMenuHandler.onCreateOptionsMenu(menu);
+ }
+
if (mMenuState == EMPTY_MENU) {
return false;
}
@@ -1379,7 +1384,10 @@ public class Controller
}
}
- boolean prepareOptionsMenu(Menu menu) {
+ boolean onPrepareOptionsMenu(Menu menu) {
+ if (mOptionsMenuHandler != null) {
+ return mOptionsMenuHandler.onPrepareOptionsMenu(menu);
+ }
// This happens when the user begins to hold down the menu key, so
// allow them to chord to get a shortcut.
mCanChord = true;
@@ -1436,8 +1444,8 @@ public class Controller
counter.setVisible(showDebugSettings);
counter.setEnabled(showDebugSettings);
- // allow the ui to adjust state based settings
- mUi.onPrepareOptionsMenu(menu);
+ final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
+ newtab.setEnabled(getTabControl().canCreateNewTab());
break;
}
@@ -1446,6 +1454,11 @@ public class Controller
}
public boolean onOptionsItemSelected(MenuItem item) {
+ if (mOptionsMenuHandler != null &&
+ mOptionsMenuHandler.onOptionsItemSelected(item)) {
+ return true;
+ }
+
if (item.getGroupId() != R.id.CONTEXT_MENU) {
// menu remains active, so ensure comboview is dismissed
// if main menu option is selected
@@ -2517,4 +2530,17 @@ public class Controller
mAutoFillSetupMessage = message;
mActivity.startActivityForResult(intent, AUTOFILL_SETUP);
}
+
+ @Override
+ public void registerOptionsMenuHandler(OptionsMenuHandler handler) {
+ mOptionsMenuHandler = handler;
+ }
+
+ @Override
+ public void unregisterOptionsMenuHandler(OptionsMenuHandler handler) {
+ if (mOptionsMenuHandler == handler) {
+ mOptionsMenuHandler = null;
+ }
+ }
+
}
diff --git a/src/com/android/browser/OptionsMenuHandler.java b/src/com/android/browser/OptionsMenuHandler.java
new file mode 100644
index 0000000..d602c7d
--- /dev/null
+++ b/src/com/android/browser/OptionsMenuHandler.java
@@ -0,0 +1,27 @@
+/*
+ * 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.view.Menu;
+import android.view.MenuItem;
+
+public interface OptionsMenuHandler {
+
+ boolean onCreateOptionsMenu(Menu menu);
+ boolean onPrepareOptionsMenu(Menu menu);
+ boolean onOptionsItemSelected(MenuItem item);
+}
diff --git a/src/com/android/browser/UI.java b/src/com/android/browser/UI.java
index e2f76f1..4738522 100644
--- a/src/com/android/browser/UI.java
+++ b/src/com/android/browser/UI.java
@@ -88,9 +88,6 @@ public interface UI {
public void revertVoiceTitleBar(Tab tab);
- // allow the ui to update state
- public void onPrepareOptionsMenu(Menu menu);
-
public void onOptionsMenuOpened();
public void onExtendedMenuOpened();
diff --git a/src/com/android/browser/UiController.java b/src/com/android/browser/UiController.java
index 68a32d3..ae38cff 100644
--- a/src/com/android/browser/UiController.java
+++ b/src/com/android/browser/UiController.java
@@ -79,4 +79,7 @@ public interface UiController extends BookmarksHistoryCallbacks {
void shareCurrentPage();
+ void registerOptionsMenuHandler(OptionsMenuHandler handler);
+
+ void unregisterOptionsMenuHandler(OptionsMenuHandler handler);
}
diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java
index 1e607a7..9b344ec 100644
--- a/src/com/android/browser/XLargeUi.java
+++ b/src/com/android/browser/XLargeUi.java
@@ -20,7 +20,6 @@ import com.android.browser.ScrollWebView.ScrollListener;
import android.app.ActionBar;
import android.app.Activity;
-import android.graphics.Bitmap;
import android.util.Log;
import android.view.ActionMode;
import android.view.Gravity;
@@ -61,9 +60,21 @@ public class XLargeUi extends BaseUi implements ScrollListener {
mFakeTitleBar.setEditable(true);
mTabBar = new TabBar(mActivity, mUiController, this);
mActionBar = mActivity.getActionBar();
+ setupActionBar();
+ setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
+ }
+
+ private void setupActionBar() {
+ mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
mActionBar.setCustomView(mTabBar);
- setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
+ }
+
+ @Override
+ public void hideComboView() {
+ super.hideComboView();
+ // ComboView changes the action bar, set it back up to what we want
+ setupActionBar();
}
private void setUseQuickControls(boolean useQuickControls) {