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 | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 46 | public AutoFillSettingsFragment() { |
| 47 | |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public void onCreate(Bundle savedState) { |
| 52 | super.onCreate(savedState); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 57 | Bundle savedInstanceState) { |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 58 | View v = inflater.inflate(R.layout.autofill_settings_fragment, container, false); |
| 59 | |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 60 | mFullNameEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_name_edit); |
| 61 | mEmailEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_email_address_edit); |
| 62 | mCompanyEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_company_name_edit); |
| 63 | mAddressLine1Edit = (EditText)v.findViewById( |
| 64 | R.id.autofill_profile_editor_address_line_1_edit); |
| 65 | mAddressLine2Edit = (EditText)v.findViewById( |
| 66 | R.id.autofill_profile_editor_address_line_2_edit); |
| 67 | mCityEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_city_edit); |
| 68 | mStateEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_state_edit); |
| 69 | mZipEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_zip_code_edit); |
| 70 | mCountryEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_country_edit); |
| 71 | mPhoneEdit = (EditText)v.findViewById(R.id.autofill_profile_editor_phone_number_edit); |
| 72 | |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 73 | Button saveButton = (Button)v.findViewById(R.id.autofill_profile_editor_save_button); |
| 74 | saveButton.setOnClickListener(new OnClickListener() { |
| 75 | public void onClick(View button) { |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 76 | BrowserSettings.getInstance().setAutoFillProfile(getActivity(), |
| 77 | new AutoFillProfile( |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 78 | mFullNameEdit.getText().toString(), |
| 79 | mEmailEdit.getText().toString(), |
| 80 | mCompanyEdit.getText().toString(), |
| 81 | mAddressLine1Edit.getText().toString(), |
| 82 | mAddressLine2Edit.getText().toString(), |
| 83 | mCityEdit.getText().toString(), |
| 84 | mStateEdit.getText().toString(), |
| 85 | mZipEdit.getText().toString(), |
| 86 | mCountryEdit.getText().toString(), |
| 87 | mPhoneEdit.getText().toString())); |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 88 | } |
| 89 | }); |
| 90 | |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 91 | Button deleteButton = (Button)v.findViewById(R.id.autofill_profile_editor_delete_button); |
| 92 | deleteButton.setOnClickListener(new OnClickListener() { |
| 93 | public void onClick(View button) { |
| 94 | Toast.makeText(getActivity(), "TODO: Implement me", Toast.LENGTH_SHORT).show(); |
| 95 | } |
| 96 | }); |
| 97 | |
| 98 | Button cancelButton = (Button)v.findViewById(R.id.autofill_profile_editor_cancel_button); |
| 99 | cancelButton.setOnClickListener(new OnClickListener() { |
| 100 | public void onClick(View button) { |
| 101 | getFragmentManager().popBackStack(); |
| 102 | } |
| 103 | }); |
| 104 | |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 105 | // Populate the text boxes with any pre existing AutoFill data. |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame] | 106 | AutoFillProfile activeProfile = BrowserSettings.getInstance().getAutoFillProfile(); |
Ben Murdoch | 36a23dd | 2010-10-13 13:20:06 +0100 | [diff] [blame] | 107 | if (activeProfile != null) { |
| 108 | mFullNameEdit.setText(activeProfile.getFullName()); |
| 109 | mEmailEdit.setText(activeProfile.getEmailAddress()); |
| 110 | mCompanyEdit.setText(activeProfile.getCompanyName()); |
| 111 | mAddressLine1Edit.setText(activeProfile.getAddressLine1()); |
| 112 | mAddressLine2Edit.setText(activeProfile.getAddressLine2()); |
| 113 | mCityEdit.setText(activeProfile.getCity()); |
| 114 | mStateEdit.setText(activeProfile.getState()); |
| 115 | mZipEdit.setText(activeProfile.getZipCode()); |
| 116 | mCountryEdit.setText(activeProfile.getCountry()); |
| 117 | mPhoneEdit.setText(activeProfile.getPhoneNumber()); |
| 118 | } |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 119 | |
| 120 | return v; |
| 121 | } |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 122 | } |