Implement ComboView for Bookmarks, History and SavedPages
- Replaces ComboViewActivity for PhoneUi.
- Lives as part of the BrowserActivity's ViewTree.
- Avoids construction of ComboViewActivity everytime the bookmarks screen is opened.
Change-Id: Ic7042de731a4cc2107a297c9f7d4356bc2c30f2e
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index fbaaad1..24435b4 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -589,6 +589,10 @@
}
@Override
+ public void hideComboView() {
+ }
+
+ @Override
public void showCustomView(View view, int requestedOrientation,
CustomViewCallback callback) {
// if a view already exists then immediately terminate the new one
@@ -637,6 +641,11 @@
return mCustomView == null;
}
+ @Override
+ public boolean isComboViewShowing() {
+ return false;
+ }
+
// -------------------------------------------------------------------------
protected void updateNavigationState(Tab tab) {
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 531a1c7..9b310e2 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -16,6 +16,7 @@
package com.android.browser;
+import android.app.ActionBar;
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;
@@ -98,6 +99,11 @@
return;
}
+ if (!isTablet(this)) {
+ final ActionBar bar = getActionBar();
+ bar.hide();
+ }
+
// If this was a web search request, pass it on to the default web
// search provider and finish this activity.
/*
@@ -342,6 +348,10 @@
@Override
public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ mUiController.getUi().hideComboView();
+ return true;
+ }
if (!mController.onOptionsItemSelected(item)) {
return super.onOptionsItemSelected(item);
}
diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java
index 3fea1ed..d026b09 100644
--- a/src/com/android/browser/BrowserBookmarksPage.java
+++ b/src/com/android/browser/BrowserBookmarksPage.java
@@ -353,6 +353,13 @@
mCallbacks = new CombinedBookmarksCallbackWrapper(
(CombinedBookmarksCallbacks) getActivity());
}
+ if (mCallbacks == null) {
+ View cb = getActivity().getWindow().getDecorView().findViewById(R.id.combo_view_container);
+ if (cb != null && cb instanceof CombinedBookmarksCallbacks) {
+ mCallbacks = new CombinedBookmarksCallbackWrapper(
+ (CombinedBookmarksCallbacks) cb);
+ }
+ }
}
@Override
diff --git a/src/com/android/browser/BrowserHistoryPage.java b/src/com/android/browser/BrowserHistoryPage.java
index 271141c..e2c831b 100644
--- a/src/com/android/browser/BrowserHistoryPage.java
+++ b/src/com/android/browser/BrowserHistoryPage.java
@@ -201,7 +201,14 @@
mDisableNewWindow = args.getBoolean(BrowserBookmarksPage.EXTRA_DISABLE_WINDOW, false);
int mvlimit = getResources().getInteger(R.integer.most_visits_limit);
mMostVisitsLimit = Integer.toString(mvlimit);
- mCallback = (CombinedBookmarksCallbacks) getActivity();
+ if (mCallback == null && getActivity() instanceof CombinedBookmarksCallbacks) {
+ mCallback = (CombinedBookmarksCallbacks) getActivity();
+ } else {
+ View cb = getActivity().getWindow().getDecorView().findViewById(R.id.combo_view_container);
+ if (cb != null && cb instanceof CombinedBookmarksCallbacks) {
+ mCallback = (CombinedBookmarksCallbacks) cb;
+ }
+ }
}
@Override
diff --git a/src/com/android/browser/BrowserSnapshotPage.java b/src/com/android/browser/BrowserSnapshotPage.java
index 5d2453b..e2194d1 100644
--- a/src/com/android/browser/BrowserSnapshotPage.java
+++ b/src/com/android/browser/BrowserSnapshotPage.java
@@ -85,7 +85,14 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mCallback = (CombinedBookmarksCallbacks) getActivity();
+ if (mCallback == null && getActivity() instanceof CombinedBookmarksCallbacks) {
+ mCallback = (CombinedBookmarksCallbacks) getActivity();
+ } else {
+ View cb = getActivity().getWindow().getDecorView().findViewById(R.id.combo_view_container);
+ if (cb != null && cb instanceof CombinedBookmarksCallbacks) {
+ mCallback = (CombinedBookmarksCallbacks) cb;
+ }
+ }
mAnimateId = getArguments().getLong(EXTRA_ANIMATE_ID);
}
diff --git a/src/com/android/browser/ComboTabsAdapter.java b/src/com/android/browser/ComboTabsAdapter.java
index 5ce20fc..f73a88c 100644
--- a/src/com/android/browser/ComboTabsAdapter.java
+++ b/src/com/android/browser/ComboTabsAdapter.java
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.android.browser;
import android.app.ActionBar;
@@ -20,147 +22,25 @@
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context;
-import android.content.Intent;
-import android.net.Uri;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
-import android.view.Menu;
-import android.view.MenuItem;
-
-import com.android.browser.UI.ComboViews;
import java.util.ArrayList;
-public class ComboViewActivity extends Activity implements CombinedBookmarksCallbacks {
-
- private static final String STATE_SELECTED_TAB = "tab";
- public static final String EXTRA_COMBO_ARGS = "combo_args";
- public static final String EXTRA_INITIAL_VIEW = "initial_view";
-
- public static final String EXTRA_OPEN_SNAPSHOT = "snapshot_id";
- public static final String EXTRA_OPEN_ALL = "open_all";
- public static final String EXTRA_CURRENT_URL = "url";
- private ViewPager mViewPager;
- private TabsAdapter mTabsAdapter;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setResult(RESULT_CANCELED);
- Bundle extras = getIntent().getExtras();
- Bundle args = extras.getBundle(EXTRA_COMBO_ARGS);
- String svStr = extras.getString(EXTRA_INITIAL_VIEW, null);
- ComboViews startingView = svStr != null
- ? ComboViews.valueOf(svStr)
- : ComboViews.Bookmarks;
- mViewPager = new ViewPager(this);
- mViewPager.setId(R.id.tab_view);
- setContentView(mViewPager);
-
- final ActionBar bar = getActionBar();
- bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
- if (BrowserActivity.isTablet(this)) {
- bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
- | ActionBar.DISPLAY_USE_LOGO);
- bar.setHomeButtonEnabled(true);
- } else {
- bar.setDisplayOptions(0);
- }
-
- mTabsAdapter = new TabsAdapter(this, mViewPager);
- mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks),
- BrowserBookmarksPage.class, args);
- mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_history),
- BrowserHistoryPage.class, args);
- mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_snapshots),
- BrowserSnapshotPage.class, args);
-
- if (savedInstanceState != null) {
- bar.setSelectedNavigationItem(
- savedInstanceState.getInt(STATE_SELECTED_TAB, 0));
- } else {
- switch (startingView) {
- case Bookmarks:
- mViewPager.setCurrentItem(0);
- break;
- case History:
- mViewPager.setCurrentItem(1);
- break;
- case Snapshots:
- mViewPager.setCurrentItem(2);
- break;
- }
- }
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putInt(STATE_SELECTED_TAB,
- getActionBar().getSelectedNavigationIndex());
- }
-
- @Override
- public void openUrl(String url) {
- Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- setResult(RESULT_OK, i);
- finish();
- }
-
- @Override
- public void openInNewTab(String... urls) {
- Intent i = new Intent();
- i.putExtra(EXTRA_OPEN_ALL, urls);
- setResult(RESULT_OK, i);
- finish();
- }
-
- @Override
- public void close() {
- finish();
- }
-
- @Override
- public void openSnapshot(long id) {
- Intent i = new Intent();
- i.putExtra(EXTRA_OPEN_SNAPSHOT, id);
- setResult(RESULT_OK, i);
- finish();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.combined, menu);
- return super.onCreateOptionsMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == android.R.id.home) {
- finish();
- return true;
- } else if (item.getItemId() == R.id.preferences_menu_id) {
- String url = getIntent().getStringExtra(EXTRA_CURRENT_URL);
- BrowserPreferencesPage.startPreferencesForResult(this, url, Controller.PREFERENCES_PAGE);
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- /**
- * This is a helper class that implements the management of tabs and all
- * details of connecting a ViewPager with associated TabHost. It relies on a
- * trick. Normally a tab host has a simple API for supplying a View or
- * Intent that each tab will show. This is not sufficient for switching
- * between pages. So instead we make the content part of the tab host
- * 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
- * view to show as the tab content. It listens to changes in tabs, and takes
- * care of switch to the correct page in the ViewPager whenever the selected
- * tab changes.
- */
- public static class TabsAdapter extends FragmentPagerAdapter
- implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
+/**
+ * This is a helper class that implements the management of tabs and all
+ * details of connecting a ViewPager with associated TabHost. It relies on a
+ * trick. Normally a tab host has a simple API for supplying a View or
+ * Intent that each tab will show. This is not sufficient for switching
+ * between pages. So instead we make the content part of the tab host
+ * 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
+ * view to show as the tab content. It listens to changes in tabs, and takes
+ * care of switch to the correct page in the ViewPager whenever the selected
+ * tab changes.
+ */
+public class ComboTabsAdapter extends FragmentPagerAdapter
+ implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
private final Context mContext;
private final ActionBar mActionBar;
private final ViewPager mViewPager;
@@ -176,7 +56,7 @@
}
}
- public TabsAdapter(Activity activity, ViewPager pager) {
+ public ComboTabsAdapter(Activity activity, ViewPager pager) {
super(activity.getFragmentManager());
mContext = activity;
mActionBar = activity.getActionBar();
@@ -185,63 +65,58 @@
mViewPager.setOnPageChangeListener(this);
}
- public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
- TabInfo info = new TabInfo(clss, args);
- tab.setTag(info);
- tab.setTabListener(this);
- mTabs.add(info);
- mActionBar.addTab(tab);
- notifyDataSetChanged();
- }
+ public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
+ TabInfo info = new TabInfo(clss, args);
+ tab.setTag(info);
+ tab.setTabListener(this);
+ mTabs.add(info);
+ mActionBar.addTab(tab);
+ notifyDataSetChanged();
+ }
- @Override
- public int getCount() {
- return mTabs.size();
- }
+ @Override
+ public int getCount() {
+ return mTabs.size();
+ }
- @Override
- public Fragment getItem(int position) {
- TabInfo info = mTabs.get(position);
- return Fragment.instantiate(mContext, info.clss.getName(), info.args);
- }
+ @Override
+ public Fragment getItem(int position) {
+ TabInfo info = mTabs.get(position);
+ return Fragment.instantiate(mContext, info.clss.getName(), info.args);
+ }
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+ }
- @Override
- public void onPageSelected(int position) {
- mActionBar.setSelectedNavigationItem(position);
- }
+ @Override
+ public void onPageSelected(int position) {
+ mActionBar.setSelectedNavigationItem(position);
+ }
- @Override
- public void onPageScrollStateChanged(int state) {
- }
+ @Override
+ public void onPageScrollStateChanged(int state) {
+ }
- @Override
- public void onTabSelected(android.app.ActionBar.Tab tab,
- FragmentTransaction ft) {
- Object tag = tab.getTag();
- for (int i=0; i<mTabs.size(); i++) {
- if (mTabs.get(i) == tag) {
- mViewPager.setCurrentItem(i);
- }
+ @Override
+ public void onTabSelected(android.app.ActionBar.Tab tab,
+ FragmentTransaction ft) {
+ Object tag = tab.getTag();
+ for (int i=0; i<mTabs.size(); i++) {
+ if (mTabs.get(i) == tag) {
+ mViewPager.setCurrentItem(i);
}
}
-
- @Override
- public void onTabUnselected(android.app.ActionBar.Tab tab,
- FragmentTransaction ft) {
- }
-
- @Override
- public void onTabReselected(android.app.ActionBar.Tab tab,
- FragmentTransaction ft) {
- }
}
- private static String makeFragmentName(int viewId, int index) {
- return "android:switcher:" + viewId + ":" + index;
+ @Override
+ public void onTabUnselected(android.app.ActionBar.Tab tab,
+ FragmentTransaction ft) {
}
+ @Override
+ public void onTabReselected(android.app.ActionBar.Tab tab,
+ FragmentTransaction ft) {
+ }
}
+
diff --git a/src/com/android/browser/ComboView.java b/src/com/android/browser/ComboView.java
index 5ce20fc..01ff54f 100644
--- a/src/com/android/browser/ComboView.java
+++ b/src/com/android/browser/ComboView.java
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,235 +14,247 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.android.browser;
import android.app.ActionBar;
import android.app.Activity;
-import android.app.Fragment;
-import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
-import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
-import android.view.Menu;
-import android.view.MenuItem;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.animation.AnimationSet;
+import android.view.animation.AnimationUtils;
+import android.widget.HorizontalScrollView;
+import android.widget.LinearLayout;
import com.android.browser.UI.ComboViews;
-import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Set;
-public class ComboViewActivity extends Activity implements CombinedBookmarksCallbacks {
+public class ComboView extends LinearLayout implements CombinedBookmarksCallbacks, View.OnLayoutChangeListener {
- private static final String STATE_SELECTED_TAB = "tab";
- public static final String EXTRA_COMBO_ARGS = "combo_args";
- public static final String EXTRA_INITIAL_VIEW = "initial_view";
-
- public static final String EXTRA_OPEN_SNAPSHOT = "snapshot_id";
- public static final String EXTRA_OPEN_ALL = "open_all";
- public static final String EXTRA_CURRENT_URL = "url";
+ private Activity mActivity;
private ViewPager mViewPager;
- private TabsAdapter mTabsAdapter;
+ private AnimationSet mInAnimation;
+ private AnimationSet mOutAnimation;
+ private int mActionBarContainerId;
+
+ private ComboTabsAdapter mTabsAdapter;
+ private Bundle mExtraArgs;
+
+ public ComboView(Context context) {
+ super(context);
+ }
+
+ public ComboView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public ComboView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public void setupViews(Activity activity) {
+ mActivity = activity;
+
+ this.setId(R.id.combo_view_container);
+
+ mViewPager = (ViewPager)this.findViewById(R.id.combo_view_pager);
+ mViewPager.setId(R.id.tab_view); // ???
+
+ mInAnimation = (AnimationSet) AnimationUtils.loadAnimation(mActivity, R.anim.combo_view_enter);
+ mOutAnimation = (AnimationSet) AnimationUtils.loadAnimation(mActivity, R.anim.combo_view_exit);
+
+ final ActionBar bar = activity.getActionBar();
+ bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+ bar.setDisplayOptions(0);
+
+ mActionBarContainerId = getResources().getIdentifier("action_bar_container", "id", "android");
+ ViewGroup actionBarContainer = (ViewGroup) mActivity.getWindow().getDecorView().findViewById(mActionBarContainerId);
+ if (actionBarContainer != null) {
+ actionBarContainer.addOnLayoutChangeListener(this);
+ }
+ }
+
+ private View getScrollingTabContainerView() {
+ ViewGroup actionBarContainer = (ViewGroup) mActivity.getWindow().getDecorView().findViewById(mActionBarContainerId);
+ int count = actionBarContainer.getChildCount();
+ for (int i = 0; i < count; i++) {
+ View child = actionBarContainer.getChildAt(i);
+ if (child instanceof HorizontalScrollView) {
+ return child;
+ }
+ }
+ return null;
+ }
@Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setResult(RESULT_CANCELED);
- Bundle extras = getIntent().getExtras();
- Bundle args = extras.getBundle(EXTRA_COMBO_ARGS);
- String svStr = extras.getString(EXTRA_INITIAL_VIEW, null);
- ComboViews startingView = svStr != null
- ? ComboViews.valueOf(svStr)
- : ComboViews.Bookmarks;
- mViewPager = new ViewPager(this);
- mViewPager.setId(R.id.tab_view);
- setContentView(mViewPager);
+ public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
+ if (mActivity != null) {
+ if (!isShowing()) {
+ View container = getScrollingTabContainerView();
+ if (container != null) {
+ container.setVisibility(View.INVISIBLE);
+ }
+ }
+ }
- final ActionBar bar = getActionBar();
+ }
+
+ private boolean compareArgs(Bundle b1, Bundle b2) {
+
+ if(b1.size() != b2.size()) {
+ return false;
+ }
+
+ Set<String> keys = b1.keySet();
+ Iterator<String> it = keys.iterator();
+ while (it.hasNext()) {
+ String key = it.next();
+ final Object v1 = b1.get(key);
+ final Object v2 = b2.get(key);
+ if (!b2.containsKey(key)) {
+ return false;
+ } else if (v1 == null) {
+ if (v2 != null) {
+ return false;
+ }
+ } else if (!v1.equals(v2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public void showViews(Activity activity, Bundle extras /*Bundle savedInstanceState*/) {
+ Bundle args = extras.getBundle(ComboViewActivity.EXTRA_COMBO_ARGS);
+ String svStr = extras.getString(ComboViewActivity.EXTRA_INITIAL_VIEW, null);
+ ComboViews startingView = svStr != null ? ComboViews.valueOf(svStr) : ComboViews.Bookmarks;
+
+
+ // Compare the items in args with old args and recreate the fragments if they don't match.
+ if (mExtraArgs != null && !compareArgs(mExtraArgs, args)) {
+ mTabsAdapter = null;
+ }
+
+ final ActionBar bar = activity.getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
- if (BrowserActivity.isTablet(this)) {
+ if (BrowserActivity.isTablet(activity)) {
bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
| ActionBar.DISPLAY_USE_LOGO);
- bar.setHomeButtonEnabled(true);
+ bar.setDisplayHomeAsUpEnabled(true);
} else {
bar.setDisplayOptions(0);
}
+ if (mTabsAdapter == null) {
+ mExtraArgs = args;
+ mTabsAdapter = new ComboTabsAdapter(activity, mViewPager);
+ mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks),
+ BrowserBookmarksPage.class, args);
+ mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_history),
+ BrowserHistoryPage.class, args);
+ mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_snapshots),
+ BrowserSnapshotPage.class, args);
+ }
- mTabsAdapter = new TabsAdapter(this, mViewPager);
- mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks),
- BrowserBookmarksPage.class, args);
- mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_history),
- BrowserHistoryPage.class, args);
- mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_snapshots),
- BrowserSnapshotPage.class, args);
-
- if (savedInstanceState != null) {
+ /*if (savedInstanceState != null) {
bar.setSelectedNavigationItem(
savedInstanceState.getInt(STATE_SELECTED_TAB, 0));
- } else {
+ } else*/ {
switch (startingView) {
- case Bookmarks:
- mViewPager.setCurrentItem(0);
- break;
- case History:
- mViewPager.setCurrentItem(1);
- break;
- case Snapshots:
- mViewPager.setCurrentItem(2);
- break;
+ case Bookmarks:
+ mViewPager.setCurrentItem(0);
+ break;
+ case History:
+ mViewPager.setCurrentItem(1);
+ break;
+ case Snapshots:
+ mViewPager.setCurrentItem(2);
+ break;
+ }
+ }
+
+ if (!bar.isShowing()) {
+ View v = getScrollingTabContainerView();
+ if (v != null) {
+ v.setVisibility(View.VISIBLE);
+ }
+ bar.show();
+ }
+
+ if (!this.isShowing()) {
+ this.setVisibility(View.VISIBLE);
+ this.requestFocus();
+ if (!(BrowserActivity.isTablet(activity))) {
+ this.startAnimation(mInAnimation);
}
}
}
- @Override
- protected void onSaveInstanceState(Bundle outState) {
+ public boolean isShowing() {
+ return (this.getVisibility() == View.VISIBLE);
+ }
+
+ public void hideViews() {
+ if(!(BrowserActivity.isTablet(mActivity)))
+ this.startAnimation(mOutAnimation);
+ this.setVisibility(View.INVISIBLE);
+ mActionBarContainerId = getResources().getIdentifier("action_bar_container", "id", "android");
+ ViewGroup actionBarContainer = (ViewGroup) mActivity.getWindow().getDecorView().findViewById(mActionBarContainerId);
+ if (actionBarContainer != null) {
+ actionBarContainer.removeOnLayoutChangeListener(this);
+ }
+ ActionBar actionBar = mActivity.getActionBar();
+ actionBar.hide();
+ }
+
+ //TODO: Save the selected tab on BrowserActivity's onSaveInstanceState
+ /*public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_SELECTED_TAB,
getActionBar().getSelectedNavigationIndex());
- }
+ }*/
@Override
public void openUrl(String url) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- setResult(RESULT_OK, i);
- finish();
+ i.setClassName(getContext().getPackageName(), BrowserActivity.class.getName());
+ i.putExtra(Controller.EXTRA_REQUEST_CODE, Controller.COMBO_VIEW);
+ i.putExtra(Controller.EXTRA_RESULT_CODE, Activity.RESULT_OK);
+ this.getContext().startActivity(i);
+ hideViews();
}
@Override
public void openInNewTab(String... urls) {
Intent i = new Intent();
- i.putExtra(EXTRA_OPEN_ALL, urls);
- setResult(RESULT_OK, i);
- finish();
+ i.putExtra(ComboViewActivity.EXTRA_OPEN_ALL, urls);
+ i.putExtra(Controller.EXTRA_REQUEST_CODE, Controller.COMBO_VIEW);
+ i.putExtra(Controller.EXTRA_RESULT_CODE, Activity.RESULT_OK);
+ i.setClassName(getContext().getPackageName(), BrowserActivity.class.getName());
+ this.getContext().startActivity(i);
+ hideViews();
}
@Override
public void close() {
- finish();
+ hideViews();
}
@Override
public void openSnapshot(long id) {
Intent i = new Intent();
- i.putExtra(EXTRA_OPEN_SNAPSHOT, id);
- setResult(RESULT_OK, i);
- finish();
+ i.putExtra(ComboViewActivity.EXTRA_OPEN_SNAPSHOT, id);
+ i.putExtra(Controller.EXTRA_REQUEST_CODE, Controller.COMBO_VIEW);
+ i.putExtra(Controller.EXTRA_RESULT_CODE, Activity.RESULT_OK);
+ i.setClassName(getContext().getPackageName(), BrowserActivity.class.getName());
+ this.getContext().startActivity(i);
+ hideViews();
}
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.combined, menu);
- return super.onCreateOptionsMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == android.R.id.home) {
- finish();
- return true;
- } else if (item.getItemId() == R.id.preferences_menu_id) {
- String url = getIntent().getStringExtra(EXTRA_CURRENT_URL);
- BrowserPreferencesPage.startPreferencesForResult(this, url, Controller.PREFERENCES_PAGE);
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- /**
- * This is a helper class that implements the management of tabs and all
- * details of connecting a ViewPager with associated TabHost. It relies on a
- * trick. Normally a tab host has a simple API for supplying a View or
- * Intent that each tab will show. This is not sufficient for switching
- * between pages. So instead we make the content part of the tab host
- * 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
- * view to show as the tab content. It listens to changes in tabs, and takes
- * care of switch to the correct page in the ViewPager whenever the selected
- * tab changes.
- */
- public static class TabsAdapter extends FragmentPagerAdapter
- implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
- private final Context mContext;
- private final ActionBar mActionBar;
- private final ViewPager mViewPager;
- private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
-
- static final class TabInfo {
- private final Class<?> clss;
- private final Bundle args;
-
- TabInfo(Class<?> _class, Bundle _args) {
- clss = _class;
- args = _args;
- }
- }
-
- public TabsAdapter(Activity activity, ViewPager pager) {
- super(activity.getFragmentManager());
- mContext = activity;
- mActionBar = activity.getActionBar();
- mViewPager = pager;
- mViewPager.setAdapter(this);
- mViewPager.setOnPageChangeListener(this);
- }
-
- public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
- TabInfo info = new TabInfo(clss, args);
- tab.setTag(info);
- tab.setTabListener(this);
- mTabs.add(info);
- mActionBar.addTab(tab);
- notifyDataSetChanged();
- }
-
- @Override
- public int getCount() {
- return mTabs.size();
- }
-
- @Override
- public Fragment getItem(int position) {
- TabInfo info = mTabs.get(position);
- return Fragment.instantiate(mContext, info.clss.getName(), info.args);
- }
-
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
-
- @Override
- public void onPageSelected(int position) {
- mActionBar.setSelectedNavigationItem(position);
- }
-
- @Override
- public void onPageScrollStateChanged(int state) {
- }
-
- @Override
- public void onTabSelected(android.app.ActionBar.Tab tab,
- FragmentTransaction ft) {
- Object tag = tab.getTag();
- for (int i=0; i<mTabs.size(); i++) {
- if (mTabs.get(i) == tag) {
- mViewPager.setCurrentItem(i);
- }
- }
- }
-
- @Override
- public void onTabUnselected(android.app.ActionBar.Tab tab,
- FragmentTransaction ft) {
- }
-
- @Override
- public void onTabReselected(android.app.ActionBar.Tab tab,
- FragmentTransaction ft) {
- }
- }
-
- private static String makeFragmentName(int viewId, int index) {
- return "android:switcher:" + viewId + ":" + index;
- }
-
}
diff --git a/src/com/android/browser/ComboViewActivity.java b/src/com/android/browser/ComboViewActivity.java
index 5ce20fc..4e672ca 100644
--- a/src/com/android/browser/ComboViewActivity.java
+++ b/src/com/android/browser/ComboViewActivity.java
@@ -17,21 +17,15 @@
import android.app.ActionBar;
import android.app.Activity;
-import android.app.Fragment;
-import android.app.FragmentTransaction;
-import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
-import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;
import com.android.browser.UI.ComboViews;
-import java.util.ArrayList;
-
public class ComboViewActivity extends Activity implements CombinedBookmarksCallbacks {
private static final String STATE_SELECTED_TAB = "tab";
@@ -42,7 +36,7 @@
public static final String EXTRA_OPEN_ALL = "open_all";
public static final String EXTRA_CURRENT_URL = "url";
private ViewPager mViewPager;
- private TabsAdapter mTabsAdapter;
+ private ComboTabsAdapter mTabsAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -68,7 +62,7 @@
bar.setDisplayOptions(0);
}
- mTabsAdapter = new TabsAdapter(this, mViewPager);
+ mTabsAdapter = new ComboTabsAdapter(this, mViewPager);
mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_bookmarks),
BrowserBookmarksPage.class, args);
mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_history),
@@ -148,98 +142,6 @@
return super.onOptionsItemSelected(item);
}
- /**
- * This is a helper class that implements the management of tabs and all
- * details of connecting a ViewPager with associated TabHost. It relies on a
- * trick. Normally a tab host has a simple API for supplying a View or
- * Intent that each tab will show. This is not sufficient for switching
- * between pages. So instead we make the content part of the tab host
- * 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
- * view to show as the tab content. It listens to changes in tabs, and takes
- * care of switch to the correct page in the ViewPager whenever the selected
- * tab changes.
- */
- public static class TabsAdapter extends FragmentPagerAdapter
- implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
- private final Context mContext;
- private final ActionBar mActionBar;
- private final ViewPager mViewPager;
- private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
-
- static final class TabInfo {
- private final Class<?> clss;
- private final Bundle args;
-
- TabInfo(Class<?> _class, Bundle _args) {
- clss = _class;
- args = _args;
- }
- }
-
- public TabsAdapter(Activity activity, ViewPager pager) {
- super(activity.getFragmentManager());
- mContext = activity;
- mActionBar = activity.getActionBar();
- mViewPager = pager;
- mViewPager.setAdapter(this);
- mViewPager.setOnPageChangeListener(this);
- }
-
- public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
- TabInfo info = new TabInfo(clss, args);
- tab.setTag(info);
- tab.setTabListener(this);
- mTabs.add(info);
- mActionBar.addTab(tab);
- notifyDataSetChanged();
- }
-
- @Override
- public int getCount() {
- return mTabs.size();
- }
-
- @Override
- public Fragment getItem(int position) {
- TabInfo info = mTabs.get(position);
- return Fragment.instantiate(mContext, info.clss.getName(), info.args);
- }
-
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
-
- @Override
- public void onPageSelected(int position) {
- mActionBar.setSelectedNavigationItem(position);
- }
-
- @Override
- public void onPageScrollStateChanged(int state) {
- }
-
- @Override
- public void onTabSelected(android.app.ActionBar.Tab tab,
- FragmentTransaction ft) {
- Object tag = tab.getTag();
- for (int i=0; i<mTabs.size(); i++) {
- if (mTabs.get(i) == tag) {
- mViewPager.setCurrentItem(i);
- }
- }
- }
-
- @Override
- public void onTabUnselected(android.app.ActionBar.Tab tab,
- FragmentTransaction ft) {
- }
-
- @Override
- public void onTabReselected(android.app.ActionBar.Tab tab,
- FragmentTransaction ft) {
- }
- }
-
private static String makeFragmentName(int viewId, int index) {
return "android:switcher:" + viewId + ":" + index;
}
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 53c7e34..3d651d8 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -137,6 +137,8 @@
private static final String SEND_APP_ID_EXTRA =
"android.speech.extras.SEND_APPLICATION_ID_EXTRA";
private static final String INCOGNITO_URI = "chrome://incognito";
+ public static final String EXTRA_REQUEST_CODE = "_fake_request_code_";
+ public static final String EXTRA_RESULT_CODE = "_fake_result_code_";
// Remind switch to data connection if wifi is unavailable
private static final int NETWORK_SWITCH_TYPE_OK = 1;
@@ -3315,8 +3317,10 @@
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0) {
// Hardware menu key
- mAppMenuHandler.showAppMenu(mActivity.findViewById(R.id.taburlbar),
- true, false);
+ if (!mUi.isComboViewShowing()) {
+ mAppMenuHandler.showAppMenu(mActivity.findViewById(R.id.taburlbar),
+ true, false);
+ }
return true;
}
diff --git a/src/com/android/browser/IntentHandler.java b/src/com/android/browser/IntentHandler.java
index 0e255e2..9e2bddf 100644
--- a/src/com/android/browser/IntentHandler.java
+++ b/src/com/android/browser/IntentHandler.java
@@ -63,6 +63,13 @@
}
void onNewIntent(Intent intent) {
+ int requestCode = intent.getIntExtra(Controller.EXTRA_REQUEST_CODE, -1);
+ if (requestCode >= Controller.COMBO_VIEW && requestCode <= Controller.MY_NAVIGATION) {
+ int resultCode = intent.getIntExtra(Controller.EXTRA_RESULT_CODE, Activity.RESULT_OK);
+ mController.onActivityResult(requestCode, resultCode, intent);
+ return;
+ }
+
Tab current = mTabControl.getCurrentTab();
// When a tab is closed on exit, the current tab index is set to -1.
// Reset before proceed as Browser requires the current tab to be set.
diff --git a/src/com/android/browser/NavTabView.java b/src/com/android/browser/NavTabView.java
index 49bd080..0fc8dfd 100644
--- a/src/com/android/browser/NavTabView.java
+++ b/src/com/android/browser/NavTabView.java
@@ -62,7 +62,7 @@
mClose = (ImageView) findViewById(R.id.closetab);
mTitle = (TextView) findViewById(R.id.title);
mTitleBar = findViewById(R.id.titlebar);
- mImage = (ImageView) findViewById(R.id.tab_view);
+ mImage = (ImageView) findViewById(R.id.tab_preview);
}
protected boolean isClose(View v) {
diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java
index e935932..c051ec0 100644
--- a/src/com/android/browser/PhoneUi.java
+++ b/src/com/android/browser/PhoneUi.java
@@ -24,6 +24,9 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.ActionMode;
@@ -32,8 +35,13 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewStub;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.DecelerateInterpolator;
+import android.webkit.ValueCallback;
+import org.codeaurora.swe.WebView;
+
+import android.widget.FrameLayout;
import android.widget.ImageView;
import com.android.browser.UrlInputView.StateListener;
@@ -50,12 +58,13 @@
private NavScreen mNavScreen;
private AnimScreen mAnimScreen;
- private NavigationBarPhone mNavigationBar;
- private Activity mBrowser;
+ private final NavigationBarPhone mNavigationBar;
+ private final Activity mBrowser;
private boolean mNavScreenRequested = false;
boolean mAnimating;
boolean mShowNav = false;
+ private ComboView mComboView;
/**
@@ -83,11 +92,42 @@
}
@Override
+ public void showComboView(ComboViews startingView, Bundle extras) {
+
+ if (mComboView == null) {
+ mNavScreen.setVisibility(View.GONE);
+ ViewStub stub = (ViewStub) mActivity.getWindow().getDecorView().findViewById(R.id.combo_view_stub);
+ mComboView = (ComboView) stub.inflate();
+ mComboView.setVisibility(View.GONE);
+ mComboView.setupViews(mActivity);
+ }
+
+ Bundle b = new Bundle();
+ b.putString(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
+ b.putBundle(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
+ Tab t = getActiveTab();
+ if (t != null) {
+ b.putString(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
+ }
+
+ mComboView.showViews(mActivity, b);
+ }
+
+ @Override
+ public void hideComboView() {
+ mComboView.hideViews();
+ }
+
+ @Override
public boolean onBackKey() {
if (showingNavScreen()) {
mNavScreen.close(mUiController.getTabControl().getCurrentPosition());
return true;
}
+ if (showingComboView()) {
+ hideComboView();
+ return true;
+ }
return super.onBackKey();
}
@@ -95,6 +135,10 @@
return mNavScreen != null && mNavScreen.getVisibility() == View.VISIBLE;
}
+ private boolean showingComboView() {
+ return mComboView != null && mComboView.getVisibility() == View.VISIBLE;
+ }
+
@Override
public boolean dispatchKey(int code, KeyEvent event) {
return false;
@@ -119,8 +163,6 @@
}
if (mAnimScreen == null) {
mAnimScreen = new AnimScreen(mActivity);
- // initialize bitmaps
- //mAnimScreen.set(getTitleBar(), getWebView());
}
}
}
@@ -179,6 +221,13 @@
menu.setGroupVisible(R.id.SNAPSHOT_MENU, false);
menu.setGroupVisible(R.id.NAV_MENU, false);
}
+
+ if (showingComboView()) {
+ menu.setGroupVisible(R.id.MAIN_MENU, false);
+ menu.setGroupEnabled(R.id.MAIN_MENU, false);
+ menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, false);
+ }
+
}
@Override
@@ -223,7 +272,12 @@
@Override
public boolean isWebShowing() {
- return super.isWebShowing() && !showingNavScreen();
+ return super.isWebShowing() && !showingNavScreen() && !showingComboView();
+ }
+
+ @Override
+ public boolean isComboViewShowing() {
+ return showingComboView();
}
@Override
diff --git a/src/com/android/browser/UI.java b/src/com/android/browser/UI.java
index 172509b..1f881b1 100644
--- a/src/com/android/browser/UI.java
+++ b/src/com/android/browser/UI.java
@@ -88,6 +88,8 @@
public void showComboView(ComboViews startingView, Bundle extra);
+ public void hideComboView();
+
public void showCustomView(View view, int requestedOrientation,
CustomViewCallback callback);
@@ -120,6 +122,8 @@
// returns if the web page is clear of any overlays (not including sub windows)
public boolean isWebShowing();
+ public boolean isComboViewShowing();
+
public void showWeb(boolean animate);
Bitmap getDefaultVideoPoster();
diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java
index 603ce08..ec62a23 100644
--- a/src/com/android/browser/XLargeUi.java
+++ b/src/com/android/browser/XLargeUi.java
@@ -32,6 +32,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewStub;
import android.webkit.WebChromeClient;
import org.codeaurora.swe.WebView;
@@ -53,6 +54,7 @@
private TabBar mTabBar;
private NavigationBarTablet mNavBar;
+ private ComboView mComboView;
private Handler mHandler;
@@ -70,13 +72,60 @@
}
private void setupActionBar() {
+ mActionBar.setHomeButtonEnabled(false);
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
mActionBar.setCustomView(mTabBar);
}
public void showComboView(ComboViews startWith, Bundle extras) {
- super.showComboView(startWith, extras);
+ if (mComboView == null) {
+ ViewStub stub = (ViewStub) mActivity.getWindow().getDecorView().findViewById(R.id.combo_view_stub);
+ mComboView = (ComboView) stub.inflate();
+ mComboView.setVisibility(View.GONE);
+ mComboView.setupViews(mActivity);
+ }
+ mNavBar.setVisibility(View.GONE);
+ if (mActionBar != null)
+ mActionBar.hide();
+ Bundle b = new Bundle();
+ b.putString(ComboViewActivity.EXTRA_INITIAL_VIEW, startWith.name());
+ b.putBundle(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
+ Tab t = getActiveTab();
+ if (t != null) {
+ b.putString(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
+ }
+ mComboView.showViews(mActivity, b);
+ }
+
+ @Override
+ public void hideComboView() {
+ if (showingComboView()) {
+ mComboView.hideViews();
+ mActionBar = mActivity.getActionBar();
+ setupActionBar();
+ if (mActionBar != null)
+ mActionBar.show();
+ mNavBar.setVisibility(View.VISIBLE);
+ }
+ }
+
+ @Override
+ public boolean onBackKey() {
+ if (showingComboView()) {
+ hideComboView();
+ return true;
+ }
+ return super.onBackKey();
+ }
+
+ private boolean showingComboView() {
+ return mComboView != null && mComboView.getVisibility() == View.VISIBLE;
+ }
+
+ @Override
+ public boolean isComboViewShowing() {
+ return showingComboView();
}
private void checkHideActionBar() {