am 50c04abe: Merge "Add Monkey protection" into ics-mr1
* commit '50c04abe67ac1eebd5a07777b5395b244d90b9ac':
Add Monkey protection
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 60a9336..30b1d6f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -41,6 +41,8 @@
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
+ <uses-permission android:name="android.permission.READ_PROFILE" />
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
diff --git a/res/layout-port/autofill_settings_fragment.xml b/res/layout-port/autofill_settings_fragment.xml
index 63dba4d..16f674d 100644
--- a/res/layout-port/autofill_settings_fragment.xml
+++ b/res/layout-port/autofill_settings_fragment.xml
@@ -43,35 +43,19 @@
android:layout_width="match_parent" />
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_name" />
<EditText android:id="@+id/autofill_profile_editor_name_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textPersonName|textCapWords"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textPersonName|textCapWords" />
+
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_company_name" />
<EditText android:id="@+id/autofill_profile_editor_company_name_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textCapWords"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -91,13 +75,9 @@
android:text="@string/autofill_profile_editor_address_line_1_hint" />
</LinearLayout>
<EditText android:id="@+id/autofill_profile_editor_address_line_1_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textCapWords"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -117,115 +97,50 @@
android:text="@string/autofill_profile_editor_address_line_2_hint" />
</LinearLayout>
<EditText android:id="@+id/autofill_profile_editor_address_line_2_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="bottom"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textCapWords"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
+
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_city" />
<EditText android:id="@+id/autofill_profile_editor_city_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:inputType="textCapWords"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
+
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_state" />
<EditText android:id="@+id/autofill_profile_editor_state_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:inputType="textCapWords"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
+
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_zip_code" />
<EditText android:id="@+id/autofill_profile_editor_zip_code_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:inputType="textCapCharacters"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapCharacters" />
+
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_country" />
<EditText android:id="@+id/autofill_profile_editor_country_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:inputType="textCapWords"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
+
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_phone_number" />
<EditText android:id="@+id/autofill_profile_editor_phone_number_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true"
+ style="@style/AutofillProfileEditText"
android:phoneNumber="true" />
+
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_email_address" />
<EditText android:id="@+id/autofill_profile_editor_email_address_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textEmailAddress"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textEmailAddress" />
</LinearLayout>
</ScrollView>
-
- <View
- android:layout_height="12dip"
- android:layout_width="match_parent" />
-
- <Button
- android:id="@+id/autofill_profile_editor_save_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/autofill_profile_editor_save_profile"
- android:textAppearance="?android:attr/textAppearanceMedium" />
-
</LinearLayout>
diff --git a/res/layout/autofill_settings_fragment.xml b/res/layout/autofill_settings_fragment.xml
index 8c90dd7..ab23ffb 100644
--- a/res/layout/autofill_settings_fragment.xml
+++ b/res/layout/autofill_settings_fragment.xml
@@ -49,37 +49,19 @@
android:stretchColumns="1">
<TableRow>
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_name" />
<EditText android:id="@+id/autofill_profile_editor_name_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textPersonName|textCapWords"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textPersonName|textCapWords" />
</TableRow>
<TableRow>
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_company_name" />
<EditText android:id="@+id/autofill_profile_editor_company_name_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textCapWords"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
</TableRow>
<TableRow>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
@@ -101,13 +83,8 @@
android:text="@string/autofill_profile_editor_address_line_1_hint" />
</LinearLayout>
<EditText android:id="@+id/autofill_profile_editor_address_line_1_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textCapWords"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
</TableRow>
<TableRow>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
@@ -129,130 +106,59 @@
android:text="@string/autofill_profile_editor_address_line_2_hint" />
</LinearLayout>
<EditText android:id="@+id/autofill_profile_editor_address_line_2_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="bottom"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textCapWords"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
</TableRow>
<TableRow>
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_city" />
<EditText android:id="@+id/autofill_profile_editor_city_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:inputType="textCapWords"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
</TableRow>
<TableRow>
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_state" />
<EditText android:id="@+id/autofill_profile_editor_state_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:inputType="textCapWords"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
</TableRow>
<TableRow>
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_zip_code" />
<EditText android:id="@+id/autofill_profile_editor_zip_code_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:inputType="textCapCharacters"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapCharacters" />
</TableRow>
<TableRow>
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_country" />
<EditText android:id="@+id/autofill_profile_editor_country_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:inputType="textCapWords"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textCapWords" />
</TableRow>
<TableRow>
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_phone_number" />
<EditText android:id="@+id/autofill_profile_editor_phone_number_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:singleLine="true"
+ style="@style/AutofillProfileEditText"
android:phoneNumber="true" />
</TableRow>
<TableRow>
<TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ style="@style/AutofillProfileTextView"
android:text="@string/autofill_profile_editor_email_address" />
<EditText android:id="@+id/autofill_profile_editor_email_address_edit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:layout_margin="2dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:inputType="textEmailAddress"
- android:singleLine="true" />
+ style="@style/AutofillProfileEditText"
+ android:inputType="textEmailAddress" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
-
- <View
- android:layout_height="12dip"
- android:layout_width="match_parent" />
-
- <Button
- android:id="@+id/autofill_profile_editor_save_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/autofill_profile_editor_save_profile"
- android:textAppearance="?android:attr/textAppearanceMedium" />
-
</LinearLayout>
diff --git a/res/menu/autofill_profile_editor.xml b/res/menu/autofill_profile_editor.xml
index 4e746e5..9dab635 100644
--- a/res/menu/autofill_profile_editor.xml
+++ b/res/menu/autofill_profile_editor.xml
@@ -15,6 +15,11 @@
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/autofill_profile_editor_save_profile_menu_id"
+ android:title="@string/autofill_profile_editor_save_profile"
+ android:icon="@android:drawable/ic_menu_save"
+ android:showAsAction="ifRoom|withText" />
+
<item android:id="@+id/autofill_profile_editor_delete_profile_menu_id"
android:title="@string/autofill_profile_editor_delete_profile"
android:icon="@android:drawable/ic_menu_delete"
diff --git a/res/values-lt/strings.xml b/res/values-lt/strings.xml
index 4c4dac0..dca8aef 100644
--- a/res/values-lt/strings.xml
+++ b/res/values-lt/strings.xml
@@ -313,7 +313,8 @@
<string name="download_sdcard_busy_dlg_msg" product="default" msgid="2629425950473358591">"SD kortelė užimta. Jei norite leisti atsisiuntimus, pranešime palieskite „Išjungti USB atmintinę“."</string>
<string name="cannot_download" msgid="8150552478556798780">"Galima atsisiųsti tik „http“ ar „https“ prasidedančius URL."</string>
<string name="download_pending" msgid="2599683668575349559">"Pradedamas atsisiuntimas..."</string>
- <string name="help_page" msgid="2906208423557552540">"Pagalba"</string>
+ <!-- no translation found for help_page (2906208423557552540) -->
+ <skip />
<string name="search_the_web" msgid="6046130189241962337">"Ieškoti žiniatinklyje"</string>
<string name="webstorage_outofspace_notification_title" msgid="1160474608059771788">"Naršyklės saugykla pilna"</string>
<string name="webstorage_outofspace_notification_text" msgid="47273584426988640">"Palieskite, jei norite atlaisvinti vietos."</string>
diff --git a/res/values-pl/strings.xml b/res/values-pl/strings.xml
index e4873c6..c12b390 100644
--- a/res/values-pl/strings.xml
+++ b/res/values-pl/strings.xml
@@ -267,7 +267,7 @@
<string name="pref_font_size_category" msgid="6683754355084218254">"Rozmiar tekstu"</string>
<string name="pref_lab_title" msgid="5571091610359629423">"Laboratorium"</string>
<string name="pref_lab_quick_controls" msgid="3267606522082281367">"Szybkie sterowanie"</string>
- <string name="pref_lab_quick_controls_summary" msgid="3149664132600968775">"Przesuń palcem od bocznej krawędzi, by wyświetlić ukryte opcje sterowania i pasek adresu"</string>
+ <string name="pref_lab_quick_controls_summary" msgid="3149664132600968775">"Przesuń palcem od bocznej krawędzi, aby w opcjach ukryć paski aplikacji i URL"</string>
<string name="pref_use_instant_search" msgid="1119176077760723740">"Wyszukiwanie dynamiczne Google"</string>
<string name="pref_use_instant_search_summary" msgid="839320474961917522">"Użyj wyszukiwania dynamicznego Google, aby uzyskiwać wyniki podczas pisania (może być pobierana większa ilość danych)."</string>
<string name="pref_lab_fullscreen" msgid="8173609016657987973">"Pełny ekran"</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 361702e..3c87e22 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -80,4 +80,17 @@
<item name="android:textColor">?android:attr/textColorSecondary</item>
<item name="android:textStyle">normal</item>
</style>
+
+ <style name="AutofillProfileTextView">
+ <item name="android:layout_width">wrap_content</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:gravity">center_vertical</item>
+ <item name="android:layout_margin">2dip</item>
+ <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
+ </style>
+ <style name="AutofillProfileEditText" parent="@style/AutofillProfileTextView">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:imeOptions">flagNoExtractUi</item>
+ <item name="android:singleLine">true</item>
+ </style>
</resources>
diff --git a/src/com/android/browser/AutoFillSettingsFragment.java b/src/com/android/browser/AutoFillSettingsFragment.java
index 04f45b5..7be657d 100644
--- a/src/com/android/browser/AutoFillSettingsFragment.java
+++ b/src/com/android/browser/AutoFillSettingsFragment.java
@@ -52,7 +52,9 @@
private EditText mCountryEdit;
private EditText mPhoneEdit;
- private Button mSaveButton;
+ private MenuItem mSaveMenuItem;
+
+ private boolean mInitialised;
// Used to display toast after DB interactions complete.
private Handler mHandler;
@@ -87,7 +89,7 @@
mPhoneEdit.setError(null);
}
- updateButtonState();
+ updateSaveMenuItemState();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@@ -99,7 +101,7 @@
private class FieldChangedListener implements TextWatcher {
public void afterTextChanged(Editable s) {
- updateButtonState();
+ updateSaveMenuItemState();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@@ -147,11 +149,14 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.autofill_profile_editor, menu);
+ mSaveMenuItem = menu.findItem(R.id.autofill_profile_editor_save_profile_menu_id);
+ updateSaveMenuItemState();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.autofill_profile_editor_delete_profile_menu_id) {
+ switch (item.getItemId()) {
+ case R.id.autofill_profile_editor_delete_profile_menu_id:
// Clear the UI.
mFullNameEdit.setText("");
mEmailEdit.setText("");
@@ -168,10 +173,30 @@
// trigger the current profile to get deleted from the DB.
mSettings.setAutoFillProfile(null,
mHandler.obtainMessage(PROFILE_DELETED_MSG));
- updateButtonState();
+ updateSaveMenuItemState();
return true;
+
+ case R.id.autofill_profile_editor_save_profile_menu_id:
+ AutoFillProfile newProfile = new AutoFillProfile(
+ mUniqueId,
+ mFullNameEdit.getText().toString(),
+ mEmailEdit.getText().toString(),
+ mCompanyEdit.getText().toString(),
+ mAddressLine1Edit.getText().toString(),
+ mAddressLine2Edit.getText().toString(),
+ mCityEdit.getText().toString(),
+ mStateEdit.getText().toString(),
+ mZipEdit.getText().toString(),
+ mCountryEdit.getText().toString(),
+ mPhoneEdit.getText().toString());
+
+ mSettings.setAutoFillProfile(newProfile,
+ mHandler.obtainMessage(PROFILE_SAVED_MSG));
+ return true;
+
+ default:
+ return false;
}
- return false;
}
@Override
@@ -203,27 +228,6 @@
mCountryEdit.addTextChangedListener(mFieldChangedListener);
mPhoneEdit.addTextChangedListener(new PhoneNumberValidator());
- mSaveButton = (Button)v.findViewById(R.id.autofill_profile_editor_save_button);
- mSaveButton.setOnClickListener(new OnClickListener() {
- public void onClick(View button) {
- AutoFillProfile newProfile = new AutoFillProfile(
- mUniqueId,
- mFullNameEdit.getText().toString(),
- mEmailEdit.getText().toString(),
- mCompanyEdit.getText().toString(),
- mAddressLine1Edit.getText().toString(),
- mAddressLine2Edit.getText().toString(),
- mCityEdit.getText().toString(),
- mStateEdit.getText().toString(),
- mZipEdit.getText().toString(),
- mCountryEdit.getText().toString(),
- mPhoneEdit.getText().toString());
-
- mSettings.setAutoFillProfile(newProfile,
- mHandler.obtainMessage(PROFILE_SAVED_MSG));
- }
- });
-
// Populate the text boxes with any pre existing AutoFill data.
AutoFillProfile activeProfile = mSettings.getAutoFillProfile();
if (activeProfile != null) {
@@ -239,14 +243,25 @@
mPhoneEdit.setText(activeProfile.getPhoneNumber());
}
- updateButtonState();
+ mInitialised = true;
+
+ updateSaveMenuItemState();
return v;
}
- public void updateButtonState() {
+ private void updateSaveMenuItemState() {
+ if (mSaveMenuItem == null) {
+ return;
+ }
- boolean valid = (mFullNameEdit.getText().toString().length() > 0 ||
+ if (!mInitialised) {
+ mSaveMenuItem.setEnabled(false);
+ return;
+ }
+
+ boolean currentState = mSaveMenuItem.isEnabled();
+ boolean newState = (mFullNameEdit.getText().toString().length() > 0 ||
mEmailEdit.getText().toString().length() > 0 ||
mCompanyEdit.getText().toString().length() > 0 ||
mAddressLine1Edit.getText().toString().length() > 0 ||
@@ -257,9 +272,9 @@
mCountryEdit.getText().toString().length() > 0) &&
mPhoneEdit.getError() == null;
- // Only enable the save buttons if we have at least one field completed
- // and the phone number (if present is valid).
- mSaveButton.setEnabled(valid);
+ if (currentState != newState) {
+ mSaveMenuItem.setEnabled(newState);
+ }
}
private void closeEditor() {
diff --git a/src/com/android/browser/AutofillHandler.java b/src/com/android/browser/AutofillHandler.java
index c4b14d7..dc23d00 100644
--- a/src/com/android/browser/AutofillHandler.java
+++ b/src/com/android/browser/AutofillHandler.java
@@ -21,9 +21,11 @@
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
+import android.net.Uri;
import android.os.AsyncTask;
import android.os.Message;
import android.preference.PreferenceManager;
+import android.provider.ContactsContract;
import android.webkit.WebSettings.AutoFillProfile;
import java.util.concurrent.CountDownLatch;
@@ -114,8 +116,58 @@
c.close();
autoFillDb.close();
+ if (mAutoFillProfile == null) {
+ // We did not load a profile from disk. Try to populate one with the user's
+ // "me" contact.
+ final Uri profileUri = Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
+ ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
+
+ String name = getContactField(profileUri,
+ ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
+ ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
+ // Only attempt to read other data and set a profile if we could successfully
+ // get a name.
+ if (name != null) {
+ String email = getContactField(profileUri,
+ ContactsContract.CommonDataKinds.Email.ADDRESS,
+ ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
+ String phone = getContactField(profileUri,
+ ContactsContract.CommonDataKinds.Phone.NUMBER,
+ ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
+ String company = getContactField(profileUri,
+ ContactsContract.CommonDataKinds.Organization.COMPANY,
+ ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
+
+ // Can't easily get structured postal address information (even using
+ // CommonDataKinds.StructuredPostal) so omit prepopulating that for now.
+ // When querying structured postal data, it often all comes back as a string
+ // inside the "street" field.
+
+ mAutoFillProfile = new AutoFillProfile(
+ 1, name, email, company, null, null, null, null,
+ null, null, phone);
+ }
+ }
+
mLoaded.countDown();
}
+
+ private String getContactField(Uri uri, String field, String itemType) {
+ String result = null;
+
+ Cursor c = mContext.getContentResolver().query(uri, new String[] { field },
+ ContactsContract.Data.MIMETYPE + "=?", new String[] { itemType }, null);
+
+ try {
+ // Just use the first returned value if we get more than one.
+ if (c.moveToFirst()) {
+ result = c.getString(0);
+ }
+ } finally {
+ c.close();
+ }
+ return result;
+ }
}
public void setAutoFillProfile(AutoFillProfile profile, Message msg) {