This commit is contained in:
Sergey Solovyev 2013-06-25 16:17:17 +04:00
parent c906e572f7
commit 2fb20dc2b5
7 changed files with 52 additions and 37 deletions

View File

@ -13,7 +13,7 @@
<style name="cpp_default_dialog_style">
<item name="android:padding">6dp</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:orientation">vertical</item>
<item name="android:layout_gravity">center_horizontal</item>

View File

@ -51,7 +51,7 @@ public final class CalculatorPreferences {
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<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> notesppAnnounceShown = BooleanPreference.of("notespp_announce_shown", false);
public static final Preference<Boolean> showReleaseNotes = BooleanPreference.of("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);

View File

@ -52,7 +52,7 @@
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
<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>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>

View File

@ -5,14 +5,13 @@
style="?cpp_dialog_style"
a:orientation="vertical">
<LinearLayout
<FrameLayout
a:orientation="vertical"
a:id="@+id/wizard_content"
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="1"
a:gravity="center"
a:minHeight="150dp"/>
a:gravity="center"/>
<LinearLayout
a:orientation="horizontal"

View File

@ -41,6 +41,9 @@ import javax.annotation.Nullable;
import static android.os.Build.VERSION_CODES.GINGERBREAD_MR1;
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 {
@ -130,27 +133,31 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
if (!CalculatorApplication.isMonkeyRunner(context)) {
boolean dialogShown = false;
if (Objects.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
// new start
context.startActivity(new Intent(context, CalculatorWizardActivity.class));
if(isWizardStarted(FIRST_TIME_WIZARD) && !isWizardFinished(FIRST_TIME_WIZARD)) {
CalculatorWizardActivity.continueWizard(FIRST_TIME_WIZARD, context);
dialogShown = true;
} else {
if (savedVersion < appVersion) {
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
if (showReleaseNotes) {
final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1);
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;
if (Objects.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
// new start
context.startActivity(new Intent(context, CalculatorWizardActivity.class));
dialogShown = true;
} else {
if (savedVersion < appVersion) {
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
if (showReleaseNotes) {
final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1);
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!");
if (!dialogShown) {
if (appOpenedCounter != null && appOpenedCounter > 100) {

View File

@ -268,16 +268,22 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
*/
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);
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) {
final String step = Wizard.getLastSavedWizardStepName(name);
final Intent intent = new Intent(context, CalculatorWizardActivity.class);
intent.putExtra(FLOW, name);
final Intent intent = createLaunchIntent(name, context);
if (step != null) {
intent.putExtra(STEP, step);
}

View File

@ -1,6 +1,5 @@
package org.solovyev.android.calculator.wizard;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.solovyev.android.calculator.CalculatorApplication;
@ -41,14 +40,18 @@ public final class Wizard {
public static boolean isWizardFinished(@Nonnull String name) {
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) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
final SharedPreferences.Editor editor = preferences.edit();
editor.putString(makeFlowStepPreferenceKey(flow), step.name());
editor.putString(makeLastStepPreferenceKey(flow), step.name());
editor.commit();
}
@ -57,35 +60,35 @@ public final class Wizard {
static String getLastSavedWizardStepName(@Nonnull String name) {
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) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
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();
}
@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;
}
@Nonnull
private static String makeFlowStepPreferenceKey(@Nonnull WizardFlow flow) {
return makeFlowStepPreferenceKey(flow.getName());
private static String makeLastStepPreferenceKey(@Nonnull WizardFlow flow) {
return makeLastStepPreferenceKey(flow.getName());
}
@Nonnull
private static String makeFlowStepPreferenceKey(@Nonnull String flowName) {
private static String makeLastStepPreferenceKey(@Nonnull String flowName) {
return FLOW + ":" + flowName;
}
@Nonnull
private static String makeFlowFinishedPreferenceKey(@Nonnull WizardFlow flow) {
return makeFlowFinishedPreferenceKey(flow.getName());
}
}