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 | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 29 | |
| 30 | public class AutoFillSettingsFragment extends Fragment { |
| 31 | |
| 32 | private static final String LOGTAG = "AutoFillSettingsFragment"; |
| 33 | |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 34 | public AutoFillSettingsFragment() { |
| 35 | |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public void onCreate(Bundle savedState) { |
| 40 | super.onCreate(savedState); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 45 | Bundle savedInstanceState) { |
| 46 | View v = inflater.inflate(R.layout.autofill_settings_fragment, container, false); |
| 47 | |
| 48 | Button saveButton = (Button)v.findViewById(R.id.autofill_profile_editor_save_button); |
| 49 | saveButton.setOnClickListener(new OnClickListener() { |
| 50 | public void onClick(View button) { |
| 51 | View v = getView(); |
| 52 | EditText fullName = (EditText)v.findViewById( |
| 53 | R.id.autofill_profile_editor_name_edit); |
| 54 | EditText email = (EditText)v.findViewById( |
| 55 | R.id.autofill_profile_editor_email_address_edit); |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame^] | 56 | BrowserSettings.getInstance().setAutoFillProfile(getActivity(), |
| 57 | new AutoFillProfile( |
| 58 | fullName.getText().toString(), |
| 59 | email.getText().toString())); |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 60 | } |
| 61 | }); |
| 62 | |
Ben Murdoch | 0cb8189 | 2010-10-08 12:41:33 +0100 | [diff] [blame^] | 63 | // Populate the text boxes with any pre existing AutoFill data. |
| 64 | EditText fullName = (EditText)v.findViewById( |
| 65 | R.id.autofill_profile_editor_name_edit); |
| 66 | EditText email = (EditText)v.findViewById( |
| 67 | R.id.autofill_profile_editor_email_address_edit); |
| 68 | AutoFillProfile activeProfile = BrowserSettings.getInstance().getAutoFillProfile(); |
| 69 | fullName.setText(activeProfile.getFullName()); |
| 70 | email.setText(activeProfile.getEmailAddress()); |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 71 | |
| 72 | return v; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void onPause() { |
| 77 | AutoFillProfileDatabase db = |
| 78 | AutoFillProfileDatabase.getInstance(getActivity()); |
| 79 | db.close(); |
| 80 | super.onPause(); |
| 81 | } |
Ben Murdoch | af55452 | 2010-09-10 22:09:30 +0100 | [diff] [blame] | 82 | } |