mobile/android/base/preferences/SyncPreference.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/preferences/SyncPreference.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +package org.mozilla.gecko.preferences;
    1.10 +
    1.11 +import org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity;
    1.12 +import org.mozilla.gecko.sync.setup.SyncAccounts;
    1.13 +import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity;
    1.14 +
    1.15 +import android.content.Context;
    1.16 +import android.content.Intent;
    1.17 +import android.preference.Preference;
    1.18 +import android.util.AttributeSet;
    1.19 +
    1.20 +class SyncPreference extends Preference {
    1.21 +    private static final boolean DEFAULT_TO_FXA = true;
    1.22 +
    1.23 +    private Context mContext;
    1.24 +
    1.25 +    public SyncPreference(Context context, AttributeSet attrs) {
    1.26 +        super(context, attrs);
    1.27 +        mContext = context;
    1.28 +    }
    1.29 +
    1.30 +    private void openSync11Settings() {
    1.31 +        // Show Sync setup if no accounts exist; otherwise, show account settings.
    1.32 +        if (SyncAccounts.syncAccountsExist(mContext)) {
    1.33 +            SyncAccounts.openSyncSettings(mContext);
    1.34 +            return;
    1.35 +        }
    1.36 +        Intent intent = new Intent(mContext, SetupSyncActivity.class);
    1.37 +        mContext.startActivity(intent);
    1.38 +    }
    1.39 +
    1.40 +    private void launchFxASetup() {
    1.41 +        Intent intent = new Intent(mContext, FxAccountGetStartedActivity.class);
    1.42 +        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    1.43 +        mContext.startActivity(intent);
    1.44 +    }
    1.45 +
    1.46 +    @Override
    1.47 +    protected void onClick() {
    1.48 +        // If we're not defaulting to FxA, just do what we've always done.
    1.49 +        if (!DEFAULT_TO_FXA) {
    1.50 +            openSync11Settings();
    1.51 +            return;
    1.52 +        }
    1.53 +
    1.54 +        // If there's a legacy Sync account (or a pickled one on disk),
    1.55 +        // open the settings page.
    1.56 +        if (SyncAccounts.syncAccountsExist(mContext)) {
    1.57 +            SyncAccounts.openSyncSettings(mContext);
    1.58 +            return;
    1.59 +        }
    1.60 +
    1.61 +        // Otherwise, launch the FxA "Get started" activity, which will
    1.62 +        // dispatch to the right location.
    1.63 +        launchFxASetup();
    1.64 +    }
    1.65 +}

mercurial