SetupWizard: Let cyanogen settings page handle finish action

Change-Id: I84e383cb3db7ef32c6097e6b1912d71a5eafb4c4
This commit is contained in:
cretin45 2015-01-30 10:55:05 -08:00
parent e39d98bdb3
commit a96968d996
2 changed files with 36 additions and 49 deletions

View File

@ -30,6 +30,7 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.IWindowManager;
import android.view.View;
import android.view.WindowManagerGlobal;
@ -40,6 +41,7 @@ import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import com.cyanogenmod.setupwizard.util.WhisperPushUtils;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
@ -52,6 +54,7 @@ public class CyanogenSettingsPage extends SetupPage {
public static final String KEY_SEND_METRICS = "send_metrics";
public static final String KEY_REGISTER_WHISPERPUSH = "register";
public static final String KEY_ENABLE_NAV_KEYS = "enable_nav_keys";
public static final String SETTING_METRICS = "settings.cyanogen.allow_metrics";
public static final String PRIVACY_POLICY_URI = "https://cyngn.com/legal/privacy-policy";
@ -114,6 +117,32 @@ public class CyanogenSettingsPage extends SetupPage {
editor.commit();
}
@Override
public void onFinishSetup() {
if (getData().containsKey(KEY_ENABLE_NAV_KEYS)) {
writeDisableNavkeysOption(mContext, getData().getBoolean(KEY_ENABLE_NAV_KEYS));
}
handleWhisperPushRegistration();
handleEnableMetrics();
}
private void handleWhisperPushRegistration() {
Bundle privacyData = getData();
if (privacyData != null && privacyData.containsKey(CyanogenSettingsPage.KEY_REGISTER_WHISPERPUSH)) {
Log.i(TAG, "Registering with WhisperPush");
WhisperPushUtils.startRegistration(mContext);
}
}
private void handleEnableMetrics() {
Bundle privacyData = getData();
if (privacyData != null
&& privacyData.containsKey(CyanogenSettingsPage.KEY_SEND_METRICS)) {
Settings.System.putInt(mContext.getContentResolver(), CyanogenSettingsPage.SETTING_METRICS,
privacyData.getBoolean(CyanogenSettingsPage.KEY_SEND_METRICS) ? 1 : 0);
}
}
private static boolean hideKeyDisabler() {
try {
return !KeyDisabler.isSupported();
@ -139,8 +168,6 @@ public class CyanogenSettingsPage extends SetupPage {
private CheckBox mNavKeys;
private CheckBox mSecureSms;
private Handler mHandler;
private View.OnClickListener mMetricsClickListener = new View.OnClickListener() {
@Override
@ -154,16 +181,9 @@ public class CyanogenSettingsPage extends SetupPage {
private View.OnClickListener mNavKeysClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
mNavKeys.setEnabled(false);
boolean checked = !mNavKeys.isChecked();
writeDisableNavkeysOption(getActivity(), checked);
updateDisableNavkeysOption();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mNavKeys.setEnabled(true);
}
}, 1000);
mNavKeys.setChecked(checked);
mPage.getData().putBoolean(KEY_ENABLE_NAV_KEYS, checked);
}
};
@ -176,11 +196,6 @@ public class CyanogenSettingsPage extends SetupPage {
}
};
public CyanogenSettingsFragment() {
super();
mHandler = new Handler();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@ -258,8 +273,10 @@ public class CyanogenSettingsPage extends SetupPage {
private void updateDisableNavkeysOption() {
boolean enabled = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.DEV_FORCE_SHOW_NAVBAR, 0) != 0;
mNavKeys.setChecked(enabled);
boolean checked = mPage.getData().containsKey(KEY_ENABLE_NAV_KEYS) ?
mPage.getData().getBoolean(KEY_ENABLE_NAV_KEYS) :
enabled;
mNavKeys.setChecked(checked);
}
}

View File

@ -25,7 +25,6 @@ import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewAnimationUtils;
@ -34,13 +33,10 @@ import android.widget.Button;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.setup.CMSetupWizardData;
import com.cyanogenmod.setupwizard.setup.CyanogenServicesPage;
import com.cyanogenmod.setupwizard.setup.CyanogenSettingsPage;
import com.cyanogenmod.setupwizard.setup.Page;
import com.cyanogenmod.setupwizard.setup.SetupDataCallbacks;
import com.cyanogenmod.setupwizard.util.EnableAccessibilityController;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import com.cyanogenmod.setupwizard.util.WhisperPushUtils;
public class SetupWizardActivity extends Activity implements SetupDataCallbacks {
@ -263,35 +259,9 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
anim.start();
}
private void handleWhisperPushRegistration() {
Page page = getPage(CyanogenServicesPage.TAG);
if (page == null) {
return;
}
Bundle privacyData = page.getData();
if (privacyData != null && privacyData.getBoolean(CyanogenSettingsPage.KEY_REGISTER_WHISPERPUSH)) {
Log.d(TAG, "Registering with WhisperPush");
WhisperPushUtils.startRegistration(this);
}
}
public void handleEnableMetrics() {
Page page = getPage(CyanogenServicesPage.TAG);
if (page == null) {
return;
}
Bundle privacyData = page.getData();
if (privacyData != null
&& privacyData.getBoolean(CyanogenSettingsPage.KEY_SEND_METRICS)) {
Settings.System.putInt(getContentResolver(), CyanogenSettingsPage.SETTING_METRICS,
privacyData.getBoolean(CyanogenSettingsPage.KEY_SEND_METRICS) ? 1 : 0);
}
}
private void finishSetup() {
getApplication().sendBroadcast(new Intent(SetupWizardApp.ACTION_FINISHED));
handleWhisperPushRegistration();
handleEnableMetrics();
mSetupData.finishPages();
Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
((SetupWizardApp)AppGlobals.getInitialApplication()).enableStatusBar();