finish wizard dialog

This commit is contained in:
Sergey Solovyev 2013-06-25 15:53:11 +04:00
parent e267e314ab
commit c906e572f7
7 changed files with 60 additions and 7 deletions

View File

@ -158,6 +158,7 @@
</style> </style>
<style name="cpp_gray_dialog_theme" parent="Theme.Sherlock.Dialog"> <style name="cpp_gray_dialog_theme" parent="Theme.Sherlock.Dialog">
<item name="android:windowCloseOnTouchOutside">false</item>
<!-- buttons --> <!-- buttons -->
<item name="cpp_digit_button_style">@style/cpp_default_digit_button_style</item> <item name="cpp_digit_button_style">@style/cpp_default_digit_button_style</item>
<item name="cpp_control_button_style">@style/cpp_default_control_button_style</item> <item name="cpp_control_button_style">@style/cpp_default_control_button_style</item>

View File

@ -53,7 +53,11 @@ abstract class AbstractCalculatorWidgetProvider extends AppWidgetProvider implem
protected AbstractCalculatorWidgetProvider() { protected AbstractCalculatorWidgetProvider() {
final Class<? extends AppWidgetProvider> componentClass = this.getComponentClass(); final Class<? extends AppWidgetProvider> componentClass = this.getComponentClass();
Locator.getInstance().getExternalListenersContainer().addExternalListener(componentClass); final CalculatorExternalListenersContainer externalListenersContainer = Locator.getInstance().getExternalListenersContainer();
// NOTE: null might be in tests, now robolectric creates widget provider before application
if (externalListenersContainer != null) {
externalListenersContainer.addExternalListener(componentClass);
}
} }
/* /*

View File

@ -52,6 +52,7 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.cpp_wizard); setContentView(R.layout.cpp_wizard);
prevButton = findViewById(R.id.wizard_prev_button); prevButton = findViewById(R.id.wizard_prev_button);
nextButton = findViewById(R.id.wizard_next_button); nextButton = findViewById(R.id.wizard_next_button);
finishButton = findViewById(R.id.wizard_finish_button); finishButton = findViewById(R.id.wizard_finish_button);
@ -143,8 +144,12 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
} }
void finishFlow() { void finishFlow() {
finishFlow(false);
}
void finishFlow(boolean forceFinish) {
if (flow != null && step != null) { if (flow != null && step != null) {
Wizard.saveWizardFinished(flow, step); Wizard.saveWizardFinished(flow, step, forceFinish);
} }
finish(); finish();
} }
@ -229,6 +234,11 @@ public final class CalculatorWizardActivity extends SherlockFragmentActivity {
} }
} }
@Override
public void onBackPressed() {
FinishWizardConfirmationDialog.show(this);
}
WizardStep getStep() { WizardStep getStep() {
return step; return step;
} }

View File

@ -0,0 +1,37 @@
package org.solovyev.android.calculator.wizard;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import javax.annotation.Nonnull;
import org.solovyev.android.sherlock.AndroidSherlockUtils;
public class FinishWizardConfirmationDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setMessage("Do you really want to finish wizard?");
b.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
((CalculatorWizardActivity) getActivity()).finishFlow(true);
}
});
b.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dismiss();
}
});
return b.create();
}
public static void show(@Nonnull CalculatorWizardActivity activity){
AndroidSherlockUtils.showDialog(new FinishWizardConfirmationDialog(), FinishWizardConfirmationDialog.class.getSimpleName(), activity.getSupportFragmentManager());
}
}

View File

@ -60,11 +60,11 @@ public final class Wizard {
return preferences.getString(makeFlowStepPreferenceKey(name), null); return preferences.getString(makeFlowStepPreferenceKey(name), null);
} }
static void saveWizardFinished(@Nonnull WizardFlow flow, @Nonnull WizardStep step) { 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), flow.getNextStep(step) == null); editor.putBoolean(makeFlowFinishedPreferenceKey(flow), forceFinish || flow.getNextStep(step) == null);
editor.commit(); editor.commit();
} }

View File

@ -56,6 +56,7 @@ public interface CalculatorLocator {
@Nonnull @Nonnull
CalculatorPreferenceService getPreferenceService(); CalculatorPreferenceService getPreferenceService();
@Nonnull // for robolectric
/*@Nonnull*/
CalculatorExternalListenersContainer getExternalListenersContainer(); CalculatorExternalListenersContainer getExternalListenersContainer();
} }

View File

@ -46,7 +46,7 @@ public class Locator implements CalculatorLocator {
@Nonnull @Nonnull
private CalculatorPreferenceService calculatorPreferenceService; private CalculatorPreferenceService calculatorPreferenceService;
@Nonnull /*@Nonnull*/
private CalculatorExternalListenersContainer calculatorExternalListenersContainer; private CalculatorExternalListenersContainer calculatorExternalListenersContainer;
@Nonnull @Nonnull
@ -154,7 +154,7 @@ public class Locator implements CalculatorLocator {
} }
@Override @Override
@Nonnull /*@Nonnull*/
public CalculatorExternalListenersContainer getExternalListenersContainer() { public CalculatorExternalListenersContainer getExternalListenersContainer() {
return calculatorExternalListenersContainer; return calculatorExternalListenersContainer;
} }