OSDN Git Service

Provide a button to allow the user to set the home page to the current page.
authorLeon Scroggins <scroggo@google.com>
Thu, 10 Dec 2009 21:11:39 +0000 (16:11 -0500)
committerLeon Scroggins <scroggo@google.com>
Thu, 10 Dec 2009 21:11:39 +0000 (16:11 -0500)
Fixes http://b/issue?id=2243560

res/values/strings.xml
res/xml/browser_preferences.xml
src/com/android/browser/BrowserActivity.java
src/com/android/browser/BrowserHomepagePreference.java
src/com/android/browser/BrowserPreferencesPage.java

index cc9857a..cff8609 100644 (file)
     <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 -->
index 1845e20..04c0ebe 100644 (file)
@@ -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>
 
index 71ed2a1..d39d897 100644 (file)
@@ -1444,6 +1444,8 @@ public class BrowserActivity extends Activity
             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;
 
index be96db3..ec603d3 100644 (file)
@@ -18,10 +18,20 @@ package com.android.browser;
 
 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 @@ public class BrowserHomepagePreference extends EditTextPreference {
     }
 
     @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 @@ public class BrowserHomepagePreference extends EditTextPreference {
         }
         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);
+    }
 }
index 1370722..b636f98 100644 (file)
@@ -39,6 +39,7 @@ public class BrowserPreferencesPage extends PreferenceActivity
         implements Preference.OnPreferenceChangeListener {
 
     private String LOGTAG = "BrowserPreferencesPage";
+    /* package */ static final String CURRENT_PAGE = "currentPage";
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -51,6 +52,8 @@ public class BrowserPreferencesPage extends PreferenceActivity
         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);