summaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2015-03-17 15:18:16 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-04-01 01:59:25 +0000
commitdbc1ceb8ca97143a0067c2b97ca14a68fb789f69 (patch)
tree386c0e08cce81bed07d24c1dc2e2affa7654871a /src/com/cyanogenmod
parent88aba00aa3bf65f992115e5334f0f8713254deec (diff)
downloadpackages_apps_SetupWizard-dbc1ceb8ca97143a0067c2b97ca14a68fb789f69.zip
packages_apps_SetupWizard-dbc1ceb8ca97143a0067c2b97ca14a68fb789f69.tar.gz
packages_apps_SetupWizard-dbc1ceb8ca97143a0067c2b97ca14a68fb789f69.tar.bz2
SetupWizard: Better handling of launching into other activities
Change-Id: I4d8dc4a1b25e45c6ff35042239a0adf4c16458f1 (cherry picked from commit ed5d46703ea6aac1c912be114523688f3f8219e8)
Diffstat (limited to 'src/com/cyanogenmod')
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java40
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java32
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/OtherSettingsPage.java11
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/Page.java1
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/SetupPage.java3
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/WifiSetupPage.java4
-rw-r--r--src/com/cyanogenmod/setupwizard/ui/LoadingFragment.java52
-rw-r--r--src/com/cyanogenmod/setupwizard/ui/SetupPageFragment.java25
-rw-r--r--src/com/cyanogenmod/setupwizard/util/SetupWizardUtils.java1
9 files changed, 106 insertions, 63 deletions
diff --git a/src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java b/src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java
index f446967..479f2be 100644
--- a/src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java
@@ -28,6 +28,7 @@ import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.util.Log;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp;
@@ -83,6 +84,7 @@ public class CyanogenServicesPage extends SetupPage {
if (!SetupWizardUtils.accountExists(mContext,
mContext.getString(R.string.cm_account_type))) {
super.doLoadAction(fragmentManager, action);
+ launchCyanogenAccountSetup();
} else {
getCallbacks().onNextPage();
}
@@ -90,11 +92,6 @@ public class CyanogenServicesPage extends SetupPage {
}
@Override
- public void onFragmentReady() {
- launchCyanogenAccountSetup();
- }
-
- @Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN) {
if (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_FIRST_USER) {
@@ -127,6 +124,7 @@ public class CyanogenServicesPage extends SetupPage {
null, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
+ boolean error = false;
try {
Bundle result = future.getResult();
Intent intent = result
@@ -135,24 +133,26 @@ public class CyanogenServicesPage extends SetupPage {
ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in,
android.R.anim.fade_out);
- if (!mFragment.isDetached()) {
- SetupStats
- .addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
- SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
- SetupStats.Label.PAGE,
- SetupStats.Label.CYANOGEN_ACCOUNT);
- mFragment.startActivityForResult(intent,
- SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN,
- options.toBundle());
- } else {
- if (getCallbacks().
- isCurrentPage(CyanogenServicesPage.this)) {
- getCallbacks().onNextPage();
- }
- }
+ SetupStats
+ .addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
+ SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
+ SetupStats.Label.PAGE,
+ SetupStats.Label.CYANOGEN_ACCOUNT);
+ mFragment.startActivityForResult(intent,
+ SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN,
+ options.toBundle());
} catch (OperationCanceledException e) {
+ error = true;
} catch (IOException e) {
+ error = true;
} catch (AuthenticatorException e) {
+ Log.e(TAG, "Error launching cm account", e);
+ error = true;
+ } finally {
+ if (error && getCallbacks().
+ isCurrentPage(CyanogenServicesPage.this)) {
+ getCallbacks().onNextPage();
+ }
}
}
}, null);
diff --git a/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java b/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java
index a9c50d1..f2df085 100644
--- a/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java
@@ -114,15 +114,11 @@ public class GmsAccountPage extends SetupPage {
getCallbacks().onPreviousPage();
} else {
super.doLoadAction(fragmentManager, action);
+ launchGmsAccountSetup();
}
}
@Override
- public void onFragmentReady() {
- launchGmsAccountSetup();
- }
-
- @Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS) {
if (!mBackupEnabled && SetupWizardUtils.isOwner() && resultCode == Activity.RESULT_OK) {
@@ -217,6 +213,7 @@ public class GmsAccountPage extends SetupPage {
bundle, null, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
+ boolean error = false;
try {
Bundle result = future.getResult();
Intent intent = result
@@ -225,20 +222,23 @@ public class GmsAccountPage extends SetupPage {
ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in,
android.R.anim.fade_out);
- if (!mFragment.isDetached()) {
- SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
- SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
- SetupStats.Label.PAGE, SetupStats.Label.GMS_ACCOUNT);
- mFragment.startActivityForResult(intent,
- SetupWizardApp.REQUEST_CODE_SETUP_GMS, options.toBundle());
- } else {
- if (getCallbacks().isCurrentPage(GmsAccountPage.this)) {
- getCallbacks().onNextPage();
- }
- }
+ SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
+ SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
+ SetupStats.Label.PAGE, SetupStats.Label.GMS_ACCOUNT);
+ mFragment.startActivityForResult(intent,
+ SetupWizardApp.REQUEST_CODE_SETUP_GMS, options.toBundle());
} catch (OperationCanceledException e) {
+ error = true;
} catch (IOException e) {
+ error = true;
} catch (AuthenticatorException e) {
+ Log.e(TAG, "Error launching gms account", e);
+ error = true;
+ } finally {
+ if (error && getCallbacks().
+ isCurrentPage(GmsAccountPage.this)) {
+ getCallbacks().onNextPage();
+ }
}
}
}, null);
diff --git a/src/com/cyanogenmod/setupwizard/setup/OtherSettingsPage.java b/src/com/cyanogenmod/setupwizard/setup/OtherSettingsPage.java
index be0ea62..aa51711 100644
--- a/src/com/cyanogenmod/setupwizard/setup/OtherSettingsPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/OtherSettingsPage.java
@@ -137,17 +137,12 @@ public class OtherSettingsPage extends SetupPage {
};
@Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- mContentResolver = getActivity().getContentResolver();
- mBackupManager = IBackupManager.Stub.asInterface(
- ServiceManager.getService(Context.BACKUP_SERVICE));
- }
-
- @Override
protected void initializePage() {
final boolean hasGms = SetupWizardUtils.hasGMS(getActivity());
final boolean hasTelephony = SetupWizardUtils.hasTelephony(getActivity());
+ mContentResolver = getActivity().getContentResolver();
+ mBackupManager = IBackupManager.Stub.asInterface(
+ ServiceManager.getService(Context.BACKUP_SERVICE));
TextView summaryView = (TextView) mRootView.findViewById(android.R.id.summary);
if (hasGms) {
String privacy_policy = getString(R.string.services_privacy_policy);
diff --git a/src/com/cyanogenmod/setupwizard/setup/Page.java b/src/com/cyanogenmod/setupwizard/setup/Page.java
index 799749a..ee5efd6 100644
--- a/src/com/cyanogenmod/setupwizard/setup/Page.java
+++ b/src/com/cyanogenmod/setupwizard/setup/Page.java
@@ -43,7 +43,6 @@ public interface Page {
public boolean doPreviousAction();
public boolean doNextAction();
public void doLoadAction(FragmentManager fragmentManager, int action);
- public void onFragmentReady();
public void onFinishSetup();
public boolean onActivityResult(int requestCode, int resultCode, Intent data);
public SetupDataCallbacks getCallbacks();
diff --git a/src/com/cyanogenmod/setupwizard/setup/SetupPage.java b/src/com/cyanogenmod/setupwizard/setup/SetupPage.java
index 67a238a..1a19fb0 100644
--- a/src/com/cyanogenmod/setupwizard/setup/SetupPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/SetupPage.java
@@ -97,9 +97,6 @@ public abstract class SetupPage implements Page {
}
@Override
- public void onFragmentReady(){}
-
- @Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
return false;
}
diff --git a/src/com/cyanogenmod/setupwizard/setup/WifiSetupPage.java b/src/com/cyanogenmod/setupwizard/setup/WifiSetupPage.java
index 2559298..a9574fd 100644
--- a/src/com/cyanogenmod/setupwizard/setup/WifiSetupPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/WifiSetupPage.java
@@ -136,8 +136,10 @@ public class WifiSetupPage extends SetupPage {
return R.string.loading;
}
+
@Override
- public void onFragmentReady() {
+ public void doLoadAction(FragmentManager fragmentManager, int action) {
+ super.doLoadAction(fragmentManager, action);
launchWifiSetup();
}
diff --git a/src/com/cyanogenmod/setupwizard/ui/LoadingFragment.java b/src/com/cyanogenmod/setupwizard/ui/LoadingFragment.java
index f7fab63..184a252 100644
--- a/src/com/cyanogenmod/setupwizard/ui/LoadingFragment.java
+++ b/src/com/cyanogenmod/setupwizard/ui/LoadingFragment.java
@@ -16,9 +16,39 @@
package com.cyanogenmod.setupwizard.ui;
+import android.content.Intent;
+import android.os.Bundle;
+
import com.cyanogenmod.setupwizard.R;
public class LoadingFragment extends SetupPageFragment {
+
+ private StartActivityForResultRunnable mStartActivityForResultRunnable;
+
+ @Override
+ public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
+ if (isResumed()) {
+ super.startActivityForResult(intent, requestCode, options);
+ } else {
+ mStartActivityForResultRunnable =
+ new StartActivityForResultRunnable(this, intent, requestCode, options);
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mStartActivityForResultRunnable != null) {
+ mStartActivityForResultRunnable.run();
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mStartActivityForResultRunnable = null;
+ }
+
@Override
protected void initializePage() {}
@@ -26,4 +56,26 @@ public class LoadingFragment extends SetupPageFragment {
protected int getLayoutResource() {
return R.layout.setup_loading_page;
}
+
+ private static class StartActivityForResultRunnable implements Runnable {
+
+ private final LoadingFragment mLoadingFragment;
+ private final Intent mIntent;
+ private final int mRequestCode;
+ private final Bundle mOptions;
+
+ private StartActivityForResultRunnable(LoadingFragment loadingFragment,
+ Intent intent, int requestCode, Bundle options) {
+ mLoadingFragment = loadingFragment;
+ mIntent = intent;
+ mRequestCode = requestCode;
+ mOptions = options;
+ }
+
+ @Override
+ public void run() {
+ mLoadingFragment.startActivityForResult(mIntent, mRequestCode, mOptions);
+ mLoadingFragment.mStartActivityForResultRunnable = null;
+ }
+ }
}
diff --git a/src/com/cyanogenmod/setupwizard/ui/SetupPageFragment.java b/src/com/cyanogenmod/setupwizard/ui/SetupPageFragment.java
index 6ba0eda..3c85f5a 100644
--- a/src/com/cyanogenmod/setupwizard/ui/SetupPageFragment.java
+++ b/src/com/cyanogenmod/setupwizard/ui/SetupPageFragment.java
@@ -58,23 +58,10 @@ public abstract class SetupPageFragment extends Fragment {
mRootView = inflater.inflate(getLayoutResource(), container, false);
mTitleView = (TextView) mRootView.findViewById(android.R.id.title);
mHeaderView = (ViewGroup ) mRootView.findViewById(R.id.header);
- getActivity().startPostponedEnterTransition();
return mRootView;
}
@Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- mPage = mCallbacks.getPage(mKey);
- if (mTitleView != null) {
- mTitleView.setText(mPage.getTitleResId());
- }
- initializePage();
- mPage.onFragmentReady();
- mCallbacks.onPageLoaded(mPage);
- }
-
- @Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (!(activity instanceof SetupDataCallbacks)) {
@@ -90,6 +77,18 @@ public abstract class SetupPageFragment extends Fragment {
}
@Override
+ public void onResume() {
+ super.onResume();
+ mPage = mCallbacks.getPage(mKey);
+ if (mTitleView != null) {
+ mTitleView.setText(mPage.getTitleResId());
+ }
+ initializePage();
+ mCallbacks.onPageLoaded(mPage);
+ getActivity().startPostponedEnterTransition();
+ }
+
+ @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mPage.onActivityResult(requestCode, resultCode, data);
}
diff --git a/src/com/cyanogenmod/setupwizard/util/SetupWizardUtils.java b/src/com/cyanogenmod/setupwizard/util/SetupWizardUtils.java
index bd6bd45..37d60a0 100644
--- a/src/com/cyanogenmod/setupwizard/util/SetupWizardUtils.java
+++ b/src/com/cyanogenmod/setupwizard/util/SetupWizardUtils.java
@@ -27,7 +27,6 @@ import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.UserHandle;
import android.os.UserManager;
-import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;