2013-02-14 06:01:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 The Android Open Source 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.android.inputmethod.latin.setup;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2013-04-18 08:19:40 +00:00
|
|
|
import android.content.ContentResolver;
|
2013-02-26 08:56:54 +00:00
|
|
|
import android.content.Context;
|
2013-02-14 06:01:53 +00:00
|
|
|
import android.content.Intent;
|
2013-02-14 07:46:39 +00:00
|
|
|
import android.content.res.Resources;
|
2013-04-18 08:19:40 +00:00
|
|
|
import android.media.MediaPlayer;
|
|
|
|
import android.net.Uri;
|
2013-02-14 06:01:53 +00:00
|
|
|
import android.os.Bundle;
|
2013-02-14 07:46:39 +00:00
|
|
|
import android.os.Message;
|
|
|
|
import android.provider.Settings;
|
2013-04-30 09:09:52 +00:00
|
|
|
import android.util.Log;
|
2013-02-14 07:46:39 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.InputMethodInfo;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2013-05-01 03:20:58 +00:00
|
|
|
import android.widget.ImageView;
|
2013-02-14 07:46:39 +00:00
|
|
|
import android.widget.TextView;
|
2013-04-18 08:19:40 +00:00
|
|
|
import android.widget.VideoView;
|
2013-02-14 06:01:53 +00:00
|
|
|
|
2013-02-14 07:46:39 +00:00
|
|
|
import com.android.inputmethod.compat.TextViewCompatUtils;
|
|
|
|
import com.android.inputmethod.compat.ViewCompatUtils;
|
|
|
|
import com.android.inputmethod.latin.CollectionUtils;
|
|
|
|
import com.android.inputmethod.latin.R;
|
|
|
|
import com.android.inputmethod.latin.RichInputMethodManager;
|
2013-02-14 06:01:53 +00:00
|
|
|
import com.android.inputmethod.latin.SettingsActivity;
|
2013-02-14 07:46:39 +00:00
|
|
|
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
|
|
|
|
2013-04-24 02:38:44 +00:00
|
|
|
import java.util.ArrayList;
|
2013-02-14 06:01:53 +00:00
|
|
|
|
2013-04-18 08:19:40 +00:00
|
|
|
// TODO: Use Fragment to implement welcome screen and setup steps.
|
2013-04-18 06:11:33 +00:00
|
|
|
public final class SetupActivity extends Activity implements View.OnClickListener {
|
2013-04-30 09:09:52 +00:00
|
|
|
private static final String TAG = SetupActivity.class.getSimpleName();
|
|
|
|
|
2013-04-18 08:19:40 +00:00
|
|
|
private View mWelcomeScreen;
|
|
|
|
private View mSetupScreen;
|
|
|
|
private Uri mWelcomeVideoUri;
|
|
|
|
private VideoView mWelcomeVideoView;
|
|
|
|
private View mActionStart;
|
2013-04-24 03:29:03 +00:00
|
|
|
private View mActionNext;
|
|
|
|
private TextView mStep1Bullet;
|
2013-04-18 06:11:33 +00:00
|
|
|
private TextView mActionFinish;
|
2013-04-24 02:38:44 +00:00
|
|
|
private SetupStepGroup mSetupStepGroup;
|
2013-02-14 07:46:39 +00:00
|
|
|
private static final String STATE_STEP = "step";
|
2013-02-26 08:56:54 +00:00
|
|
|
private int mStepNumber;
|
2013-05-02 09:16:12 +00:00
|
|
|
private static final int STEP_WELCOME = 0;
|
2013-02-14 07:46:39 +00:00
|
|
|
private static final int STEP_1 = 1;
|
|
|
|
private static final int STEP_2 = 2;
|
|
|
|
private static final int STEP_3 = 3;
|
2013-05-09 04:14:18 +00:00
|
|
|
private static final int STEP_LAUNCHING_IME_SETTINGS = 4;
|
|
|
|
private static final int STEP_BACK_FROM_IME_SETTINGS = 5;
|
2013-02-14 07:46:39 +00:00
|
|
|
|
|
|
|
private final SettingsPoolingHandler mHandler = new SettingsPoolingHandler(this);
|
|
|
|
|
|
|
|
static final class SettingsPoolingHandler extends StaticInnerHandlerWrapper<SetupActivity> {
|
|
|
|
private static final int MSG_POLLING_IME_SETTINGS = 0;
|
|
|
|
private static final long IME_SETTINGS_POLLING_INTERVAL = 200;
|
|
|
|
|
|
|
|
public SettingsPoolingHandler(final SetupActivity outerInstance) {
|
|
|
|
super(outerInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleMessage(final Message msg) {
|
|
|
|
final SetupActivity setupActivity = getOuterInstance();
|
2013-03-14 03:19:10 +00:00
|
|
|
if (setupActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-14 07:46:39 +00:00
|
|
|
switch (msg.what) {
|
|
|
|
case MSG_POLLING_IME_SETTINGS:
|
2013-05-09 04:14:18 +00:00
|
|
|
if (isThisImeEnabled(setupActivity)) {
|
2013-02-14 07:46:39 +00:00
|
|
|
setupActivity.invokeSetupWizardOfThisIme();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
startPollingImeSettings();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startPollingImeSettings() {
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_POLLING_IME_SETTINGS),
|
|
|
|
IME_SETTINGS_POLLING_INTERVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelPollingImeSettings() {
|
|
|
|
removeMessages(MSG_POLLING_IME_SETTINGS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 06:01:53 +00:00
|
|
|
@Override
|
2013-02-14 07:46:39 +00:00
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
|
|
|
setTheme(android.R.style.Theme_DeviceDefault_Light_NoActionBar);
|
2013-02-14 06:01:53 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2013-02-14 07:46:39 +00:00
|
|
|
setContentView(R.layout.setup_wizard);
|
|
|
|
|
|
|
|
RichInputMethodManager.init(this);
|
|
|
|
|
|
|
|
if (savedInstanceState == null) {
|
2013-05-09 04:14:18 +00:00
|
|
|
mStepNumber = determineSetupStepNumberFromLauncher();
|
2013-02-14 07:46:39 +00:00
|
|
|
} else {
|
2013-02-26 08:56:54 +00:00
|
|
|
mStepNumber = savedInstanceState.getInt(STATE_STEP);
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
2013-04-17 09:53:43 +00:00
|
|
|
final String applicationName = getResources().getString(getApplicationInfo().labelRes);
|
2013-04-18 08:19:40 +00:00
|
|
|
mWelcomeScreen = findViewById(R.id.setup_welcome_screen);
|
|
|
|
final TextView welcomeTitle = (TextView)findViewById(R.id.setup_welcome_title);
|
|
|
|
welcomeTitle.setText(getString(R.string.setup_welcome_title, applicationName));
|
|
|
|
|
|
|
|
mSetupScreen = findViewById(R.id.setup_steps_screen);
|
|
|
|
final TextView stepsTitle = (TextView)findViewById(R.id.setup_title);
|
2013-04-18 08:19:40 +00:00
|
|
|
stepsTitle.setText(getString(R.string.setup_steps_title, applicationName));
|
2013-02-14 07:46:39 +00:00
|
|
|
|
2013-04-24 02:38:44 +00:00
|
|
|
final SetupStepIndicatorView indicatorView =
|
|
|
|
(SetupStepIndicatorView)findViewById(R.id.setup_step_indicator);
|
|
|
|
mSetupStepGroup = new SetupStepGroup(indicatorView);
|
2013-02-14 07:46:39 +00:00
|
|
|
|
2013-04-24 03:29:03 +00:00
|
|
|
mStep1Bullet = (TextView)findViewById(R.id.setup_step1_bullet);
|
|
|
|
mStep1Bullet.setOnClickListener(this);
|
2013-04-24 02:38:44 +00:00
|
|
|
final SetupStep step1 = new SetupStep(STEP_1, applicationName,
|
2013-04-24 03:29:03 +00:00
|
|
|
mStep1Bullet, findViewById(R.id.setup_step1),
|
2013-04-17 09:53:43 +00:00
|
|
|
R.string.setup_step1_title, R.string.setup_step1_instruction,
|
2013-04-24 03:29:03 +00:00
|
|
|
R.string.setup_step1_finished_instruction, R.drawable.ic_setup_step1,
|
|
|
|
R.string.setup_step1_action);
|
2013-02-14 07:46:39 +00:00
|
|
|
step1.setAction(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
invokeLanguageAndInputSettings();
|
|
|
|
mHandler.startPollingImeSettings();
|
|
|
|
}
|
|
|
|
});
|
2013-04-24 02:38:44 +00:00
|
|
|
mSetupStepGroup.addStep(step1);
|
2013-02-14 07:46:39 +00:00
|
|
|
|
2013-04-24 02:38:44 +00:00
|
|
|
final SetupStep step2 = new SetupStep(STEP_2, applicationName,
|
2013-04-17 09:53:43 +00:00
|
|
|
(TextView)findViewById(R.id.setup_step2_bullet), findViewById(R.id.setup_step2),
|
|
|
|
R.string.setup_step2_title, R.string.setup_step2_instruction,
|
2013-04-24 03:29:03 +00:00
|
|
|
0 /* finishedInstruction */, R.drawable.ic_setup_step2,
|
|
|
|
R.string.setup_step2_action);
|
2013-02-14 07:46:39 +00:00
|
|
|
step2.setAction(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// Invoke input method picker.
|
|
|
|
RichInputMethodManager.getInstance().getInputMethodManager()
|
|
|
|
.showInputMethodPicker();
|
|
|
|
}
|
|
|
|
});
|
2013-04-24 02:38:44 +00:00
|
|
|
mSetupStepGroup.addStep(step2);
|
2013-02-14 07:46:39 +00:00
|
|
|
|
2013-04-24 02:38:44 +00:00
|
|
|
final SetupStep step3 = new SetupStep(STEP_3, applicationName,
|
2013-04-17 09:53:43 +00:00
|
|
|
(TextView)findViewById(R.id.setup_step3_bullet), findViewById(R.id.setup_step3),
|
|
|
|
R.string.setup_step3_title, R.string.setup_step3_instruction,
|
2013-04-24 03:29:03 +00:00
|
|
|
0 /* finishedInstruction */, R.drawable.ic_setup_step3,
|
|
|
|
R.string.setup_step3_action);
|
2013-02-14 07:46:39 +00:00
|
|
|
step3.setAction(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
invokeSubtypeEnablerOfThisIme();
|
|
|
|
}
|
|
|
|
});
|
2013-04-24 02:38:44 +00:00
|
|
|
mSetupStepGroup.addStep(step3);
|
2013-04-18 06:11:33 +00:00
|
|
|
|
2013-04-18 08:19:40 +00:00
|
|
|
mWelcomeVideoUri = new Uri.Builder()
|
|
|
|
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
|
|
|
.authority(getPackageName())
|
|
|
|
.path(Integer.toString(R.raw.setup_welcome_video))
|
|
|
|
.build();
|
|
|
|
mWelcomeVideoView = (VideoView)findViewById(R.id.setup_welcome_video);
|
2013-04-26 05:55:08 +00:00
|
|
|
mWelcomeVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
|
|
|
@Override
|
|
|
|
public void onPrepared(final MediaPlayer mp) {
|
|
|
|
// Now VideoView has been laid-out and ready to play, remove background of it to
|
|
|
|
// reveal the video.
|
|
|
|
mWelcomeVideoView.setBackgroundResource(0);
|
2013-05-08 03:09:04 +00:00
|
|
|
mp.setLooping(true);
|
2013-04-26 05:55:08 +00:00
|
|
|
}
|
|
|
|
});
|
2013-05-01 03:20:58 +00:00
|
|
|
final ImageView welcomeImageView = (ImageView)findViewById(R.id.setup_welcome_image);
|
2013-04-30 09:09:52 +00:00
|
|
|
mWelcomeVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onError(final MediaPlayer mp, final int what, final int extra) {
|
|
|
|
Log.e(TAG, "Playing welcome video causes error: what=" + what + " extra=" + extra);
|
|
|
|
mWelcomeVideoView.setVisibility(View.GONE);
|
2013-05-01 03:20:58 +00:00
|
|
|
welcomeImageView.setImageResource(R.raw.setup_welcome_image);
|
|
|
|
welcomeImageView.setVisibility(View.VISIBLE);
|
2013-04-30 09:09:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2013-04-18 08:19:40 +00:00
|
|
|
|
|
|
|
mActionStart = findViewById(R.id.setup_start_label);
|
|
|
|
mActionStart.setOnClickListener(this);
|
2013-04-24 03:29:03 +00:00
|
|
|
mActionNext = findViewById(R.id.setup_next);
|
|
|
|
mActionNext.setOnClickListener(this);
|
2013-04-18 06:11:33 +00:00
|
|
|
mActionFinish = (TextView)findViewById(R.id.setup_finish);
|
|
|
|
TextViewCompatUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(mActionFinish,
|
|
|
|
getResources().getDrawable(R.drawable.ic_setup_finish), null, null, null);
|
|
|
|
mActionFinish.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
|
|
|
if (v == mActionFinish) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2013-05-02 09:16:12 +00:00
|
|
|
final int currentStep = determineSetupStepNumber();
|
2013-04-24 03:29:03 +00:00
|
|
|
final int nextStep;
|
|
|
|
if (v == mActionStart) {
|
|
|
|
nextStep = STEP_1;
|
|
|
|
} else if (v == mActionNext) {
|
|
|
|
nextStep = mStepNumber + 1;
|
2013-05-02 09:16:12 +00:00
|
|
|
} else if (v == mStep1Bullet && currentStep == STEP_2) {
|
2013-04-24 03:29:03 +00:00
|
|
|
nextStep = STEP_1;
|
|
|
|
} else {
|
|
|
|
nextStep = mStepNumber;
|
|
|
|
}
|
|
|
|
if (mStepNumber != nextStep) {
|
|
|
|
mStepNumber = nextStep;
|
|
|
|
updateSetupStepView();
|
|
|
|
}
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void invokeSetupWizardOfThisIme() {
|
|
|
|
final Intent intent = new Intent();
|
|
|
|
intent.setClass(this, SetupActivity.class);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void invokeSettingsOfThisIme() {
|
2013-02-14 06:01:53 +00:00
|
|
|
final Intent intent = new Intent();
|
|
|
|
intent.setClass(this, SettingsActivity.class);
|
2013-02-14 07:46:39 +00:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
2013-04-26 04:03:37 +00:00
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
2013-02-14 06:01:53 +00:00
|
|
|
startActivity(intent);
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void invokeLanguageAndInputSettings() {
|
|
|
|
final Intent intent = new Intent();
|
|
|
|
intent.setAction(Settings.ACTION_INPUT_METHOD_SETTINGS);
|
|
|
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void invokeSubtypeEnablerOfThisIme() {
|
|
|
|
final InputMethodInfo imi =
|
|
|
|
RichInputMethodManager.getInstance().getInputMethodInfoOfThisIme();
|
|
|
|
final Intent intent = new Intent();
|
|
|
|
intent.setAction(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
|
|
|
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
|
|
intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, imi.getId());
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2013-02-26 08:56:54 +00:00
|
|
|
/**
|
|
|
|
* Check if the IME specified by the context is enabled.
|
|
|
|
* Note that {@link RichInputMethodManager} must have been initialized before calling this
|
|
|
|
* method.
|
|
|
|
*
|
|
|
|
* @param context package context of the IME to be checked.
|
|
|
|
* @return true if this IME is enabled.
|
|
|
|
*/
|
|
|
|
public static boolean isThisImeEnabled(final Context context) {
|
|
|
|
final String packageName = context.getPackageName();
|
2013-02-14 07:46:39 +00:00
|
|
|
final InputMethodManager imm = RichInputMethodManager.getInstance().getInputMethodManager();
|
|
|
|
for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
|
|
|
|
if (packageName.equals(imi.getPackageName())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-26 08:56:54 +00:00
|
|
|
/**
|
|
|
|
* Check if the IME specified by the context is the current IME.
|
|
|
|
* Note that {@link RichInputMethodManager} must have been initialized before calling this
|
|
|
|
* method.
|
|
|
|
*
|
|
|
|
* @param context package context of the IME to be checked.
|
|
|
|
* @return true if this IME is the current IME.
|
|
|
|
*/
|
|
|
|
public static boolean isThisImeCurrent(final Context context) {
|
2013-02-14 07:46:39 +00:00
|
|
|
final InputMethodInfo myImi =
|
|
|
|
RichInputMethodManager.getInstance().getInputMethodInfoOfThisIme();
|
|
|
|
final String currentImeId = Settings.Secure.getString(
|
2013-02-26 08:56:54 +00:00
|
|
|
context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
2013-02-14 07:46:39 +00:00
|
|
|
return myImi.getId().equals(currentImeId);
|
|
|
|
}
|
|
|
|
|
2013-05-09 04:14:18 +00:00
|
|
|
private int determineSetupStepNumberFromLauncher() {
|
|
|
|
final int stepNumber = determineSetupStepNumber();
|
|
|
|
if (stepNumber == STEP_1) {
|
|
|
|
return STEP_WELCOME;
|
|
|
|
}
|
|
|
|
if (stepNumber == STEP_3) {
|
|
|
|
return STEP_LAUNCHING_IME_SETTINGS;
|
|
|
|
}
|
|
|
|
return stepNumber;
|
|
|
|
}
|
|
|
|
|
2013-05-02 09:16:12 +00:00
|
|
|
private int determineSetupStepNumber() {
|
2013-02-14 07:46:39 +00:00
|
|
|
mHandler.cancelPollingImeSettings();
|
2013-02-26 08:56:54 +00:00
|
|
|
if (!isThisImeEnabled(this)) {
|
2013-04-24 02:38:44 +00:00
|
|
|
return STEP_1;
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
2013-02-26 08:56:54 +00:00
|
|
|
if (!isThisImeCurrent(this)) {
|
2013-02-14 07:46:39 +00:00
|
|
|
return STEP_2;
|
|
|
|
}
|
|
|
|
return STEP_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(final Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
2013-02-26 08:56:54 +00:00
|
|
|
outState.putInt(STATE_STEP, mStepNumber);
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onRestoreInstanceState(final Bundle savedInstanceState) {
|
|
|
|
super.onRestoreInstanceState(savedInstanceState);
|
2013-02-26 08:56:54 +00:00
|
|
|
mStepNumber = savedInstanceState.getInt(STATE_STEP);
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 04:14:18 +00:00
|
|
|
private static boolean isInSetupSteps(final int stepNumber) {
|
|
|
|
return stepNumber >= STEP_1 && stepNumber <= STEP_3;
|
|
|
|
}
|
|
|
|
|
2013-02-14 07:46:39 +00:00
|
|
|
@Override
|
|
|
|
protected void onRestart() {
|
|
|
|
super.onRestart();
|
2013-05-09 04:14:18 +00:00
|
|
|
if (isInSetupSteps(mStepNumber)) {
|
2013-05-02 09:16:12 +00:00
|
|
|
mStepNumber = determineSetupStepNumber();
|
|
|
|
}
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2013-05-09 04:14:18 +00:00
|
|
|
if (mStepNumber == STEP_LAUNCHING_IME_SETTINGS) {
|
|
|
|
invokeSettingsOfThisIme();
|
|
|
|
mStepNumber = STEP_BACK_FROM_IME_SETTINGS;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mStepNumber == STEP_BACK_FROM_IME_SETTINGS) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2013-02-14 07:46:39 +00:00
|
|
|
updateSetupStepView();
|
|
|
|
}
|
|
|
|
|
2013-04-18 08:19:40 +00:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (mStepNumber == STEP_1) {
|
2013-05-02 09:16:12 +00:00
|
|
|
mStepNumber = STEP_WELCOME;
|
2013-04-18 08:19:40 +00:00
|
|
|
updateSetupStepView();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
2013-05-08 03:09:04 +00:00
|
|
|
private static void hideAndStopVideo(final VideoView videoView) {
|
|
|
|
videoView.stopPlayback();
|
|
|
|
videoView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
|
2013-04-18 08:19:40 +00:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
2013-05-08 03:09:04 +00:00
|
|
|
hideAndStopVideo(mWelcomeVideoView);
|
2013-04-18 08:19:40 +00:00
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
2013-02-14 07:46:39 +00:00
|
|
|
@Override
|
|
|
|
public void onWindowFocusChanged(final boolean hasFocus) {
|
|
|
|
super.onWindowFocusChanged(hasFocus);
|
2013-05-09 04:14:18 +00:00
|
|
|
if (hasFocus && isInSetupSteps(mStepNumber)) {
|
2013-05-02 09:16:12 +00:00
|
|
|
mStepNumber = determineSetupStepNumber();
|
|
|
|
updateSetupStepView();
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSetupStepView() {
|
2013-05-02 09:16:12 +00:00
|
|
|
final boolean welcomeScreen = (mStepNumber == STEP_WELCOME);
|
2013-04-18 08:19:40 +00:00
|
|
|
mWelcomeScreen.setVisibility(welcomeScreen ? View.VISIBLE : View.GONE);
|
2013-05-09 04:14:18 +00:00
|
|
|
mSetupScreen.setVisibility(welcomeScreen ? View.GONE : View.VISIBLE);
|
2013-04-18 08:19:40 +00:00
|
|
|
if (welcomeScreen) {
|
2013-05-08 03:09:04 +00:00
|
|
|
mWelcomeVideoView.setVisibility(View.VISIBLE);
|
2013-04-18 08:19:40 +00:00
|
|
|
mWelcomeVideoView.setVideoURI(mWelcomeVideoUri);
|
|
|
|
mWelcomeVideoView.start();
|
|
|
|
return;
|
|
|
|
}
|
2013-05-08 03:09:04 +00:00
|
|
|
hideAndStopVideo(mWelcomeVideoView);
|
2013-05-02 09:16:12 +00:00
|
|
|
final boolean isStepActionAlreadyDone = mStepNumber < determineSetupStepNumber();
|
2013-04-24 03:29:03 +00:00
|
|
|
mSetupStepGroup.enableStep(mStepNumber, isStepActionAlreadyDone);
|
|
|
|
mActionNext.setVisibility(isStepActionAlreadyDone ? View.VISIBLE : View.GONE);
|
2013-04-18 06:11:33 +00:00
|
|
|
mActionFinish.setVisibility((mStepNumber == STEP_3) ? View.VISIBLE : View.GONE);
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static final class SetupStep implements View.OnClickListener {
|
2013-04-24 02:38:44 +00:00
|
|
|
public final int mStepNo;
|
2013-04-17 09:53:43 +00:00
|
|
|
private final View mStepView;
|
|
|
|
private final TextView mBulletView;
|
|
|
|
private final int mActivatedColor;
|
|
|
|
private final int mDeactivatedColor;
|
2013-04-24 03:29:03 +00:00
|
|
|
private final String mInstruction;
|
|
|
|
private final String mFinishedInstruction;
|
2013-02-14 07:46:39 +00:00
|
|
|
private final TextView mActionLabel;
|
|
|
|
private Runnable mAction;
|
|
|
|
|
2013-04-24 02:38:44 +00:00
|
|
|
public SetupStep(final int stepNo, final String applicationName, final TextView bulletView,
|
2013-04-24 03:29:03 +00:00
|
|
|
final View stepView, final int title, final int instruction,
|
2013-05-09 04:14:18 +00:00
|
|
|
final int finishedInstruction, final int actionIcon, final int actionLabel) {
|
2013-04-24 02:38:44 +00:00
|
|
|
mStepNo = stepNo;
|
2013-04-17 09:53:43 +00:00
|
|
|
mStepView = stepView;
|
|
|
|
mBulletView = bulletView;
|
|
|
|
final Resources res = stepView.getResources();
|
|
|
|
mActivatedColor = res.getColor(R.color.setup_text_action);
|
|
|
|
mDeactivatedColor = res.getColor(R.color.setup_text_dark);
|
2013-02-14 07:46:39 +00:00
|
|
|
|
2013-04-17 09:53:43 +00:00
|
|
|
final TextView titleView = (TextView)mStepView.findViewById(R.id.setup_step_title);
|
2013-02-14 07:46:39 +00:00
|
|
|
titleView.setText(res.getString(title, applicationName));
|
2013-04-24 03:29:03 +00:00
|
|
|
mInstruction = (instruction == 0) ? null
|
|
|
|
: res.getString(instruction, applicationName);
|
|
|
|
mFinishedInstruction = (finishedInstruction == 0) ? null
|
|
|
|
: res.getString(finishedInstruction, applicationName);
|
2013-02-14 07:46:39 +00:00
|
|
|
|
2013-04-17 09:53:43 +00:00
|
|
|
mActionLabel = (TextView)mStepView.findViewById(R.id.setup_step_action_label);
|
2013-02-14 07:46:39 +00:00
|
|
|
mActionLabel.setText(res.getString(actionLabel));
|
|
|
|
if (actionIcon == 0) {
|
|
|
|
final int paddingEnd = ViewCompatUtils.getPaddingEnd(mActionLabel);
|
|
|
|
ViewCompatUtils.setPaddingRelative(mActionLabel, paddingEnd, 0, paddingEnd, 0);
|
|
|
|
} else {
|
2013-04-18 03:13:08 +00:00
|
|
|
TextViewCompatUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(
|
|
|
|
mActionLabel, res.getDrawable(actionIcon), null, null, null);
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-24 03:29:03 +00:00
|
|
|
public void setEnabled(final boolean enabled, final boolean isStepActionAlreadyDone) {
|
2013-04-17 09:53:43 +00:00
|
|
|
mStepView.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
|
|
|
mBulletView.setTextColor(enabled ? mActivatedColor : mDeactivatedColor);
|
2013-04-24 03:29:03 +00:00
|
|
|
final TextView instructionView = (TextView)mStepView.findViewById(
|
|
|
|
R.id.setup_step_instruction);
|
|
|
|
instructionView.setText(isStepActionAlreadyDone ? mFinishedInstruction : mInstruction);
|
|
|
|
mActionLabel.setVisibility(isStepActionAlreadyDone ? View.GONE : View.VISIBLE);
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setAction(final Runnable action) {
|
|
|
|
mActionLabel.setOnClickListener(this);
|
|
|
|
mAction = action;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
2013-04-18 06:11:33 +00:00
|
|
|
if (v == mActionLabel && mAction != null) {
|
2013-02-14 07:46:39 +00:00
|
|
|
mAction.run();
|
2013-04-18 06:11:33 +00:00
|
|
|
return;
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static final class SetupStepGroup {
|
2013-04-24 02:38:44 +00:00
|
|
|
private final SetupStepIndicatorView mIndicatorView;
|
|
|
|
private final ArrayList<SetupStep> mGroup = CollectionUtils.newArrayList();
|
2013-02-14 07:46:39 +00:00
|
|
|
|
2013-04-24 02:38:44 +00:00
|
|
|
public SetupStepGroup(final SetupStepIndicatorView indicatorView) {
|
|
|
|
mIndicatorView = indicatorView;
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
2013-04-24 02:38:44 +00:00
|
|
|
public void addStep(final SetupStep step) {
|
|
|
|
mGroup.add(step);
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
|
|
|
|
2013-04-24 03:29:03 +00:00
|
|
|
public void enableStep(final int enableStepNo, final boolean isStepActionAlreadyDone) {
|
2013-04-24 02:38:44 +00:00
|
|
|
for (final SetupStep step : mGroup) {
|
2013-04-24 03:29:03 +00:00
|
|
|
step.setEnabled(step.mStepNo == enableStepNo, isStepActionAlreadyDone);
|
2013-04-24 02:38:44 +00:00
|
|
|
}
|
|
|
|
mIndicatorView.setIndicatorPosition(enableStepNo - STEP_1, mGroup.size());
|
2013-02-14 07:46:39 +00:00
|
|
|
}
|
2013-02-14 06:01:53 +00:00
|
|
|
}
|
|
|
|
}
|