зеркало из https://github.com/mozilla/gecko-dev.git
Bug 778216 - Add a pref to show the url instead of title. r=mfinkle
This commit is contained in:
Родитель
0dc0f0ffb2
Коммит
4af0b9382d
|
@ -9,7 +9,11 @@ import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
|||
import org.mozilla.gecko.gfx.LayerView;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.util.UiAsyncTask;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Rect;
|
||||
|
@ -51,8 +55,11 @@ import java.util.List;
|
|||
public class BrowserToolbar implements ViewSwitcher.ViewFactory,
|
||||
Tabs.OnTabsChangedListener,
|
||||
GeckoMenu.ActionItemBarPresenter,
|
||||
Animation.AnimationListener {
|
||||
Animation.AnimationListener,
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final String LOGTAG = "GeckoToolbar";
|
||||
public static final String PREFS_NAME = "BrowserToolbar";
|
||||
public static final String PREFS_SHOW_URL = "ShowUrl";
|
||||
private GeckoRelativeLayout mLayout;
|
||||
private LayoutParams mAwesomeBarParams;
|
||||
private View mAwesomeBarContent;
|
||||
|
@ -115,6 +122,8 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
|
|||
|
||||
private static final int FORWARD_ANIMATION_DURATION = 450;
|
||||
|
||||
private boolean mShowUrl;
|
||||
|
||||
public BrowserToolbar(BrowserApp activity) {
|
||||
// BrowserToolbar is attached to BrowserApp only.
|
||||
mActivity = activity;
|
||||
|
@ -125,6 +134,27 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
|
|||
mAnimateSiteSecurity = true;
|
||||
|
||||
mAnimatingEntry = false;
|
||||
mShowUrl = false;
|
||||
|
||||
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
|
||||
@Override
|
||||
public synchronized Void doInBackground(Void... params) {
|
||||
SharedPreferences settings = mActivity.getSharedPreferences(PREFS_NAME, 0);
|
||||
settings.registerOnSharedPreferenceChangeListener(BrowserToolbar.this);
|
||||
mShowUrl = settings.getBoolean(PREFS_SHOW_URL, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute(Void v) {
|
||||
if (mShowUrl) {
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
setTitle(tab.getURL());
|
||||
}
|
||||
}
|
||||
}
|
||||
}).execute();
|
||||
}
|
||||
|
||||
public void from(RelativeLayout layout) {
|
||||
|
@ -431,7 +461,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
|
|||
switch(msg) {
|
||||
case TITLE:
|
||||
if (Tabs.getInstance().isSelectedTab(tab)) {
|
||||
setTitle(tab.getDisplayTitle());
|
||||
setTitle(mShowUrl ? tab.getURL() : tab.getDisplayTitle());
|
||||
}
|
||||
break;
|
||||
case START:
|
||||
|
@ -451,7 +481,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
|
|||
updateForwardButton(tab.canDoForward());
|
||||
setProgressVisibility(false);
|
||||
// Reset the title in case we haven't navigated to a new page yet.
|
||||
setTitle(tab.getDisplayTitle());
|
||||
setTitle(mShowUrl ? tab.getURL() : tab.getDisplayTitle());
|
||||
}
|
||||
break;
|
||||
case RESTORED:
|
||||
|
@ -1189,7 +1219,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
|
|||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
String url = tab.getURL();
|
||||
setTitle(tab.getDisplayTitle());
|
||||
setTitle(mShowUrl ? tab.getURL() : tab.getDisplayTitle());
|
||||
setFavicon(tab.getFavicon());
|
||||
setProgressVisibility(tab.getState() == Tab.STATE_LOADING);
|
||||
setSecurityMode(tab.getSecurityMode());
|
||||
|
@ -1237,4 +1267,14 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals(PREFS_SHOW_URL)) {
|
||||
mShowUrl = sharedPreferences.getBoolean(key, false);
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
setTitle(mShowUrl ? tab.getURL() : tab.getDisplayTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ public class GeckoPreferences
|
|||
private static String PREFS_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
|
||||
private static String PREFS_TELEMETRY_ENABLED_PRERELEASE = "toolkit.telemetry.enabledPreRelease";
|
||||
private static String PREFS_UPDATER_AUTODOWNLOAD = "app.update.autodownload";
|
||||
private static String PREFS_TITLEBAR_MODE = "android.not_a_preference.privacy.titlebar";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -173,6 +174,8 @@ public class GeckoPreferences
|
|||
i--;
|
||||
continue;
|
||||
}
|
||||
} else if (PREFS_TITLEBAR_MODE.equals(key)) {
|
||||
setupTitlebarPref((ListPreference)pref);
|
||||
}
|
||||
|
||||
// Some Preference UI elements are not actually preferences,
|
||||
|
@ -536,4 +539,29 @@ public class GeckoPreferences
|
|||
public boolean isGeckoActivityOpened() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setupTitlebarPref(final ListPreference pref) {
|
||||
final SharedPreferences settings = getSharedPreferences(BrowserToolbar.PREFS_NAME, 0);
|
||||
boolean value = settings.getBoolean(BrowserToolbar.PREFS_SHOW_URL, false);
|
||||
|
||||
final String[] entries = new String[] {
|
||||
getResources().getString(R.string.pref_titlebar_mode_url),
|
||||
getResources().getString(R.string.pref_titlebar_mode_title)
|
||||
};
|
||||
pref.setEntries(entries);
|
||||
pref.setEntryValues(entries);
|
||||
pref.setValueIndex(value ? 0 : 1);
|
||||
pref.setSummary(value ? entries[0] : entries[1]);
|
||||
|
||||
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
settings.edit()
|
||||
.putBoolean(BrowserToolbar.PREFS_SHOW_URL, newValue.toString().equals(entries[0]))
|
||||
.commit();
|
||||
pref.setSummary(newValue.toString());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,6 +174,10 @@ size. -->
|
|||
<!ENTITY contextmenu_subscribe "Subscribe to Page">
|
||||
<!ENTITY contextmenu_site_settings "Edit Site Settings">
|
||||
|
||||
<!ENTITY pref_titlebar_mode "Title bar">
|
||||
<!ENTITY pref_titlebar_mode_title "Show page title">
|
||||
<!ENTITY pref_titlebar_mode_url "Show page address">
|
||||
|
||||
<!ENTITY history_removed "Page removed">
|
||||
|
||||
<!ENTITY bookmark_edit_title "Edit Bookmark">
|
||||
|
|
|
@ -54,6 +54,10 @@
|
|||
android:defaultValue="true"
|
||||
android:persistent="true" />
|
||||
|
||||
<ListPreference android:key="android.not_a_preference.privacy.titlebar"
|
||||
android:title="@string/pref_titlebar_mode"
|
||||
android:persistent="true" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
@ -177,6 +177,10 @@
|
|||
<string name="contextmenu_subscribe">&contextmenu_subscribe;</string>
|
||||
<string name="contextmenu_site_settings">&contextmenu_site_settings;</string>
|
||||
|
||||
<string name="pref_titlebar_mode">&pref_titlebar_mode;</string>
|
||||
<string name="pref_titlebar_mode_title">&pref_titlebar_mode_title;</string>
|
||||
<string name="pref_titlebar_mode_url">&pref_titlebar_mode_url;</string>
|
||||
|
||||
<string name="history_removed">&history_removed;</string>
|
||||
|
||||
<string name="bookmark_edit_title">&bookmark_edit_title;</string>
|
||||
|
|
Загрузка…
Ссылка в новой задаче