diff options
author | Ben Murdoch <benm@google.com> | 2010-10-14 07:48:43 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-10-14 07:48:43 -0700 |
commit | daece2e96475d269ea54cd92a290a787071e7298 (patch) | |
tree | 076100cbe30aa8575bcabf830f120765daae6153 /src | |
parent | 5a49c5977c23f720aa70266e99b93f931869d16c (diff) | |
parent | 36a23dd3e46167507070bd9f0e6237570d721b2f (diff) | |
download | packages_apps_Browser-daece2e96475d269ea54cd92a290a787071e7298.zip packages_apps_Browser-daece2e96475d269ea54cd92a290a787071e7298.tar.gz packages_apps_Browser-daece2e96475d269ea54cd92a290a787071e7298.tar.bz2 |
Merge "Full profile editor and syncing with WebSettings."
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/browser/AutoFillProfileDatabase.java | 66 | ||||
-rw-r--r-- | src/com/android/browser/AutoFillSettingsFragment.java | 84 | ||||
-rw-r--r-- | src/com/android/browser/BrowserSettings.java | 40 |
3 files changed, 148 insertions, 42 deletions
diff --git a/src/com/android/browser/AutoFillProfileDatabase.java b/src/com/android/browser/AutoFillProfileDatabase.java index 5557aaf..0204d7e 100644 --- a/src/com/android/browser/AutoFillProfileDatabase.java +++ b/src/com/android/browser/AutoFillProfileDatabase.java @@ -29,7 +29,7 @@ public class AutoFillProfileDatabase { static final String LOGTAG = "AutoFillProfileDatabase"; static final String DATABASE_NAME = "autofill.db"; - static final int DATABASE_VERSION = 1; + static final int DATABASE_VERSION = 2; static final String PROFILES_TABLE_NAME = "profiles"; private AutoFillProfileDatabaseHelper mOpenHelper; private static AutoFillProfileDatabase sInstance; @@ -39,6 +39,14 @@ public class AutoFillProfileDatabase { static final String FULL_NAME = "fullname"; static final String EMAIL_ADDRESS = "email"; + static final String COMPANY_NAME = "companyname"; + static final String ADDRESS_LINE_1 = "addressline1"; + static final String ADDRESS_LINE_2 = "addressline2"; + static final String CITY = "city"; + static final String STATE = "state"; + static final String ZIP_CODE = "zipcode"; + static final String COUNTRY = "country"; + static final String PHONE_NUMBER = "phone"; } private static class AutoFillProfileDatabaseHelper extends SQLiteOpenHelper { @@ -51,7 +59,15 @@ public class AutoFillProfileDatabase { db.execSQL("CREATE TABLE " + PROFILES_TABLE_NAME + " (" + Profiles._ID + " INTEGER PRIMARY KEY," + Profiles.FULL_NAME + " TEXT," - + Profiles.EMAIL_ADDRESS + " TEXT" + + Profiles.EMAIL_ADDRESS + " TEXT," + + Profiles.COMPANY_NAME + " TEXT," + + Profiles.ADDRESS_LINE_1 + " TEXT," + + Profiles.ADDRESS_LINE_2 + " TEXT," + + Profiles.CITY + " TEXT," + + Profiles.STATE + " TEXT," + + Profiles.ZIP_CODE + " TEXT," + + Profiles.COUNTRY + " TEXT," + + Profiles.PHONE_NUMBER + " TEXT" + " );"); } @@ -80,19 +96,49 @@ public class AutoFillProfileDatabase { } public void addOrUpdateProfile(final int id, AutoFillProfile profile) { - final String SQL = "INSERT OR REPLACE INTO " + PROFILES_TABLE_NAME + " (" + final String sql = "INSERT OR REPLACE INTO " + PROFILES_TABLE_NAME + " (" + Profiles._ID + "," + Profiles.FULL_NAME + "," - + Profiles.EMAIL_ADDRESS - + ") VALUES (?,?,?);"; - final Object[] PARAMS = { id, profile.getFullName(), profile.getEmailAddress() }; - getDatabase(true).execSQL(SQL, PARAMS); + + Profiles.EMAIL_ADDRESS + "," + + Profiles.COMPANY_NAME + "," + + Profiles.ADDRESS_LINE_1 + "," + + Profiles.ADDRESS_LINE_2 + "," + + Profiles.CITY + "," + + Profiles.STATE + "," + + Profiles.ZIP_CODE + "," + + Profiles.COUNTRY + "," + + Profiles.PHONE_NUMBER + + ") VALUES (?,?,?,?,?,?,?,?,?,?,?);"; + final Object[] params = { id, + profile.getFullName(), + profile.getEmailAddress(), + profile.getCompanyName(), + profile.getAddressLine1(), + profile.getAddressLine2(), + profile.getCity(), + profile.getState(), + profile.getZipCode(), + profile.getCountry(), + profile.getPhoneNumber() }; + getDatabase(true).execSQL(sql, params); } public Cursor getProfile(int id) { - final String[] COLS = {Profiles.FULL_NAME, Profiles.EMAIL_ADDRESS }; - final String[] SEL_ARGS = { Integer.toString(id) }; - return getDatabase(false).query(PROFILES_TABLE_NAME, COLS, Profiles._ID + "=?", SEL_ARGS, + final String[] cols = { + Profiles.FULL_NAME, + Profiles.EMAIL_ADDRESS, + Profiles.COMPANY_NAME, + Profiles.ADDRESS_LINE_1, + Profiles.ADDRESS_LINE_2, + Profiles.CITY, + Profiles.STATE, + Profiles.ZIP_CODE, + Profiles.COUNTRY, + Profiles.PHONE_NUMBER + }; + + final String[] selectArgs = { Integer.toString(id) }; + return getDatabase(false).query(PROFILES_TABLE_NAME, cols, Profiles._ID + "=?", selectArgs, null, null, null, "1"); } diff --git a/src/com/android/browser/AutoFillSettingsFragment.java b/src/com/android/browser/AutoFillSettingsFragment.java index e41ca56..608c3de 100644 --- a/src/com/android/browser/AutoFillSettingsFragment.java +++ b/src/com/android/browser/AutoFillSettingsFragment.java @@ -26,11 +26,23 @@ import android.view.LayoutInflater; import android.webkit.WebSettings.AutoFillProfile; import android.widget.Button; import android.widget.EditText; +import android.widget.Toast; public class AutoFillSettingsFragment extends Fragment { private static final String LOGTAG = "AutoFillSettingsFragment"; + private EditText mFullNameEdit; + private EditText mEmailEdit; + private EditText mCompanyEdit; + private EditText mAddressLine1Edit; + private EditText mAddressLine2Edit; + private EditText mCityEdit; + private EditText mStateEdit; + private EditText mZipEdit; + private EditText mCountryEdit; + private EditText mPhoneEdit; + public AutoFillSettingsFragment() { } @@ -42,41 +54,69 @@ public class AutoFillSettingsFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + Bundle savedInstanceState) { View v = inflater.inflate(R.layout.autofill_settings_fragment, container, false); + mFullNameEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_name_edit); + mEmailEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_email_address_edit); + mCompanyEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_company_name_edit); + mAddressLine1Edit = (EditText)v.findViewById( + R.id.autofill_profile_editor_address_line_1_edit); + mAddressLine2Edit = (EditText)v.findViewById( + R.id.autofill_profile_editor_address_line_2_edit); + mCityEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_city_edit); + mStateEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_state_edit); + mZipEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_zip_code_edit); + mCountryEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_country_edit); + mPhoneEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_phone_number_edit); + Button saveButton = (Button)v.findViewById(R.id.autofill_profile_editor_save_button); saveButton.setOnClickListener(new OnClickListener() { public void onClick(View button) { - View v = getView(); - EditText fullName = (EditText)v.findViewById( - R.id.autofill_profile_editor_name_edit); - EditText email = (EditText)v.findViewById( - R.id.autofill_profile_editor_email_address_edit); BrowserSettings.getInstance().setAutoFillProfile(getActivity(), new AutoFillProfile( - fullName.getText().toString(), - email.getText().toString())); + 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())); + } + }); + + Button deleteButton = (Button)v.findViewById(R.id.autofill_profile_editor_delete_button); + deleteButton.setOnClickListener(new OnClickListener() { + public void onClick(View button) { + Toast.makeText(getActivity(), "TODO: Implement me", Toast.LENGTH_SHORT).show(); } }); + Button cancelButton = (Button)v.findViewById(R.id.autofill_profile_editor_cancel_button); + cancelButton.setOnClickListener(new OnClickListener() { + public void onClick(View button) { + getFragmentManager().popBackStack(); + } + }); + // Populate the text boxes with any pre existing AutoFill data. - EditText fullName = (EditText)v.findViewById( - R.id.autofill_profile_editor_name_edit); - EditText email = (EditText)v.findViewById( - R.id.autofill_profile_editor_email_address_edit); AutoFillProfile activeProfile = BrowserSettings.getInstance().getAutoFillProfile(); - fullName.setText(activeProfile.getFullName()); - email.setText(activeProfile.getEmailAddress()); + if (activeProfile != null) { + mFullNameEdit.setText(activeProfile.getFullName()); + mEmailEdit.setText(activeProfile.getEmailAddress()); + mCompanyEdit.setText(activeProfile.getCompanyName()); + mAddressLine1Edit.setText(activeProfile.getAddressLine1()); + mAddressLine2Edit.setText(activeProfile.getAddressLine2()); + mCityEdit.setText(activeProfile.getCity()); + mStateEdit.setText(activeProfile.getState()); + mZipEdit.setText(activeProfile.getZipCode()); + mCountryEdit.setText(activeProfile.getCountry()); + mPhoneEdit.setText(activeProfile.getPhoneNumber()); + } return v; } - - @Override - public void onPause() { - AutoFillProfileDatabase db = - AutoFillProfileDatabase.getInstance(getActivity()); - db.close(); - super.onPause(); - } } diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index d3c1c00..96b6fd2 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -316,16 +316,35 @@ public class BrowserSettings extends Observable { // Load the autofill profile data from the database. We use a database separate // to the browser preference DB to make it easier to support multiple profiles // and switching between them. - mAutoFillProfile = new AutoFillProfile(); AutoFillProfileDatabase autoFillDb = AutoFillProfileDatabase.getInstance(ctx); Cursor c = autoFillDb.getProfile(mActiveAutoFillProfileId); if (c.getCount() > 0) { c.moveToFirst(); - mAutoFillProfile.setFullName(c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.FULL_NAME))); - mAutoFillProfile.setEmailAddress(c.getString(c.getColumnIndex( - AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS))); + + String fullName = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.FULL_NAME)); + String email = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.EMAIL_ADDRESS)); + String company = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.COMPANY_NAME)); + String addressLine1 = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.ADDRESS_LINE_1)); + String addressLine2 = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.ADDRESS_LINE_2)); + String city = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.CITY)); + String state = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.STATE)); + String zip = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.ZIP_CODE)); + String country = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.COUNTRY)); + String phone = c.getString(c.getColumnIndex( + AutoFillProfileDatabase.Profiles.PHONE_NUMBER)); + mAutoFillProfile = new AutoFillProfile(fullName, email, company, + addressLine1, addressLine2, city, state, zip, country, + phone); } c.close(); autoFillDb.close(); @@ -686,21 +705,22 @@ public class BrowserSettings extends Observable { private class SaveProfileToDbTask extends AsyncTask<AutoFillProfile, Void, Void> { Context mContext; + AutoFillProfileDatabase mAutoFillProfileDb; public SaveProfileToDbTask(Context ctx) { mContext = ctx; } protected Void doInBackground(AutoFillProfile... values) { - AutoFillProfileDatabase db = - AutoFillProfileDatabase.getInstance(mContext); - db.addOrUpdateProfile(mActiveAutoFillProfileId, values[0]); + mAutoFillProfileDb = AutoFillProfileDatabase.getInstance(mContext); + mAutoFillProfileDb.addOrUpdateProfile(mActiveAutoFillProfileId, values[0]); return null; } protected void onPostExecute(Void result) { - String message = mContext.getString(R.string.autofill_profile_successful_save); - Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show(); + Toast.makeText(mContext, R.string.autofill_profile_successful_save, + Toast.LENGTH_SHORT).show(); + mAutoFillProfileDb.close(); } } |