michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.preferences; michael@0: michael@0: import org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity; michael@0: import org.mozilla.gecko.sync.setup.SyncAccounts; michael@0: import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity; michael@0: michael@0: import android.content.Context; michael@0: import android.content.Intent; michael@0: import android.preference.Preference; michael@0: import android.util.AttributeSet; michael@0: michael@0: class SyncPreference extends Preference { michael@0: private static final boolean DEFAULT_TO_FXA = true; michael@0: michael@0: private Context mContext; michael@0: michael@0: public SyncPreference(Context context, AttributeSet attrs) { michael@0: super(context, attrs); michael@0: mContext = context; michael@0: } michael@0: michael@0: private void openSync11Settings() { michael@0: // Show Sync setup if no accounts exist; otherwise, show account settings. michael@0: if (SyncAccounts.syncAccountsExist(mContext)) { michael@0: SyncAccounts.openSyncSettings(mContext); michael@0: return; michael@0: } michael@0: Intent intent = new Intent(mContext, SetupSyncActivity.class); michael@0: mContext.startActivity(intent); michael@0: } michael@0: michael@0: private void launchFxASetup() { michael@0: Intent intent = new Intent(mContext, FxAccountGetStartedActivity.class); michael@0: intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); michael@0: mContext.startActivity(intent); michael@0: } michael@0: michael@0: @Override michael@0: protected void onClick() { michael@0: // If we're not defaulting to FxA, just do what we've always done. michael@0: if (!DEFAULT_TO_FXA) { michael@0: openSync11Settings(); michael@0: return; michael@0: } michael@0: michael@0: // If there's a legacy Sync account (or a pickled one on disk), michael@0: // open the settings page. michael@0: if (SyncAccounts.syncAccountsExist(mContext)) { michael@0: SyncAccounts.openSyncSettings(mContext); michael@0: return; michael@0: } michael@0: michael@0: // Otherwise, launch the FxA "Get started" activity, which will michael@0: // dispatch to the right location. michael@0: launchFxASetup(); michael@0: } michael@0: }