From 68636d82786217ff2e4f443b472d2c00daa4b496 Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 27 Jan 2015 15:08:47 +0100 Subject: [PATCH] Sherlock -> AppCompat --- android-app-tests/android-app-tests.iml | 26 +- android-app/android-app.iml | 10 +- android-app/build.gradle | 8 +- android-app/proguard-debug.cfg | 3 + android-app/proguard.cfg | 3 + .../android/calculator/ActivityUi.java | 29 +- .../android/calculator/BaseActivity.java | 4 +- .../calculator/CalculatorActivity.java | 11 +- .../CalculatorActivityLauncher.java | 6 +- .../calculator/CalculatorDialogActivity.java | 4 +- .../calculator/CalculatorDisplayFragment.java | 4 +- .../calculator/CalculatorEditorFragment.java | 14 +- .../calculator/CalculatorFragment.java | 4 +- .../CalculatorKeyboardFragment.java | 4 +- .../calculator/CalculatorListFragment.java | 4 +- .../android/calculator/CalculatorMenu.java | 2 +- .../calculator/FixableMessagesDialog.java | 10 +- .../function/FunctionEditDialogFragment.java | 6 +- .../history/BaseHistoryFragment.java | 14 +- .../edit/AbstractMathEntityListFragment.java | 4 +- .../edit/CalculatorFunctionsFragment.java | 10 +- .../math/edit/CalculatorVarsFragment.java | 10 +- .../matrix/CalculatorMatrixActivity.java | 2 +- .../plot/AbstractCalculatorPlotFragment.java | 34 +- .../plot/CalculatorPlotActivity.java | 2 +- ...alculatorPlotFunctionSettingsActivity.java | 4 +- .../plot/CalculatorPlotFunctionsActivity.java | 4 +- .../plot/CalculatorPlotRangeActivity.java | 4 +- .../preferences/BasePreferencesActivity.java | 4 +- .../preferences/PurchaseDialogActivity.java | 4 +- .../android/fragments/FragmentUtils.java | 19 +- .../sherlock/AndroidSherlockUtils.java | 80 +++++ .../android/sherlock/FragmentItem.java | 39 ++ .../android/sherlock/FragmentItemImpl.java | 116 ++++++ .../solovyev/android/sherlock/Fragments.java | 43 +++ .../tabs/ActionBarFragmentTabListener.java | 76 ++++ .../solovyev/android/wizard/BaseWizard.java | 95 +++++ .../android/wizard/BaseWizardActivity.java | 44 +++ .../FinishWizardConfirmationDialog.java | 68 ++++ .../android/wizard/ListWizardFlow.java | 81 +++++ .../org/solovyev/android/wizard/Wizard.java | 24 ++ .../solovyev/android/wizard/WizardFlow.java | 41 +++ .../solovyev/android/wizard/WizardStep.java | 32 ++ .../org/solovyev/android/wizard/WizardUi.java | 333 ++++++++++++++++++ .../org/solovyev/android/wizard/Wizards.java | 15 + .../solovyev/android/wizard/WizardsAware.java | 9 + ...default_abs__item_background_holo_dark.xml | 5 +- .../default_abs__list_selector_holo_dark.xml | 5 +- .../default_abs__spinner_ab_holo_dark.xml | 29 -- .../src/main/res/values-de/strings.xml | 8 + .../src/main/res/values-es/strings.xml | 8 + .../src/main/res/values-fr/strings.xml | 8 + .../src/main/res/values-it/strings.xml | 8 + .../src/main/res/values-pl/strings.xml | 8 + .../src/main/res/values-pt-rBR/strings.xml | 8 + .../src/main/res/values-ru/strings.xml | 8 + .../src/main/res/values-uk/strings.xml | 8 + android-app/src/main/res/values/strings.xml | 8 + .../src/main/res/values/theme_gray.xml | 22 +- .../src/main/res/values/theme_metro_blue.xml | 2 +- 60 files changed, 1309 insertions(+), 189 deletions(-) create mode 100644 android-app/src/main/java/org/solovyev/android/sherlock/AndroidSherlockUtils.java create mode 100644 android-app/src/main/java/org/solovyev/android/sherlock/FragmentItem.java create mode 100644 android-app/src/main/java/org/solovyev/android/sherlock/FragmentItemImpl.java create mode 100644 android-app/src/main/java/org/solovyev/android/sherlock/Fragments.java create mode 100644 android-app/src/main/java/org/solovyev/android/sherlock/tabs/ActionBarFragmentTabListener.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/BaseWizard.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/BaseWizardActivity.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/FinishWizardConfirmationDialog.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/ListWizardFlow.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/Wizard.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/WizardFlow.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/WizardStep.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/WizardUi.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/Wizards.java create mode 100644 android-app/src/main/java/org/solovyev/android/wizard/WizardsAware.java delete mode 100644 android-app/src/main/res/drawable/default_abs__spinner_ab_holo_dark.xml create mode 100644 android-app/src/main/res/values-de/strings.xml create mode 100644 android-app/src/main/res/values-es/strings.xml create mode 100644 android-app/src/main/res/values-fr/strings.xml create mode 100644 android-app/src/main/res/values-it/strings.xml create mode 100644 android-app/src/main/res/values-pl/strings.xml create mode 100644 android-app/src/main/res/values-pt-rBR/strings.xml create mode 100644 android-app/src/main/res/values-ru/strings.xml create mode 100644 android-app/src/main/res/values-uk/strings.xml create mode 100644 android-app/src/main/res/values/strings.xml diff --git a/android-app-tests/android-app-tests.iml b/android-app-tests/android-app-tests.iml index dfee8079..38698c84 100644 --- a/android-app-tests/android-app-tests.iml +++ b/android-app-tests/android-app-tests.iml @@ -71,40 +71,36 @@ + - + - - - + + - - - + + + + + - - - - - - - - + + \ No newline at end of file diff --git a/android-app/android-app.iml b/android-app/android-app.iml index 2c2f13d0..8ba4dc70 100644 --- a/android-app/android-app.iml +++ b/android-app/android-app.iml @@ -81,18 +81,15 @@ - + - - - - + @@ -101,8 +98,8 @@ - + @@ -110,7 +107,6 @@ - diff --git a/android-app/build.gradle b/android-app/build.gradle index b364887a..5eb6046a 100644 --- a/android-app/build.gradle +++ b/android-app/build.gradle @@ -56,16 +56,13 @@ dependencies { compile 'org.solovyev:common-text:1.0.7' compile 'org.solovyev:common-security:1.0.7' compile 'com.android.support:support-v4:21.0.3' - compile ('ch.acra:acra:4.5.0') { + compile 'com.android.support:appcompat-v7:21.0.3' + compile('ch.acra:acra:4.5.0') { exclude group: 'org.json' } - compile 'org.solovyev.android:android-common-sherlock:1.1.18@aar' compile 'org.solovyev.android:android-common-lists:1.1.18@aar' - compile 'org.solovyev.android:android-common-wizard:1.1.18@aar' compile 'org.solovyev.android:android-common-core:1.1.18@aar' compile 'org.solovyev.android:android-common-other:1.1.18@aar' - compile 'org.solovyev.android:android-common-db:1.1.18@aar' - compile 'org.solovyev.android:android-common-security:1.1.18@aar' compile 'org.solovyev.android:android-common-views:1.1.18@aar' compile 'org.solovyev.android:android-common-menus:1.1.18@aar' compile 'org.solovyev.android:android-common-preferences:1.1.18@aar' @@ -73,7 +70,6 @@ dependencies { exclude(module: 'xercesImpl') } compile 'org.solovyev.android:checkout:0.6.0@aar' - compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' compile 'com.google.android.gms:play-services:6.5.87@aar' compile 'com.melnykov:floatingactionbutton:1.1.0' } diff --git a/android-app/proguard-debug.cfg b/android-app/proguard-debug.cfg index 62cd3f66..7c237aa5 100644 --- a/android-app/proguard-debug.cfg +++ b/android-app/proguard-debug.cfg @@ -67,6 +67,9 @@ -dontwarn com.actionbarsherlock.BuildConfig -dontwarn com.google.android.gms.** -dontwarn com.melnykov.fab.** +-dontwarn android.support.v7.** +-keep class android.support.v7.** { *; } +-keep interface android.support.v7.** { *; } -keep class org.simpleframework.xml.** { *; } -keep class * implements org.solovyev.android.calculator.model.MathPersistenceEntity diff --git a/android-app/proguard.cfg b/android-app/proguard.cfg index ebae0859..10f6c572 100644 --- a/android-app/proguard.cfg +++ b/android-app/proguard.cfg @@ -66,6 +66,9 @@ -dontwarn com.actionbarsherlock.BuildConfig -dontwarn com.google.android.gms.** -dontwarn com.melnykov.fab.** +-dontwarn android.support.v7.** +-keep class android.support.v7.** { *; } +-keep interface android.support.v7.** { *; } -keep class org.simpleframework.xml.** { *; } -keep class * implements org.solovyev.android.calculator.model.MathPersistenceEntity diff --git a/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java index 788666d8..36f1893e 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/ActivityUi.java @@ -36,8 +36,8 @@ import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import com.actionbarsherlock.app.ActionBar; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBar; +import android.support.v7.app.ActionBarActivity; import org.solovyev.android.Activities; import org.solovyev.android.Views; import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener; @@ -111,9 +111,8 @@ public class ActivityUi extends BaseUi { } } - public void onCreate(@Nonnull final SherlockFragmentActivity activity) { - onCreate((Activity)activity); - + public void onCreate(@Nonnull final ActionBarActivity activity) { + onCreate((Activity) activity); final ActionBar actionBar = activity.getSupportActionBar(); actionBar.setDisplayUseLogoEnabled(false); actionBar.setDisplayHomeAsUpEnabled(homeIcon); @@ -126,7 +125,7 @@ public class ActivityUi extends BaseUi { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } - private void toggleTitle(@Nonnull SherlockFragmentActivity activity, boolean showTitle) { + private void toggleTitle(@Nonnull ActionBarActivity activity, boolean showTitle) { final ActionBar actionBar = activity.getSupportActionBar(); if (activity instanceof CalculatorActivity) { @@ -140,14 +139,14 @@ public class ActivityUi extends BaseUi { } } - public void restoreSavedTab(@Nonnull SherlockFragmentActivity activity) { + public void restoreSavedTab(@Nonnull ActionBarActivity activity) { final ActionBar actionBar = activity.getSupportActionBar(); if (selectedNavigationIndex >= 0 && selectedNavigationIndex < actionBar.getTabCount()) { actionBar.setSelectedNavigationItem(selectedNavigationIndex); } } - public void onSaveInstanceState(@Nonnull SherlockFragmentActivity activity, @Nonnull Bundle outState) { + public void onSaveInstanceState(@Nonnull ActionBarActivity activity, @Nonnull Bundle outState) { onSaveInstanceState((Activity) activity, outState); } @@ -166,7 +165,7 @@ public class ActivityUi extends BaseUi { public void onPause(@Nonnull Activity activity) { } - public void onPause(@Nonnull SherlockFragmentActivity activity) { + public void onPause(@Nonnull ActionBarActivity activity) { onPause((Activity) activity); final int selectedNavigationIndex = activity.getSupportActionBar().getSelectedNavigationIndex(); @@ -193,11 +192,11 @@ public class ActivityUi extends BaseUi { } } - public void onDestroy(@Nonnull SherlockFragmentActivity activity) { + public void onDestroy(@Nonnull ActionBarActivity activity) { this.onDestroy((Activity) activity); } - public void addTab(@Nonnull SherlockFragmentActivity activity, + public void addTab(@Nonnull ActionBarActivity activity, @Nonnull String tag, @Nonnull Class fragmentClass, @Nullable Bundle fragmentArgs, @@ -214,11 +213,11 @@ public class ActivityUi extends BaseUi { actionBar.addTab(tab); } - public void addTab(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) { + public void addTab(@Nonnull ActionBarActivity activity, @Nonnull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) { addTab(activity, fragmentType.getFragmentTag(), fragmentType.getFragmentClass(), fragmentArgs, fragmentType.getDefaultTitleResId(), parentViewId); } - public void setFragment(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) { + public void setFragment(@Nonnull ActionBarActivity activity, @Nonnull CalculatorFragmentType fragmentType, @Nullable Bundle fragmentArgs, int parentViewId) { final FragmentManager fm = activity.getSupportFragmentManager(); Fragment fragment = fm.findFragmentByTag(fragmentType.getFragmentTag()); @@ -237,7 +236,7 @@ public class ActivityUi extends BaseUi { } } - public void selectTab(@Nonnull SherlockFragmentActivity activity, @Nonnull CalculatorFragmentType fragmentType) { + public void selectTab(@Nonnull ActionBarActivity activity, @Nonnull CalculatorFragmentType fragmentType) { final ActionBar actionBar = activity.getSupportActionBar(); for (int i = 0; i < actionBar.getTabCount(); i++) { final ActionBar.Tab tab = actionBar.getTabAt(i); @@ -262,7 +261,7 @@ public class ActivityUi extends BaseUi { return layout; } - public void onResume(@Nonnull SherlockFragmentActivity activity) { + public void onResume(@Nonnull ActionBarActivity activity) { onResume((Activity) activity); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java index b52dd6d1..066ed25f 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/BaseActivity.java @@ -2,11 +2,11 @@ package org.solovyev.android.calculator; import android.os.Bundle; import android.support.annotation.LayoutRes; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBarActivity; import javax.annotation.Nonnull; -public class BaseActivity extends SherlockFragmentActivity { +public class BaseActivity extends ActionBarActivity { @Nonnull protected final ActivityUi ui; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 337193a8..06035e3b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -36,8 +36,8 @@ import android.util.Log; import android.view.*; import android.widget.Button; import android.widget.TextView; -import com.actionbarsherlock.app.ActionBar; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBar; +import android.support.v7.app.ActionBarActivity; import org.solovyev.android.Activities; import org.solovyev.android.Android; import org.solovyev.android.Threads; @@ -62,7 +62,7 @@ import static org.solovyev.android.calculator.Preferences.Gui.preventScreenFromF import static org.solovyev.android.wizard.WizardUi.continueWizard; import static org.solovyev.android.wizard.WizardUi.startWizard; -public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener { +public class CalculatorActivity extends ActionBarActivity implements SharedPreferences.OnSharedPreferenceChangeListener, CalculatorEventListener { @Nonnull public static final String TAG = CalculatorActivity.class.getSimpleName(); @@ -77,6 +77,8 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar */ @Override public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final Preferences.Gui.Layout layout = Preferences.Gui.layout.getPreferenceNoError(preferences); @@ -85,9 +87,6 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar activityUi.logDebug("onCreate"); activityUi.onCreate(this); - super.onCreate(savedInstanceState); - activityUi.logDebug("super.onCreate"); - if (isMultiPane()) { activityUi.addTab(this, CalculatorFragmentType.history, null, R.id.main_second_pane); activityUi.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_second_pane); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java index c4510907..e5b17ec8 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorActivityLauncher.java @@ -32,7 +32,7 @@ import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBarActivity; import jscl.math.Generic; import org.solovyev.android.Android; import org.solovyev.android.calculator.about.CalculatorAboutActivity; @@ -129,8 +129,8 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener final String varValue = viewState.getText(); if (!Strings.isEmpty(varValue)) { if (CalculatorVarsFragment.isValidValue(varValue)) { - if (context instanceof SherlockFragmentActivity) { - VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((SherlockFragmentActivity) context).getSupportFragmentManager()); + if (context instanceof ActionBarActivity) { + VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((ActionBarActivity) context).getSupportFragmentManager()); } else { final Intent intent = new Intent(context, CalculatorVarsActivity.class); intent.putExtra(CalculatorVarsFragment.CREATE_VAR_EXTRA_STRING, varValue); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDialogActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDialogActivity.java index 30190288..b22c4c92 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDialogActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDialogActivity.java @@ -31,7 +31,7 @@ import android.view.View; import android.widget.Button; import android.widget.TextView; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBarActivity; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -46,7 +46,7 @@ import org.solovyev.common.text.Strings; * Date: 1/20/13 * Time: 12:50 PM */ -public class CalculatorDialogActivity extends SherlockFragmentActivity { +public class CalculatorDialogActivity extends ActionBarActivity { @Nonnull private static final String TAG = CalculatorDialogActivity.class.getSimpleName(); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java index af6fef66..fd64313d 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorDisplayFragment.java @@ -29,7 +29,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.actionbarsherlock.app.SherlockFragment; +import android.support.v4.app.Fragment; import javax.annotation.Nonnull; @@ -38,7 +38,7 @@ import javax.annotation.Nonnull; * Date: 25.09.12 * Time: 12:03 */ -public class CalculatorDisplayFragment extends SherlockFragment { +public class CalculatorDisplayFragment extends Fragment { @Nonnull private FragmentUi fragmentHelper; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java index a5ea970b..07e5c02b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorEditorFragment.java @@ -30,29 +30,29 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.actionbarsherlock.app.SherlockFragment; -import com.actionbarsherlock.view.Menu; -import com.actionbarsherlock.view.MenuInflater; -import com.actionbarsherlock.view.MenuItem; +import android.support.v4.app.Fragment; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import javax.annotation.Nonnull; import org.solovyev.android.menu.ActivityMenu; import org.solovyev.android.menu.ListActivityMenu; -import org.solovyev.android.sherlock.menu.SherlockMenuHelper; +import org.solovyev.android.menu.AndroidMenuHelper; /** * User: Solovyev_S * Date: 25.09.12 * Time: 10:49 */ -public class CalculatorEditorFragment extends SherlockFragment { +public class CalculatorEditorFragment extends Fragment { @Nonnull private FragmentUi fragmentHelper; @Nonnull - private ActivityMenu menu = ListActivityMenu.fromEnum(CalculatorMenu.class, SherlockMenuHelper.getInstance()); + private ActivityMenu menu = ListActivityMenu.fromEnum(CalculatorMenu.class, AndroidMenuHelper.getInstance()); public CalculatorEditorFragment() { } diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java index bb193cef..f969cb7b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorFragment.java @@ -28,7 +28,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.actionbarsherlock.app.SherlockFragment; +import android.support.v4.app.Fragment; import javax.annotation.Nonnull; @@ -37,7 +37,7 @@ import javax.annotation.Nonnull; * Date: 03.10.12 * Time: 14:18 */ -public abstract class CalculatorFragment extends SherlockFragment { +public abstract class CalculatorFragment extends Fragment { @Nonnull private final FragmentUi fragmentHelper; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java index 6bcbece8..5eb7dc5a 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java @@ -28,7 +28,7 @@ import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.actionbarsherlock.app.SherlockFragment; +import android.support.v4.app.Fragment; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -44,7 +44,7 @@ import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Pref * Date: 25.09.12 * Time: 12:25 */ -public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener { +public class CalculatorKeyboardFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener { @Nonnull private Preferences.Gui.Theme theme; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java index f105164b..37e06cea 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorListFragment.java @@ -28,7 +28,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.actionbarsherlock.app.SherlockListFragment; +import android.support.v4.app.ListFragment; import javax.annotation.Nonnull; @@ -37,7 +37,7 @@ import javax.annotation.Nonnull; * Date: 03.10.12 * Time: 14:18 */ -public abstract class CalculatorListFragment extends SherlockListFragment { +public abstract class CalculatorListFragment extends ListFragment { @Nonnull private final FragmentUi fragmentHelper; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java index 237b5d7e..654e73a3 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/CalculatorMenu.java @@ -26,7 +26,7 @@ import android.app.Activity; import android.content.Context; import android.util.Log; -import com.actionbarsherlock.view.MenuItem; +import android.view.MenuItem; import javax.annotation.Nonnull; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/FixableMessagesDialog.java b/android-app/src/main/java/org/solovyev/android/calculator/FixableMessagesDialog.java index 1ac7f871..a93bf83b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/FixableMessagesDialog.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/FixableMessagesDialog.java @@ -29,21 +29,17 @@ import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.preference.PreferenceManager; +import android.support.v7.app.ActionBarActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; import android.widget.TextView; - -import com.actionbarsherlock.app.SherlockActivity; - -import javax.annotation.Nonnull; - -import org.solovyev.android.calculator.R; import org.solovyev.common.msg.Message; import org.solovyev.common.text.Strings; +import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -53,7 +49,7 @@ import java.util.List; * Date: 11/17/12 * Time: 3:37 PM */ -public class FixableMessagesDialog extends SherlockActivity { +public class FixableMessagesDialog extends ActionBarActivity { private static final String INPUT = "input"; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditDialogFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditDialogFragment.java index ba8ec531..b9e44d7f 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditDialogFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/function/FunctionEditDialogFragment.java @@ -34,7 +34,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.EditText; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBarActivity; import jscl.math.Generic; import jscl.math.function.Constant; @@ -189,8 +189,8 @@ public class FunctionEditDialogFragment extends DialogFragment implements Calcul */ public static void showDialog(@Nonnull Input input, @Nonnull Context context) { - if (context instanceof SherlockFragmentActivity) { - FunctionEditDialogFragment.showDialog(input, ((SherlockFragmentActivity) context).getSupportFragmentManager()); + if (context instanceof ActionBarActivity) { + FunctionEditDialogFragment.showDialog(input, ((ActionBarActivity) context).getSupportFragmentManager()); } else { final Intent intent = new Intent(context, CalculatorFunctionsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java index cd407770..f234a43a 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java @@ -35,16 +35,16 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; -import com.actionbarsherlock.app.SherlockListFragment; -import com.actionbarsherlock.view.Menu; -import com.actionbarsherlock.view.MenuInflater; -import com.actionbarsherlock.view.MenuItem; +import android.support.v4.app.ListFragment; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import com.melnykov.fab.FloatingActionButton; import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.menu.*; -import org.solovyev.android.sherlock.menu.SherlockMenuHelper; +import org.solovyev.android.menu.AndroidMenuHelper; import org.solovyev.common.JPredicate; import org.solovyev.common.collections.Collections; import org.solovyev.common.equals.Equalizer; @@ -60,7 +60,7 @@ import java.util.List; import static org.solovyev.android.calculator.CalculatorEventType.clear_history_requested; -public abstract class BaseHistoryFragment extends SherlockListFragment implements CalculatorEventListener { +public abstract class BaseHistoryFragment extends ListFragment implements CalculatorEventListener { /* ********************************************************************** @@ -103,7 +103,7 @@ public abstract class BaseHistoryFragment extends SherlockListFragment implement @Nonnull private FragmentUi fragmentHelper; - private final ActivityMenu menu = ListActivityMenu.fromResource(R.menu.history_menu, HistoryMenu.class, SherlockMenuHelper.getInstance(), new HistoryMenuFilter()); + private final ActivityMenu menu = ListActivityMenu.fromResource(R.menu.history_menu, HistoryMenu.class, AndroidMenuHelper.getInstance(), new HistoryMenuFilter()); @Nonnull private final SharedPreferences.OnSharedPreferenceChangeListener preferencesListener = new HistoryOnPreferenceChangeListener(); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java index b7419d36..33850bd0 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/AbstractMathEntityListFragment.java @@ -58,7 +58,7 @@ import org.solovyev.common.filter.Filter; import org.solovyev.common.math.MathEntity; import org.solovyev.common.text.Strings; -import com.actionbarsherlock.app.SherlockListFragment; +import android.support.v4.app.ListFragment; import static org.solovyev.android.calculator.CalculatorEventType.show_wiki_description; @@ -67,7 +67,7 @@ import static org.solovyev.android.calculator.CalculatorEventType.show_wiki_desc * Date: 12/21/11 * Time: 9:24 PM */ -public abstract class AbstractMathEntityListFragment extends SherlockListFragment implements CalculatorEventListener { +public abstract class AbstractMathEntityListFragment extends ListFragment implements CalculatorEventListener { /* ********************************************************************** diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsFragment.java index a6f5dd44..d6ef0752 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorFunctionsFragment.java @@ -28,10 +28,10 @@ import android.os.Bundle; import android.os.Parcelable; import android.text.ClipboardManager; -import com.actionbarsherlock.app.SherlockFragmentActivity; -import com.actionbarsherlock.view.Menu; -import com.actionbarsherlock.view.MenuInflater; -import com.actionbarsherlock.view.MenuItem; +import android.support.v7.app.ActionBarActivity; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import jscl.math.function.Function; import jscl.math.function.IFunction; @@ -251,7 +251,7 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment< @Override public void onClick(@Nonnull Function function, @Nonnull Context context) { if (function instanceof IFunction) { - FunctionEditDialogFragment.showDialog(FunctionEditDialogFragment.Input.newFromFunction((IFunction) function), ((SherlockFragmentActivity) context).getSupportFragmentManager()); + FunctionEditDialogFragment.showDialog(FunctionEditDialogFragment.Input.newFromFunction((IFunction) function), ((ActionBarActivity) context).getSupportFragmentManager()); } } }, diff --git a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsFragment.java b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsFragment.java index f7308c73..118aee3a 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsFragment.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/math/edit/CalculatorVarsFragment.java @@ -25,10 +25,10 @@ package org.solovyev.android.calculator.math.edit; import android.content.Context; import android.os.Bundle; import android.view.View; -import com.actionbarsherlock.app.SherlockFragmentActivity; -import com.actionbarsherlock.view.Menu; -import com.actionbarsherlock.view.MenuInflater; -import com.actionbarsherlock.view.MenuItem; +import android.support.v7.app.ActionBarActivity; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import jscl.math.function.IConstant; import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.math.MathType; @@ -249,7 +249,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment>() { + fragmentMenu = ListActivityMenu.fromResource(R.menu.plot_menu, menuItems, AndroidMenuHelper.getInstance(), new JPredicate>() { @Override public boolean apply(@Nullable AMenuItem menuItem) { if (menuItem == plot3dMenuItem) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotActivity.java index c6dc0beb..c9de1484 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotActivity.java @@ -32,7 +32,7 @@ import org.solovyev.android.calculator.R; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_STANDARD; +import static android.support.v7.app.ActionBar.NAVIGATION_MODE_STANDARD; /** * User: serso diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionSettingsActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionSettingsActivity.java index 304e2a46..2da70a8e 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionSettingsActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionSettingsActivity.java @@ -33,7 +33,7 @@ import android.widget.Button; import android.widget.SeekBar; import android.widget.Spinner; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBarActivity; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -44,7 +44,7 @@ import org.solovyev.android.calculator.Locator; import org.solovyev.android.calculator.R; import org.solovyev.android.fragments.FragmentUtils; -public class CalculatorPlotFunctionSettingsActivity extends SherlockFragmentActivity { +public class CalculatorPlotFunctionSettingsActivity extends ActionBarActivity { private static final String INPUT_FUNCTION_ID = "plot-function-id"; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionsActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionsActivity.java index 8aff1bc4..57ae5ba8 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionsActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotFunctionsActivity.java @@ -23,7 +23,7 @@ package org.solovyev.android.calculator.plot; import android.os.Bundle; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBarActivity; import com.google.common.base.Function; import com.google.common.collect.Lists; import org.solovyev.android.calculator.CalculatorFragmentType; @@ -41,7 +41,7 @@ import java.util.List; * Date: 1/13/13 * Time: 5:05 PM */ -public class CalculatorPlotFunctionsActivity extends SherlockFragmentActivity { +public class CalculatorPlotFunctionsActivity extends ActionBarActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotRangeActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotRangeActivity.java index 9ab3bf65..14ac6091 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotRangeActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorPlotRangeActivity.java @@ -26,7 +26,7 @@ import android.os.Bundle; import android.view.View; import android.widget.EditText; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBarActivity; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -43,7 +43,7 @@ import org.solovyev.common.msg.MessageType; * Date: 1/19/13 * Time: 5:14 PM */ -public class CalculatorPlotRangeActivity extends SherlockFragmentActivity { +public class CalculatorPlotRangeActivity extends ActionBarActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { diff --git a/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java index fdad814e..10b5e67b 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/preferences/BasePreferencesActivity.java @@ -2,8 +2,8 @@ package org.solovyev.android.calculator.preferences; import android.content.Intent; import android.os.Bundle; +import android.preference.PreferenceActivity; import android.view.LayoutInflater; -import com.actionbarsherlock.app.SherlockPreferenceActivity; import org.solovyev.android.calculator.ActivityUi; import org.solovyev.android.calculator.AdView; import org.solovyev.android.calculator.App; @@ -15,7 +15,7 @@ import org.solovyev.android.checkout.ProductTypes; import javax.annotation.Nonnull; -public abstract class BasePreferencesActivity extends SherlockPreferenceActivity { +public abstract class BasePreferencesActivity extends PreferenceActivity { private final ActivityCheckout checkout = Checkout.forActivity(this, App.getBilling(), App.getProducts()); private Inventory inventory; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java b/android-app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java index e2f2e946..d3cb6466 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/preferences/PurchaseDialogActivity.java @@ -28,7 +28,7 @@ import android.os.Bundle; import android.text.method.ScrollingMovementMethod; import android.view.View; import android.widget.TextView; -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBarActivity; import org.solovyev.android.calculator.*; import org.solovyev.android.checkout.*; import org.solovyev.android.fragments.FragmentUtils; @@ -41,7 +41,7 @@ import javax.annotation.Nullable; * Date: 1/20/13 * Time: 2:36 PM */ -public class PurchaseDialogActivity extends SherlockFragmentActivity { +public class PurchaseDialogActivity extends ActionBarActivity { @Nonnull private final ActivityCheckout checkout = Checkout.forActivity(this, App.getBilling(), App.getProducts()); diff --git a/android-app/src/main/java/org/solovyev/android/fragments/FragmentUtils.java b/android-app/src/main/java/org/solovyev/android/fragments/FragmentUtils.java index 08a47a75..eecebc33 100644 --- a/android-app/src/main/java/org/solovyev/android/fragments/FragmentUtils.java +++ b/android-app/src/main/java/org/solovyev/android/fragments/FragmentUtils.java @@ -27,14 +27,11 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; - -import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.support.v7.app.ActionBarActivity; +import org.solovyev.common.collections.Collections; import javax.annotation.Nonnull; import javax.annotation.Nullable; - -import org.solovyev.common.collections.Collections; - import java.util.List; /** @@ -75,27 +72,27 @@ public class FragmentUtils { } } - public static void removeFragments(@Nonnull SherlockFragmentActivity activity, @Nonnull String... fragmentTags) { + public static void removeFragments(@Nonnull ActionBarActivity activity, @Nonnull String... fragmentTags) { removeFragments(activity, Collections.asList(fragmentTags)); } - public static void removeFragments(@Nonnull SherlockFragmentActivity activity, @Nonnull List fragmentTags) { + public static void removeFragments(@Nonnull ActionBarActivity activity, @Nonnull List fragmentTags) { for (String fragmentTag : fragmentTags) { removeFragment(activity, fragmentTag); } } - public static void detachFragments(@Nonnull SherlockFragmentActivity activity, @Nonnull String... fragmentTags) { + public static void detachFragments(@Nonnull ActionBarActivity activity, @Nonnull String... fragmentTags) { detachFragments(activity, Collections.asList(fragmentTags)); } - public static void detachFragments(@Nonnull SherlockFragmentActivity activity, @Nonnull List fragmentTags) { + public static void detachFragments(@Nonnull ActionBarActivity activity, @Nonnull List fragmentTags) { for (String fragmentTag : fragmentTags) { detachFragment(activity, fragmentTag); } } - public static void detachFragment(@Nonnull SherlockFragmentActivity activity, @Nonnull String fragmentTag) { + public static void detachFragment(@Nonnull ActionBarActivity activity, @Nonnull String fragmentTag) { final Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(fragmentTag); if (fragment != null) { if (!fragment.isDetached()) { @@ -106,7 +103,7 @@ public class FragmentUtils { } } - public static void removeFragment(@Nonnull SherlockFragmentActivity activity, @Nonnull String fragmentTag) { + public static void removeFragment(@Nonnull ActionBarActivity activity, @Nonnull String fragmentTag) { final Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(fragmentTag); if (fragment != null) { if (fragment.isAdded()) { diff --git a/android-app/src/main/java/org/solovyev/android/sherlock/AndroidSherlockUtils.java b/android-app/src/main/java/org/solovyev/android/sherlock/AndroidSherlockUtils.java new file mode 100644 index 00000000..c35a574b --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/sherlock/AndroidSherlockUtils.java @@ -0,0 +1,80 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * 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. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.sherlock; + +import android.app.Activity; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.ActionBar; +import android.support.v7.app.ActionBarActivity; +import android.view.MenuInflater; + +import javax.annotation.Nonnull; + +/** + * User: serso + * Date: 8/13/12 + * Time: 2:04 AM + */ +public final class AndroidSherlockUtils { + + private AndroidSherlockUtils() { + throw new AssertionError("Not intended for instantiation!"); + } + + @Nonnull + public static ActionBar getSupportActionBar(@Nonnull Activity activity) { + if (activity instanceof ActionBarActivity) { + return ((ActionBarActivity) activity).getSupportActionBar(); + } + + throw new IllegalArgumentException(activity.getClass() + " is not supported!"); + + } + + public static ActionBar getSupportActionBar(@Nonnull Fragment fragment) { + return ((ActionBarActivity) fragment.getActivity()).getSupportActionBar(); + } + + + @Nonnull + public static MenuInflater getSupportMenuInflater(@Nonnull Activity activity) { + return activity.getMenuInflater(); + } + + public static void showDialog(@Nonnull DialogFragment dialogFragment, + @Nonnull String fragmentTag, + @Nonnull FragmentManager fm) { + final FragmentTransaction ft = fm.beginTransaction(); + + Fragment prev = fm.findFragmentByTag(fragmentTag); + if (prev != null) { + ft.remove(prev); + } + + // Create and show the dialog. + dialogFragment.show(ft, fragmentTag); + } +} diff --git a/android-app/src/main/java/org/solovyev/android/sherlock/FragmentItem.java b/android-app/src/main/java/org/solovyev/android/sherlock/FragmentItem.java new file mode 100644 index 00000000..c7ef060e --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/sherlock/FragmentItem.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * 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. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.sherlock; + +import android.support.v4.app.FragmentTransaction; + +import javax.annotation.Nonnull; + +/** + * User: serso + * Date: 8/7/12 + * Time: 11:57 AM + */ +public interface FragmentItem { + + public void onSelected(@Nonnull FragmentTransaction ft); + + public void onUnselected(@Nonnull FragmentTransaction ft); +} diff --git a/android-app/src/main/java/org/solovyev/android/sherlock/FragmentItemImpl.java b/android-app/src/main/java/org/solovyev/android/sherlock/FragmentItemImpl.java new file mode 100644 index 00000000..8ac390c0 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/sherlock/FragmentItemImpl.java @@ -0,0 +1,116 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * 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. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.sherlock; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.ActionBarActivity; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * User: serso + * Date: 8/7/12 + * Time: 11:55 AM + */ +public class FragmentItemImpl implements FragmentItem { + + @Nonnull + private final ActionBarActivity activity; + + // Fragment + + @Nonnull + private final String tag; + + @Nonnull + private final Class fragmentClass; + + @Nullable + private Bundle fragmentArgs; + + @Nullable + private Fragment fragment; + + @Nullable + private final Integer parentViewId; + + /** + * Constructor used each time a new tab is created. + * + * @param activity The host Activity, used to instantiate the fragment + * @param tag The identifier tag for the fragment + * @param fragmentClass The fragment's Class, used to instantiate the fragment + * @param fragmentArgs arguments to be passed to fragment + * @param parentViewId parent view id + */ + + public FragmentItemImpl(@Nonnull ActionBarActivity activity, + @Nonnull String tag, + @Nonnull Class fragmentClass, + @Nullable Bundle fragmentArgs, + @Nullable Integer parentViewId) { + this.activity = activity; + this.tag = tag; + this.fragmentClass = fragmentClass; + this.fragmentArgs = fragmentArgs; + this.parentViewId = parentViewId; + + final FragmentManager supportFragmentManager = activity.getSupportFragmentManager(); + this.fragment = supportFragmentManager.findFragmentByTag(tag); + } + + + @Override + public void onSelected(@Nonnull FragmentTransaction ft) { + if (fragment == null) { + fragment = activity.getSupportFragmentManager().findFragmentByTag(this.tag); + } + + // Check if the fragment is already initialized + if (fragment == null) { + // If not, instantiate and add it to the activity + fragment = Fragment.instantiate(activity, fragmentClass.getName(), fragmentArgs); + if (parentViewId != null) { + ft.add(parentViewId, fragment, tag); + } else { + ft.add(fragment, tag); + } + } else { + if (fragment.isDetached()) { + // If it exists, simply attach it in order to show it + ft.attach(fragment); + } + } + } + + @Override + public void onUnselected(@Nonnull FragmentTransaction ft) { + if (fragment != null) { + ft.detach(fragment); + } + } +} diff --git a/android-app/src/main/java/org/solovyev/android/sherlock/Fragments.java b/android-app/src/main/java/org/solovyev/android/sherlock/Fragments.java new file mode 100644 index 00000000..901c41bb --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/sherlock/Fragments.java @@ -0,0 +1,43 @@ +package org.solovyev.android.sherlock; + +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; + +import javax.annotation.Nonnull; + +public class Fragments extends org.solovyev.android.Fragments { + + private Fragments() { + } + + public static void showDialog(@Nonnull DialogFragment dialogFragment, + @Nonnull String fragmentTag, + @Nonnull FragmentManager fm) { + showDialog(dialogFragment, fragmentTag, fm, true); + } + + public static void showDialog(DialogFragment dialogFragment, String fragmentTag, FragmentManager fm, boolean useExisting) { + Fragment prev = fm.findFragmentByTag(fragmentTag); + if (prev != null) { + if (!useExisting) { + final FragmentTransaction ft = fm.beginTransaction(); + ft.remove(prev); + ft.addToBackStack(null); + + // Create and show the dialog. + dialogFragment.show(ft, fragmentTag); + fm.executePendingTransactions(); + } + } else { + final FragmentTransaction ft = fm.beginTransaction(); + + ft.addToBackStack(null); + + // Create and show the dialog. + dialogFragment.show(ft, fragmentTag); + fm.executePendingTransactions(); + } + } +} diff --git a/android-app/src/main/java/org/solovyev/android/sherlock/tabs/ActionBarFragmentTabListener.java b/android-app/src/main/java/org/solovyev/android/sherlock/tabs/ActionBarFragmentTabListener.java new file mode 100644 index 00000000..99db16e5 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/sherlock/tabs/ActionBarFragmentTabListener.java @@ -0,0 +1,76 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * 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. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.sherlock.tabs; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.ActionBar; +import android.support.v7.app.ActionBarActivity; +import org.solovyev.android.sherlock.FragmentItem; +import org.solovyev.android.sherlock.FragmentItemImpl; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * User: serso + * Date: 8/4/12 + * Time: 12:42 PM + */ +public class ActionBarFragmentTabListener implements ActionBar.TabListener { + + private final FragmentItem fragmentItem; + + /** + * Constructor used each time a new tab is created. + * + * @param activity The host Activity, used to instantiate the fragment + * @param tag The identifier tag for the fragment + * @param fragmentClass The fragment's Class, used to instantiate the fragment + * @param fragmentArgs arguments to be passed to fragment + * @param parentViewId parent view id + */ + + public ActionBarFragmentTabListener(@Nonnull ActionBarActivity activity, + @Nonnull String tag, + @Nonnull Class fragmentClass, + @Nullable Bundle fragmentArgs, + @Nullable Integer parentViewId) { + this.fragmentItem = new FragmentItemImpl(activity, tag, fragmentClass, fragmentArgs, parentViewId); + } + + + /* The following are each of the ActionBar.TabListener callbacks */ + + public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { + this.fragmentItem.onSelected(ft); + } + + public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { + this.fragmentItem.onUnselected(ft); + } + + public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { + } +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/BaseWizard.java b/android-app/src/main/java/org/solovyev/android/wizard/BaseWizard.java new file mode 100644 index 00000000..42dd0259 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/BaseWizard.java @@ -0,0 +1,95 @@ +package org.solovyev.android.wizard; + +import android.content.Context; +import android.content.SharedPreferences; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static android.preference.PreferenceManager.getDefaultSharedPreferences; + +public class BaseWizard implements Wizard { + + static final String FLOW = "flow"; + static final String FLOW_FINISHED = "flow_finished"; + + @Nonnull + private final String name; + + @Nonnull + private final Context context; + + @Nonnull + private final WizardFlow flow; + + public BaseWizard(@Nonnull String name, + @Nonnull Context context, + @Nonnull WizardFlow flow) { + this.name = name; + this.context = context; + this.flow = flow; + } + + @Override + public void saveLastStep(@Nonnull WizardStep step) { + final SharedPreferences preferences = getPreferences(); + final SharedPreferences.Editor editor = preferences.edit(); + + editor.putString(makeLastStepPreferenceKey(name), step.getName()); + + editor.commit(); + } + + @Override + public void saveFinished(@Nonnull WizardStep step, boolean forceFinish) { + final SharedPreferences preferences = getPreferences(); + final SharedPreferences.Editor editor = preferences.edit(); + + editor.putBoolean(makeFinishedPreferenceKey(name), forceFinish || flow.getNextStep(step) == null); + + editor.commit(); + } + + @Nonnull + private SharedPreferences getPreferences() { + return getDefaultSharedPreferences(context); + } + + @Override + @Nullable + public String getLastSavedStepName() { + return getPreferences().getString(makeLastStepPreferenceKey(name), null); + } + + @Override + public boolean isFinished() { + return getPreferences().getBoolean(makeFinishedPreferenceKey(name), false); + } + + @Override + public boolean isStarted() { + return getLastSavedStepName() != null; + } + + @Nonnull + static String makeFinishedPreferenceKey(@Nonnull String flowName) { + return FLOW_FINISHED + ":" + flowName; + } + + @Nonnull + static String makeLastStepPreferenceKey(@Nonnull String flowName) { + return FLOW + ":" + flowName; + } + + @Override + @Nonnull + public WizardFlow getFlow() { + return flow; + } + + @Nonnull + @Override + public String getName() { + return name; + } +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/BaseWizardActivity.java b/android-app/src/main/java/org/solovyev/android/wizard/BaseWizardActivity.java new file mode 100644 index 00000000..ca393151 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/BaseWizardActivity.java @@ -0,0 +1,44 @@ +package org.solovyev.android.wizard; + +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; + +import javax.annotation.Nonnull; + +public abstract class BaseWizardActivity extends ActionBarActivity implements WizardsAware, FinishWizardConfirmationDialog.Listener { + + @Nonnull + private WizardUi ui; + + protected BaseWizardActivity(int layoutResId) { + ui = new WizardUi(this, this, layoutResId); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ui.onCreate(savedInstanceState); + } + + @Override + protected void onSaveInstanceState(Bundle out) { + super.onSaveInstanceState(out); + ui.onSaveInstanceState(out); + } + + @Override + public void onPause() { + super.onPause(); + ui.onPause(); + } + + @Override + public void onBackPressed() { + ui.onBackPressed(); + } + + @Override + public void finishWizardAbruptly() { + ui.finishWizardAbruptly(); + } +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/FinishWizardConfirmationDialog.java b/android-app/src/main/java/org/solovyev/android/wizard/FinishWizardConfirmationDialog.java new file mode 100644 index 00000000..cb3c7a0f --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/FinishWizardConfirmationDialog.java @@ -0,0 +1,68 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * 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. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.wizard; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentActivity; +import org.solovyev.android.calculator.R; +import org.solovyev.android.sherlock.AndroidSherlockUtils; + +import javax.annotation.Nonnull; + +public class FinishWizardConfirmationDialog extends DialogFragment { + + @Nonnull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); + b.setMessage(R.string.acl_wizard_finish_confirmation); + b.setPositiveButton(R.string.acl_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + ((Listener) getActivity()).finishWizardAbruptly(); + } + }); + b.setNegativeButton(R.string.acl_no, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + dismiss(); + } + }); + return b.create(); + } + + public static void show(@Nonnull A activity) { + if (!(activity instanceof Listener)) { + throw new IllegalArgumentException("Activity should implement " + Listener.class); + } + AndroidSherlockUtils.showDialog(new FinishWizardConfirmationDialog(), FinishWizardConfirmationDialog.class.getSimpleName(), activity.getSupportFragmentManager()); + } + + public static interface Listener { + void finishWizardAbruptly(); + } +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/ListWizardFlow.java b/android-app/src/main/java/org/solovyev/android/wizard/ListWizardFlow.java new file mode 100644 index 00000000..d7699c5b --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/ListWizardFlow.java @@ -0,0 +1,81 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * 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. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.wizard; + +import org.solovyev.common.JPredicate; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.List; + +import static org.solovyev.common.collections.Collections.find; + +public final class ListWizardFlow implements WizardFlow { + + @Nonnull + private final List steps; + + public ListWizardFlow(@Nonnull List steps) { + this.steps = steps; + } + + @Nullable + @Override + public WizardStep getStepByName(@Nonnull final String name) { + return find(steps, new JPredicate() { + @Override + public boolean apply(@Nullable WizardStep step) { + assert step != null; + return step.getName().equals(name); + } + }); + } + + @Nullable + @Override + public WizardStep getNextStep(@Nonnull WizardStep step) { + final int i = steps.indexOf(step); + if (i >= 0 && i + 1 < steps.size()) { + return steps.get(i + 1); + } else { + return null; + } + } + + @Nullable + @Override + public WizardStep getPrevStep(@Nonnull WizardStep step) { + final int i = steps.indexOf(step); + if (i >= 1) { + return steps.get(i - 1); + } else { + return null; + } + } + + @Nonnull + @Override + public WizardStep getFirstStep() { + return steps.get(0); + } +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/Wizard.java b/android-app/src/main/java/org/solovyev/android/wizard/Wizard.java new file mode 100644 index 00000000..d7a50a4d --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/Wizard.java @@ -0,0 +1,24 @@ +package org.solovyev.android.wizard; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public interface Wizard { + + @Nullable + String getLastSavedStepName(); + + boolean isFinished(); + + boolean isStarted(); + + void saveLastStep(@Nonnull WizardStep step); + + void saveFinished(@Nonnull WizardStep step, boolean forceFinish); + + @Nonnull + WizardFlow getFlow(); + + @Nonnull + String getName(); +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/WizardFlow.java b/android-app/src/main/java/org/solovyev/android/wizard/WizardFlow.java new file mode 100644 index 00000000..4c343799 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/WizardFlow.java @@ -0,0 +1,41 @@ +/* + * Copyright 2013 serso aka se.solovyev + * + * 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. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Contact details + * + * Email: se.solovyev@gmail.com + * Site: http://se.solovyev.org + */ + +package org.solovyev.android.wizard; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public interface WizardFlow { + + @Nullable + WizardStep getStepByName(@Nonnull String name); + + @Nullable + WizardStep getNextStep(@Nonnull WizardStep step); + + @Nullable + WizardStep getPrevStep(@Nonnull WizardStep step); + + @Nonnull + WizardStep getFirstStep(); +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/WizardStep.java b/android-app/src/main/java/org/solovyev/android/wizard/WizardStep.java new file mode 100644 index 00000000..9cb80ef5 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/WizardStep.java @@ -0,0 +1,32 @@ +package org.solovyev.android.wizard; + +import android.os.Bundle; +import android.support.v4.app.Fragment; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public interface WizardStep { + + @Nonnull + String getFragmentTag(); + + @Nonnull + Class getFragmentClass(); + + @Nullable + Bundle getFragmentArgs(); + + int getTitleResId(); + + int getNextButtonTitleResId(); + + boolean onNext(@Nonnull Fragment fragment); + + boolean onPrev(@Nonnull Fragment fragment); + + boolean isVisible(); + + @Nonnull + String getName(); +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/WizardUi.java b/android-app/src/main/java/org/solovyev/android/wizard/WizardUi.java new file mode 100644 index 00000000..8dbac768 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/WizardUi.java @@ -0,0 +1,333 @@ +package org.solovyev.android.wizard; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.view.View; +import android.widget.Button; +import org.solovyev.android.calculator.R; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static android.view.View.GONE; +import static android.view.View.VISIBLE; + +public class WizardUi { + + /* + ********************************************************************** + * + * CONSTANTS + * + ********************************************************************** + */ + + private static final String FLOW = "flow"; + private static final String STEP = "step"; + + /* + ********************************************************************** + * + * FIELDS + * + ********************************************************************** + */ + + private WizardStep step; + + private Wizard wizard; + + /* + ********************************************************************** + * + * VIEWS + * + ********************************************************************** + */ + + @Nullable + private View prevButton; + + @Nonnull + private Button nextButton; + + @Nonnull + private final A activity; + + @Nonnull + private final WizardsAware wizardsAware; + + private final int layoutResId; + + public WizardUi(@Nonnull A activity, @Nonnull WizardsAware wizardsAware, int layoutResId) { + this.activity = activity; + this.wizardsAware = wizardsAware; + this.layoutResId = layoutResId; + } + + /* + ********************************************************************** + * + * LIFECYCLE + * + ********************************************************************** + */ + + public void onCreate(@Nullable Bundle savedInstanceState) { + activity.setContentView(layoutResId); + + prevButton = activity.findViewById(R.id.acl_wizard_prev_button); + nextButton = (Button) activity.findViewById(R.id.acl_wizard_next_button); + + String wizardName = activity.getIntent().getStringExtra(FLOW); + String stepName = activity.getIntent().getStringExtra(STEP); + if (savedInstanceState != null) { + wizardName = savedInstanceState.getString(FLOW); + stepName = savedInstanceState.getString(STEP); + } + + wizard = wizardsAware.getWizards().getWizard(wizardName); + + WizardStep step = null; + if (stepName != null) { + step = wizard.getFlow().getStepByName(stepName); + } + + if (step == null) { + step = wizard.getFlow().getFirstStep(); + } + + setStep(step); + } + + + public void setStep(@Nonnull WizardStep step) { + if (this.step == null || !this.step.equals(step)) { + hideFragment(); + this.step = step; + showFragment(); + + initTitle(); + initNextButton(); + initPrevButton(); + } + } + + private void initTitle() { + activity.setTitle(step.getTitleResId()); + } + + private void initPrevButton() { + if (prevButton != null) { + final WizardStep prevStep = wizard.getFlow().getPrevStep(step); + if (prevStep == null) { + prevButton.setVisibility(GONE); + prevButton.setOnClickListener(null); + } else { + prevButton.setVisibility(VISIBLE); + prevButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (tryGoPrev()) { + setStep(prevStep); + } + } + }); + } + } + } + + private void initNextButton() { + final WizardStep nextStep = wizard.getFlow().getNextStep(step); + if (nextStep == null) { + nextButton.setText(R.string.acl_wizard_finish); + nextButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (tryGoNext()) { + finishWizard(); + } + } + }); + } else { + nextButton.setText(step.getNextButtonTitleResId()); + nextButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (tryGoNext()) { + setStep(nextStep); + } + } + }); + } + } + + public void finishWizardAbruptly() { + finishWizard(true); + } + + public void finishWizard() { + finishWizard(false); + } + + void finishWizard(boolean forceFinish) { + if (wizard != null && step != null) { + wizard.saveFinished(step, forceFinish); + } + activity.finish(); + } + + private boolean tryGoPrev() { + if (step == null) { + return true; + } else { + final Fragment fragment = getFragmentManager().findFragmentByTag(step.getFragmentTag()); + return fragment == null || step.onPrev(fragment); + } + } + + @Nonnull + private FragmentManager getFragmentManager() { + return activity.getSupportFragmentManager(); + } + + private boolean tryGoNext() { + if (step == null) { + return true; + } else { + final Fragment fragment = getFragmentManager().findFragmentByTag(step.getFragmentTag()); + return fragment == null || step.onNext(fragment); + } + } + + @Nonnull + private Fragment showFragment() { + final FragmentManager fm = getFragmentManager(); + final FragmentTransaction ft = fm.beginTransaction(); + + Fragment newFragment = fm.findFragmentByTag(step.getFragmentTag()); + + if (newFragment == null) { + newFragment = Fragment.instantiate(activity, step.getFragmentClass().getName(), step.getFragmentArgs()); + ft.add(R.id.acl_wizard_content, newFragment, step.getFragmentTag()); + } + + ft.commit(); + fm.executePendingTransactions(); + + return newFragment; + } + + private void hideFragment() { + final FragmentManager fm = getFragmentManager(); + final FragmentTransaction ft = fm.beginTransaction(); + + if (step != null) { + hideFragmentByTag(fm, ft, step.getFragmentTag()); + } + + ft.commit(); + fm.executePendingTransactions(); + } + + private void hideFragmentByTag(@Nonnull FragmentManager fm, @Nonnull FragmentTransaction ft, @Nonnull String fragmentTag) { + final Fragment oldFragment = fm.findFragmentByTag(fragmentTag); + if (oldFragment != null) { + ft.remove(oldFragment); + } + } + + public void onSaveInstanceState(@Nonnull Bundle out) { + out.putString(FLOW, wizard.getName()); + out.putString(STEP, step.getName()); + } + + public void onPause() { + if (wizard != null && step != null) { + wizard.saveLastStep(step); + } + } + + public void onBackPressed() { + FinishWizardConfirmationDialog.show(activity); + } + + /* + ********************************************************************** + * + * GETTERS + * + ********************************************************************** + */ + + public WizardStep getStep() { + return step; + } + + public WizardFlow getFlow() { + return wizard.getFlow(); + } + + public Wizard getWizard() { + return wizard; + } + + @Nullable + public View getPrevButton() { + return prevButton; + } + + public View getNextButton() { + return nextButton; + } + + /* + ********************************************************************** + * + * STATIC + * + ********************************************************************** + */ + + public static void startWizard(@Nonnull Wizards wizards, @Nonnull Context context) { + context.startActivity(createLaunchIntent(wizards, null, context)); + } + + public static void startWizard(@Nonnull Wizards wizards, @Nullable String name, @Nonnull Context context) { + context.startActivity(createLaunchIntent(wizards, name, context)); + } + + public static void continueWizard(@Nonnull Wizards wizards, @Nonnull String name, @Nonnull Context context) { + final Intent intent = createLaunchIntent(wizards, name, context); + + final Wizard wizard = wizards.getWizard(name); + final String step = wizard.getLastSavedStepName(); + tryPutStep(intent, step); + + context.startActivity(intent); + } + + public static void tryPutStep(@Nonnull Intent intent, @Nullable WizardStep step) { + tryPutStep(intent, step != null ? step.getName() : null); + } + + private static void tryPutStep(@Nonnull Intent intent, @Nullable String step) { + if (step != null) { + intent.putExtra(STEP, step); + } + } + + @Nonnull + private static Intent createLaunchIntent(@Nonnull Wizards wizards, @Nullable String name, @Nonnull Context context) { + final Intent intent = new Intent(context, wizards.getActivityClassName()); + intent.putExtra(FLOW, name); + intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + return intent; + } + +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/Wizards.java b/android-app/src/main/java/org/solovyev/android/wizard/Wizards.java new file mode 100644 index 00000000..23d6deb8 --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/Wizards.java @@ -0,0 +1,15 @@ +package org.solovyev.android.wizard; + +import android.app.Activity; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public interface Wizards { + + @Nonnull + Class getActivityClassName(); + + @Nonnull + public Wizard getWizard(@Nullable String name) throws IllegalArgumentException; +} diff --git a/android-app/src/main/java/org/solovyev/android/wizard/WizardsAware.java b/android-app/src/main/java/org/solovyev/android/wizard/WizardsAware.java new file mode 100644 index 00000000..73e5a1aa --- /dev/null +++ b/android-app/src/main/java/org/solovyev/android/wizard/WizardsAware.java @@ -0,0 +1,9 @@ +package org.solovyev.android.wizard; + +import javax.annotation.Nonnull; + +public interface WizardsAware { + + @Nonnull + Wizards getWizards(); +} diff --git a/android-app/src/main/res/drawable/default_abs__item_background_holo_dark.xml b/android-app/src/main/res/drawable/default_abs__item_background_holo_dark.xml index 0998eb96..5fa51ea9 100644 --- a/android-app/src/main/res/drawable/default_abs__item_background_holo_dark.xml +++ b/android-app/src/main/res/drawable/default_abs__item_background_holo_dark.xml @@ -23,10 +23,11 @@ - + - + - - - - - - - diff --git a/android-app/src/main/res/values-de/strings.xml b/android-app/src/main/res/values-de/strings.xml new file mode 100644 index 00000000..7be0abb2 --- /dev/null +++ b/android-app/src/main/res/values-de/strings.xml @@ -0,0 +1,8 @@ + + + Wollen Sie den Assistenten wirklich beenden? + Weiter + Zurück + Beenden + Wizard starten + \ No newline at end of file diff --git a/android-app/src/main/res/values-es/strings.xml b/android-app/src/main/res/values-es/strings.xml new file mode 100644 index 00000000..fb19f02e --- /dev/null +++ b/android-app/src/main/res/values-es/strings.xml @@ -0,0 +1,8 @@ + + + ¿Realmente quiere finalizar el asistente? + Siguiente + Atrás + Finalizar + Iniciar el asistente + \ No newline at end of file diff --git a/android-app/src/main/res/values-fr/strings.xml b/android-app/src/main/res/values-fr/strings.xml new file mode 100644 index 00000000..2d119b94 --- /dev/null +++ b/android-app/src/main/res/values-fr/strings.xml @@ -0,0 +1,8 @@ + + + Quitter l\'assistant ? + Suivant + Retour + Terminer + Commencer l\'assistant + \ No newline at end of file diff --git a/android-app/src/main/res/values-it/strings.xml b/android-app/src/main/res/values-it/strings.xml new file mode 100644 index 00000000..f210fae5 --- /dev/null +++ b/android-app/src/main/res/values-it/strings.xml @@ -0,0 +1,8 @@ + + + Vuoi veramente terminare la procedura guidata? + Successivo + Indietro + Termina + Avvia la procedura guidata + \ No newline at end of file diff --git a/android-app/src/main/res/values-pl/strings.xml b/android-app/src/main/res/values-pl/strings.xml new file mode 100644 index 00000000..7558c1df --- /dev/null +++ b/android-app/src/main/res/values-pl/strings.xml @@ -0,0 +1,8 @@ + + + Czy na pewno chcesz zakończyć konfigurację programu? + Następny + Wstecz + Koniec + Zacznij konfigurację + \ No newline at end of file diff --git a/android-app/src/main/res/values-pt-rBR/strings.xml b/android-app/src/main/res/values-pt-rBR/strings.xml new file mode 100644 index 00000000..e3fafa13 --- /dev/null +++ b/android-app/src/main/res/values-pt-rBR/strings.xml @@ -0,0 +1,8 @@ + + + Parar a configuração da aplicação? + Avançar + Voltar + Terminar + Iniciar assistente de configuração + \ No newline at end of file diff --git a/android-app/src/main/res/values-ru/strings.xml b/android-app/src/main/res/values-ru/strings.xml new file mode 100644 index 00000000..0acb3ee4 --- /dev/null +++ b/android-app/src/main/res/values-ru/strings.xml @@ -0,0 +1,8 @@ + + + Вы действительно хотите завершить визард? + Далее + Назад + Завершить + Начать визард + \ No newline at end of file diff --git a/android-app/src/main/res/values-uk/strings.xml b/android-app/src/main/res/values-uk/strings.xml new file mode 100644 index 00000000..bc89f9c1 --- /dev/null +++ b/android-app/src/main/res/values-uk/strings.xml @@ -0,0 +1,8 @@ + + + Ви дійсно бажаєте вийти з майстра? + Далі + Назад + Завершити + Запустити майстер + \ No newline at end of file diff --git a/android-app/src/main/res/values/strings.xml b/android-app/src/main/res/values/strings.xml new file mode 100644 index 00000000..86a94f0c --- /dev/null +++ b/android-app/src/main/res/values/strings.xml @@ -0,0 +1,8 @@ + + + Do you really want to finish wizard? + Next + Back + Finish + Start wizard + \ No newline at end of file diff --git a/android-app/src/main/res/values/theme_gray.xml b/android-app/src/main/res/values/theme_gray.xml index 84bcd6ef..3df5c3c2 100644 --- a/android-app/src/main/res/values/theme_gray.xml +++ b/android-app/src/main/res/values/theme_gray.xml @@ -115,32 +115,32 @@ match_parent - - - - - - - -