Full profile editor and syncing with WebSettings.

Add all fields to the AutoFill profile editor and sync them
over to WebSettings through BrowserSettings.

Change-Id: I5eb69ba802571d2261ea11851bdf1b515ca8fb8c
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.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 @@
 
     @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();
-    }
 }