Refactor SetupStepGroup
Bug: 8159728 Change-Id: I1ab846d0910aacbd2f979289d72bafea8a8e0378main
parent
81b4661f96
commit
e918bf07a0
|
@ -40,18 +40,17 @@ import com.android.inputmethod.latin.RichInputMethodManager;
|
||||||
import com.android.inputmethod.latin.SettingsActivity;
|
import com.android.inputmethod.latin.SettingsActivity;
|
||||||
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
// TODO: Use Fragment to implement welcome screen and setup steps.
|
// TODO: Use Fragment to implement welcome screen and setup steps.
|
||||||
public final class SetupActivity extends Activity implements View.OnClickListener {
|
public final class SetupActivity extends Activity implements View.OnClickListener {
|
||||||
private View mWelcomeScreen;
|
private View mWelcomeScreen;
|
||||||
private View mSetupScreen;
|
private View mSetupScreen;
|
||||||
private SetupStepIndicatorView mStepIndicatorView;
|
|
||||||
private Uri mWelcomeVideoUri;
|
private Uri mWelcomeVideoUri;
|
||||||
private VideoView mWelcomeVideoView;
|
private VideoView mWelcomeVideoView;
|
||||||
private View mActionStart;
|
private View mActionStart;
|
||||||
private TextView mActionFinish;
|
private TextView mActionFinish;
|
||||||
private final SetupStepGroup mSetupStepGroup = new SetupStepGroup();
|
private SetupStepGroup mSetupStepGroup;
|
||||||
private static final String STATE_STEP = "step";
|
private static final String STATE_STEP = "step";
|
||||||
private int mStepNumber;
|
private int mStepNumber;
|
||||||
private static final int STEP_0 = 0;
|
private static final int STEP_0 = 0;
|
||||||
|
@ -129,9 +128,11 @@ public final class SetupActivity extends Activity implements View.OnClickListene
|
||||||
final TextView stepsTitle = (TextView)findViewById(R.id.setup_title);
|
final TextView stepsTitle = (TextView)findViewById(R.id.setup_title);
|
||||||
stepsTitle.setText(getString(R.string.setup_steps_title, applicationName));
|
stepsTitle.setText(getString(R.string.setup_steps_title, applicationName));
|
||||||
|
|
||||||
mStepIndicatorView = (SetupStepIndicatorView)findViewById(R.id.setup_step_indicator);
|
final SetupStepIndicatorView indicatorView =
|
||||||
|
(SetupStepIndicatorView)findViewById(R.id.setup_step_indicator);
|
||||||
|
mSetupStepGroup = new SetupStepGroup(indicatorView);
|
||||||
|
|
||||||
final SetupStep step1 = new SetupStep(applicationName,
|
final SetupStep step1 = new SetupStep(STEP_1, applicationName,
|
||||||
(TextView)findViewById(R.id.setup_step1_bullet), findViewById(R.id.setup_step1),
|
(TextView)findViewById(R.id.setup_step1_bullet), findViewById(R.id.setup_step1),
|
||||||
R.string.setup_step1_title, R.string.setup_step1_instruction,
|
R.string.setup_step1_title, R.string.setup_step1_instruction,
|
||||||
R.drawable.ic_setup_step1, R.string.setup_step1_action);
|
R.drawable.ic_setup_step1, R.string.setup_step1_action);
|
||||||
|
@ -142,9 +143,9 @@ public final class SetupActivity extends Activity implements View.OnClickListene
|
||||||
mHandler.startPollingImeSettings();
|
mHandler.startPollingImeSettings();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mSetupStepGroup.addStep(STEP_1, step1);
|
mSetupStepGroup.addStep(step1);
|
||||||
|
|
||||||
final SetupStep step2 = new SetupStep(applicationName,
|
final SetupStep step2 = new SetupStep(STEP_2, applicationName,
|
||||||
(TextView)findViewById(R.id.setup_step2_bullet), findViewById(R.id.setup_step2),
|
(TextView)findViewById(R.id.setup_step2_bullet), findViewById(R.id.setup_step2),
|
||||||
R.string.setup_step2_title, R.string.setup_step2_instruction,
|
R.string.setup_step2_title, R.string.setup_step2_instruction,
|
||||||
R.drawable.ic_setup_step2, R.string.setup_step2_action);
|
R.drawable.ic_setup_step2, R.string.setup_step2_action);
|
||||||
|
@ -156,9 +157,9 @@ public final class SetupActivity extends Activity implements View.OnClickListene
|
||||||
.showInputMethodPicker();
|
.showInputMethodPicker();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mSetupStepGroup.addStep(STEP_2, step2);
|
mSetupStepGroup.addStep(step2);
|
||||||
|
|
||||||
final SetupStep step3 = new SetupStep(applicationName,
|
final SetupStep step3 = new SetupStep(STEP_3, applicationName,
|
||||||
(TextView)findViewById(R.id.setup_step3_bullet), findViewById(R.id.setup_step3),
|
(TextView)findViewById(R.id.setup_step3_bullet), findViewById(R.id.setup_step3),
|
||||||
R.string.setup_step3_title, R.string.setup_step3_instruction,
|
R.string.setup_step3_title, R.string.setup_step3_instruction,
|
||||||
R.drawable.ic_setup_step3, R.string.setup_step3_action);
|
R.drawable.ic_setup_step3, R.string.setup_step3_action);
|
||||||
|
@ -168,7 +169,7 @@ public final class SetupActivity extends Activity implements View.OnClickListene
|
||||||
invokeSubtypeEnablerOfThisIme();
|
invokeSubtypeEnablerOfThisIme();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mSetupStepGroup.addStep(STEP_3, step3);
|
mSetupStepGroup.addStep(step3);
|
||||||
|
|
||||||
mWelcomeVideoUri = new Uri.Builder()
|
mWelcomeVideoUri = new Uri.Builder()
|
||||||
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
||||||
|
@ -274,10 +275,10 @@ public final class SetupActivity extends Activity implements View.OnClickListene
|
||||||
return myImi.getId().equals(currentImeId);
|
return myImi.getId().equals(currentImeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int determineSetupStepNumber() {
|
private int determineSetupState() {
|
||||||
mHandler.cancelPollingImeSettings();
|
mHandler.cancelPollingImeSettings();
|
||||||
if (!isThisImeEnabled(this)) {
|
if (!isThisImeEnabled(this)) {
|
||||||
return mWasLanguageAndInputSettingsInvoked ? STEP_1 : STEP_0;
|
return STEP_1;
|
||||||
}
|
}
|
||||||
if (!isThisImeCurrent(this)) {
|
if (!isThisImeCurrent(this)) {
|
||||||
return STEP_2;
|
return STEP_2;
|
||||||
|
@ -285,6 +286,14 @@ public final class SetupActivity extends Activity implements View.OnClickListene
|
||||||
return STEP_3;
|
return STEP_3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int determineSetupStepNumber() {
|
||||||
|
final int stepState = determineSetupState();
|
||||||
|
if (stepState == STEP_1) {
|
||||||
|
return mWasLanguageAndInputSettingsInvoked ? STEP_1 : STEP_0;
|
||||||
|
}
|
||||||
|
return stepState;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(final Bundle outState) {
|
protected void onSaveInstanceState(final Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
@ -351,20 +360,12 @@ public final class SetupActivity extends Activity implements View.OnClickListene
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mWelcomeVideoView.stopPlayback();
|
mWelcomeVideoView.stopPlayback();
|
||||||
final int layoutDirection = ViewCompatUtils.getLayoutDirection(mStepIndicatorView);
|
|
||||||
mStepIndicatorView.setIndicatorPosition(
|
|
||||||
getIndicatorPosition(mStepNumber, mSetupStepGroup.getTotalStep(), layoutDirection));
|
|
||||||
mSetupStepGroup.enableStep(mStepNumber);
|
mSetupStepGroup.enableStep(mStepNumber);
|
||||||
mActionFinish.setVisibility((mStepNumber == STEP_3) ? View.VISIBLE : View.GONE);
|
mActionFinish.setVisibility((mStepNumber == STEP_3) ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float getIndicatorPosition(final int step, final int totalStep,
|
|
||||||
final int layoutDirection) {
|
|
||||||
final float pos = ((step - STEP_1) * 2 + 1) / (float)(totalStep * 2);
|
|
||||||
return (layoutDirection == ViewCompatUtils.LAYOUT_DIRECTION_RTL) ? 1.0f - pos : pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final class SetupStep implements View.OnClickListener {
|
static final class SetupStep implements View.OnClickListener {
|
||||||
|
public final int mStepNo;
|
||||||
private final View mStepView;
|
private final View mStepView;
|
||||||
private final TextView mBulletView;
|
private final TextView mBulletView;
|
||||||
private final int mActivatedColor;
|
private final int mActivatedColor;
|
||||||
|
@ -372,9 +373,10 @@ public final class SetupActivity extends Activity implements View.OnClickListene
|
||||||
private final TextView mActionLabel;
|
private final TextView mActionLabel;
|
||||||
private Runnable mAction;
|
private Runnable mAction;
|
||||||
|
|
||||||
public SetupStep(final String applicationName, final TextView bulletView,
|
public SetupStep(final int stepNo, final String applicationName, final TextView bulletView,
|
||||||
final View stepView, final int title, final int instruction, final int actionIcon,
|
final View stepView, final int title, final int instruction, final int actionIcon,
|
||||||
final int actionLabel) {
|
final int actionLabel) {
|
||||||
|
mStepNo = stepNo;
|
||||||
mStepView = stepView;
|
mStepView = stepView;
|
||||||
mBulletView = bulletView;
|
mBulletView = bulletView;
|
||||||
final Resources res = stepView.getResources();
|
final Resources res = stepView.getResources();
|
||||||
|
@ -423,21 +425,22 @@ public final class SetupActivity extends Activity implements View.OnClickListene
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class SetupStepGroup {
|
static final class SetupStepGroup {
|
||||||
private final HashMap<Integer, SetupStep> mGroup = CollectionUtils.newHashMap();
|
private final SetupStepIndicatorView mIndicatorView;
|
||||||
|
private final ArrayList<SetupStep> mGroup = CollectionUtils.newArrayList();
|
||||||
|
|
||||||
public void addStep(final int stepNo, final SetupStep step) {
|
public SetupStepGroup(final SetupStepIndicatorView indicatorView) {
|
||||||
mGroup.put(stepNo, step);
|
mIndicatorView = indicatorView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addStep(final SetupStep step) {
|
||||||
|
mGroup.add(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableStep(final int enableStepNo) {
|
public void enableStep(final int enableStepNo) {
|
||||||
for (final Integer stepNo : mGroup.keySet()) {
|
for (final SetupStep step : mGroup) {
|
||||||
final SetupStep step = mGroup.get(stepNo);
|
step.setEnabled(step.mStepNo == enableStepNo);
|
||||||
step.setEnabled(stepNo == enableStepNo);
|
|
||||||
}
|
}
|
||||||
}
|
mIndicatorView.setIndicatorPosition(enableStepNo - STEP_1, mGroup.size());
|
||||||
|
|
||||||
public int getTotalStep() {
|
|
||||||
return mGroup.size();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.graphics.Path;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.android.inputmethod.compat.ViewCompatUtils;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
|
||||||
public final class SetupStepIndicatorView extends View {
|
public final class SetupStepIndicatorView extends View {
|
||||||
|
@ -36,8 +37,13 @@ public final class SetupStepIndicatorView extends View {
|
||||||
mIndicatorPaint.setStyle(Paint.Style.FILL);
|
mIndicatorPaint.setStyle(Paint.Style.FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndicatorPosition(final float xRatio) {
|
public void setIndicatorPosition(final int stepPos, final int totalStepNum) {
|
||||||
mXRatio = xRatio;
|
final int layoutDirection = ViewCompatUtils.getLayoutDirection(this);
|
||||||
|
// The indicator position is the center of the partition that is equally divided into
|
||||||
|
// the total step number.
|
||||||
|
final float partionWidth = 1.0f / totalStepNum;
|
||||||
|
final float pos = stepPos * partionWidth + partionWidth / 2.0f;
|
||||||
|
mXRatio = (layoutDirection == ViewCompatUtils.LAYOUT_DIRECTION_RTL) ? 1.0f - pos : pos;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue