2012-01-26 02:44:59 +04:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-01-26 02:44:59 +04:00
|
|
|
|
2013-11-11 22:41:16 +04:00
|
|
|
package org.mozilla.gecko.preferences;
|
2012-01-26 02:44:59 +04:00
|
|
|
|
2015-09-15 21:18:46 +03:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.preference.Preference;
|
|
|
|
import android.util.AttributeSet;
|
2014-09-06 02:39:49 +04:00
|
|
|
import org.mozilla.gecko.Telemetry;
|
|
|
|
import org.mozilla.gecko.TelemetryContract;
|
|
|
|
import org.mozilla.gecko.TelemetryContract.Method;
|
2015-09-15 21:18:46 +03:00
|
|
|
import org.mozilla.gecko.fxa.FxAccountConstants;
|
2015-09-17 23:22:26 +03:00
|
|
|
import org.mozilla.gecko.fxa.activities.FxAccountWebFlowActivity;
|
2012-07-28 04:53:54 +04:00
|
|
|
import org.mozilla.gecko.sync.setup.SyncAccounts;
|
|
|
|
import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity;
|
2012-01-26 02:44:59 +04:00
|
|
|
|
2012-07-18 04:54:54 +04:00
|
|
|
class SyncPreference extends Preference {
|
2014-02-02 07:05:28 +04:00
|
|
|
private static final boolean DEFAULT_TO_FXA = true;
|
2014-02-01 04:02:42 +04:00
|
|
|
|
2014-10-11 03:17:01 +04:00
|
|
|
private final Context mContext;
|
2012-01-26 02:44:59 +04:00
|
|
|
|
|
|
|
public SyncPreference(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
2014-01-29 03:18:16 +04:00
|
|
|
private void openSync11Settings() {
|
2012-07-07 03:46:24 +04:00
|
|
|
// Show Sync setup if no accounts exist; otherwise, show account settings.
|
2012-07-07 05:35:29 +04:00
|
|
|
if (SyncAccounts.syncAccountsExist(mContext)) {
|
2014-07-09 07:39:53 +04:00
|
|
|
// We don't check for failure here. If you already have Sync set up,
|
|
|
|
// then there's nothing we can do.
|
2012-07-07 03:46:24 +04:00
|
|
|
SyncAccounts.openSyncSettings(mContext);
|
2014-01-29 03:18:16 +04:00
|
|
|
return;
|
2012-07-07 03:46:24 +04:00
|
|
|
}
|
2014-01-29 03:18:16 +04:00
|
|
|
Intent intent = new Intent(mContext, SetupSyncActivity.class);
|
|
|
|
mContext.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void launchFxASetup() {
|
2015-09-15 21:18:46 +03:00
|
|
|
final Intent intent = new Intent(FxAccountConstants.ACTION_FXA_GET_STARTED);
|
2015-09-17 23:22:26 +03:00
|
|
|
intent.putExtra(FxAccountWebFlowActivity.EXTRA_ENDPOINT, FxAccountConstants.ENDPOINT_PREFERENCES);
|
2014-01-29 03:18:16 +04:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
2015-09-15 21:18:46 +03:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
2014-01-29 03:18:16 +04:00
|
|
|
mContext.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onClick() {
|
2014-02-01 04:02:42 +04:00
|
|
|
// If we're not defaulting to FxA, just do what we've always done.
|
|
|
|
if (!DEFAULT_TO_FXA) {
|
|
|
|
openSync11Settings();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's a legacy Sync account (or a pickled one on disk),
|
|
|
|
// open the settings page.
|
|
|
|
if (SyncAccounts.syncAccountsExist(mContext)) {
|
2014-07-09 07:39:53 +04:00
|
|
|
if (SyncAccounts.openSyncSettings(mContext) != null) {
|
2014-09-06 02:39:49 +04:00
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, Method.SETTINGS, "sync_settings");
|
2014-07-09 07:39:53 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-02-01 04:02:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, launch the FxA "Get started" activity, which will
|
|
|
|
// dispatch to the right location.
|
|
|
|
launchFxASetup();
|
2014-09-06 02:39:49 +04:00
|
|
|
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, Method.SETTINGS, "sync_setup");
|
2012-01-26 02:44:59 +04:00
|
|
|
}
|
|
|
|
}
|