Changes
This commit is contained in:
@@ -1,183 +1,189 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.plot.GraphLineColor;
|
||||
import org.solovyev.android.prefs.BooleanPreference;
|
||||
import org.solovyev.android.prefs.IntegerPreference;
|
||||
import org.solovyev.android.prefs.Preference;
|
||||
import org.solovyev.android.prefs.StringPreference;
|
||||
import org.solovyev.android.view.VibratorContainer;
|
||||
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/20/12
|
||||
* Time: 12:42 PM
|
||||
*/
|
||||
public final class CalculatorPreferences {
|
||||
|
||||
private CalculatorPreferences() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final Preference<Integer> appVersion = new IntegerPreference("application.version", -1);
|
||||
public static final Preference<Integer> appOpenedCounter = new IntegerPreference("app_opened_counter", 0);
|
||||
|
||||
public static class Gui {
|
||||
|
||||
public static final Preference<Theme> theme = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.metro_blue_theme, Theme.class);
|
||||
public static final Preference<Layout> layout = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.main_calculator, Layout.class);
|
||||
public static final Preference<Boolean> feedbackWindowShown = new BooleanPreference("feedback_window_shown", false);
|
||||
public static final Preference<Boolean> notesppAnnounceShown = new BooleanPreference("notespp_announce_shown", false);
|
||||
public static final Preference<Boolean> showReleaseNotes = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
|
||||
public static final Preference<Boolean> usePrevAsBack = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false);
|
||||
public static final Preference<Boolean> showEqualsButton = new BooleanPreference("showEqualsButton", true);
|
||||
public static final Preference<Boolean> autoOrientation = new BooleanPreference("autoOrientation", true);
|
||||
public static final Preference<Boolean> hideNumeralBaseDigits = new BooleanPreference("hideNumeralBaseDigits", true);
|
||||
|
||||
@NotNull
|
||||
public static Theme getTheme(@NotNull SharedPreferences preferences) {
|
||||
return theme.getPreferenceNoError(preferences);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Layout getLayout(@NotNull SharedPreferences preferences) {
|
||||
return layout.getPreferenceNoError(preferences);
|
||||
}
|
||||
|
||||
public static enum Theme {
|
||||
|
||||
default_theme(ThemeType.other, R.style.default_theme),
|
||||
violet_theme(ThemeType.other, R.style.violet_theme),
|
||||
light_blue_theme(ThemeType.other, R.style.light_blue_theme),
|
||||
metro_blue_theme(ThemeType.metro, R.style.metro_blue_theme),
|
||||
metro_purple_theme(ThemeType.metro, R.style.metro_purple_theme),
|
||||
metro_green_theme(ThemeType.metro, R.style.metro_green_theme);
|
||||
|
||||
@NotNull
|
||||
private final ThemeType themeType;
|
||||
|
||||
@NotNull
|
||||
private final Integer themeId;
|
||||
|
||||
Theme(@NotNull ThemeType themeType, Integer themeId) {
|
||||
this.themeType = themeType;
|
||||
this.themeId = themeId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ThemeType getThemeType() {
|
||||
return themeType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Integer getThemeId() {
|
||||
return themeId;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ThemeType {
|
||||
metro,
|
||||
other
|
||||
}
|
||||
|
||||
public static enum Layout {
|
||||
main_calculator(R.layout.main_calculator),
|
||||
|
||||
// not used anymore
|
||||
@Deprecated
|
||||
main_cellphone(R.layout.main_calculator),
|
||||
|
||||
simple(R.layout.main_calculator);
|
||||
|
||||
private final int layoutId;
|
||||
|
||||
Layout(int layoutId) {
|
||||
this.layoutId = layoutId;
|
||||
}
|
||||
|
||||
public int getLayoutId() {
|
||||
return layoutId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Graph {
|
||||
public static final Preference<Boolean> interpolate = new BooleanPreference("graph_interpolate", true);
|
||||
public static final Preference<GraphLineColor> lineColorReal = StringPreference.newInstance("graph_line_color_real", GraphLineColor.white, GraphLineColor.class);
|
||||
public static final Preference<GraphLineColor> lineColorImag = StringPreference.newInstance("graph_line_color_imag", GraphLineColor.blue, GraphLineColor.class);
|
||||
}
|
||||
|
||||
|
||||
static void setDefaultValues(@NotNull SharedPreferences preferences) {
|
||||
if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) {
|
||||
final Locale locale = Locale.getDefault();
|
||||
if (locale != null) {
|
||||
final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
|
||||
int index = MathType.grouping_separator.getTokens().indexOf(String.valueOf(decimalFormatSymbols.getGroupingSeparator()));
|
||||
final String groupingSeparator;
|
||||
if (index >= 0) {
|
||||
groupingSeparator = MathType.grouping_separator.getTokens().get(index);
|
||||
} else {
|
||||
groupingSeparator = " ";
|
||||
}
|
||||
|
||||
AndroidCalculatorEngine.Preferences.groupingSeparator.putPreference(preferences, groupingSeparator);
|
||||
}
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.angleUnit.isSet(preferences)) {
|
||||
AndroidCalculatorEngine.Preferences.angleUnit.putDefault(preferences);
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.numeralBase.isSet(preferences)) {
|
||||
AndroidCalculatorEngine.Preferences.numeralBase.putDefault(preferences);
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.multiplicationSign.isSet(preferences)) {
|
||||
if ( AndroidUtils.isPhoneModel(AndroidUtils.PhoneModel.samsung_galaxy_s) || AndroidUtils.isPhoneModel(AndroidUtils.PhoneModel.samsung_galaxy_s_2) ) {
|
||||
// workaround ofr samsung galaxy s phones
|
||||
AndroidCalculatorEngine.Preferences.multiplicationSign.putPreference(preferences, "*");
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultPreference(preferences, Gui.theme);
|
||||
applyDefaultPreference(preferences, Gui.layout);
|
||||
if ( Gui.layout.getPreference(preferences) == Gui.Layout.main_cellphone ) {
|
||||
Gui.layout.putDefault(preferences);
|
||||
}
|
||||
applyDefaultPreference(preferences, Gui.feedbackWindowShown);
|
||||
applyDefaultPreference(preferences, Gui.notesppAnnounceShown);
|
||||
applyDefaultPreference(preferences, Gui.showReleaseNotes);
|
||||
applyDefaultPreference(preferences, Gui.usePrevAsBack);
|
||||
applyDefaultPreference(preferences, Gui.showEqualsButton);
|
||||
applyDefaultPreference(preferences, Gui.autoOrientation);
|
||||
applyDefaultPreference(preferences, Gui.hideNumeralBaseDigits);
|
||||
|
||||
applyDefaultPreference(preferences, Graph.interpolate);
|
||||
applyDefaultPreference(preferences, Graph.lineColorImag);
|
||||
applyDefaultPreference(preferences, Graph.lineColorReal);
|
||||
|
||||
if ( !VibratorContainer.Preferences.hapticFeedbackEnabled.isSet(preferences) ) {
|
||||
VibratorContainer.Preferences.hapticFeedbackEnabled.putPreference(preferences, true);
|
||||
}
|
||||
|
||||
if ( !VibratorContainer.Preferences.hapticFeedbackDuration.isSet(preferences) ) {
|
||||
VibratorContainer.Preferences.hapticFeedbackDuration.putPreference(preferences, 60L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void applyDefaultPreference(@NotNull SharedPreferences preferences, @NotNull Preference<?> preference) {
|
||||
if (!preference.isSet(preferences)) {
|
||||
preference.putDefault(preferences);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.plot.GraphLineColor;
|
||||
import org.solovyev.android.prefs.BooleanPreference;
|
||||
import org.solovyev.android.prefs.IntegerPreference;
|
||||
import org.solovyev.android.prefs.Preference;
|
||||
import org.solovyev.android.prefs.StringPreference;
|
||||
import org.solovyev.android.view.VibratorContainer;
|
||||
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/20/12
|
||||
* Time: 12:42 PM
|
||||
*/
|
||||
public final class CalculatorPreferences {
|
||||
|
||||
private CalculatorPreferences() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static final Preference<Integer> appVersion = new IntegerPreference("application.version", -1);
|
||||
public static final Preference<Integer> appOpenedCounter = new IntegerPreference("app_opened_counter", 0);
|
||||
|
||||
public static class Gui {
|
||||
|
||||
public static final Preference<Theme> theme = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.metro_blue_theme, Theme.class);
|
||||
public static final Preference<Layout> layout = StringPreference.newInstance("org.solovyev.android.calculator.CalculatorActivity_calc_layout", Layout.main_calculator, Layout.class);
|
||||
public static final Preference<Boolean> feedbackWindowShown = new BooleanPreference("feedback_window_shown", false);
|
||||
public static final Preference<Boolean> notesppAnnounceShown = new BooleanPreference("notespp_announce_shown", false);
|
||||
public static final Preference<Boolean> showReleaseNotes = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_show_release_notes", true);
|
||||
public static final Preference<Boolean> usePrevAsBack = new BooleanPreference("org.solovyev.android.calculator.CalculatorActivity_use_back_button_as_prev", false);
|
||||
public static final Preference<Boolean> showEqualsButton = new BooleanPreference("showEqualsButton", true);
|
||||
public static final Preference<Boolean> autoOrientation = new BooleanPreference("autoOrientation", true);
|
||||
public static final Preference<Boolean> hideNumeralBaseDigits = new BooleanPreference("hideNumeralBaseDigits", true);
|
||||
|
||||
@NotNull
|
||||
public static Theme getTheme(@NotNull SharedPreferences preferences) {
|
||||
return theme.getPreferenceNoError(preferences);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Layout getLayout(@NotNull SharedPreferences preferences) {
|
||||
return layout.getPreferenceNoError(preferences);
|
||||
}
|
||||
|
||||
public static enum Theme {
|
||||
|
||||
default_theme(ThemeType.other, R.style.default_theme),
|
||||
violet_theme(ThemeType.other, R.style.violet_theme),
|
||||
light_blue_theme(ThemeType.other, R.style.light_blue_theme),
|
||||
metro_blue_theme(ThemeType.metro, R.style.metro_blue_theme),
|
||||
metro_purple_theme(ThemeType.metro, R.style.metro_purple_theme),
|
||||
metro_green_theme(ThemeType.metro, R.style.metro_green_theme);
|
||||
|
||||
@NotNull
|
||||
private final ThemeType themeType;
|
||||
|
||||
@NotNull
|
||||
private final Integer themeId;
|
||||
|
||||
Theme(@NotNull ThemeType themeType, Integer themeId) {
|
||||
this.themeType = themeType;
|
||||
this.themeId = themeId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ThemeType getThemeType() {
|
||||
return themeType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Integer getThemeId() {
|
||||
return themeId;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ThemeType {
|
||||
metro,
|
||||
other
|
||||
}
|
||||
|
||||
public static enum Layout {
|
||||
main_calculator(R.layout.main_calculator),
|
||||
|
||||
// not used anymore
|
||||
@Deprecated
|
||||
main_cellphone(R.layout.main_calculator),
|
||||
|
||||
simple(R.layout.main_calculator);
|
||||
|
||||
private final int layoutId;
|
||||
|
||||
Layout(int layoutId) {
|
||||
this.layoutId = layoutId;
|
||||
}
|
||||
|
||||
public int getLayoutId() {
|
||||
return layoutId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Graph {
|
||||
public static final Preference<Boolean> interpolate = new BooleanPreference("graph_interpolate", true);
|
||||
public static final Preference<GraphLineColor> lineColorReal = StringPreference.newInstance("graph_line_color_real", GraphLineColor.white, GraphLineColor.class);
|
||||
public static final Preference<GraphLineColor> lineColorImag = StringPreference.newInstance("graph_line_color_imag", GraphLineColor.blue, GraphLineColor.class);
|
||||
}
|
||||
|
||||
public static class History {
|
||||
public static final Preference<Boolean> showIntermediateCalculations = new BooleanPreference("history_show_intermediate_calculations", false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void setDefaultValues(@NotNull SharedPreferences preferences) {
|
||||
if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) {
|
||||
final Locale locale = Locale.getDefault();
|
||||
if (locale != null) {
|
||||
final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
|
||||
int index = MathType.grouping_separator.getTokens().indexOf(String.valueOf(decimalFormatSymbols.getGroupingSeparator()));
|
||||
final String groupingSeparator;
|
||||
if (index >= 0) {
|
||||
groupingSeparator = MathType.grouping_separator.getTokens().get(index);
|
||||
} else {
|
||||
groupingSeparator = " ";
|
||||
}
|
||||
|
||||
AndroidCalculatorEngine.Preferences.groupingSeparator.putPreference(preferences, groupingSeparator);
|
||||
}
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.angleUnit.isSet(preferences)) {
|
||||
AndroidCalculatorEngine.Preferences.angleUnit.putDefault(preferences);
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.numeralBase.isSet(preferences)) {
|
||||
AndroidCalculatorEngine.Preferences.numeralBase.putDefault(preferences);
|
||||
}
|
||||
|
||||
if (!AndroidCalculatorEngine.Preferences.multiplicationSign.isSet(preferences)) {
|
||||
if ( AndroidUtils.isPhoneModel(AndroidUtils.PhoneModel.samsung_galaxy_s) || AndroidUtils.isPhoneModel(AndroidUtils.PhoneModel.samsung_galaxy_s_2) ) {
|
||||
// workaround ofr samsung galaxy s phones
|
||||
AndroidCalculatorEngine.Preferences.multiplicationSign.putPreference(preferences, "*");
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultPreference(preferences, Gui.theme);
|
||||
applyDefaultPreference(preferences, Gui.layout);
|
||||
if ( Gui.layout.getPreference(preferences) == Gui.Layout.main_cellphone ) {
|
||||
Gui.layout.putDefault(preferences);
|
||||
}
|
||||
applyDefaultPreference(preferences, Gui.feedbackWindowShown);
|
||||
applyDefaultPreference(preferences, Gui.notesppAnnounceShown);
|
||||
applyDefaultPreference(preferences, Gui.showReleaseNotes);
|
||||
applyDefaultPreference(preferences, Gui.usePrevAsBack);
|
||||
applyDefaultPreference(preferences, Gui.showEqualsButton);
|
||||
applyDefaultPreference(preferences, Gui.autoOrientation);
|
||||
applyDefaultPreference(preferences, Gui.hideNumeralBaseDigits);
|
||||
|
||||
applyDefaultPreference(preferences, Graph.interpolate);
|
||||
applyDefaultPreference(preferences, Graph.lineColorImag);
|
||||
applyDefaultPreference(preferences, Graph.lineColorReal);
|
||||
applyDefaultPreference(preferences, History.showIntermediateCalculations);
|
||||
|
||||
if ( !VibratorContainer.Preferences.hapticFeedbackEnabled.isSet(preferences) ) {
|
||||
VibratorContainer.Preferences.hapticFeedbackEnabled.putPreference(preferences, true);
|
||||
}
|
||||
|
||||
if ( !VibratorContainer.Preferences.hapticFeedbackDuration.isSet(preferences) ) {
|
||||
VibratorContainer.Preferences.hapticFeedbackDuration.putPreference(preferences, 60L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void applyDefaultPreference(@NotNull SharedPreferences preferences, @NotNull Preference<?> preference) {
|
||||
if (!preference.isSet(preferences)) {
|
||||
preference.putDefault(preferences);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,200 +1,203 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
import com.actionbarsherlock.app.SherlockPreferenceActivity;
|
||||
import net.robotmedia.billing.BillingController;
|
||||
import net.robotmedia.billing.IBillingObserver;
|
||||
import net.robotmedia.billing.ResponseCode;
|
||||
import net.robotmedia.billing.helper.AbstractBillingObserver;
|
||||
import net.robotmedia.billing.model.Transaction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.view.VibratorContainer;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 7/16/11
|
||||
* Time: 6:37 PM
|
||||
*/
|
||||
public class CalculatorPreferencesActivity extends SherlockPreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener, IBillingObserver {
|
||||
|
||||
public static final String CLEAR_BILLING_INFO = "clear_billing_info";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//noinspection deprecation
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
//noinspection deprecation
|
||||
addPreferencesFromResource(R.xml.plot_preferences);
|
||||
|
||||
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||
adFreePreference.setEnabled(false);
|
||||
|
||||
// observer must be set before net.robotmedia.billing.BillingController.checkBillingSupported()
|
||||
BillingController.registerObserver(this);
|
||||
|
||||
BillingController.checkBillingSupported(CalculatorPreferencesActivity.this);
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
onSharedPreferenceChanged(preferences, AndroidCalculatorEngine.Preferences.roundResult.getKey());
|
||||
onSharedPreferenceChanged(preferences, VibratorContainer.Preferences.hapticFeedbackEnabled.getKey());
|
||||
|
||||
final Preference clearBillingInfoPreference = findPreference(CLEAR_BILLING_INFO);
|
||||
if (clearBillingInfoPreference != null) {
|
||||
clearBillingInfoPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
||||
Toast.makeText(CalculatorPreferencesActivity.this, R.string.c_calc_clearing, Toast.LENGTH_SHORT).show();
|
||||
|
||||
removeBillingInformation(CalculatorPreferencesActivity.this, PreferenceManager.getDefaultSharedPreferences(CalculatorPreferencesActivity.this));
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeBillingInformation(@NotNull Context context, @NotNull SharedPreferences preferences) {
|
||||
final SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean(AbstractBillingObserver.KEY_TRANSACTIONS_RESTORED, false);
|
||||
editor.commit();
|
||||
|
||||
BillingController.dropBillingData(context);
|
||||
}
|
||||
|
||||
private void setAdFreeAction() {
|
||||
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||
|
||||
if (!AdsController.getInstance().isAdFree(this)) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Ad free is not purchased - enable preference!");
|
||||
|
||||
adFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
||||
// check billing availability
|
||||
if (BillingController.checkBillingSupported(CalculatorPreferencesActivity.this) != BillingController.BillingStatus.SUPPORTED) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is not supported - warn user!");
|
||||
// warn about not supported billing
|
||||
new AlertDialog.Builder(CalculatorPreferencesActivity.this).setTitle(R.string.c_error).setMessage(R.string.c_billing_error).create().show();
|
||||
} else {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is supported - continue!");
|
||||
if (!AdsController.getInstance().isAdFree(CalculatorPreferencesActivity.this)) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Item not purchased - try to purchase!");
|
||||
|
||||
// not purchased => purchasing
|
||||
Toast.makeText(CalculatorPreferencesActivity.this, R.string.c_calc_purchasing, Toast.LENGTH_SHORT).show();
|
||||
|
||||
// show purchase window for user
|
||||
BillingController.requestPurchase(CalculatorPreferencesActivity.this, CalculatorApplication.AD_FREE_PRODUCT_ID, true);
|
||||
} else {
|
||||
// disable preference
|
||||
adFreePreference.setEnabled(false);
|
||||
// and show message to user
|
||||
Toast.makeText(CalculatorPreferencesActivity.this, R.string.c_calc_already_purchased, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
adFreePreference.setEnabled(true);
|
||||
} else {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Ad free is not purchased - disable preference!");
|
||||
adFreePreference.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
BillingController.unregisterObserver(this);
|
||||
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (AndroidCalculatorEngine.Preferences.roundResult.getKey().equals(key)) {
|
||||
findPreference(AndroidCalculatorEngine.Preferences.precision.getKey()).setEnabled(preferences.getBoolean(key, AndroidCalculatorEngine.Preferences.roundResult.getDefaultValue()));
|
||||
} else if (VibratorContainer.Preferences.hapticFeedbackEnabled.getKey().equals(key)) {
|
||||
findPreference(VibratorContainer.Preferences.hapticFeedbackDuration.getKey()).setEnabled(VibratorContainer.Preferences.hapticFeedbackEnabled.getPreference(preferences));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckBillingSupportedResponse(boolean supported) {
|
||||
if (supported) {
|
||||
setAdFreeAction();
|
||||
} else {
|
||||
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||
adFreePreference.setEnabled(false);
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is not supported!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseIntentOK(@NotNull String productId, @NotNull PendingIntent purchaseIntent) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseIntentFailure(@NotNull String productId, @NotNull ResponseCode responseCode) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseStateChanged(@NotNull String itemId, @NotNull Transaction.PurchaseState state) {
|
||||
if (CalculatorApplication.AD_FREE_PRODUCT_ID.equals(itemId)) {
|
||||
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||
if (adFreePreference != null) {
|
||||
switch (state) {
|
||||
case PURCHASED:
|
||||
adFreePreference.setEnabled(false);
|
||||
// restart activity to disable ads
|
||||
AndroidUtils.restartActivity(this);
|
||||
break;
|
||||
case CANCELLED:
|
||||
adFreePreference.setEnabled(true);
|
||||
break;
|
||||
case REFUNDED:
|
||||
adFreePreference.setEnabled(true);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPurchaseResponse(@NotNull String itemId, @NotNull ResponseCode response) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionsRestored() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onErrorRestoreTransactions(@NotNull ResponseCode responseCode) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
import com.actionbarsherlock.app.SherlockPreferenceActivity;
|
||||
import net.robotmedia.billing.BillingController;
|
||||
import net.robotmedia.billing.IBillingObserver;
|
||||
import net.robotmedia.billing.ResponseCode;
|
||||
import net.robotmedia.billing.helper.AbstractBillingObserver;
|
||||
import net.robotmedia.billing.model.Transaction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.view.VibratorContainer;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 7/16/11
|
||||
* Time: 6:37 PM
|
||||
*/
|
||||
public class CalculatorPreferencesActivity extends SherlockPreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener, IBillingObserver {
|
||||
|
||||
public static final String CLEAR_BILLING_INFO = "clear_billing_info";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//noinspection deprecation
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
//noinspection deprecation
|
||||
addPreferencesFromResource(R.xml.calculations_preferences);
|
||||
addPreferencesFromResource(R.xml.appearance_preferences);
|
||||
addPreferencesFromResource(R.xml.plot_preferences);
|
||||
addPreferencesFromResource(R.xml.other_preferences);
|
||||
|
||||
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||
adFreePreference.setEnabled(false);
|
||||
|
||||
// observer must be set before net.robotmedia.billing.BillingController.checkBillingSupported()
|
||||
BillingController.registerObserver(this);
|
||||
|
||||
BillingController.checkBillingSupported(CalculatorPreferencesActivity.this);
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
onSharedPreferenceChanged(preferences, AndroidCalculatorEngine.Preferences.roundResult.getKey());
|
||||
onSharedPreferenceChanged(preferences, VibratorContainer.Preferences.hapticFeedbackEnabled.getKey());
|
||||
|
||||
final Preference clearBillingInfoPreference = findPreference(CLEAR_BILLING_INFO);
|
||||
if (clearBillingInfoPreference != null) {
|
||||
clearBillingInfoPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
||||
Toast.makeText(CalculatorPreferencesActivity.this, R.string.c_calc_clearing, Toast.LENGTH_SHORT).show();
|
||||
|
||||
removeBillingInformation(CalculatorPreferencesActivity.this, PreferenceManager.getDefaultSharedPreferences(CalculatorPreferencesActivity.this));
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeBillingInformation(@NotNull Context context, @NotNull SharedPreferences preferences) {
|
||||
final SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean(AbstractBillingObserver.KEY_TRANSACTIONS_RESTORED, false);
|
||||
editor.commit();
|
||||
|
||||
BillingController.dropBillingData(context);
|
||||
}
|
||||
|
||||
private void setAdFreeAction() {
|
||||
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||
|
||||
if (!AdsController.getInstance().isAdFree(this)) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Ad free is not purchased - enable preference!");
|
||||
|
||||
adFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
||||
// check billing availability
|
||||
if (BillingController.checkBillingSupported(CalculatorPreferencesActivity.this) != BillingController.BillingStatus.SUPPORTED) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is not supported - warn user!");
|
||||
// warn about not supported billing
|
||||
new AlertDialog.Builder(CalculatorPreferencesActivity.this).setTitle(R.string.c_error).setMessage(R.string.c_billing_error).create().show();
|
||||
} else {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is supported - continue!");
|
||||
if (!AdsController.getInstance().isAdFree(CalculatorPreferencesActivity.this)) {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Item not purchased - try to purchase!");
|
||||
|
||||
// not purchased => purchasing
|
||||
Toast.makeText(CalculatorPreferencesActivity.this, R.string.c_calc_purchasing, Toast.LENGTH_SHORT).show();
|
||||
|
||||
// show purchase window for user
|
||||
BillingController.requestPurchase(CalculatorPreferencesActivity.this, CalculatorApplication.AD_FREE_PRODUCT_ID, true);
|
||||
} else {
|
||||
// disable preference
|
||||
adFreePreference.setEnabled(false);
|
||||
// and show message to user
|
||||
Toast.makeText(CalculatorPreferencesActivity.this, R.string.c_calc_already_purchased, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
adFreePreference.setEnabled(true);
|
||||
} else {
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Ad free is not purchased - disable preference!");
|
||||
adFreePreference.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
BillingController.unregisterObserver(this);
|
||||
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (AndroidCalculatorEngine.Preferences.roundResult.getKey().equals(key)) {
|
||||
findPreference(AndroidCalculatorEngine.Preferences.precision.getKey()).setEnabled(preferences.getBoolean(key, AndroidCalculatorEngine.Preferences.roundResult.getDefaultValue()));
|
||||
} else if (VibratorContainer.Preferences.hapticFeedbackEnabled.getKey().equals(key)) {
|
||||
findPreference(VibratorContainer.Preferences.hapticFeedbackDuration.getKey()).setEnabled(VibratorContainer.Preferences.hapticFeedbackEnabled.getPreference(preferences));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckBillingSupportedResponse(boolean supported) {
|
||||
if (supported) {
|
||||
setAdFreeAction();
|
||||
} else {
|
||||
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||
adFreePreference.setEnabled(false);
|
||||
Log.d(CalculatorPreferencesActivity.class.getName(), "Billing is not supported!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseIntentOK(@NotNull String productId, @NotNull PendingIntent purchaseIntent) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseIntentFailure(@NotNull String productId, @NotNull ResponseCode responseCode) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPurchaseStateChanged(@NotNull String itemId, @NotNull Transaction.PurchaseState state) {
|
||||
if (CalculatorApplication.AD_FREE_PRODUCT_ID.equals(itemId)) {
|
||||
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
|
||||
if (adFreePreference != null) {
|
||||
switch (state) {
|
||||
case PURCHASED:
|
||||
adFreePreference.setEnabled(false);
|
||||
// restart activity to disable ads
|
||||
AndroidUtils.restartActivity(this);
|
||||
break;
|
||||
case CANCELLED:
|
||||
adFreePreference.setEnabled(true);
|
||||
break;
|
||||
case REFUNDED:
|
||||
adFreePreference.setEnabled(true);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPurchaseResponse(@NotNull String itemId, @NotNull ResponseCode response) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionsRestored() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onErrorRestoreTransactions(@NotNull ResponseCode responseCode) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
@@ -1,149 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.common.history.HistoryAction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/9/11
|
||||
* Time: 6:35 PM
|
||||
*/
|
||||
public class AndroidCalculatorHistory implements CalculatorHistory {
|
||||
|
||||
@NotNull
|
||||
private final CalculatorHistoryImpl calculatorHistory;
|
||||
|
||||
@NotNull
|
||||
private final Context context;
|
||||
|
||||
public AndroidCalculatorHistory(@NotNull Application application, @NotNull Calculator calculator) {
|
||||
this.context = application;
|
||||
calculatorHistory = new CalculatorHistoryImpl(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (preferences != null) {
|
||||
final String value = preferences.getString(context.getString(R.string.p_calc_history), null);
|
||||
if (value != null) {
|
||||
calculatorHistory.fromXml(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final SharedPreferences.Editor editor = settings.edit();
|
||||
|
||||
editor.putString(context.getString(R.string.p_calc_history), calculatorHistory.toXml());
|
||||
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public void clearSavedHistory() {
|
||||
calculatorHistory.clearSavedHistory();
|
||||
save();
|
||||
}
|
||||
|
||||
public void removeSavedHistory(@NotNull CalculatorHistoryState historyState) {
|
||||
historyState.setSaved(false);
|
||||
calculatorHistory.removeSavedHistory(historyState);
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return calculatorHistory.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorHistoryState getLastHistoryState() {
|
||||
return calculatorHistory.getLastHistoryState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUndoAvailable() {
|
||||
return calculatorHistory.isUndoAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorHistoryState undo(@Nullable CalculatorHistoryState currentState) {
|
||||
return calculatorHistory.undo(currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRedoAvailable() {
|
||||
return calculatorHistory.isRedoAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorHistoryState redo(@Nullable CalculatorHistoryState currentState) {
|
||||
return calculatorHistory.redo(currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActionAvailable(@NotNull HistoryAction historyAction) {
|
||||
return calculatorHistory.isActionAvailable(historyAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorHistoryState doAction(@NotNull HistoryAction historyAction, @Nullable CalculatorHistoryState currentState) {
|
||||
return calculatorHistory.doAction(historyAction, currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addState(@Nullable CalculatorHistoryState currentState) {
|
||||
calculatorHistory.addState(currentState);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<CalculatorHistoryState> getStates() {
|
||||
return calculatorHistory.getStates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
calculatorHistory.clear();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<CalculatorHistoryState> getSavedHistory() {
|
||||
return calculatorHistory.getSavedHistory();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorHistoryState addSavedState(@NotNull CalculatorHistoryState historyState) {
|
||||
return calculatorHistory.addSavedState(historyState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromXml(@NotNull String xml) {
|
||||
calculatorHistory.fromXml(xml);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toXml() {
|
||||
return calculatorHistory.toXml();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||
calculatorHistory.onCalculatorEvent(calculatorEventData, calculatorEventType, data);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.Calculator;
|
||||
import org.solovyev.android.calculator.CalculatorEventData;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.history.HistoryAction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/9/11
|
||||
* Time: 6:35 PM
|
||||
*/
|
||||
public class AndroidCalculatorHistory implements CalculatorHistory {
|
||||
|
||||
@NotNull
|
||||
private final CalculatorHistoryImpl calculatorHistory;
|
||||
|
||||
@NotNull
|
||||
private final Context context;
|
||||
|
||||
public AndroidCalculatorHistory(@NotNull Application application, @NotNull Calculator calculator) {
|
||||
this.context = application;
|
||||
calculatorHistory = new CalculatorHistoryImpl(calculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (preferences != null) {
|
||||
final String value = preferences.getString(context.getString(R.string.p_calc_history), null);
|
||||
if (value != null) {
|
||||
calculatorHistory.fromXml(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final SharedPreferences.Editor editor = settings.edit();
|
||||
|
||||
editor.putString(context.getString(R.string.p_calc_history), calculatorHistory.toXml());
|
||||
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public void clearSavedHistory() {
|
||||
calculatorHistory.clearSavedHistory();
|
||||
save();
|
||||
}
|
||||
|
||||
public void removeSavedHistory(@NotNull CalculatorHistoryState historyState) {
|
||||
historyState.setSaved(false);
|
||||
calculatorHistory.removeSavedHistory(historyState);
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return calculatorHistory.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorHistoryState getLastHistoryState() {
|
||||
return calculatorHistory.getLastHistoryState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUndoAvailable() {
|
||||
return calculatorHistory.isUndoAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorHistoryState undo(@Nullable CalculatorHistoryState currentState) {
|
||||
return calculatorHistory.undo(currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRedoAvailable() {
|
||||
return calculatorHistory.isRedoAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorHistoryState redo(@Nullable CalculatorHistoryState currentState) {
|
||||
return calculatorHistory.redo(currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActionAvailable(@NotNull HistoryAction historyAction) {
|
||||
return calculatorHistory.isActionAvailable(historyAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorHistoryState doAction(@NotNull HistoryAction historyAction, @Nullable CalculatorHistoryState currentState) {
|
||||
return calculatorHistory.doAction(historyAction, currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addState(@Nullable CalculatorHistoryState currentState) {
|
||||
calculatorHistory.addState(currentState);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<CalculatorHistoryState> getStates() {
|
||||
return calculatorHistory.getStates();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<CalculatorHistoryState> getStates(boolean includeIntermediateStates) {
|
||||
return calculatorHistory.getStates(includeIntermediateStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
calculatorHistory.clear();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<CalculatorHistoryState> getSavedHistory() {
|
||||
return calculatorHistory.getSavedHistory();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorHistoryState addSavedState(@NotNull CalculatorHistoryState historyState) {
|
||||
return calculatorHistory.addSavedState(historyState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromXml(@NotNull String xml) {
|
||||
calculatorHistory.fromXml(xml);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toXml() {
|
||||
return calculatorHistory.toXml();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||
calculatorHistory.onCalculatorEvent(calculatorEventData, calculatorEventType, data);
|
||||
}
|
||||
}
|
||||
|
@@ -6,8 +6,10 @@
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.preference.PreferenceManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
|
||||
@@ -33,7 +35,8 @@ public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<CalculatorHistoryState> getHistoryItems() {
|
||||
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getStates());
|
||||
final boolean showIntermediateCalculations = CalculatorPreferences.History.showIntermediateCalculations.getPreference(PreferenceManager.getDefaultSharedPreferences(getActivity()));
|
||||
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getStates(showIntermediateCalculations));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user