wizard
This commit is contained in:
parent
c906e572f7
commit
2fb20dc2b5
@ -13,7 +13,7 @@
|
|||||||
<style name="cpp_default_dialog_style">
|
<style name="cpp_default_dialog_style">
|
||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
<item name="android:minWidth">200dp</item>
|
<item name="android:minWidth">200dp</item>
|
||||||
<item name="android:layout_width">wrap_content</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="android:layout_height">wrap_content</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
<item name="android:orientation">vertical</item>
|
<item name="android:orientation">vertical</item>
|
||||||
<item name="android:layout_gravity">center_horizontal</item>
|
<item name="android:layout_gravity">center_horizontal</item>
|
||||||
|
@ -51,7 +51,7 @@ public final class CalculatorPreferences {
|
|||||||
public static class Gui {
|
public static class Gui {
|
||||||
|
|
||||||
public static final Preference<Theme> theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.metro_blue_theme, Theme.class);
|
public static final Preference<Theme> theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.metro_blue_theme, Theme.class);
|
||||||
public static final Preference<Layout> layout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.main_calculator, Layout.class);
|
public static final Preference<Layout> layout = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.simple, Layout.class);
|
||||||
public static final Preference<Boolean> feedbackWindowShown = BooleanPreference.of("feedback_window_shown", false);
|
public static final Preference<Boolean> feedbackWindowShown = BooleanPreference.of("feedback_window_shown", false);
|
||||||
public static final Preference<Boolean> notesppAnnounceShown = BooleanPreference.of("notespp_announce_shown", false);
|
public static final Preference<Boolean> notesppAnnounceShown = BooleanPreference.of("notespp_announce_shown", false);
|
||||||
public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
|
public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
|
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
|
||||||
<activity android:name=".CalculatorWikiActivity"/>
|
<activity android:name=".CalculatorWikiActivity"/>
|
||||||
<activity android:name=".wizard.CalculatorWizardActivity" android:theme="@style/cpp_metro_blue_dialog_theme">
|
<activity android:name=".wizard.CalculatorWizardActivity" android:theme="@style/cpp_metro_blue_dialog_theme" android:launchMode="singleTop">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
@ -5,14 +5,13 @@
|
|||||||
style="?cpp_dialog_style"
|
style="?cpp_dialog_style"
|
||||||
a:orientation="vertical">
|
a:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:id="@+id/wizard_content"
|
a:id="@+id/wizard_content"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp"
|
a:layout_height="0dp"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:gravity="center"
|
a:gravity="center"/>
|
||||||
a:minHeight="150dp"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
a:orientation="horizontal"
|
a:orientation="horizontal"
|
||||||
|
@ -41,6 +41,9 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
import static android.os.Build.VERSION_CODES.GINGERBREAD_MR1;
|
import static android.os.Build.VERSION_CODES.GINGERBREAD_MR1;
|
||||||
import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
|
import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
|
||||||
|
import static org.solovyev.android.calculator.wizard.Wizard.FIRST_TIME_WIZARD;
|
||||||
|
import static org.solovyev.android.calculator.wizard.Wizard.isWizardFinished;
|
||||||
|
import static org.solovyev.android.calculator.wizard.Wizard.isWizardStarted;
|
||||||
|
|
||||||
public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener {
|
public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener {
|
||||||
|
|
||||||
@ -130,27 +133,31 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
|
|||||||
if (!CalculatorApplication.isMonkeyRunner(context)) {
|
if (!CalculatorApplication.isMonkeyRunner(context)) {
|
||||||
|
|
||||||
boolean dialogShown = false;
|
boolean dialogShown = false;
|
||||||
if (Objects.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
|
if(isWizardStarted(FIRST_TIME_WIZARD) && !isWizardFinished(FIRST_TIME_WIZARD)) {
|
||||||
// new start
|
CalculatorWizardActivity.continueWizard(FIRST_TIME_WIZARD, context);
|
||||||
context.startActivity(new Intent(context, CalculatorWizardActivity.class));
|
|
||||||
dialogShown = true;
|
dialogShown = true;
|
||||||
} else {
|
} else {
|
||||||
if (savedVersion < appVersion) {
|
if (Objects.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
|
||||||
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
// new start
|
||||||
if (showReleaseNotes) {
|
context.startActivity(new Intent(context, CalculatorWizardActivity.class));
|
||||||
final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1);
|
dialogShown = true;
|
||||||
if (!Strings.isEmpty(releaseNotes)) {
|
} else {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
if (savedVersion < appVersion) {
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
||||||
builder.setTitle(R.string.c_release_notes);
|
if (showReleaseNotes) {
|
||||||
builder.create().show();
|
final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1);
|
||||||
dialogShown = true;
|
if (!Strings.isEmpty(releaseNotes)) {
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
||||||
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
|
builder.setTitle(R.string.c_release_notes);
|
||||||
|
builder.create().show();
|
||||||
|
dialogShown = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
|
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
|
||||||
if (!dialogShown) {
|
if (!dialogShown) {
|
||||||
if (appOpenedCounter != null && appOpenedCounter > 100) {
|
if (appOpenedCounter != null && appOpenedCounter > 100) {
|
||||||
|
@ -268,16 +268,22 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public static void startWizard(@Nonnull String name, @Nonnull Context context) {
|
public static void startWizard(@Nonnull String name, @Nonnull Context context) {
|
||||||
|
final Intent intent = createLaunchIntent(name, context);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private static Intent createLaunchIntent(@Nonnull String name, @Nonnull Context context) {
|
||||||
final Intent intent = new Intent(context, CalculatorWizardActivity.class);
|
final Intent intent = new Intent(context, CalculatorWizardActivity.class);
|
||||||
intent.putExtra(FLOW, name);
|
intent.putExtra(FLOW, name);
|
||||||
context.startActivity(intent);
|
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void continueWizard(@Nonnull String name, @Nonnull Context context) {
|
public static void continueWizard(@Nonnull String name, @Nonnull Context context) {
|
||||||
final String step = Wizard.getLastSavedWizardStepName(name);
|
final String step = Wizard.getLastSavedWizardStepName(name);
|
||||||
|
|
||||||
final Intent intent = new Intent(context, CalculatorWizardActivity.class);
|
final Intent intent = createLaunchIntent(name, context);
|
||||||
intent.putExtra(FLOW, name);
|
|
||||||
if (step != null) {
|
if (step != null) {
|
||||||
intent.putExtra(STEP, step);
|
intent.putExtra(STEP, step);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package org.solovyev.android.calculator.wizard;
|
package org.solovyev.android.calculator.wizard;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import org.solovyev.android.calculator.CalculatorApplication;
|
import org.solovyev.android.calculator.CalculatorApplication;
|
||||||
@ -41,14 +40,18 @@ public final class Wizard {
|
|||||||
|
|
||||||
public static boolean isWizardFinished(@Nonnull String name) {
|
public static boolean isWizardFinished(@Nonnull String name) {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
||||||
return preferences.getBoolean(makeFlowFinishedPreferenceKey(name), false);
|
return preferences.getBoolean(makeFinishedPreferenceKey(name), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWizardStarted(@Nonnull String name) {
|
||||||
|
return getLastSavedWizardStepName(name) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveLastWizardStep(@Nonnull WizardFlow flow, @Nonnull WizardStep step) {
|
static void saveLastWizardStep(@Nonnull WizardFlow flow, @Nonnull WizardStep step) {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
||||||
final SharedPreferences.Editor editor = preferences.edit();
|
final SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
|
||||||
editor.putString(makeFlowStepPreferenceKey(flow), step.name());
|
editor.putString(makeLastStepPreferenceKey(flow), step.name());
|
||||||
|
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
@ -57,35 +60,35 @@ public final class Wizard {
|
|||||||
static String getLastSavedWizardStepName(@Nonnull String name) {
|
static String getLastSavedWizardStepName(@Nonnull String name) {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
||||||
|
|
||||||
return preferences.getString(makeFlowStepPreferenceKey(name), null);
|
return preferences.getString(makeLastStepPreferenceKey(name), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveWizardFinished(@Nonnull WizardFlow flow, @Nonnull WizardStep step, boolean forceFinish) {
|
static void saveWizardFinished(@Nonnull WizardFlow flow, @Nonnull WizardStep step, boolean forceFinish) {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
|
||||||
final SharedPreferences.Editor editor = preferences.edit();
|
final SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
|
||||||
editor.putBoolean(makeFlowFinishedPreferenceKey(flow), forceFinish || flow.getNextStep(step) == null);
|
editor.putBoolean(makeFinishedPreferenceKey(flow), forceFinish || flow.getNextStep(step) == null);
|
||||||
|
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static String makeFlowFinishedPreferenceKey(@Nonnull String flowName) {
|
private static String makeFinishedPreferenceKey(@Nonnull WizardFlow flow) {
|
||||||
|
return makeFinishedPreferenceKey(flow.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private static String makeFinishedPreferenceKey(@Nonnull String flowName) {
|
||||||
return FLOW_FINISHED + ":" + flowName;
|
return FLOW_FINISHED + ":" + flowName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static String makeFlowStepPreferenceKey(@Nonnull WizardFlow flow) {
|
private static String makeLastStepPreferenceKey(@Nonnull WizardFlow flow) {
|
||||||
return makeFlowStepPreferenceKey(flow.getName());
|
return makeLastStepPreferenceKey(flow.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static String makeFlowStepPreferenceKey(@Nonnull String flowName) {
|
private static String makeLastStepPreferenceKey(@Nonnull String flowName) {
|
||||||
return FLOW + ":" + flowName;
|
return FLOW + ":" + flowName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private static String makeFlowFinishedPreferenceKey(@Nonnull WizardFlow flow) {
|
|
||||||
return makeFlowFinishedPreferenceKey(flow.getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user