blob: 608c3deffef140506b153454f69c99385fd34b27 [file] [log] [blame]
Ben Murdochaf554522010-09-10 22:09:30 +01001/*
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
17package com.android.browser;
18
19import android.app.Fragment;
Ben Murdochaf554522010-09-10 22:09:30 +010020import android.os.Bundle;
21import android.util.Log;
22import android.view.View;
23import android.view.ViewGroup;
24import android.view.View.OnClickListener;
25import android.view.LayoutInflater;
Ben Murdoch0cb81892010-10-08 12:41:33 +010026import android.webkit.WebSettings.AutoFillProfile;
Ben Murdochaf554522010-09-10 22:09:30 +010027import android.widget.Button;
28import android.widget.EditText;
Ben Murdoch36a23dd2010-10-13 13:20:06 +010029import android.widget.Toast;
Ben Murdochaf554522010-09-10 22:09:30 +010030
31public class AutoFillSettingsFragment extends Fragment {
32
33 private static final String LOGTAG = "AutoFillSettingsFragment";
34
Ben Murdoch36a23dd2010-10-13 13:20:06 +010035 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 Murdochaf554522010-09-10 22:09:30 +010046 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 Murdoch36a23dd2010-10-13 13:20:06 +010057 Bundle savedInstanceState) {
Ben Murdochaf554522010-09-10 22:09:30 +010058 View v = inflater.inflate(R.layout.autofill_settings_fragment, container, false);
59
Ben Murdoch36a23dd2010-10-13 13:20:06 +010060 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 Murdochaf554522010-09-10 22:09:30 +010073 Button saveButton = (Button)v.findViewById(R.id.autofill_profile_editor_save_button);
74 saveButton.setOnClickListener(new OnClickListener() {
75 public void onClick(View button) {
Ben Murdoch0cb81892010-10-08 12:41:33 +010076 BrowserSettings.getInstance().setAutoFillProfile(getActivity(),
77 new AutoFillProfile(
Ben Murdoch36a23dd2010-10-13 13:20:06 +010078 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 Murdochaf554522010-09-10 22:09:30 +010088 }
89 });
90
Ben Murdoch36a23dd2010-10-13 13:20:06 +010091 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 Murdoch0cb81892010-10-08 12:41:33 +0100105 // Populate the text boxes with any pre existing AutoFill data.
Ben Murdoch0cb81892010-10-08 12:41:33 +0100106 AutoFillProfile activeProfile = BrowserSettings.getInstance().getAutoFillProfile();
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100107 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 Murdochaf554522010-09-10 22:09:30 +0100119
120 return v;
121 }
Ben Murdochaf554522010-09-10 22:09:30 +0100122}