SetupWizard: Better handling of launching into other activities
Change-Id: I4d8dc4a1b25e45c6ff35042239a0adf4c16458f1 (cherry picked from commit ed5d46703ea6aac1c912be114523688f3f8219e8)
This commit is contained in:
parent
88aba00aa3
commit
dbc1ceb8ca
@ -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,17 +84,13 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
if (!SetupWizardUtils.accountExists(mContext,
|
||||
mContext.getString(R.string.cm_account_type))) {
|
||||
super.doLoadAction(fragmentManager, action);
|
||||
launchCyanogenAccountSetup();
|
||||
} else {
|
||||
getCallbacks().onNextPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentReady() {
|
||||
launchCyanogenAccountSetup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN) {
|
||||
@ -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);
|
||||
|
@ -114,14 +114,10 @@ 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) {
|
||||
@ -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);
|
||||
|
@ -136,18 +136,13 @@ 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);
|
||||
|
@ -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();
|
||||
|
@ -96,9 +96,6 @@ public abstract class SetupPage implements Page {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentReady(){}
|
||||
|
||||
@Override
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
return false;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,22 +58,9 @@ 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);
|
||||
@ -89,6 +76,18 @@ public abstract class SetupPageFragment extends Fragment {
|
||||
mCallbacks = null;
|
||||
}
|
||||
|
||||
@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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user