SetupWizard: More refactor to match redlines
Change-Id: I74f422ba0c294d5e91aefb9356458c681cc53b37
This commit is contained in:
@@ -18,7 +18,6 @@ package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -104,10 +103,6 @@ public abstract class AbstractSetupData implements SetupDataCallbacks {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageViewCreated(LayoutInflater inflater, Bundle savedInstanceState,
|
||||
int layoutResource) {}
|
||||
|
||||
private boolean advanceToNextUncompleted() {
|
||||
while (mCurrentPageIndex < mPageList.size()) {
|
||||
mCurrentPageIndex++;
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerCallback;
|
||||
import android.accounts.AccountManagerFuture;
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
@@ -137,8 +135,6 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
private CheckBox mNavKeys;
|
||||
private CheckBox mSecureSms;
|
||||
|
||||
private Runnable mDeferredAction;
|
||||
|
||||
private Handler mHandler;
|
||||
|
||||
|
||||
@@ -250,23 +246,10 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
return R.layout.setup_cyanogen_services;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderLayoutResource() {
|
||||
return R.layout.header_condensed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateDisableNavkeysOption();
|
||||
runDeferredAction();
|
||||
}
|
||||
|
||||
private void runDeferredAction() {
|
||||
if (mDeferredAction != null) {
|
||||
mDeferredAction.run();
|
||||
mDeferredAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDisableNavkeysOption() {
|
||||
@@ -279,28 +262,9 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
private void launchCyanogenAccountSetup(final Activity activity) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true);
|
||||
AccountManager
|
||||
.get(activity).addAccount(SetupWizardApp.ACCOUNT_TYPE_CYANOGEN, null, null, bundle,
|
||||
activity, new AccountManagerCallback<Bundle>() {
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Bundle> bundleAccountManagerFuture) {
|
||||
if (activity == null) return; //There is a chance this activity has been torn down.
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!SetupWizardUtils.accountExists(activity,
|
||||
SetupWizardApp.ACCOUNT_TYPE_CYANOGEN)) {
|
||||
mPage.getCallbacks().onNextPage();
|
||||
}
|
||||
}
|
||||
};
|
||||
if (activity.isResumed()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
mDeferredAction = runnable;
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AccountManager.get(activity)
|
||||
.addAccount(SetupWizardApp.ACCOUNT_TYPE_CYANOGEN, null, null, bundle,
|
||||
activity, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,14 +19,20 @@ package com.cyanogenmod.setupwizard.setup;
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.view.ViewAnimationUtils;
|
||||
|
||||
public class FinishPage extends SetupPage {
|
||||
|
||||
public static final String TAG = "FinishPage";
|
||||
|
||||
private FinishFragment mFinishFragment;
|
||||
|
||||
public FinishPage(Context context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
@@ -36,9 +42,9 @@ public class FinishPage extends SetupPage {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
||||
|
||||
FinishFragment fragment = new FinishFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
mFinishFragment = new FinishFragment();
|
||||
mFinishFragment.setArguments(args);
|
||||
return mFinishFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,7 +59,7 @@ public class FinishPage extends SetupPage {
|
||||
|
||||
@Override
|
||||
public boolean doNextAction() {
|
||||
getCallbacks().onFinish();
|
||||
mFinishFragment.animateOut(getCallbacks());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,18 +75,58 @@ public class FinishPage extends SetupPage {
|
||||
|
||||
public static class FinishFragment extends SetupPageFragment {
|
||||
|
||||
private View mReveal;
|
||||
|
||||
private Handler mHandler;
|
||||
|
||||
@Override
|
||||
protected void initializePage() {}
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mHandler = new Handler();
|
||||
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.primary));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializePage() {
|
||||
mReveal = mRootView.findViewById(R.id.reveal);
|
||||
}
|
||||
|
||||
private void animateOut(final SetupDataCallbacks callbacks) {
|
||||
int cx = (mReveal.getLeft() + mReveal.getRight()) / 2;
|
||||
int cy = (mReveal.getTop() + mReveal.getBottom()) / 2;
|
||||
int finalRadius = Math.max(mReveal.getWidth(), mReveal.getHeight());
|
||||
Animator anim =
|
||||
ViewAnimationUtils.createCircularReveal(mReveal, cx, cy, 0, finalRadius);
|
||||
|
||||
anim.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mReveal.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callbacks.onFinish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {}
|
||||
});
|
||||
anim.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.setup_finished_page;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderLayoutResource() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -127,11 +127,6 @@ public class LocationSettingsPage extends SetupPage {
|
||||
return R.layout.location_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderLayoutResource() {
|
||||
return R.layout.header_condensed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
public interface SetupDataCallbacks {
|
||||
void onNextPage();
|
||||
void onPreviousPage();
|
||||
@@ -27,5 +24,4 @@ public interface SetupDataCallbacks {
|
||||
void onFinish();
|
||||
Page getPage(String key);
|
||||
Page getPage(int key);
|
||||
void onPageViewCreated(LayoutInflater inflater, Bundle savedInstanceState, int layoutResource);
|
||||
}
|
||||
|
||||
@@ -21,10 +21,12 @@ import com.cyanogenmod.setupwizard.R;
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.transition.Slide;
|
||||
import android.transition.Transition;
|
||||
import android.view.Gravity;
|
||||
|
||||
|
||||
public abstract class SetupPage implements Page {
|
||||
@@ -71,14 +73,19 @@ public abstract class SetupPage implements Page {
|
||||
public void doLoadAction(Activity context, int action) {
|
||||
if (context == null || context.isFinishing()) { return; }
|
||||
final FragmentManager fragmentManager = context.getFragmentManager();
|
||||
Fragment fragment = getFragment();
|
||||
if (action == Page.ACTION_NEXT) {
|
||||
FragmentTransaction transaction = fragmentManager.beginTransaction();
|
||||
transaction.replace(R.id.content, getFragment(), getKey());
|
||||
transaction.commit();
|
||||
Transition t = new Slide(Gravity.RIGHT);
|
||||
fragment.setEnterTransition(t);
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.content,fragment, getKey())
|
||||
.commit();
|
||||
} else {
|
||||
FragmentTransaction transaction = fragmentManager.beginTransaction();
|
||||
transaction.replace(R.id.content, getFragment(), getKey());
|
||||
transaction.commit();
|
||||
Transition t = new Slide(Gravity.LEFT);
|
||||
fragment.setEnterTransition(t);
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.content, fragment, getKey())
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,12 @@ public class WelcomePage extends SetupPage {
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.primary));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializePage() {
|
||||
mLanguagePicker = (LocalePicker) mRootView.findViewById(R.id.locale_list);
|
||||
@@ -152,10 +158,6 @@ public class WelcomePage extends SetupPage {
|
||||
return R.layout.setup_welcome_page;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderLayoutResource() {
|
||||
return R.layout.logo_header;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -585,11 +585,7 @@ public class LocalePicker extends LinearLayout {
|
||||
|
||||
mSelectionDivider = context.getDrawable(com.cyanogenmod.setupwizard.R.drawable.divider);
|
||||
|
||||
final int defSelectionDividerHeight = (int) TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT,
|
||||
getResources().getDisplayMetrics());
|
||||
mSelectionDividerHeight = attributesArray.getDimensionPixelSize(
|
||||
R.styleable.NumberPicker_selectionDividerHeight, defSelectionDividerHeight);
|
||||
mSelectionDividerHeight = UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT;
|
||||
|
||||
final int defSelectionDividerDistance = (int) TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE,
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.setup.Page;
|
||||
@@ -33,6 +34,8 @@ public abstract class SetupPageFragment extends Fragment {
|
||||
protected String mKey;
|
||||
protected Page mPage;
|
||||
protected View mRootView;
|
||||
protected TextView mTitleView;
|
||||
protected ViewGroup mHeaderView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -48,7 +51,9 @@ public abstract class SetupPageFragment extends Fragment {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
mRootView = inflater.inflate(getLayoutResource(), container, false);
|
||||
mCallbacks.onPageViewCreated(inflater, savedInstanceState, getHeaderLayoutResource());
|
||||
mTitleView = (TextView) mRootView.findViewById(android.R.id.title);
|
||||
mHeaderView = (ViewGroup ) mRootView.findViewById(R.id.header);
|
||||
getActivity().startPostponedEnterTransition();
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
@@ -56,9 +61,12 @@ public abstract class SetupPageFragment extends Fragment {
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mPage = mCallbacks.getPage(mKey);
|
||||
if (mTitleView != null) {
|
||||
mTitleView.setText(mPage.getTitleResId());
|
||||
}
|
||||
initializePage();
|
||||
mCallbacks.onPageLoaded(mPage);
|
||||
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.primary));
|
||||
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.status_bar));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,10 +84,6 @@ public abstract class SetupPageFragment extends Fragment {
|
||||
mCallbacks = null;
|
||||
}
|
||||
|
||||
protected int getHeaderLayoutResource() {
|
||||
return R.layout.header;
|
||||
}
|
||||
|
||||
protected abstract void initializePage();
|
||||
protected abstract int getLayoutResource();
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ package com.cyanogenmod.setupwizard.ui;
|
||||
import android.app.Activity;
|
||||
import android.app.AppGlobals;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
@@ -45,11 +47,8 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
|
||||
private static final String TAG = SetupWizardActivity.class.getSimpleName();
|
||||
|
||||
private View mRootView;
|
||||
private View mPageView;
|
||||
private Button mNextButton;
|
||||
private Button mPrevButton;
|
||||
private TextView mTitleView;
|
||||
private ViewGroup mHeaderView;
|
||||
|
||||
private AbstractSetupData mSetupData;
|
||||
|
||||
@@ -57,13 +56,11 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.setup_main);
|
||||
mRootView = findViewById(R.id.root);
|
||||
mPageView = findViewById(R.id.page);
|
||||
((SetupWizardApp)getApplicationContext()).disableStatusBar();
|
||||
mSetupData = (AbstractSetupData)getLastNonConfigurationInstance();
|
||||
if (mSetupData == null) {
|
||||
mSetupData = new CMSetupWizardData(this);
|
||||
}
|
||||
mHeaderView = (ViewGroup)findViewById(R.id.header);
|
||||
mNextButton = (Button) findViewById(R.id.next_button);
|
||||
mPrevButton = (Button) findViewById(R.id.prev_button);
|
||||
mSetupData.registerListener(this);
|
||||
@@ -118,24 +115,9 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
mSetupData.onPreviousPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageViewCreated(LayoutInflater inflater, Bundle savedInstanceState,
|
||||
int layoutResource) {
|
||||
if (layoutResource != -1) {
|
||||
mHeaderView.setVisibility(View.VISIBLE);
|
||||
mHeaderView.removeAllViews();
|
||||
inflater.inflate(layoutResource, mHeaderView, true);
|
||||
} else {
|
||||
mHeaderView.setVisibility(View.GONE);
|
||||
}
|
||||
mTitleView = (TextView) findViewById(android.R.id.title);
|
||||
if (mTitleView != null) {
|
||||
Page page = mSetupData.getCurrentPage();
|
||||
mTitleView.setText(page.getTitleResId());
|
||||
}
|
||||
if (!mSetupData.isFirstPage()) {
|
||||
mSetupData.onPreviousPage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,6 +134,14 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
|
||||
|
||||
@Override
|
||||
public void onPageLoaded(Page page) {
|
||||
if (getResources().getConfiguration().orientation
|
||||
== Configuration.ORIENTATION_LANDSCAPE &&
|
||||
mSetupData.isFirstPage()) {
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
| View.SYSTEM_UI_FLAG_FULLSCREEN);
|
||||
} else {
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
updateButtonBar();
|
||||
}
|
||||
|
||||
@@ -179,18 +169,12 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
|
||||
if (mSetupData.isLastPage()) {
|
||||
mPrevButton.setVisibility(View.INVISIBLE);
|
||||
mRootView.setBackgroundColor(resources.getColor(R.color.primary));
|
||||
mPageView.setBackgroundColor(resources.getColor(R.color.primary));
|
||||
mNextButton.setCompoundDrawablesWithIntrinsicBounds(null, null,
|
||||
getDrawable(R.drawable.ic_chevron_right_wht), null);
|
||||
mNextButton.setTextColor(resources.getColor(R.color.white));
|
||||
} else {
|
||||
mPrevButton.setVisibility(View.VISIBLE);
|
||||
mPageView.setBackgroundColor(resources.getColor(R.color.page_background));
|
||||
if (mSetupData.isFirstPage()) {
|
||||
mRootView.setBackgroundColor(resources.getColor(R.color.page_background));
|
||||
} else {
|
||||
mRootView.setBackgroundColor(resources.getColor(R.color.window_background));
|
||||
}
|
||||
mRootView.setBackgroundColor(resources.getColor(R.color.window_background));
|
||||
mNextButton.setCompoundDrawablesWithIntrinsicBounds(null, null,
|
||||
getDrawable(R.drawable.ic_chevron_right_dark), null);
|
||||
mNextButton.setTextColor(resources.getColor(R.color.primary_text));
|
||||
|
||||
Reference in New Issue
Block a user