Bug 729463 - Implement switch to tab for fennec. r=mfinkle

This commit is contained in:
Wes Johnston 2013-04-30 10:21:15 -07:00
Родитель 566850eec8
Коммит c55f928a95
14 изменённых файлов: 93 добавлений и 23 удалений

Просмотреть файл

@ -56,6 +56,7 @@ public class AwesomeBar extends GeckoActivity
private static final String LOGTAG = "GeckoAwesomeBar";
public static final String URL_KEY = "url";
public static final String TAB_KEY = "tab";
public static final String CURRENT_URL_KEY = "currenturl";
public static final String TARGET_KEY = "target";
public static final String SEARCH_KEY = "search";
@ -120,6 +121,13 @@ public class AwesomeBar extends GeckoActivity
}
});
}
@Override
public void onSwitchToTab(final int tabId) {
Intent resultIntent = new Intent();
resultIntent.putExtra(TAB_KEY, Integer.toString(tabId));
finishWithResult(resultIntent);
}
});
mGoButton.setOnClickListener(new Button.OnClickListener() {

Просмотреть файл

@ -42,6 +42,7 @@ public class AwesomeBarTabs extends TabHost
public void onUrlOpen(String url, String title);
public void onSearch(SearchEngine engine, String text);
public void onEditSuggestion(String suggestion);
public void onSwitchToTab(final int tabId);
}
private class AwesomePagerAdapter extends PagerAdapter {

Просмотреть файл

@ -7,6 +7,7 @@ package org.mozilla.gecko;
import org.mozilla.gecko.util.ActivityResultHandler;
import android.content.Intent;
import android.util.Log;
class AwesomebarResultHandler implements ActivityResultHandler {
private static final String LOGTAG = "GeckoAwesomebarResultHandler";
@ -14,6 +15,12 @@ class AwesomebarResultHandler implements ActivityResultHandler {
@Override
public void onActivityResult(int resultCode, Intent data) {
if (data != null) {
String tab = data.getStringExtra(AwesomeBar.TAB_KEY);
if (tab != null) {
Tabs.getInstance().selectTab(Integer.parseInt(tab));
return;
}
String url = data.getStringExtra(AwesomeBar.URL_KEY);
AwesomeBar.Target target = AwesomeBar.Target.valueOf(data.getStringExtra(AwesomeBar.TARGET_KEY));
String searchEngine = data.getStringExtra(AwesomeBar.SEARCH_KEY);

Просмотреть файл

@ -578,6 +578,7 @@ RES_DRAWABLE_MDPI = \
res/drawable-mdpi/ic_awesomebar_reader.png \
res/drawable-mdpi/ic_awesomebar_search.png \
res/drawable-mdpi/ic_awesomebar_star.png \
res/drawable-mdpi/ic_awesomebar_tab.png \
res/drawable-mdpi/ic_menu_addons_filler.png \
res/drawable-mdpi/ic_menu_bookmark_add.png \
res/drawable-mdpi/ic_menu_bookmark_remove.png \
@ -690,6 +691,7 @@ RES_DRAWABLE_HDPI = \
res/drawable-hdpi/ic_awesomebar_reader.png \
res/drawable-hdpi/ic_awesomebar_search.png \
res/drawable-hdpi/ic_awesomebar_star.png \
res/drawable-hdpi/ic_awesomebar_tab.png \
res/drawable-hdpi/ic_menu_addons_filler.png \
res/drawable-hdpi/ic_menu_bookmark_add.png \
res/drawable-hdpi/ic_menu_bookmark_remove.png \
@ -782,6 +784,7 @@ RES_DRAWABLE_XHDPI = \
res/drawable-xhdpi/ic_awesomebar_reader.png \
res/drawable-xhdpi/ic_awesomebar_search.png \
res/drawable-xhdpi/ic_awesomebar_star.png \
res/drawable-xhdpi/ic_awesomebar_tab.png \
res/drawable-xhdpi/ic_menu_addons_filler.png \
res/drawable-xhdpi/ic_menu_bookmark_add.png \
res/drawable-xhdpi/ic_menu_bookmark_remove.png \

Просмотреть файл

@ -155,6 +155,15 @@ public class Tabs implements GeckoEventListener {
return count;
}
public synchronized int isOpen(String url) {
for (Tab tab : mOrder) {
if (tab.getURL().equals(url)) {
return tab.getId();
}
}
return -1;
}
// Must be synchronized to avoid racing on mContentObserver.
private void lazyRegisterBookmarkObserver() {
if (mContentObserver == null) {

Просмотреть файл

@ -151,6 +151,8 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
@Override
public void destroy() {
super.destroy();
unregisterEventListener("SearchEngines:Data");
mHandler.removeMessages(MESSAGE_UPDATE_FAVICONS);
@ -321,13 +323,9 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
@Override
public void onClick() {
AwesomeBarTabs.OnUrlOpenListener listener = getUrlListener();
if (listener == null)
return;
String url = mCursor.getString(mCursor.getColumnIndexOrThrow(URLColumns.URL));
String title = mCursor.getString(mCursor.getColumnIndexOrThrow(URLColumns.TITLE));
listener.onUrlOpen(url, title);
sendToListener(url, title);
}
@Override

Просмотреть файл

@ -24,10 +24,11 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.HashMap;
abstract public class AwesomeBarTab {
abstract public String getTag();
abstract public int getTitleStringId();
abstract public void destroy();
abstract public boolean onBackPressed();
abstract public ContextMenuSubject getSubject(ContextMenu menu, View view, ContextMenuInfo menuInfo);
abstract public View getView();
@ -41,11 +42,16 @@ abstract public class AwesomeBarTab {
// FIXME: This value should probably come from a prefs key
public static final int MAX_RESULTS = 100;
protected Context mContext = null;
public static HashMap<String, Integer> sOpenTabs;
public AwesomeBarTab(Context context) {
mContext = context;
}
public void destroy() {
sOpenTabs = null;
}
public void setListTouchListener(View.OnTouchListener listener) {
mListListener = listener;
if (mView != null)
@ -81,6 +87,17 @@ abstract public class AwesomeBarTab {
return mContentResolver;
}
private HashMap<String, Integer> getOpenTabs() {
if (sOpenTabs == null || sOpenTabs.isEmpty()) {
Iterable<Tab> tabs = Tabs.getInstance().getTabsInOrder();
sOpenTabs = new HashMap<String, Integer>();
for (Tab tab : tabs) {
sOpenTabs.put(tab.getURL(), tab.getId());
}
}
return sOpenTabs;
}
protected Resources getResources() {
if (mResources == null) {
mResources = mContext.getResources();
@ -95,22 +112,54 @@ abstract public class AwesomeBarTab {
protected void updateTitle(TextView titleView, Cursor cursor) {
int titleIndex = cursor.getColumnIndexOrThrow(URLColumns.TITLE);
String title = cursor.getString(titleIndex);
String url = "";
// Use the URL instead of an empty title for consistency with the normal URL
// bar view - this is the equivalent of getDisplayTitle() in Tab.java
if (TextUtils.isEmpty(title)) {
int urlIndex = cursor.getColumnIndexOrThrow(URLColumns.URL);
title = cursor.getString(urlIndex);
url = cursor.getString(urlIndex);
}
titleView.setText(title);
updateTitle(titleView, title, url);
}
protected void updateTitle(TextView titleView, String title, String url) {
if (TextUtils.isEmpty(title)) {
titleView.setText(url);
} else {
titleView.setText(title);
}
}
public void sendToListener(String url, String title) {
AwesomeBarTabs.OnUrlOpenListener listener = getUrlListener();
if (listener == null)
return;
Integer tabId = getOpenTabs().get(url);
if (tabId != null) {
listener.onSwitchToTab(tabId);
} else {
listener.onUrlOpen(url, title);
}
}
protected void updateUrl(TextView urlView, Cursor cursor) {
int urlIndex = cursor.getColumnIndexOrThrow(URLColumns.URL);
String url = cursor.getString(urlIndex);
updateUrl(urlView, url);
}
urlView.setText(url);
protected void updateUrl(TextView urlView, String url) {
Integer tabId = getOpenTabs().get(url);
if (tabId != null) {
urlView.setText(R.string.awesomebar_switch_to_tab);
urlView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_awesomebar_tab, 0, 0, 0);
} else {
urlView.setText(url);
urlView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
}
protected boolean hideSoftInput(View view) {

Просмотреть файл

@ -95,6 +95,7 @@ public class BookmarksTab extends AwesomeBarTab {
@Override
public void destroy() {
super.destroy();
// Can't use getters for adapter. It will create one if null.
if (mCursorAdapter != null && mView != null) {
ListView list = (ListView)mView;
@ -203,18 +204,13 @@ public class BookmarksTab extends AwesomeBarTab {
}
// Otherwise, just open the URL
AwesomeBarTabs.OnUrlOpenListener listener = getUrlListener();
if (listener == null) {
return;
}
String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
String title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE));
long parentId = cursor.getLong(cursor.getColumnIndexOrThrow(Bookmarks.PARENT));
if (parentId == Bookmarks.FIXED_READING_LIST_ID) {
url = ReaderModeUtils.getAboutReaderForUrl(url, true);
}
listener.onUrlOpen(url, title);
sendToListener(url, title);
}
private class BookmarksListAdapter extends SimpleCursorAdapter {

Просмотреть файл

@ -124,6 +124,8 @@ public class HistoryTab extends AwesomeBarTab {
@Override
public void destroy() {
super.destroy();
if (mContentObserver != null)
BrowserDB.unregisterContentObserver(getContentResolver(), mContentObserver);
}
@ -183,11 +185,8 @@ public class HistoryTab extends AwesomeBarTab {
String title = (String) historyItem.get(URLColumns.TITLE);
String url = (String) historyItem.get(URLColumns.URL);
if (TextUtils.isEmpty(title))
title = url;
viewHolder.titleView.setText(title);
viewHolder.urlView.setText(url);
updateTitle(viewHolder.titleView, title, url);
updateUrl(viewHolder.urlView, url);
byte[] b = (byte[]) historyItem.get(URLColumns.FAVICON);
Bitmap favicon = null;
@ -412,9 +411,7 @@ public class HistoryTab extends AwesomeBarTab {
String url = (String) historyItem.get(URLColumns.URL);
String title = (String) historyItem.get(URLColumns.TITLE);
AwesomeBarTabs.OnUrlOpenListener listener = getUrlListener();
if (!TextUtils.isEmpty(url) && listener != null)
listener.onUrlOpen(url, title);
sendToListener(url, title);
return true;
}

Просмотреть файл

@ -12,6 +12,7 @@
<!ENTITY awesomebar_all_pages_title "Top Sites">
<!ENTITY awesomebar_bookmarks_title "Bookmarks">
<!ENTITY awesomebar_history_title "History">
<!ENTITY awesomebar_switch_to_tab "Switch to tab">
<!ENTITY crash_reporter_title "&brandShortName; Crash Reporter">
<!ENTITY crash_message2 "&brandShortName; had a problem and crashed. Your tabs should be listed on the &brandShortName; Start page when you restart.">

Двоичные данные
mobile/android/base/resources/drawable-hdpi/ic_awesomebar_tab.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 297 B

Двоичные данные
mobile/android/base/resources/drawable-mdpi/ic_awesomebar_tab.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 246 B

Двоичные данные
mobile/android/base/resources/drawable-xhdpi/ic_awesomebar_tab.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 376 B

Просмотреть файл

@ -26,6 +26,7 @@
<string name="awesomebar_all_pages_title">&awesomebar_all_pages_title;</string>
<string name="awesomebar_bookmarks_title">&awesomebar_bookmarks_title;</string>
<string name="awesomebar_history_title">&awesomebar_history_title;</string>
<string name="awesomebar_switch_to_tab">&awesomebar_switch_to_tab;</string>
<string name="crash_reporter_title">&crash_reporter_title;</string>
<string name="crash_message2">&crash_message2;</string>