2015-01-16 00:04:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 The CyanogenMod Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.cyanogenmod.setupwizard.ui;
|
|
|
|
|
2015-01-27 23:23:16 +00:00
|
|
|
import android.animation.Animator;
|
2015-01-16 00:04:44 +00:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AppGlobals;
|
|
|
|
import android.content.Intent;
|
2015-01-21 23:55:03 +00:00
|
|
|
import android.content.res.Configuration;
|
2015-01-16 00:04:44 +00:00
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.os.Bundle;
|
2015-01-27 23:23:16 +00:00
|
|
|
import android.os.Handler;
|
2015-01-16 00:04:44 +00:00
|
|
|
import android.provider.Settings;
|
2015-01-19 22:29:43 +00:00
|
|
|
import android.util.Log;
|
2015-01-27 19:10:09 +00:00
|
|
|
import android.view.MotionEvent;
|
2015-01-16 00:04:44 +00:00
|
|
|
import android.view.View;
|
2015-01-27 23:23:16 +00:00
|
|
|
import android.view.ViewAnimationUtils;
|
2015-01-16 00:04:44 +00:00
|
|
|
import android.widget.Button;
|
|
|
|
|
|
|
|
import com.cyanogenmod.setupwizard.R;
|
|
|
|
import com.cyanogenmod.setupwizard.SetupWizardApp;
|
|
|
|
import com.cyanogenmod.setupwizard.setup.CMSetupWizardData;
|
2015-01-19 22:29:43 +00:00
|
|
|
import com.cyanogenmod.setupwizard.setup.CyanogenServicesPage;
|
2015-01-24 00:06:26 +00:00
|
|
|
import com.cyanogenmod.setupwizard.setup.CyanogenSettingsPage;
|
2015-01-16 00:04:44 +00:00
|
|
|
import com.cyanogenmod.setupwizard.setup.Page;
|
|
|
|
import com.cyanogenmod.setupwizard.setup.SetupDataCallbacks;
|
2015-01-27 19:10:09 +00:00
|
|
|
import com.cyanogenmod.setupwizard.util.EnableAccessibilityController;
|
2015-01-16 00:04:44 +00:00
|
|
|
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
2015-01-19 22:29:43 +00:00
|
|
|
import com.cyanogenmod.setupwizard.util.WhisperPushUtils;
|
2015-01-16 00:04:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class SetupWizardActivity extends Activity implements SetupDataCallbacks {
|
|
|
|
|
|
|
|
private static final String TAG = SetupWizardActivity.class.getSimpleName();
|
|
|
|
|
|
|
|
private View mRootView;
|
|
|
|
private Button mNextButton;
|
|
|
|
private Button mPrevButton;
|
2015-01-27 23:23:16 +00:00
|
|
|
private View mReveal;
|
2015-01-16 00:04:44 +00:00
|
|
|
|
2015-01-30 01:36:30 +00:00
|
|
|
private EnableAccessibilityController mEnableAccessibilityController;
|
|
|
|
|
|
|
|
private CMSetupWizardData mSetupData;
|
2015-01-16 00:04:44 +00:00
|
|
|
|
2015-01-27 23:23:16 +00:00
|
|
|
private final Handler mHandler = new Handler();
|
|
|
|
|
2015-01-16 00:04:44 +00:00
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.setup_main);
|
2015-01-23 23:26:45 +00:00
|
|
|
getWindow().setWindowAnimations(android.R.anim.fade_in);
|
2015-01-16 00:04:44 +00:00
|
|
|
mRootView = findViewById(R.id.root);
|
|
|
|
((SetupWizardApp)getApplicationContext()).disableStatusBar();
|
2015-01-30 01:36:30 +00:00
|
|
|
mSetupData = (CMSetupWizardData)getLastNonConfigurationInstance();
|
2015-01-16 00:04:44 +00:00
|
|
|
if (mSetupData == null) {
|
|
|
|
mSetupData = new CMSetupWizardData(this);
|
|
|
|
}
|
|
|
|
mNextButton = (Button) findViewById(R.id.next_button);
|
|
|
|
mPrevButton = (Button) findViewById(R.id.prev_button);
|
2015-01-27 23:23:16 +00:00
|
|
|
mReveal = findViewById(R.id.reveal);
|
2015-01-16 00:04:44 +00:00
|
|
|
mSetupData.registerListener(this);
|
|
|
|
mNextButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
mSetupData.onNextPage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mPrevButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
mSetupData.onPreviousPage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
Page page = mSetupData.getCurrentPage();
|
|
|
|
page.doLoadAction(this, Page.ACTION_NEXT);
|
|
|
|
}
|
|
|
|
if (savedInstanceState != null && savedInstanceState.containsKey("data")) {
|
|
|
|
mSetupData.load(savedInstanceState.getBundle("data"));
|
|
|
|
}
|
2015-01-30 01:36:30 +00:00
|
|
|
if (EnableAccessibilityController.canEnableAccessibilityViaGesture(this)) {
|
|
|
|
mEnableAccessibilityController = new EnableAccessibilityController(this);
|
|
|
|
mRootView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return mEnableAccessibilityController.onInterceptTouchEvent(event);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-27 00:08:19 +00:00
|
|
|
// Since this is a new component, we need to disable here if the user
|
|
|
|
// has already been through setup on a previous version.
|
|
|
|
try {
|
|
|
|
if (Settings.Secure.getInt(getContentResolver(),
|
|
|
|
Settings.Secure.USER_SETUP_COMPLETE) == 1) {
|
|
|
|
finishSetup();
|
|
|
|
}
|
|
|
|
} catch (Settings.SettingNotFoundException e) {
|
|
|
|
// Continue with setup
|
|
|
|
}
|
2015-01-30 01:36:30 +00:00
|
|
|
registerReceiver(mSetupData, mSetupData.getIntentFilter());
|
2015-01-16 00:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
onPageTreeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
2015-01-30 01:36:30 +00:00
|
|
|
if (mEnableAccessibilityController != null) {
|
|
|
|
mEnableAccessibilityController.onDestroy();
|
|
|
|
}
|
2015-01-16 00:04:44 +00:00
|
|
|
mSetupData.unregisterListener(this);
|
2015-01-30 01:36:30 +00:00
|
|
|
unregisterReceiver(mSetupData);
|
2015-01-16 00:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
mSetupData.getCurrentPage().onActivityResult(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object onRetainNonConfigurationInstance() {
|
|
|
|
return mSetupData;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
outState.putBundle("data", mSetupData.save());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2015-01-30 01:36:30 +00:00
|
|
|
if (!mSetupData.isFirstPage()) {
|
|
|
|
mSetupData.onPreviousPage();
|
|
|
|
}
|
2015-01-16 00:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNextPage() {
|
|
|
|
Page page = mSetupData.getCurrentPage();
|
|
|
|
page.doLoadAction(this, Page.ACTION_NEXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreviousPage() {
|
|
|
|
Page page = mSetupData.getCurrentPage();
|
|
|
|
page.doLoadAction(this, Page.ACTION_PREVIOUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageLoaded(Page page) {
|
2015-01-21 23:55:03 +00:00
|
|
|
if (getResources().getConfiguration().orientation
|
|
|
|
== Configuration.ORIENTATION_LANDSCAPE &&
|
|
|
|
mSetupData.isFirstPage()) {
|
2015-01-30 01:36:30 +00:00
|
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE
|
|
|
|
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
2015-01-21 23:55:03 +00:00
|
|
|
} else {
|
2015-01-30 01:36:30 +00:00
|
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE
|
|
|
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
2015-01-21 23:55:03 +00:00
|
|
|
}
|
2015-01-16 00:04:44 +00:00
|
|
|
updateButtonBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageTreeChanged() {
|
|
|
|
updateButtonBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateButtonBar() {
|
|
|
|
Page page = mSetupData.getCurrentPage();
|
|
|
|
mNextButton.setText(page.getNextButtonTitleResId());
|
|
|
|
if (page.getPrevButtonTitleResId() != -1) {
|
|
|
|
mPrevButton.setText(page.getPrevButtonTitleResId());
|
|
|
|
} else {
|
|
|
|
mPrevButton.setText("");
|
|
|
|
}
|
|
|
|
if (mSetupData.isFirstPage()) {
|
|
|
|
mPrevButton.setCompoundDrawables(null, null, null, null);
|
|
|
|
} else {
|
|
|
|
mPrevButton.setCompoundDrawablesWithIntrinsicBounds(
|
|
|
|
getDrawable(R.drawable.ic_chevron_left_dark),
|
|
|
|
null, null, null);
|
|
|
|
}
|
|
|
|
final Resources resources = getResources();
|
|
|
|
if (mSetupData.isLastPage()) {
|
|
|
|
mRootView.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));
|
2015-01-30 01:36:30 +00:00
|
|
|
mPrevButton.setCompoundDrawablesWithIntrinsicBounds(
|
|
|
|
getDrawable(R.drawable.ic_chevron_left_wht), null,
|
|
|
|
null, null);
|
|
|
|
mPrevButton.setTextColor(resources.getColor(R.color.white));
|
2015-01-16 00:04:44 +00:00
|
|
|
} else {
|
2015-01-21 23:55:03 +00:00
|
|
|
mRootView.setBackgroundColor(resources.getColor(R.color.window_background));
|
2015-01-16 00:04:44 +00:00
|
|
|
mNextButton.setCompoundDrawablesWithIntrinsicBounds(null, null,
|
|
|
|
getDrawable(R.drawable.ic_chevron_right_dark), null);
|
|
|
|
mNextButton.setTextColor(resources.getColor(R.color.primary_text));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Page getPage(String key) {
|
|
|
|
return mSetupData.getPage(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Page getPage(int key) {
|
|
|
|
return mSetupData.getPage(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
2015-01-27 23:23:16 +00:00
|
|
|
animateOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void animateOut() {
|
|
|
|
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() {
|
|
|
|
finishSetup();;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animator animation) {}
|
|
|
|
});
|
|
|
|
anim.start();
|
2015-01-16 00:04:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 22:29:43 +00:00
|
|
|
private void handleWhisperPushRegistration() {
|
|
|
|
Page page = getPage(CyanogenServicesPage.TAG);
|
|
|
|
if (page == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bundle privacyData = page.getData();
|
2015-01-24 00:06:26 +00:00
|
|
|
if (privacyData != null && privacyData.getBoolean(CyanogenSettingsPage.KEY_REGISTER_WHISPERPUSH)) {
|
2015-01-19 22:29:43 +00:00
|
|
|
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
|
2015-01-24 00:06:26 +00:00
|
|
|
&& privacyData.getBoolean(CyanogenSettingsPage.KEY_SEND_METRICS)) {
|
|
|
|
Settings.System.putInt(getContentResolver(), CyanogenSettingsPage.SETTING_METRICS,
|
|
|
|
privacyData.getBoolean(CyanogenSettingsPage.KEY_SEND_METRICS) ? 1 : 0);
|
2015-01-19 22:29:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 00:04:44 +00:00
|
|
|
private void finishSetup() {
|
2015-01-19 22:29:43 +00:00
|
|
|
getApplication().sendBroadcast(new Intent(SetupWizardApp.ACTION_FINISHED));
|
|
|
|
handleWhisperPushRegistration();
|
|
|
|
handleEnableMetrics();
|
2015-01-16 00:04:44 +00:00
|
|
|
Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
|
|
|
|
Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
|
|
|
|
((SetupWizardApp)AppGlobals.getInitialApplication()).enableStatusBar();
|
|
|
|
SetupWizardUtils.disableSetupWizards(this);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|