|
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 package org.mozilla.gecko.preferences; |
|
7 |
|
8 import org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity; |
|
9 import org.mozilla.gecko.sync.setup.SyncAccounts; |
|
10 import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity; |
|
11 |
|
12 import android.content.Context; |
|
13 import android.content.Intent; |
|
14 import android.preference.Preference; |
|
15 import android.util.AttributeSet; |
|
16 |
|
17 class SyncPreference extends Preference { |
|
18 private static final boolean DEFAULT_TO_FXA = true; |
|
19 |
|
20 private Context mContext; |
|
21 |
|
22 public SyncPreference(Context context, AttributeSet attrs) { |
|
23 super(context, attrs); |
|
24 mContext = context; |
|
25 } |
|
26 |
|
27 private void openSync11Settings() { |
|
28 // Show Sync setup if no accounts exist; otherwise, show account settings. |
|
29 if (SyncAccounts.syncAccountsExist(mContext)) { |
|
30 SyncAccounts.openSyncSettings(mContext); |
|
31 return; |
|
32 } |
|
33 Intent intent = new Intent(mContext, SetupSyncActivity.class); |
|
34 mContext.startActivity(intent); |
|
35 } |
|
36 |
|
37 private void launchFxASetup() { |
|
38 Intent intent = new Intent(mContext, FxAccountGetStartedActivity.class); |
|
39 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
40 mContext.startActivity(intent); |
|
41 } |
|
42 |
|
43 @Override |
|
44 protected void onClick() { |
|
45 // If we're not defaulting to FxA, just do what we've always done. |
|
46 if (!DEFAULT_TO_FXA) { |
|
47 openSync11Settings(); |
|
48 return; |
|
49 } |
|
50 |
|
51 // If there's a legacy Sync account (or a pickled one on disk), |
|
52 // open the settings page. |
|
53 if (SyncAccounts.syncAccountsExist(mContext)) { |
|
54 SyncAccounts.openSyncSettings(mContext); |
|
55 return; |
|
56 } |
|
57 |
|
58 // Otherwise, launch the FxA "Get started" activity, which will |
|
59 // dispatch to the right location. |
|
60 launchFxASetup(); |
|
61 } |
|
62 } |