John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) 2011 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame^] | 18 | package com.android.browser; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 19 | |
| 20 | import android.content.Context; |
| 21 | import android.content.SharedPreferences; |
| 22 | import android.content.SharedPreferences.Editor; |
| 23 | import android.database.Cursor; |
Ben Murdoch | 3d6c719 | 2011-10-27 18:04:58 +0100 | [diff] [blame] | 24 | import android.net.Uri; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 25 | import android.os.AsyncTask; |
| 26 | import android.os.Message; |
| 27 | import android.preference.PreferenceManager; |
Ben Murdoch | 3d6c719 | 2011-10-27 18:04:58 +0100 | [diff] [blame] | 28 | import android.provider.ContactsContract; |
Ben Murdoch | 234eadc | 2012-05-14 16:39:50 +0100 | [diff] [blame] | 29 | import android.util.Log; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 30 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 31 | |
John Reck | 7b06c90 | 2011-04-26 13:48:09 -0700 | [diff] [blame] | 32 | import java.util.concurrent.CountDownLatch; |
| 33 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 34 | import org.codeaurora.swe.AutoFillProfile; |
| 35 | |
| 36 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 37 | public class AutofillHandler { |
| 38 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 39 | protected AutoFillProfile mAutoFillProfile = null; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 40 | // Default to zero. In the case no profile is set up, the initial |
| 41 | // value will come from the AutoFillSettingsFragment when the user |
| 42 | // creates a profile. Otherwise, we'll read the ID of the last used |
| 43 | // profile from the prefs db. |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 44 | protected String mAutoFillActiveProfileId = ""; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 45 | private static final int NO_AUTOFILL_PROFILE_SET = 0; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 46 | private Context mContext; |
| 47 | |
Ben Murdoch | 234eadc | 2012-05-14 16:39:50 +0100 | [diff] [blame] | 48 | private static final String LOGTAG = "AutofillHandler"; |
| 49 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 50 | public AutofillHandler(Context context) { |
Ben Murdoch | 914c559 | 2011-08-01 13:58:47 +0100 | [diff] [blame] | 51 | mContext = context.getApplicationContext(); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 52 | SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(mContext); |
| 53 | mAutoFillActiveProfileId = p.getString( |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 54 | PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID, |
| 55 | mAutoFillActiveProfileId); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 58 | public synchronized void setAutoFillProfile(AutoFillProfile profile) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 59 | mAutoFillProfile = profile; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 60 | if (profile == null) |
| 61 | setActiveAutoFillProfileId(""); |
| 62 | else |
| 63 | setActiveAutoFillProfileId(profile.getUniqueId()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Ben Murdoch | 234eadc | 2012-05-14 16:39:50 +0100 | [diff] [blame] | 66 | public synchronized AutoFillProfile getAutoFillProfile() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 67 | return mAutoFillProfile; |
| 68 | } |
| 69 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 70 | public synchronized String getAutoFillProfileId() { |
| 71 | return mAutoFillActiveProfileId; |
| 72 | } |
| 73 | |
| 74 | private synchronized void setActiveAutoFillProfileId(String activeProfileId) { |
| 75 | if (mAutoFillActiveProfileId.equals(activeProfileId)) { |
| 76 | return; |
| 77 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 78 | mAutoFillActiveProfileId = activeProfileId; |
| 79 | Editor ed = PreferenceManager. |
| 80 | getDefaultSharedPreferences(mContext).edit(); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 81 | ed.putString(PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 82 | ed.apply(); |
| 83 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 84 | } |