SetupWizard: Add callback for actions to run post finish

Change-Id: Ifa62c94f61afbe33a97a66dc0acb72e303023579
This commit is contained in:
cretin45 2015-03-03 12:31:16 -08:00
parent 4e192fd22b
commit c9c13f20c9
4 changed files with 50 additions and 18 deletions

View File

@ -191,6 +191,13 @@ public abstract class AbstractSetupData extends BroadcastReceiver implements Set
} }
} }
@Override
public void addFinishRunnable(Runnable runnable) {
for (int i = 0; i < mListeners.size(); i++) {
mListeners.get(i).addFinishRunnable(runnable);
}
}
public Bundle save() { public Bundle save() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
for (Page page : mPageList.values()) { for (Page page : mPageList.values()) {

View File

@ -123,9 +123,14 @@ public class CyanogenSettingsPage extends SetupPage {
@Override @Override
public void onFinishSetup() { public void onFinishSetup() {
if (getData().containsKey(KEY_ENABLE_NAV_KEYS)) { getCallbacks().addFinishRunnable(new Runnable() {
writeDisableNavkeysOption(mContext, getData().getBoolean(KEY_ENABLE_NAV_KEYS)); @Override
} public void run() {
if (getData().containsKey(KEY_ENABLE_NAV_KEYS)) {
writeDisableNavkeysOption(mContext, getData().getBoolean(KEY_ENABLE_NAV_KEYS));
}
}
});
handleWhisperPushRegistration(); handleWhisperPushRegistration();
handleEnableMetrics(); handleEnableMetrics();
handleDefaultThemeSetup(); handleDefaultThemeSetup();

View File

@ -26,4 +26,5 @@ public interface SetupDataCallbacks {
boolean isCurrentPage(Page page); boolean isCurrentPage(Page page);
Page getPage(String key); Page getPage(String key);
Page getPage(int key); Page getPage(int key);
void addFinishRunnable(Runnable runnable);
} }

View File

@ -47,6 +47,8 @@ import com.cyanogenmod.setupwizard.setup.SetupDataCallbacks;
import com.cyanogenmod.setupwizard.util.EnableAccessibilityController; import com.cyanogenmod.setupwizard.util.EnableAccessibilityController;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.util.ArrayList;
public class SetupWizardActivity extends Activity implements SetupDataCallbacks { public class SetupWizardActivity extends Activity implements SetupDataCallbacks {
@ -69,6 +71,8 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
private volatile boolean mIsFinishing = false; private volatile boolean mIsFinishing = false;
private final ArrayList<Runnable> mFinishRunnables = new ArrayList<Runnable>();
private ThemeManager.ThemeChangeListener mThemeChangeListener = new ThemeManager.ThemeChangeListener() { private ThemeManager.ThemeChangeListener mThemeChangeListener = new ThemeManager.ThemeChangeListener() {
@Override @Override
public void onProgress(int progress) { public void onProgress(int progress) {
@ -273,6 +277,11 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
return mSetupData.isCurrentPage(page); return mSetupData.isCurrentPage(page);
} }
@Override
public void addFinishRunnable(Runnable runnable) {
mFinishRunnables.add(runnable);
}
@Override @Override
public void onFinish() { public void onFinish() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
@ -313,6 +322,9 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
@Override @Override
public void finish() { public void finish() {
super.finish(); super.finish();
for (Runnable runnable : mFinishRunnables) {
runnable.run();
}
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
} }
@ -390,21 +402,28 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
} }
private void finalizeSetup() { private void finalizeSetup() {
Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1); mFinishRunnables.add(new Runnable() {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1); @Override
public void run() {
Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
Settings.Secure.putInt(getContentResolver(),
Settings.Secure.USER_SETUP_COMPLETE, 1);
if (mEnableAccessibilityController != null) {
mEnableAccessibilityController.onDestroy();
}
SetupWizardUtils.disableGMSSetupWizard(SetupWizardActivity.this);
SetupWizardUtils.disableSetupWizard(SetupWizardActivity.this);
final ThemeManager tm =
(ThemeManager) SetupWizardActivity.this.getSystemService(THEME_SERVICE);
tm.removeClient(mThemeChangeListener);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
final WallpaperManager wallpaperManager =
WallpaperManager.getInstance(SetupWizardActivity.this);
wallpaperManager.forgetLoadedWallpaper();
}
});
finish(); finish();
if (mEnableAccessibilityController != null) {
mEnableAccessibilityController.onDestroy();
}
SetupWizardUtils.disableGMSSetupWizard(this);
SetupWizardUtils.disableSetupWizard(this);
final ThemeManager tm = (ThemeManager) this.getSystemService(THEME_SERVICE);
tm.removeClient(mThemeChangeListener);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
final WallpaperManager wallpaperManager =
WallpaperManager.getInstance(SetupWizardActivity.this);
wallpaperManager.forgetLoadedWallpaper();
} }
} }