Provide a button to allow the user to set the home page to the current page.
Fixes http://b/issue?id=2243560
diff --git a/res/values/strings.xml b/res/values/strings.xml
index cc9857a..cff8609 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -316,6 +316,8 @@
<string name="pref_content_open_in_background_summary">Open new windows behind the current one</string>
<!-- Settings label -->
<string name="pref_content_homepage">Set home page</string>
+ <!-- Settings button label -->
+ <string name="pref_use_current">Use current page</string>
<!-- Settings label -->
<string name="pref_content_autofit">Auto-fit pages</string>
<!-- Settings summary -->
diff --git a/res/xml/browser_preferences.xml b/res/xml/browser_preferences.xml
index 1845e20..04c0ebe 100644
--- a/res/xml/browser_preferences.xml
+++ b/res/xml/browser_preferences.xml
@@ -93,8 +93,7 @@
android:key="homepage"
android:title="@string/pref_content_homepage"
android:hint="@string/http"
- android:inputType="textUri"
- android:singleLine="true" />
+ android:inputType="textUri|textMultiLine" />
</PreferenceCategory>
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 71ed2a1..d39d897 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -1444,6 +1444,8 @@
case R.id.preferences_menu_id:
Intent intent = new Intent(this,
BrowserPreferencesPage.class);
+ intent.putExtra(BrowserPreferencesPage.CURRENT_PAGE,
+ getTopWindow().getUrl());
startActivityForResult(intent, PREFERENCES_PAGE);
break;
diff --git a/src/com/android/browser/BrowserHomepagePreference.java b/src/com/android/browser/BrowserHomepagePreference.java
index be96db3..ec603d3 100644
--- a/src/com/android/browser/BrowserHomepagePreference.java
+++ b/src/com/android/browser/BrowserHomepagePreference.java
@@ -18,10 +18,20 @@
import android.app.AlertDialog;
import android.content.Context;
+import android.os.Bundle;
import android.preference.EditTextPreference;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
import android.util.AttributeSet;
public class BrowserHomepagePreference extends EditTextPreference {
+ private String mCurrentPage;
public BrowserHomepagePreference(Context context, AttributeSet attrs,
int defStyle) {
@@ -37,6 +47,27 @@
}
@Override
+ protected void onAddEditTextToDialogView(View dialogView,
+ EditText editText) {
+ super.onAddEditTextToDialogView(dialogView, editText);
+ // Now the EditText has a parent. Add a button to set to the current
+ // page.
+ ViewGroup parent = (ViewGroup) editText.getParent();
+ Button button = new Button(getContext());
+ button.setText(R.string.pref_use_current);
+ button.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ getEditText().setText(mCurrentPage);
+ }
+ });
+ if (parent instanceof LinearLayout) {
+ ((LinearLayout) parent).setGravity(Gravity.CENTER_HORIZONTAL);
+ }
+ parent.addView(button, ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT);
+ }
+
+ @Override
protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
String url = getEditText().getText().toString();
@@ -60,4 +91,26 @@
}
super.onDialogClosed(positiveResult);
}
+
+ /**
+ * Set the current page of the browser.
+ * @param currentPage This String will replace the text in the EditText
+ * when the user clicks the "Use current page" button.
+ */
+ /* package */ void setCurrentPage(String currentPage) {
+ mCurrentPage = currentPage;
+ }
+
+ @Override
+ protected void showDialog(Bundle state) {
+ super.showDialog(state);
+ // The dialog has its width set to wrap_content. Change it to
+ // fill_parent so there is more room to type in a url.
+ Window window = getDialog().getWindow();
+ View decorView = window.getDecorView();
+ WindowManager.LayoutParams params
+ = (WindowManager.LayoutParams) decorView.getLayoutParams();
+ params.width = ViewGroup.LayoutParams.FILL_PARENT;
+ window.getWindowManager().updateViewLayout(decorView, params);
+ }
}
diff --git a/src/com/android/browser/BrowserPreferencesPage.java b/src/com/android/browser/BrowserPreferencesPage.java
index 1370722..b636f98 100644
--- a/src/com/android/browser/BrowserPreferencesPage.java
+++ b/src/com/android/browser/BrowserPreferencesPage.java
@@ -39,6 +39,7 @@
implements Preference.OnPreferenceChangeListener {
private String LOGTAG = "BrowserPreferencesPage";
+ /* package */ static final String CURRENT_PAGE = "currentPage";
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -51,6 +52,8 @@
e.setOnPreferenceChangeListener(this);
e.setSummary(getPreferenceScreen().getSharedPreferences()
.getString(BrowserSettings.PREF_HOMEPAGE, null));
+ ((BrowserHomepagePreference) e).setCurrentPage(
+ getIntent().getStringExtra(CURRENT_PAGE));
e = findPreference(BrowserSettings.PREF_EXTRAS_RESET_DEFAULTS);
e.setOnPreferenceChangeListener(this);