зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1201181 - Add "Set a Homepage" item in Settings > Customize > Home; r=mfinkle
--HG-- extra : commitid : JWKQqTwemxR
This commit is contained in:
Родитель
eb5f28c49a
Коммит
d3b9b2fd8f
|
@ -189,6 +189,9 @@
|
|||
<!ENTITY pref_home_updates_wifi "Only over Wi-Fi">
|
||||
<!ENTITY pref_home_suggested_sites "Show site suggestions">
|
||||
<!ENTITY pref_home_suggested_sites_summary "Display shortcuts to sites on your homepage that we think you might find interesting">
|
||||
<!ENTITY pref_category_home_homepage "Homepage">
|
||||
<!ENTITY home_homepage_title "Set a Homepage">
|
||||
<!ENTITY home_homepage_use_current_tab "Use current tab">
|
||||
|
||||
<!-- Localization note: These are shown in the left sidebar on tablets -->
|
||||
<!ENTITY pref_header_customize "Customize">
|
||||
|
|
|
@ -419,6 +419,7 @@ gbjar.sources += [
|
|||
'preferences/PrivateDataPreference.java',
|
||||
'preferences/SearchEnginePreference.java',
|
||||
'preferences/SearchPreferenceCategory.java',
|
||||
'preferences/SetHomepagePreference.java',
|
||||
'preferences/SyncPreference.java',
|
||||
'PrefsHelper.java',
|
||||
'PrintHelper.java',
|
||||
|
|
|
@ -5,16 +5,7 @@
|
|||
|
||||
package org.mozilla.gecko.preferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.AboutPages;
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.AppConstants.Versions;
|
||||
import org.mozilla.gecko.BrowserApp;
|
||||
|
@ -43,8 +34,8 @@ import org.mozilla.gecko.updater.UpdateService;
|
|||
import org.mozilla.gecko.updater.UpdateServiceHelper;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.util.InputOptionsUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.widget.FloatingHintEditText;
|
||||
|
||||
import android.app.ActionBar;
|
||||
|
@ -60,6 +51,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
|
@ -84,6 +76,14 @@ import android.widget.LinearLayout;
|
|||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeckoPreferences
|
||||
extends PreferenceActivity
|
||||
|
@ -670,7 +670,7 @@ OnSharedPreferenceChangeListener
|
|||
*/
|
||||
private void setupPreferences(PreferenceGroup preferences, ArrayList<String> prefs) {
|
||||
for (int i = 0; i < preferences.getPreferenceCount(); i++) {
|
||||
Preference pref = preferences.getPreference(i);
|
||||
final Preference pref = preferences.getPreference(i);
|
||||
|
||||
// Eliminate locale switching if necessary.
|
||||
// This logic will need to be extended when
|
||||
|
@ -878,6 +878,16 @@ OnSharedPreferenceChangeListener
|
|||
i--;
|
||||
continue;
|
||||
}
|
||||
} else if (PREFS_HOMEPAGE.equals(key)) {
|
||||
String setUrl = GeckoSharedPrefs.forProfile(getBaseContext()).getString(PREFS_HOMEPAGE, AboutPages.HOME);
|
||||
setHomePageSummary(pref, setUrl);
|
||||
pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
|
||||
setHomePageSummary(pref, String.valueOf(newValue));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Some Preference UI elements are not actually preferences,
|
||||
|
@ -893,6 +903,14 @@ OnSharedPreferenceChangeListener
|
|||
}
|
||||
}
|
||||
|
||||
private void setHomePageSummary(Preference pref, String value) {
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
pref.setSummary(value);
|
||||
} else {
|
||||
pref.setSummary(AboutPages.HOME);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isGeckoPref(String key) {
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package org.mozilla.gecko.preferences;
|
||||
|
||||
import org.mozilla.gecko.AboutPages;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.Tabs;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.DialogPreference;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class SetHomepagePreference extends DialogPreference {
|
||||
SharedPreferences prefs;
|
||||
EditText homepageTextEdit;
|
||||
CheckBox useCurrentTabCheck;
|
||||
|
||||
public SetHomepagePreference(final Context context, final AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
setPersistent(false);
|
||||
setDialogLayoutResource(R.layout.preference_set_homepage);
|
||||
|
||||
prefs = GeckoSharedPrefs.forProfile(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
// Without this GB devices have a black background to the dialog.
|
||||
builder.setInverseBackgroundForced(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(final View view) {
|
||||
super.onBindDialogView(view);
|
||||
|
||||
homepageTextEdit = (EditText) view.findViewById(R.id.homepage_url);
|
||||
homepageTextEdit.requestFocus();
|
||||
|
||||
homepageTextEdit.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(homepageTextEdit, InputMethodManager.SHOW_IMPLICIT);
|
||||
homepageTextEdit.selectAll();
|
||||
}
|
||||
});
|
||||
|
||||
final String url = prefs.getString(GeckoPreferences.PREFS_HOMEPAGE, AboutPages.HOME);
|
||||
if (!AboutPages.HOME.equals(url)) {
|
||||
homepageTextEdit.setText(url);
|
||||
}
|
||||
|
||||
useCurrentTabCheck = (CheckBox) view.findViewById(R.id.use_current_checkbox);
|
||||
|
||||
view.findViewById(R.id.use_current_title).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
useCurrentTabCheck.toggle();
|
||||
}
|
||||
});
|
||||
|
||||
useCurrentTabCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
|
||||
homepageTextEdit.setEnabled(!isChecked);
|
||||
if (isChecked) {
|
||||
homepageTextEdit.setText(Tabs.getInstance().getSelectedTab().getURL());
|
||||
} else {
|
||||
homepageTextEdit.selectAll();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(final boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
if (positiveResult) {
|
||||
final SharedPreferences.Editor editor = prefs.edit();
|
||||
String newValue = homepageTextEdit.getText().toString();
|
||||
if (AboutPages.HOME.equals(newValue) || TextUtils.isEmpty(newValue)) {
|
||||
editor.remove(GeckoPreferences.PREFS_HOMEPAGE);
|
||||
newValue = "";
|
||||
} else {
|
||||
editor.putString(GeckoPreferences.PREFS_HOMEPAGE, newValue);
|
||||
}
|
||||
editor.apply();
|
||||
if (getOnPreferenceChangeListener() != null) {
|
||||
getOnPreferenceChangeListener().onPreferenceChange(this, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingRight="20dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/homepage_url"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textUri"
|
||||
android:layout_marginTop="8dp" />
|
||||
|
||||
<LinearLayout android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<CheckBox android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:id="@+id/use_current_checkbox" />
|
||||
|
||||
<TextView android:id="@+id/use_current_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/home_homepage_use_current_tab"
|
||||
|
||||
tools:text="Use current tab" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -4,10 +4,17 @@
|
|||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:gecko="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/pref_category_home"
|
||||
android:enabled="false">
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_category_home_homepage">
|
||||
|
||||
<org.mozilla.gecko.preferences.SetHomepagePreference
|
||||
android:key="android.not_a_preference.homepage"
|
||||
android:title="@string/home_homepage_title" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<org.mozilla.gecko.preferences.PanelsPreferenceCategory
|
||||
android:title="@string/pref_category_home_panels"/>
|
||||
|
||||
|
|
|
@ -171,6 +171,9 @@
|
|||
<string name="pref_home_updates_wifi">&pref_home_updates_wifi;</string>
|
||||
<string name="pref_home_suggested_sites">&pref_home_suggested_sites;</string>
|
||||
<string name="pref_home_suggested_sites_summary">&pref_home_suggested_sites_summary;</string>
|
||||
<string name="pref_category_home_homepage">&pref_category_home_homepage;</string>
|
||||
<string name="home_homepage_title">&home_homepage_title;</string>
|
||||
<string name="home_homepage_use_current_tab">&home_homepage_use_current_tab;</string>
|
||||
|
||||
<string name="pref_header_customize">&pref_header_customize;</string>
|
||||
<string name="pref_header_display">&pref_header_display;</string>
|
||||
|
|
Загрузка…
Ссылка в новой задаче