blob: 77281494366b6d59660c9b4e3838702267d68801 [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 Murdoch6fa32ba2010-10-20 14:01:25 +010046 // 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 Murdochaf554522010-09-10 22:09:30 +010051 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 Murdoch36a23dd2010-10-13 13:20:06 +010062 Bundle savedInstanceState) {
Ben Murdochaf554522010-09-10 22:09:30 +010063 View v = inflater.inflate(R.layout.autofill_settings_fragment, container, false);
64
Ben Murdoch36a23dd2010-10-13 13:20:06 +010065 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 Murdochaf554522010-09-10 22:09:30 +010078 Button saveButton = (Button)v.findViewById(R.id.autofill_profile_editor_save_button);
79 saveButton.setOnClickListener(new OnClickListener() {
80 public void onClick(View button) {
Ben Murdoch0cb81892010-10-08 12:41:33 +010081 BrowserSettings.getInstance().setAutoFillProfile(getActivity(),
82 new AutoFillProfile(
Ben Murdoch6fa32ba2010-10-20 14:01:25 +010083 mUniqueId,
Ben Murdoch36a23dd2010-10-13 13:20:06 +010084 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 Murdochaf554522010-09-10 22:09:30 +010094 }
95 });
96
Ben Murdoch36a23dd2010-10-13 13:20:06 +010097 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 Murdoch0cb81892010-10-08 12:41:33 +0100111 // Populate the text boxes with any pre existing AutoFill data.
Ben Murdoch0cb81892010-10-08 12:41:33 +0100112 AutoFillProfile activeProfile = BrowserSettings.getInstance().getAutoFillProfile();
Ben Murdoch36a23dd2010-10-13 13:20:06 +0100113 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 Murdochaf554522010-09-10 22:09:30 +0100125
126 return v;
127 }
Ben Murdochaf554522010-09-10 22:09:30 +0100128}