Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import android.app.Fragment; |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 20 | import android.os.Bundle; |
| 21 | import android.util.Log; |
| 22 | import android.view.View; |
| 23 | import android.view.ViewGroup; |
| 24 | import android.view.View.OnClickListener; |
| 25 | import android.view.LayoutInflater; |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 26 | import android.webkit.WebSettings.AutoFillProfile; |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 27 | import android.widget.Button; |
| 28 | import android.widget.EditText; |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 29 | import android.widget.Toast; |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 30 | |
| 31 | public class AutoFillSettingsFragment extends Fragment { |
| 32 | |
| 33 | private static final String LOGTAG = "AutoFillSettingsFragment"; |
| 34 | |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 35 | private EditText mFullNameEdit; |
| 36 | private EditText mEmailEdit; |
| 37 | private EditText mCompanyEdit; |
| 38 | private EditText mAddressLine1Edit; |
| 39 | private EditText mAddressLine2Edit; |
| 40 | private EditText mCityEdit; |
| 41 | private EditText mStateEdit; |
| 42 | private EditText mZipEdit; |
| 43 | private EditText mCountryEdit; |
| 44 | private EditText mPhoneEdit; |
| 45 | |
Ben Murdoch | 6fa32ba | 2010-10-20 14:01:25 +0100 | [diff] [blame] | 46 | // For now we support just one profile so it's safe to hardcode the |
| 47 | // id to 1 here. In the future this unique identifier will be set |
| 48 | // dynamically. |
| 49 | private int mUniqueId = 1; |
| 50 | |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 51 | public AutoFillSettingsFragment() { |
| 52 | |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void onCreate(Bundle savedState) { |
| 57 | super.onCreate(savedState); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 62 | Bundle savedInstanceState) { |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 63 | View v = inflater.inflate(R.layout.autofill_settings_fragment, container, false); |
| 64 | |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 65 | mFullNameEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_name_edit); |
| 66 | mEmailEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_email_address_edit); |
| 67 | mCompanyEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_company_name_edit); |
| 68 | mAddressLine1Edit = (EditText)v.findViewById( |
| 69 | R.id.autofill_profile_editor_address_line_1_edit); |
| 70 | mAddressLine2Edit = (EditText)v.findViewById( |
| 71 | R.id.autofill_profile_editor_address_line_2_edit); |
| 72 | mCityEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_city_edit); |
| 73 | mStateEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_state_edit); |
| 74 | mZipEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_zip_code_edit); |
| 75 | mCountryEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_country_edit); |
| 76 | mPhoneEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_phone_number_edit); |
| 77 | |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 78 | Button saveButton = (Button)v.findViewById(R.id.autofill_profile_editor_save_button); |
| 79 | saveButton.setOnClickListener(new OnClickListener() { |
| 80 | public void onClick(View button) { |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 81 | BrowserSettings.getInstance().setAutoFillProfile(getActivity(), |
| 82 | new AutoFillProfile( |
Ben Murdoch | 6fa32ba | 2010-10-20 14:01:25 +0100 | [diff] [blame] | 83 | mUniqueId, |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 84 | mFullNameEdit.getText().toString(), |
| 85 | mEmailEdit.getText().toString(), |
| 86 | mCompanyEdit.getText().toString(), |
| 87 | mAddressLine1Edit.getText().toString(), |
| 88 | mAddressLine2Edit.getText().toString(), |
| 89 | mCityEdit.getText().toString(), |
| 90 | mStateEdit.getText().toString(), |
| 91 | mZipEdit.getText().toString(), |
| 92 | mCountryEdit.getText().toString(), |
| 93 | mPhoneEdit.getText().toString())); |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 94 | } |
| 95 | }); |
| 96 | |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 97 | Button deleteButton = (Button)v.findViewById(R.id.autofill_profile_editor_delete_button); |
| 98 | deleteButton.setOnClickListener(new OnClickListener() { |
| 99 | public void onClick(View button) { |
| 100 | Toast.makeText(getActivity(), "TODO: Implement me", Toast.LENGTH_SHORT).show(); |
| 101 | } |
| 102 | }); |
| 103 | |
| 104 | Button cancelButton = (Button)v.findViewById(R.id.autofill_profile_editor_cancel_button); |
| 105 | cancelButton.setOnClickListener(new OnClickListener() { |
| 106 | public void onClick(View button) { |
| 107 | getFragmentManager().popBackStack(); |
| 108 | } |
| 109 | }); |
| 110 | |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 111 | // Populate the text boxes with any pre existing AutoFill data. |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 112 | AutoFillProfile activeProfile = BrowserSettings.getInstance().getAutoFillProfile(); |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 113 | if (activeProfile != null) { |
| 114 | mFullNameEdit.setText(activeProfile.getFullName()); |
| 115 | mEmailEdit.setText(activeProfile.getEmailAddress()); |
| 116 | mCompanyEdit.setText(activeProfile.getCompanyName()); |
| 117 | mAddressLine1Edit.setText(activeProfile.getAddressLine1()); |
| 118 | mAddressLine2Edit.setText(activeProfile.getAddressLine2()); |
| 119 | mCityEdit.setText(activeProfile.getCity()); |
| 120 | mStateEdit.setText(activeProfile.getState()); |
| 121 | mZipEdit.setText(activeProfile.getZipCode()); |
| 122 | mCountryEdit.setText(activeProfile.getCountry()); |
| 123 | mPhoneEdit.setText(activeProfile.getPhoneNumber()); |
| 124 | } |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 125 | |
| 126 | return v; |
| 127 | } |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 128 | } |