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; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 23 | import android.preference.PreferenceManager; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 24 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 25 | |
John Reck | 7b06c90 | 2011-04-26 13:48:09 -0700 | [diff] [blame] | 26 | import java.util.concurrent.CountDownLatch; |
| 27 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 28 | import org.codeaurora.swe.AutoFillProfile; |
| 29 | |
| 30 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 31 | public class AutofillHandler { |
| 32 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 33 | protected AutoFillProfile mAutoFillProfile = null; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 34 | // Default to zero. In the case no profile is set up, the initial |
| 35 | // value will come from the AutoFillSettingsFragment when the user |
| 36 | // creates a profile. Otherwise, we'll read the ID of the last used |
| 37 | // profile from the prefs db. |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 38 | protected String mAutoFillActiveProfileId = ""; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 39 | private static final int NO_AUTOFILL_PROFILE_SET = 0; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 40 | private Context mContext; |
| 41 | |
Ben Murdoch | 234eadc | 2012-05-14 16:39:50 +0100 | [diff] [blame] | 42 | private static final String LOGTAG = "AutofillHandler"; |
| 43 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 44 | public AutofillHandler(Context context) { |
Ben Murdoch | 914c559 | 2011-08-01 13:58:47 +0100 | [diff] [blame] | 45 | mContext = context.getApplicationContext(); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 46 | SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(mContext); |
| 47 | mAutoFillActiveProfileId = p.getString( |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 48 | PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID, |
| 49 | mAutoFillActiveProfileId); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 52 | public synchronized void setAutoFillProfile(AutoFillProfile profile) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 53 | mAutoFillProfile = profile; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 54 | if (profile == null) |
| 55 | setActiveAutoFillProfileId(""); |
| 56 | else |
| 57 | setActiveAutoFillProfileId(profile.getUniqueId()); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Ben Murdoch | 234eadc | 2012-05-14 16:39:50 +0100 | [diff] [blame] | 60 | public synchronized AutoFillProfile getAutoFillProfile() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 61 | return mAutoFillProfile; |
| 62 | } |
| 63 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 64 | public synchronized String getAutoFillProfileId() { |
| 65 | return mAutoFillActiveProfileId; |
| 66 | } |
| 67 | |
| 68 | private synchronized void setActiveAutoFillProfileId(String activeProfileId) { |
| 69 | if (mAutoFillActiveProfileId.equals(activeProfileId)) { |
| 70 | return; |
| 71 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 72 | mAutoFillActiveProfileId = activeProfileId; |
| 73 | Editor ed = PreferenceManager. |
| 74 | getDefaultSharedPreferences(mContext).edit(); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 75 | ed.putString(PreferenceKeys.PREF_AUTOFILL_ACTIVE_PROFILE_ID, activeProfileId); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 76 | ed.apply(); |
| 77 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 78 | } |