Application refactor

This commit is contained in:
serso 2016-01-08 21:01:56 +01:00
parent 72654932f2
commit 7f5d3c9fe4
29 changed files with 320 additions and 516 deletions

View File

@ -70,8 +70,8 @@ public class ActivityUi extends BaseUi {
public static boolean restartIfThemeChanged(@Nonnull Activity activity, @Nonnull Preferences.Gui.Theme oldTheme) { public static boolean restartIfThemeChanged(@Nonnull Activity activity, @Nonnull Preferences.Gui.Theme oldTheme) {
final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(App.getPreferences()); final Preferences.Gui.Theme newTheme = Preferences.Gui.theme.getPreference(App.getPreferences());
final int themeId = oldTheme.getThemeId(activity); final int themeId = oldTheme.getThemeFor(activity);
final int newThemeId = newTheme.getThemeId(activity); final int newThemeId = newTheme.getThemeFor(activity);
if (themeId != newThemeId) { if (themeId != newThemeId) {
Activities.restartActivity(activity); Activities.restartActivity(activity);
return true; return true;
@ -100,7 +100,7 @@ public class ActivityUi extends BaseUi {
final SharedPreferences preferences = App.getPreferences(); final SharedPreferences preferences = App.getPreferences();
theme = Preferences.Gui.getTheme(preferences); theme = Preferences.Gui.getTheme(preferences);
activity.setTheme(theme.getThemeId(activity)); activity.setTheme(theme.getThemeFor(activity));
layout = Preferences.Gui.getLayout(preferences); layout = Preferences.Gui.getLayout(preferences);
language = App.getLanguages().getCurrent(); language = App.getLanguages().getCurrent();
@ -109,7 +109,7 @@ public class ActivityUi extends BaseUi {
@Override @Override
public void onCreate(@Nonnull Activity activity) { public void onCreate(@Nonnull Activity activity) {
super.onCreate(activity); super.onCreate(activity);
App.getLanguages().updateLanguage(activity, false); App.getLanguages().updateContextLocale(activity, false);
if (activity instanceof CalculatorEventListener) { if (activity instanceof CalculatorEventListener) {
Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity); Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity);
@ -302,7 +302,7 @@ public class ActivityUi extends BaseUi {
} }
private void addHelpInfo(@Nonnull Activity activity, @Nonnull View root) { private void addHelpInfo(@Nonnull Activity activity, @Nonnull View root) {
if (CalculatorApplication.isMonkeyRunner(activity)) { if (App.isMonkeyRunner(activity)) {
if (root instanceof ViewGroup) { if (root instanceof ViewGroup) {
final TextView helperTextView = new TextView(activity); final TextView helperTextView = new TextView(activity);

View File

@ -184,46 +184,46 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
switch (calculatorEventType) { switch (calculatorEventType) {
case calculation_messages: case calculation_messages:
CalculatorActivityLauncher.showCalculationMessagesDialog(CalculatorApplication.getInstance(), (List<Message>) data); CalculatorActivityLauncher.showCalculationMessagesDialog(App.getApplication(), (List<Message>) data);
break; break;
case show_history: case show_history:
CalculatorActivityLauncher.showHistory(CalculatorApplication.getInstance()); CalculatorActivityLauncher.showHistory(App.getApplication());
break; break;
case show_history_detached: case show_history_detached:
CalculatorActivityLauncher.showHistory(CalculatorApplication.getInstance(), true); CalculatorActivityLauncher.showHistory(App.getApplication(), true);
break; break;
case show_functions: case show_functions:
CalculatorActivityLauncher.showFunctions(CalculatorApplication.getInstance()); CalculatorActivityLauncher.showFunctions(App.getApplication());
break; break;
case show_functions_detached: case show_functions_detached:
CalculatorActivityLauncher.showFunctions(CalculatorApplication.getInstance(), true); CalculatorActivityLauncher.showFunctions(App.getApplication(), true);
break; break;
case show_operators: case show_operators:
CalculatorActivityLauncher.showOperators(CalculatorApplication.getInstance()); CalculatorActivityLauncher.showOperators(App.getApplication());
break; break;
case show_operators_detached: case show_operators_detached:
CalculatorActivityLauncher.showOperators(CalculatorApplication.getInstance(), true); CalculatorActivityLauncher.showOperators(App.getApplication(), true);
break; break;
case show_vars: case show_vars:
CalculatorActivityLauncher.showVars(CalculatorApplication.getInstance()); CalculatorActivityLauncher.showVars(App.getApplication());
break; break;
case show_vars_detached: case show_vars_detached:
CalculatorActivityLauncher.showVars(CalculatorApplication.getInstance(), true); CalculatorActivityLauncher.showVars(App.getApplication(), true);
break; break;
case show_settings: case show_settings:
CalculatorActivityLauncher.showSettings(CalculatorApplication.getInstance()); CalculatorActivityLauncher.showSettings(App.getApplication());
break; break;
case show_settings_detached: case show_settings_detached:
CalculatorActivityLauncher.showSettings(CalculatorApplication.getInstance(), true); CalculatorActivityLauncher.showSettings(App.getApplication(), true);
break; break;
case show_settings_widget: case show_settings_widget:
CalculatorActivityLauncher.showWidgetSettings(CalculatorApplication.getInstance(), true); CalculatorActivityLauncher.showWidgetSettings(App.getApplication(), true);
break; break;
case show_like_dialog: case show_like_dialog:
CalculatorActivityLauncher.likeButtonPressed(CalculatorApplication.getInstance()); CalculatorActivityLauncher.likeButtonPressed(App.getApplication());
break; break;
case open_app: case open_app:
CalculatorActivityLauncher.openApp(CalculatorApplication.getInstance()); CalculatorActivityLauncher.openApp(App.getApplication());
break; break;
} }
} }

View File

@ -25,10 +25,13 @@ package org.solovyev.android.calculator;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Build; import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -37,13 +40,16 @@ import android.support.v4.app.FragmentTransaction;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import org.solovyev.android.Check;
import org.solovyev.android.UiThreadExecutor; import org.solovyev.android.UiThreadExecutor;
import org.solovyev.android.Views; import org.solovyev.android.Views;
import org.solovyev.android.calculator.ga.Ga; import org.solovyev.android.calculator.ga.Ga;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService; import org.solovyev.android.calculator.onscreen.CalculatorOnscreenService;
import org.solovyev.android.calculator.view.ScreenMetrics; import org.solovyev.android.calculator.view.ScreenMetrics;
import org.solovyev.android.calculator.wizard.CalculatorWizards;
import org.solovyev.android.checkout.*; import org.solovyev.android.checkout.*;
import org.solovyev.android.wizard.Wizards;
import org.solovyev.common.listeners.JEvent; import org.solovyev.common.listeners.JEvent;
import org.solovyev.common.listeners.JEventListener; import org.solovyev.common.listeners.JEventListener;
import org.solovyev.common.listeners.JEventListeners; import org.solovyev.common.listeners.JEventListeners;
@ -54,6 +60,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
/** /**
* User: serso * User: serso
@ -69,7 +76,7 @@ import java.util.concurrent.Executor;
*/ */
public final class App { public final class App {
public static final String TAG = "Calculator++"; public static final String TAG = "C++";
@Nonnull @Nonnull
public static String subTag(@Nonnull String subTag) { public static String subTag(@Nonnull String subTag) {
@ -84,7 +91,7 @@ public final class App {
@Nonnull @Nonnull
private static final Products products = Products.create().add(ProductTypes.IN_APP, Arrays.asList("ad_free")); private static final Products products = Products.create().add(ProductTypes.IN_APP, Arrays.asList("ad_free"));
@Nonnull @Nonnull
private static final Languages languages = new Languages(); private static Languages languages;
@Nonnull @Nonnull
private static volatile Application application; private static volatile Application application;
@Nonnull @Nonnull
@ -102,59 +109,60 @@ public final class App {
private static volatile Billing billing; private static volatile Billing billing;
@Nullable @Nullable
private static Boolean lg = null; private static Boolean lg = null;
@Nullable
private static Typeface typeFace;
@Nonnull @Nonnull
private static volatile ScreenMetrics screenMetrics; private static volatile ScreenMetrics screenMetrics;
@Nonnull
private static final Handler handler = new Handler(Looper.getMainLooper());
@Nonnull
private static Wizards wizards;
@Nonnull
private static final Executor initializer = Executors.newSingleThreadExecutor();
private App() { private App() {
throw new AssertionError(); throw new AssertionError();
} }
/* public static void init(@Nonnull Application application, @Nonnull Languages languages) {
********************************************************************** init(application, new UiThreadExecutor(), Listeners.newEventBus(), languages);
*
* METHODS
*
**********************************************************************
*/
public static void init(@Nonnull Application application) {
init(application, new UiThreadExecutor(), Listeners.newEventBus());
} }
public static void init(@Nonnull Application application, public static void init(@Nonnull Application application,
@Nonnull UiThreadExecutor uiThreadExecutor, @Nonnull UiThreadExecutor uiThreadExecutor,
@Nonnull JEventListeners<JEventListener<? extends JEvent>, JEvent> eventBus) { @Nonnull JEventListeners<JEventListener<? extends JEvent>, JEvent> eventBus,
if (!initialized) { @Nonnull Languages languages) {
App.application = application; if (initialized) {
App.preferences = PreferenceManager.getDefaultSharedPreferences(application);
App.uiThreadExecutor = uiThreadExecutor;
App.eventBus = eventBus;
App.ga = new Ga(application, preferences, eventBus);
App.billing = new Billing(application, new Billing.DefaultConfiguration() {
@Nonnull
@Override
public String getPublicKey() {
return CalculatorSecurity.getPK();
}
@Nullable
@Override
public Inventory getFallbackInventory(@Nonnull Checkout checkout, @Nonnull Executor onLoadExecutor) {
if (RobotmediaDatabase.exists(billing.getContext())) {
return new RobotmediaInventory(checkout, onLoadExecutor);
} else {
return null;
}
}
});
App.broadcaster = new CalculatorBroadcaster(application, preferences);
App.screenMetrics = new ScreenMetrics(application);
App.languages.init(App.preferences);
App.initialized = true;
} else {
throw new IllegalStateException("Already initialized!"); throw new IllegalStateException("Already initialized!");
} }
App.application = application;
App.preferences = PreferenceManager.getDefaultSharedPreferences(application);
App.uiThreadExecutor = uiThreadExecutor;
App.eventBus = eventBus;
App.ga = new Ga(application, preferences, eventBus);
App.billing = new Billing(application, new Billing.DefaultConfiguration() {
@Nonnull
@Override
public String getPublicKey() {
return CalculatorSecurity.getPK();
}
@Nullable
@Override
public Inventory getFallbackInventory(@Nonnull Checkout checkout, @Nonnull Executor onLoadExecutor) {
if (RobotmediaDatabase.exists(billing.getContext())) {
return new RobotmediaInventory(checkout, onLoadExecutor);
} else {
return null;
}
}
});
App.broadcaster = new CalculatorBroadcaster(application, preferences);
App.screenMetrics = new ScreenMetrics(application);
App.languages = languages;
App.wizards = new CalculatorWizards(application);
App.initialized = true;
} }
private static void checkInit() { private static void checkInit() {
@ -163,21 +171,13 @@ public final class App {
} }
} }
/**
* @return if App has already been initialized, false otherwise
*/
public static boolean isInitialized() {
return initialized;
}
/** /**
* @param <A> real type of application * @param <A> real type of application
* @return application instance which was provided in {@link App#init(android.app.Application)} method * @return application instance which was provided in {@link App#init} method
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Nonnull @Nonnull
public static <A extends Application> A getApplication() { public static <A extends Application> A getApplication() {
checkInit();
return (A) application; return (A) application;
} }
@ -188,7 +188,6 @@ public final class App {
*/ */
@Nonnull @Nonnull
public static DelayedExecutor getUiThreadExecutor() { public static DelayedExecutor getUiThreadExecutor() {
checkInit();
return uiThreadExecutor; return uiThreadExecutor;
} }
@ -197,7 +196,6 @@ public final class App {
*/ */
@Nonnull @Nonnull
public static JEventListeners<JEventListener<? extends JEvent>, JEvent> getEventBus() { public static JEventListeners<JEventListener<? extends JEvent>, JEvent> getEventBus() {
checkInit();
return eventBus; return eventBus;
} }
@ -206,6 +204,16 @@ public final class App {
return broadcaster; return broadcaster;
} }
@Nonnull
public static Wizards getWizards() {
return wizards;
}
@Nonnull
public static Handler getHandler() {
return handler;
}
@Nonnull @Nonnull
public static Ga getGa() { public static Ga getGa() {
return ga; return ga;
@ -240,6 +248,11 @@ public final class App {
return Preferences.Widget.getTheme(getPreferences()); return Preferences.Widget.getTheme(getPreferences());
} }
@Nonnull
public static Executor getInitializer() {
return initializer;
}
@Nonnull @Nonnull
public static Preferences.Gui.Theme getThemeIn(@Nonnull Context context) { public static Preferences.Gui.Theme getThemeIn(@Nonnull Context context) {
if (context instanceof CalculatorOnscreenService) { if (context instanceof CalculatorOnscreenService) {
@ -289,15 +302,24 @@ public final class App {
dialogFragment.show(ft, fragmentTag); dialogFragment.show(ft, fragmentTag);
} }
@NonNull
public static String toColorString(@ColorInt int color) {
return Integer.toHexString(color).substring(2);
}
@NonNull @NonNull
public static SpannableString colorString(@Nonnull String s, int color) { public static SpannableString colorString(@Nonnull String s, int color) {
final SpannableString spannable = new SpannableString(s); final SpannableString spannable = new SpannableString(s);
spannable.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable; return spannable;
} }
}
@Nonnull
public static Typeface getTypeFace() {
Check.isMainThread();
if (typeFace == null) {
typeFace = Typeface.createFromAsset(application.getAssets(), "fonts/Roboto-Regular.ttf");
}
return typeFace;
}
public static boolean isMonkeyRunner(@Nonnull Context context) {
// NOTE: this code is only for monkeyrunner
return context.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) == PackageManager.PERMISSION_GRANTED;
}
}

View File

@ -126,7 +126,7 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
// let's disable locking of screen for monkeyrunner // let's disable locking of screen for monkeyrunner
if (CalculatorApplication.isMonkeyRunner(activity)) { if (App.isMonkeyRunner(activity)) {
final KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE); final KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
//noinspection deprecation //noinspection deprecation
km.newKeyguardLock(activity.getClass().getName()).disableKeyguard(); km.newKeyguardLock(activity.getClass().getName()).disableKeyguard();
@ -145,7 +145,7 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
protected void fixFonts(@Nonnull View root) { protected void fixFonts(@Nonnull View root) {
// some devices ship own fonts which causes issues with rendering. Let's use our own font for all text views // some devices ship own fonts which causes issues with rendering. Let's use our own font for all text views
final Typeface typeFace = CalculatorApplication.getInstance().getTypeFace(); final Typeface typeFace = App.getTypeFace();
Views.processViewsOfType(root, TextView.class, new Views.ViewProcessor<TextView>() { Views.processViewsOfType(root, TextView.class, new Views.ViewProcessor<TextView>() {
@Override @Override
public void process(@Nonnull TextView view) { public void process(@Nonnull TextView view) {

View File

@ -86,10 +86,10 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
Preferences.appVersion.putPreference(preferences, appVersion); Preferences.appVersion.putPreference(preferences, appVersion);
if (!CalculatorApplication.isMonkeyRunner(context)) { if (!App.isMonkeyRunner(context)) {
boolean dialogShown = false; boolean dialogShown = false;
final Wizards wizards = CalculatorApplication.getInstance().getWizards(); final Wizards wizards = App.getWizards();
final Wizard wizard = wizards.getWizard(CalculatorWizards.FIRST_TIME_WIZARD); final Wizard wizard = wizards.getWizard(CalculatorWizards.FIRST_TIME_WIZARD);
if (wizard.isStarted() && !wizard.isFinished()) { if (wizard.isStarted() && !wizard.isFinished()) {
continueWizard(wizards, wizard.getName(), context); continueWizard(wizards, wizard.getName(), context);
@ -186,7 +186,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
Locator.getInstance().getPreferenceService().checkPreferredPreferences(false); Locator.getInstance().getPreferenceService().checkPreferredPreferences(false);
if (CalculatorApplication.isMonkeyRunner(this)) { if (App.isMonkeyRunner(this)) {
Locator.getInstance().getKeyboard().buttonPressed("123"); Locator.getInstance().getKeyboard().buttonPressed("123");
Locator.getInstance().getKeyboard().buttonPressed("+"); Locator.getInstance().getKeyboard().buttonPressed("+");
Locator.getInstance().getKeyboard().buttonPressed("321"); Locator.getInstance().getKeyboard().buttonPressed("321");

View File

@ -42,7 +42,7 @@ public class CalculatorActivityMobile extends CalculatorActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (!CalculatorApplication.isMonkeyRunner(this)) { if (!App.isMonkeyRunner(this)) {
this.finish(); this.finish();
} }
} }

View File

@ -22,143 +22,50 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.util.TimingLogger;
import com.squareup.leakcanary.LeakCanary; import com.squareup.leakcanary.LeakCanary;
import org.acra.ACRA; import org.acra.ACRA;
import org.acra.ReportingInteractionMode; import org.acra.ACRAConfiguration;
import org.acra.annotation.ReportsCrashes; import org.acra.sender.HttpSender;
import org.solovyev.android.Android; import org.solovyev.android.Android;
import org.solovyev.android.calculator.history.AndroidCalculatorHistory; import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.onscreen.CalculatorOnscreenStartActivity; import org.solovyev.android.calculator.onscreen.CalculatorOnscreenStartActivity;
import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter; import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter;
import org.solovyev.android.calculator.plot.CalculatorPlotterImpl; import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
import org.solovyev.android.calculator.view.EditorTextProcessor; import org.solovyev.android.calculator.view.EditorTextProcessor;
import org.solovyev.android.calculator.wizard.CalculatorWizards;
import org.solovyev.android.wizard.Wizards;
import org.solovyev.common.msg.MessageType; import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
@ReportsCrashes(
formUri = "https://serso.cloudant.com/acra-cpp/_design/acra-storage/_update/report",
reportType = org.acra.sender.HttpSender.Type.JSON,
httpMethod = org.acra.sender.HttpSender.Method.PUT,
formUriBasicAuthLogin = "timbeenterumisideffecird",
formUriBasicAuthPassword = "ECL65PO2TH5quIFNAK4hQ5Ng",
mode = ReportingInteractionMode.TOAST,
resToastText = R.string.crashed)
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
public static final String AD_FREE_PRODUCT_ID = "ad_free";
public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free";
public static final String ADMOB = "ca-app-pub-2228934497384784/2916398892";
@Nonnull @Nonnull
static final String MAIL = "se.solovyev@gmail.com"; private final List<CalculatorEventListener> listeners = new ArrayList<>();
private static final String TAG = "C++";
@Nonnull
private static CalculatorApplication instance;
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@Nonnull
protected final Handler uiHandler = new Handler();
@Nonnull
private final List<CalculatorEventListener> listeners = new ArrayList<CalculatorEventListener>();
@Nonnull
private final Wizards wizards = new CalculatorWizards(this);
private Typeface typeFace;
/*
**********************************************************************
*
* CONSTRUCTORS
*
**********************************************************************
*/
public CalculatorApplication() {
instance = this;
}
/*
**********************************************************************
*
* METHODS
*
**********************************************************************
*/
@Nonnull
public static CalculatorApplication getInstance() {
return instance;
}
@Nonnull
public static SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(getInstance());
}
public static boolean isMonkeyRunner(@Nonnull Context context) {
// NOTE: this code is only for monkeyrunner
return context.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) == PackageManager.PERMISSION_GRANTED;
}
@Override @Override
public void onCreate() { public void onCreate() {
if (!BuildConfig.DEBUG) {
ACRA.init(this);
} else {
LeakCanary.install(this);
}
if (!App.isInitialized()) {
App.init(this);
}
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Preferences.setDefaultValues(preferences); final Languages languages = new Languages(preferences);
onPreCreate(preferences, languages);
super.onCreate();
onPostCreate(preferences, languages);
}
private void onPostCreate(@Nonnull SharedPreferences preferences, @Nonnull Languages languages) {
App.init(this, languages);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
languages.updateContextLocale(this, true);
setTheme(preferences); App.getGa().reportInitially(preferences);
setLanguageInitially();
super.onCreate();
App.getLanguages().updateLanguage(this, true);
if (!Preferences.Ga.initialReportDone.getPreference(preferences)) {
App.getGa().reportInitially(preferences);
Preferences.Ga.initialReportDone.putPreference(preferences, true);
}
final AndroidCalculator calculator = new AndroidCalculator(this); final AndroidCalculator calculator = new AndroidCalculator(this);
@ -186,86 +93,55 @@ public class CalculatorApplication extends android.app.Application implements Sh
Locator.getInstance().getCalculator().init(); Locator.getInstance().getCalculator().init();
new Thread(new Runnable() { App.getInitializer().execute(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
// prepare engine // warm-up engine
Locator.getInstance().getEngine().getMathEngine0().evaluate("1+1"); CalculatorMathEngine mathEngine = Locator.getInstance().getEngine().getMathEngine();
Locator.getInstance().getEngine().getMathEngine0().evaluate("1*1"); mathEngine.evaluate("1+1");
mathEngine.evaluate("1*1");
} catch (Throwable e) { } catch (Throwable e) {
Log.e(TAG, e.getMessage(), e); Log.e(App.TAG, e.getMessage(), e);
} }
} }
}).start(); });
Locator.getInstance().getLogger().debug(TAG, "Application started!"); App.getHandler().postDelayed(new Runnable() {
Locator.getInstance().getNotifier().showDebugMessage(TAG, "Application started!");
App.getUiThreadExecutor().execute(new Runnable() {
@Override @Override
public void run() { public void run() {
// we must update the widget when app starts // we must update the widget when app starts
App.getBroadcaster().sendEditorStateChangedIntent(); App.getBroadcaster().sendInitIntent();
} }
}, 100, TimeUnit.MILLISECONDS); }, 100);
} }
private void setLanguageInitially() { private void onPreCreate(@Nonnull SharedPreferences preferences, @Nonnull Languages languages) {
// should be called before onCreate() // first we need to setup crash handler and memory leak analyzer
final Language language = App.getLanguages().getCurrent(); if (!BuildConfig.DEBUG) {
ACRA.init(this, new ACRAConfiguration()
.setFormUri("https://serso.cloudant.com/acra-cpp/_design/acra-storage/_update/report")
.setReportType(HttpSender.Type.JSON)
.setHttpMethod(HttpSender.Method.PUT)
.setFormUriBasicAuthLogin("timbeenterumisideffecird")
.setFormUriBasicAuthPassword("ECL65PO2TH5quIFNAK4hQ5Ng"));
} else {
LeakCanary.install(this);
}
// then we should set default preferences
Preferences.setDefaultValues(preferences);
// and change application's theme/language is needed
final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(preferences);
setTheme(theme.theme);
final Language language = languages.getCurrent();
if (!language.isSystem() && !language.locale.equals(Locale.getDefault())) { if (!language.isSystem() && !language.locale.equals(Locale.getDefault())) {
Locale.setDefault(language.locale); Locale.setDefault(language.locale);
} }
} }
private void setTheme(@Nonnull SharedPreferences preferences) {
final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(preferences);
setTheme(theme.getThemeId());
}
@Nonnull
public FragmentUi createFragmentHelper(int layoutId) {
return new FragmentUi(layoutId);
}
@Nonnull
public FragmentUi createFragmentHelper(int layoutId, int titleResId) {
return new FragmentUi(layoutId, titleResId);
}
@Nonnull
public FragmentUi createFragmentHelper(int layoutId, int titleResId, boolean listenersOnCreate) {
return new FragmentUi(layoutId, titleResId, listenersOnCreate);
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
@Nonnull
public Handler getUiHandler() {
return uiHandler;
}
@Nonnull
public Wizards getWizards() {
return wizards;
}
@Nonnull
public Typeface getTypeFace() {
if (typeFace == null) {
typeFace = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
}
return typeFace;
}
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (Preferences.Onscreen.showAppIcon.getKey().equals(key)) { if (Preferences.Onscreen.showAppIcon.getKey().equals(key)) {

View File

@ -43,6 +43,10 @@ public final class CalculatorBroadcaster implements CalculatorEventListener, Sha
sendBroadcastIntent(ACTION_EDITOR_STATE_CHANGED); sendBroadcastIntent(ACTION_EDITOR_STATE_CHANGED);
} }
public void sendInitIntent() {
sendBroadcastIntent(ACTION_INIT);
}
public void sendBroadcastIntent(@Nonnull String action) { public void sendBroadcastIntent(@Nonnull String action) {
context.sendBroadcast(new Intent(action)); context.sendBroadcast(new Intent(action));
} }

View File

@ -51,9 +51,9 @@ public class CalculatorDisplayFragment extends Fragment {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(prefs); final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(prefs);
if (!layout.isOptimized()) { if (!layout.isOptimized()) {
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display_mobile, R.string.result); fragmentUi = new FragmentUi(R.layout.cpp_app_display_mobile, R.string.result);
} else { } else {
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display, R.string.result); fragmentUi = new FragmentUi(R.layout.cpp_app_display, R.string.result);
} }
fragmentUi.onCreate(this); fragmentUi.onCreate(this);

View File

@ -81,9 +81,9 @@ public class CalculatorEditorFragment extends Fragment {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(prefs); final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(prefs);
if (!layout.isOptimized()) { if (!layout.isOptimized()) {
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_editor_mobile, R.string.editor); fragmentUi = new FragmentUi(R.layout.cpp_app_editor_mobile, R.string.editor);
} else { } else {
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_editor, R.string.editor); fragmentUi = new FragmentUi(R.layout.cpp_app_editor, R.string.editor);
} }
fragmentUi.onCreate(this); fragmentUi.onCreate(this);

View File

@ -42,11 +42,11 @@ public abstract class CalculatorFragment extends Fragment {
private final FragmentUi fragmentUi; private final FragmentUi fragmentUi;
protected CalculatorFragment(int layoutResId, int titleResId) { protected CalculatorFragment(int layoutResId, int titleResId) {
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId); fragmentUi = new FragmentUi(layoutResId, titleResId);
} }
protected CalculatorFragment(@Nonnull CalculatorFragmentType fragmentType) { protected CalculatorFragment(@Nonnull CalculatorFragmentType fragmentType) {
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId()); fragmentUi = new FragmentUi(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
} }
protected CalculatorFragment(@Nonnull FragmentUi fragmentUi) { protected CalculatorFragment(@Nonnull FragmentUi fragmentUi) {

View File

@ -55,9 +55,9 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences); final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences);
if (!layout.isOptimized()) { if (!layout.isOptimized()) {
ui = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_keyboard_mobile); ui = new FragmentUi(R.layout.cpp_app_keyboard_mobile);
} else { } else {
ui = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_keyboard); ui = new FragmentUi(R.layout.cpp_app_keyboard);
} }
ui.onCreate(this); ui.onCreate(this);

View File

@ -42,11 +42,11 @@ public abstract class CalculatorListFragment extends ListFragment {
private final FragmentUi ui; private final FragmentUi ui;
protected CalculatorListFragment(int layoutResId, int titleResId) { protected CalculatorListFragment(int layoutResId, int titleResId) {
ui = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId); ui = new FragmentUi(layoutResId, titleResId);
} }
protected CalculatorListFragment(@Nonnull CalculatorFragmentType fragmentType) { protected CalculatorListFragment(@Nonnull CalculatorFragmentType fragmentType) {
ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId()); ui = new FragmentUi(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
} }
protected CalculatorListFragment(@Nonnull FragmentUi ui) { protected CalculatorListFragment(@Nonnull FragmentUi ui) {

View File

@ -31,31 +31,23 @@ import android.support.annotation.LayoutRes;
import android.support.annotation.StyleRes; import android.support.annotation.StyleRes;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import jscl.AngleUnit;
import jscl.NumeralBase;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
import org.solovyev.android.calculator.wizard.WizardActivity; import org.solovyev.android.calculator.wizard.WizardActivity;
import org.solovyev.android.prefs.BooleanPreference; import org.solovyev.android.prefs.*;
import org.solovyev.android.prefs.IntegerPreference;
import org.solovyev.android.prefs.LongPreference;
import org.solovyev.android.prefs.NumberToStringPreference;
import org.solovyev.android.prefs.Preference;
import org.solovyev.android.prefs.StringPreference;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.AngleUnit;
import jscl.NumeralBase;
import static org.solovyev.android.Android.isPhoneModel; import static org.solovyev.android.Android.isPhoneModel;
import static org.solovyev.android.DeviceModel.samsung_galaxy_s; import static org.solovyev.android.DeviceModel.samsung_galaxy_s;
import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2; import static org.solovyev.android.DeviceModel.samsung_galaxy_s_2;
@ -128,9 +120,6 @@ public final class Preferences {
applyDefaultPreference(preferences, Widget.theme); applyDefaultPreference(preferences, Widget.theme);
applyDefaultPreference(preferences, Ga.initialReportDone);
// renew value after each application start // renew value after each application start
Calculations.showCalculationMessagesDialog.putDefault(preferences); Calculations.showCalculationMessagesDialog.putDefault(preferences);
Calculations.lastPreferredPreferencesCheck.putDefault(preferences); Calculations.lastPreferredPreferencesCheck.putDefault(preferences);
@ -258,10 +247,6 @@ public final class Preferences {
} }
public static class Ga {
public static final Preference<Boolean> initialReportDone = BooleanPreference.of("ga.initial_report_done", false);
}
public static class Gui { public static class Gui {
public static final Preference<Theme> theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.material_theme, Theme.class); public static final Preference<Theme> theme = StringPreference.ofEnum("org.solovyev.android.calculator.CalculatorActivity_calc_theme", Theme.material_theme, Theme.class);
@ -300,39 +285,38 @@ public final class Preferences {
private static final SparseArray<TextColor> textColors = new SparseArray<>(); private static final SparseArray<TextColor> textColors = new SparseArray<>();
private final int themeId; @StyleRes
private final int wizardThemeId; public final int theme;
private final int dialogThemeId; @StyleRes
public final int wizardTheme;
@StyleRes
public final int dialogTheme;
public final boolean light; public final boolean light;
Theme(@StyleRes int themeId) { Theme(@StyleRes int theme) {
this(themeId, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Dialog_Material); this(theme, R.style.Cpp_Theme_Wizard, R.style.Cpp_Theme_Dialog_Material);
} }
Theme(@StyleRes int themeId, @StyleRes int wizardThemeId, int dialogThemeId) { Theme(@StyleRes int theme, @StyleRes int wizardTheme, @StyleRes int dialogTheme) {
this.themeId = themeId; this.theme = theme;
this.wizardThemeId = wizardThemeId; this.wizardTheme = wizardTheme;
this.dialogThemeId = dialogThemeId; this.dialogTheme = dialogTheme;
this.light = themeId == R.style.Cpp_Theme_Material_Light; this.light = theme == R.style.Cpp_Theme_Material_Light;
} }
public int getThemeId() { public int getThemeFor(@Nullable Context context) {
return getThemeId(null);
}
public int getThemeId(@Nullable Context context) {
if (context instanceof WizardActivity) { if (context instanceof WizardActivity) {
return wizardThemeId; return wizardTheme;
} }
if (context instanceof PurchaseDialogActivity) { if (context instanceof PurchaseDialogActivity) {
return dialogThemeId; return dialogTheme;
} }
return themeId; return theme;
} }
@Nonnull @Nonnull
public TextColor getTextColor(@Nonnull Context context) { public TextColor getTextColor(@Nonnull Context context) {
final int themeId = getThemeId(context); final int themeId = getThemeFor(context);
TextColor textColor = textColors.get(themeId); TextColor textColor = textColors.get(themeId);
if (textColor == null) { if (textColor == null) {
final ContextThemeWrapper themeContext = new ContextThemeWrapper(context, themeId); final ContextThemeWrapper themeContext = new ContextThemeWrapper(context, themeId);

View File

@ -32,35 +32,15 @@ import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.*;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.ListView;
import com.melnykov.fab.FloatingActionButton; import com.melnykov.fab.FloatingActionButton;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.FragmentUi;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.*;
import org.solovyev.android.menu.ActivityMenu;
import org.solovyev.android.menu.AndroidMenuHelper;
import org.solovyev.android.menu.ContextMenuBuilder;
import org.solovyev.android.menu.IdentifiableMenuItem;
import org.solovyev.android.menu.ListActivityMenu;
import org.solovyev.android.menu.ListContextMenu;
import org.solovyev.common.JPredicate; import org.solovyev.common.JPredicate;
import org.solovyev.common.collections.Collections; import org.solovyev.common.collections.Collections;
import org.solovyev.common.equals.Equalizer; import org.solovyev.common.equals.Equalizer;
@ -68,13 +48,12 @@ import org.solovyev.common.filter.Filter;
import org.solovyev.common.filter.FilterRulesChain; import org.solovyev.common.filter.FilterRulesChain;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.solovyev.android.calculator.CalculatorEventType.clear_history_requested; import static org.solovyev.android.calculator.CalculatorEventType.clear_history_requested;
public abstract class BaseHistoryFragment extends ListFragment implements CalculatorEventListener { public abstract class BaseHistoryFragment extends ListFragment implements CalculatorEventListener {
@ -126,7 +105,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
private AlertDialog clearDialog; private AlertDialog clearDialog;
protected BaseHistoryFragment(@Nonnull CalculatorFragmentType fragmentType) { protected BaseHistoryFragment(@Nonnull CalculatorFragmentType fragmentType) {
ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false); ui = new FragmentUi(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false);
} }
public static boolean isAlreadySaved(@Nonnull HistoryState historyState) { public static boolean isAlreadySaved(@Nonnull HistoryState historyState) {
@ -402,7 +381,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
toggle_datetime(R.id.menu_history_toggle_datetime) { toggle_datetime(R.id.menu_history_toggle_datetime) {
@Override @Override
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) { public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance()); final SharedPreferences preferences = App.getPreferences();
final Boolean showDatetime = Preferences.History.showDatetime.getPreference(preferences); final Boolean showDatetime = Preferences.History.showDatetime.getPreference(preferences);
Preferences.History.showDatetime.putPreference(preferences, !showDatetime); Preferences.History.showDatetime.putPreference(preferences, !showDatetime);
} }

View File

@ -29,7 +29,6 @@ import org.solovyev.common.history.SimpleHistoryHelper;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -37,11 +36,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.solovyev.android.calculator.CalculatorEventType.*; import static org.solovyev.android.calculator.CalculatorEventType.*;
/**
* User: Solovyev_S
* Date: 20.09.12
* Time: 16:12
*/
public class CalculatorHistoryImpl implements CalculatorHistory { public class CalculatorHistoryImpl implements CalculatorHistory {
private final AtomicInteger counter = new AtomicInteger(0); private final AtomicInteger counter = new AtomicInteger(0);
@ -50,7 +44,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
private final HistoryHelper<HistoryState> history = SimpleHistoryHelper.newInstance(); private final HistoryHelper<HistoryState> history = SimpleHistoryHelper.newInstance();
@Nonnull @Nonnull
private final List<HistoryState> savedHistory = new ArrayList<HistoryState>(); private final History savedHistory = new History();
@Nonnull @Nonnull
private final CalculatorEventHolder lastEventData = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId()); private final CalculatorEventHolder lastEventData = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId());
@ -188,7 +182,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
@Override @Override
@Nonnull @Nonnull
public List<HistoryState> getSavedHistory() { public List<HistoryState> getSavedHistory() {
return Collections.unmodifiableList(savedHistory); return Collections.unmodifiableList(savedHistory.getItems());
} }
@Override @Override
@ -222,21 +216,25 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
public void fromXml(@Nonnull String xml) { public void fromXml(@Nonnull String xml) {
clearSavedHistory(); clearSavedHistory();
HistoryUtils.fromXml(xml, this.savedHistory); final History history = History.fromXml(xml);
for (HistoryState historyState : savedHistory) { if (history == null) {
return;
}
for (HistoryState historyState : history.getItems()) {
historyState.setSaved(true); historyState.setSaved(true);
historyState.setId(counter.incrementAndGet()); historyState.setId(counter.incrementAndGet());
savedHistory.add(historyState);
} }
} }
@Override @Override
public String toXml() { public String toXml() {
return HistoryUtils.toXml(this.savedHistory); return savedHistory.toXml();
} }
@Override @Override
public void clearSavedHistory() { public void clearSavedHistory() {
this.savedHistory.clear(); savedHistory.clear();
} }
@Override @Override

View File

@ -24,26 +24,64 @@ package org.solovyev.android.calculator.history;
import org.simpleframework.xml.ElementList; import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root; import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.StringWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* User: serso
* Date: 12/17/11
* Time: 9:30 PM
*/
@Root @Root
public class History { public class History {
@ElementList(type = HistoryState.class) @Nonnull
private List<HistoryState> historyItems = new ArrayList<HistoryState>(); @ElementList(type = HistoryState.class, name = "historyItems")
private List<HistoryState> items = new ArrayList<HistoryState>();
public History() { public History() {
} }
public List<HistoryState> getHistoryItems() { @Nullable
return historyItems; public static History fromXml(@Nullable String xml) {
if (xml == null) {
return null;
}
final Serializer serializer = new Persister();
try {
return serializer.read(History.class, xml);
} catch (Exception e) {
return null;
}
}
@Nonnull
public String toXml() {
final StringWriter xml = new StringWriter();
final Serializer serializer = new Persister();
try {
serializer.write(this, xml);
} catch (Exception e) {
return "";
}
return xml.toString();
}
@Nonnull
public List<HistoryState> getItems() {
return items;
}
public void add(@Nonnull HistoryState state) {
items.add(state);
}
public void clear() {
items.clear();
}
public void remove(@Nonnull HistoryState state) {
items.remove(state);
} }
} }

View File

@ -22,57 +22,11 @@
package org.solovyev.android.calculator.history; package org.solovyev.android.calculator.history;
import org.simpleframework.xml.Serializer; final class HistoryUtils {
import org.simpleframework.xml.core.Persister;
import java.io.StringWriter;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* User: serso
* Date: 12/17/11
* Time: 9:59 PM
*/
class HistoryUtils {
// not intended for instantiation // not intended for instantiation
private HistoryUtils() { private HistoryUtils() {
throw new AssertionError(); throw new AssertionError();
} }
public static void fromXml(@Nullable String xml, @Nonnull List<HistoryState> historyItems) {
if (xml != null) {
final Serializer serializer = new Persister();
try {
final History history = serializer.read(History.class, xml);
for (HistoryState historyItem : history.getHistoryItems()) {
historyItems.add(historyItem);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@Nonnull
public static String toXml(@Nonnull List<HistoryState> historyItems) {
final History history = new History();
for (HistoryState historyState : historyItems) {
if (historyState.isSaved()) {
history.getHistoryItems().add(historyState);
}
}
final StringWriter xml = new StringWriter();
final Serializer serializer = new Persister();
try {
serializer.write(history, xml);
} catch (Exception e) {
throw new RuntimeException(e);
}
return xml.toString();
}
} }

View File

@ -7,19 +7,13 @@ import android.content.res.Resources;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.*;
public final class Languages implements SharedPreferences.OnSharedPreferenceChangeListener { public final class Languages implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -31,6 +25,13 @@ public final class Languages implements SharedPreferences.OnSharedPreferenceChan
private static final Locale[] locales = Locale.getAvailableLocales(); private static final Locale[] locales = Locale.getAvailableLocales();
@Nonnull @Nonnull
private final List<Language> list = new ArrayList<>(); private final List<Language> list = new ArrayList<>();
@Nonnull
private final SharedPreferences preferences;
public Languages(@Nonnull SharedPreferences preferences) {
this.preferences = preferences;
this.preferences.registerOnSharedPreferenceChangeListener(this);
}
@Nullable @Nullable
private static Language makeLanguage(@Nonnull String localeId) { private static Language makeLanguage(@Nonnull String localeId) {
@ -67,10 +68,6 @@ public final class Languages implements SharedPreferences.OnSharedPreferenceChan
return null; return null;
} }
public void init(@Nonnull SharedPreferences preferences) {
preferences.registerOnSharedPreferenceChangeListener(this);
}
@Nonnull @Nonnull
public List<Language> getList() { public List<Language> getList() {
Check.isMainThread(); Check.isMainThread();
@ -120,7 +117,7 @@ public final class Languages implements SharedPreferences.OnSharedPreferenceChan
@Nonnull @Nonnull
public Language getCurrent() { public Language getCurrent() {
return get(Preferences.Gui.language.getPreference(App.getPreferences())); return get(Preferences.Gui.language.getPreference(preferences));
} }
@Nonnull @Nonnull
@ -145,25 +142,26 @@ public final class Languages implements SharedPreferences.OnSharedPreferenceChan
@Override @Override
public void onSharedPreferenceChanged(@Nonnull SharedPreferences p, String key) { public void onSharedPreferenceChanged(@Nonnull SharedPreferences p, String key) {
if (Preferences.Gui.language.isSameKey(key)) { if (Preferences.Gui.language.isSameKey(key)) {
updateLanguage(App.getApplication(), false); updateContextLocale(App.getApplication(), false);
} }
} }
public void updateLanguage(@Nonnull Context context, boolean initial) { public void updateContextLocale(@Nonnull Context context, boolean initial) {
final Language language = getCurrent(); final Language language = getCurrent();
// we don't need to set system language while starting up the app // we don't need to set system language while starting up the app
if (!initial || !language.isSystem()) { if (initial && language.isSystem()) {
if (!Locale.getDefault().equals(language.locale)) { return;
Locale.setDefault(language.locale); }
} if (!Locale.getDefault().equals(language.locale)) {
Locale.setDefault(language.locale);
}
final Resources r = context.getResources(); final Resources r = context.getResources();
final DisplayMetrics dm = r.getDisplayMetrics(); final DisplayMetrics dm = r.getDisplayMetrics();
final Configuration c = r.getConfiguration(); final Configuration c = r.getConfiguration();
if (c.locale == null || !c.locale.equals(language.locale)) { if (c.locale == null || !c.locale.equals(language.locale)) {
c.locale = language.locale; c.locale = language.locale;
r.updateConfiguration(c, dm); r.updateConfiguration(c, dm);
}
} }
} }
} }

View File

@ -33,15 +33,7 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.CalculatorMathRegistry;
import org.solovyev.android.calculator.FragmentUi;
import org.solovyev.android.calculator.R;
import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.ContextMenuBuilder; import org.solovyev.android.menu.ContextMenuBuilder;
import org.solovyev.android.menu.LabeledMenuItem; import org.solovyev.android.menu.LabeledMenuItem;
@ -52,11 +44,10 @@ import org.solovyev.common.filter.Filter;
import org.solovyev.common.math.MathEntity; import org.solovyev.common.math.MathEntity;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import java.util.Comparator;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.List;
/** /**
@ -94,7 +85,7 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
private String category; private String category;
protected AbstractMathEntityListFragment(@Nonnull CalculatorFragmentType fragmentType) { protected AbstractMathEntityListFragment(@Nonnull CalculatorFragmentType fragmentType) {
ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId()); ui = new FragmentUi(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
} }
@Nonnull @Nonnull

View File

@ -98,7 +98,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
public AbstractCalculatorPlotFragment() { public AbstractCalculatorPlotFragment() {
super(CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_plot_fragment, R.string.c_graph, false)); super(new FragmentUi(R.layout.cpp_plot_fragment, R.string.c_graph, false));
} }
public static void applyToPaint(@Nonnull PlotLineDef plotLineDef, @Nonnull Paint paint) { public static void applyToPaint(@Nonnull PlotLineDef plotLineDef, @Nonnull Paint paint) {

View File

@ -10,12 +10,7 @@ import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.AdView;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.checkout.BillingRequests; import org.solovyev.android.checkout.BillingRequests;
@ -23,10 +18,9 @@ import org.solovyev.android.checkout.Checkout;
import org.solovyev.android.checkout.ProductTypes; import org.solovyev.android.checkout.ProductTypes;
import org.solovyev.android.checkout.RequestListener; import org.solovyev.android.checkout.RequestListener;
import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.precision; import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.precision;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.roundResult; import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.roundResult;
@ -81,7 +75,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
restartWizardPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { restartWizardPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
startWizard(CalculatorApplication.getInstance().getWizards(), DEFAULT_WIZARD_FLOW, getActivity()); startWizard(App.getWizards(), DEFAULT_WIZARD_FLOW, getActivity());
return true; return true;
} }
}); });
@ -105,7 +99,7 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
getCheckout().whenReady(new Checkout.ListenerAdapter() { getCheckout().whenReady(new Checkout.ListenerAdapter() {
@Override @Override
public void onReady(@Nonnull BillingRequests requests) { public void onReady(@Nonnull BillingRequests requests) {
requests.isPurchased(ProductTypes.IN_APP, CalculatorApplication.AD_FREE_PRODUCT_ID, new RequestListener<Boolean>() { requests.isPurchased(ProductTypes.IN_APP, "ad_free", new RequestListener<Boolean>() {
@Override @Override
public void onSuccess(@Nonnull Boolean purchased) { public void onSuccess(@Nonnull Boolean purchased) {
if (buyPremiumPreference != null) { if (buyPremiumPreference != null) {

View File

@ -41,28 +41,19 @@ import android.text.SpannedString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import org.solovyev.android.Check; import org.solovyev.android.Check;
import org.solovyev.android.Views; import org.solovyev.android.Views;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.CalculatorButton;
import org.solovyev.android.calculator.DisplayState;
import org.solovyev.android.calculator.EditorState;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.Preferences.SimpleTheme; import org.solovyev.android.calculator.Preferences.SimpleTheme;
import org.solovyev.android.calculator.R;
import java.util.EnumMap;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.EnumMap;
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT; import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT;
import static android.content.Intent.ACTION_CONFIGURATION_CHANGED; import static android.content.Intent.ACTION_CONFIGURATION_CHANGED;
import static android.os.Build.VERSION_CODES.JELLY_BEAN; import static android.os.Build.VERSION_CODES.JELLY_BEAN;
import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_DISPLAY_STATE_CHANGED; import static org.solovyev.android.calculator.CalculatorBroadcaster.*;
import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_EDITOR_STATE_CHANGED;
import static org.solovyev.android.calculator.CalculatorBroadcaster.ACTION_THEME_CHANGED;
import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClickedIntent; import static org.solovyev.android.calculator.CalculatorReceiver.newButtonClickedIntent;
public class CalculatorWidget extends AppWidgetProvider { public class CalculatorWidget extends AppWidgetProvider {
@ -211,6 +202,7 @@ public class CalculatorWidget extends AppWidgetProvider {
case ACTION_CONFIGURATION_CHANGED: case ACTION_CONFIGURATION_CHANGED:
case ACTION_APPWIDGET_OPTIONS_CHANGED: case ACTION_APPWIDGET_OPTIONS_CHANGED:
case ACTION_THEME_CHANGED: case ACTION_THEME_CHANGED:
case ACTION_INIT:
updateWidget(context, false); updateWidget(context, false);
break; break;
} }

View File

@ -27,13 +27,12 @@ import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Spinner; import android.widget.Spinner;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
import static org.solovyev.android.calculator.wizard.CalculatorLayout.big_buttons; import static org.solovyev.android.calculator.wizard.CalculatorLayout.big_buttons;
import static org.solovyev.android.calculator.wizard.CalculatorLayout.optimized; import static org.solovyev.android.calculator.wizard.CalculatorLayout.optimized;
@ -55,7 +54,7 @@ public class ChooseLayoutWizardStep extends WizardFragment implements AdapterVie
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
final CalculatorLayout layout = CalculatorLayout.fromGuiLayout(Preferences.Gui.layout.getPreference(getPreferences())); final CalculatorLayout layout = CalculatorLayout.fromGuiLayout(Preferences.Gui.layout.getPreference(App.getPreferences()));
image = (ImageView) root.findViewById(R.id.wizard_layout_image); image = (ImageView) root.findViewById(R.id.wizard_layout_image);
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_layout_spinner); final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_layout_spinner);
@ -78,7 +77,7 @@ public class ChooseLayoutWizardStep extends WizardFragment implements AdapterVie
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final CalculatorLayout layout = position == 0 ? big_buttons : optimized; final CalculatorLayout layout = position == 0 ? big_buttons : optimized;
layout.apply(getPreferences()); layout.apply(App.getPreferences());
updateImage(layout); updateImage(layout);
} }

View File

@ -27,25 +27,17 @@ import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
import static org.solovyev.android.calculator.wizard.CalculatorMode.engineer; import static org.solovyev.android.calculator.wizard.CalculatorMode.engineer;
import static org.solovyev.android.calculator.wizard.CalculatorMode.simple; import static org.solovyev.android.calculator.wizard.CalculatorMode.simple;
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.down; import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.*;
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.left;
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.up;
/**
* User: serso
* Date: 6/16/13
* Time: 9:59 PM
*/
public class ChooseModeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener { public class ChooseModeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener {
private DirectionDragButton button; private DirectionDragButton button;
@ -60,7 +52,7 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
final CalculatorMode mode = CalculatorMode.fromGuiLayout(Preferences.Gui.layout.getPreference(getPreferences())); final CalculatorMode mode = CalculatorMode.fromGuiLayout(Preferences.Gui.layout.getPreference(App.getPreferences()));
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner); final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_mode_spinner);
spinner.setAdapter(WizardArrayAdapter.create(getActivity(), R.array.cpp_modes)); spinner.setAdapter(WizardArrayAdapter.create(getActivity(), R.array.cpp_modes));
spinner.setSelection(mode == simple ? 0 : 1); spinner.setSelection(mode == simple ? 0 : 1);
@ -88,7 +80,7 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final CalculatorMode mode = position == 0 ? simple : engineer; final CalculatorMode mode = position == 0 ? simple : engineer;
mode.apply(getPreferences()); mode.apply(App.getPreferences());
updateDescription(mode); updateDescription(mode);
} }

View File

@ -30,17 +30,14 @@ import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.Spinner; import android.widget.Spinner;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
public class ChooseThemeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener { public class ChooseThemeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener {
@Nonnull @Nonnull
@ -57,7 +54,7 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(getPreferences()); final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(App.getPreferences());
final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_theme_spinner); final Spinner spinner = (Spinner) root.findViewById(R.id.wizard_theme_spinner);
themes.clear(); themes.clear();
themes.add(new ThemeUi(Preferences.Gui.Theme.material_theme, R.string.p_material_theme)); themes.add(new ThemeUi(Preferences.Gui.Theme.material_theme, R.string.p_material_theme));
@ -86,14 +83,14 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
private void updateImage(@Nonnull Preferences.Gui.Theme theme) { private void updateImage(@Nonnull Preferences.Gui.Theme theme) {
preview.removeAllViews(); preview.removeAllViews();
final ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), theme.getThemeId()); final ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), theme.theme);
LayoutInflater.from(context).inflate(R.layout.cpp_wizard_step_choose_theme_preview, preview); LayoutInflater.from(context).inflate(R.layout.cpp_wizard_step_choose_theme_preview, preview);
} }
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final ThemeUi theme = adapter.getItem(position); final ThemeUi theme = adapter.getItem(position);
Preferences.Gui.theme.putPreference(getPreferences(), theme.theme); Preferences.Gui.theme.putPreference(App.getPreferences(), theme.theme);
updateImage(theme.theme); updateImage(theme.theme);
} }

View File

@ -34,7 +34,6 @@ import org.solovyev.android.calculator.R;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
public class OnScreenCalculatorWizardStep extends WizardFragment implements CompoundButton.OnCheckedChangeListener { public class OnScreenCalculatorWizardStep extends WizardFragment implements CompoundButton.OnCheckedChangeListener {
@ -50,7 +49,7 @@ public class OnScreenCalculatorWizardStep extends WizardFragment implements Comp
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
final Boolean enabled = Preferences.Onscreen.showAppIcon.getPreference(getPreferences()); final Boolean enabled = Preferences.Onscreen.showAppIcon.getPreference(App.getPreferences());
checkbox = (CheckBox) root.findViewById(R.id.wizard_onscreen_app_enabled_checkbox); checkbox = (CheckBox) root.findViewById(R.id.wizard_onscreen_app_enabled_checkbox);
checkbox.setChecked(enabled); checkbox.setChecked(enabled);
checkbox.setOnCheckedChangeListener(this); checkbox.setOnCheckedChangeListener(this);
@ -68,7 +67,7 @@ public class OnScreenCalculatorWizardStep extends WizardFragment implements Comp
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) { public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
Preferences.Onscreen.showAppIcon.putPreference(getPreferences(), checked); Preferences.Onscreen.showAppIcon.putPreference(App.getPreferences(), checked);
} }
} }

View File

@ -8,22 +8,9 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import com.viewpagerindicator.PageIndicator; import com.viewpagerindicator.PageIndicator;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.ActivityUi; import org.solovyev.android.wizard.*;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.wizard.ListWizardFlow;
import org.solovyev.android.wizard.Wizard;
import org.solovyev.android.wizard.WizardFlow;
import org.solovyev.android.wizard.WizardStep;
import org.solovyev.android.wizard.WizardUi;
import org.solovyev.android.wizard.Wizards;
import org.solovyev.android.wizard.WizardsAware;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -38,7 +25,7 @@ public class WizardActivity extends BaseActivity implements WizardsAware, Shared
@Nonnull @Nonnull
private WizardPagerAdapter pagerAdapter; private WizardPagerAdapter pagerAdapter;
@Nonnull @Nonnull
private Wizards wizards = CalculatorApplication.getInstance().getWizards(); private Wizards wizards = App.getWizards();
@Nullable @Nullable
private AlertDialog dialog; private AlertDialog dialog;

View File

@ -140,24 +140,24 @@ public class HistoryUtilsTest {
DisplayState calculatorDisplay = DisplayState.createError(JsclOperation.simplify, "Error"); DisplayState calculatorDisplay = DisplayState.createError(JsclOperation.simplify, "Error");
CalculatorEditorViewState calculatorEditor = EditorState.create("1+1", 3); EditorState calculatorEditor = EditorState.create("1+1", 3);
HistoryState state = HistoryState.newInstance(calculatorEditor, calculatorDisplay); HistoryState state = HistoryState.create(calculatorEditor, calculatorDisplay);
state.setTime(date.getTime()); state.setTime(date.getTime());
history.addState(state); history.addState(state);
assertEquals(emptyHistory, HistoryUtils.toXml(history.getStates())); assertEquals(emptyHistory, History.toXml(history.getStates()));
state.setSaved(true); state.setSaved(true);
assertEquals(toXml1, HistoryUtils.toXml(history.getStates())); assertEquals(toXml1, History.toXml(history.getStates()));
calculatorDisplay = DisplayState.createValid(JsclOperation.numeric, null, "5/6", 3); calculatorDisplay = DisplayState.createValid(JsclOperation.numeric, null, "5/6", 3);
calculatorEditor = EditorState.create("5/6", 2); calculatorEditor = EditorState.create("5/6", 2);
state = HistoryState.newInstance(calculatorEditor, calculatorDisplay); state = HistoryState.create(calculatorEditor, calculatorDisplay);
state.setSaved(true); state.setSaved(true);
state.setTime(date.getTime()); state.setTime(date.getTime());
history.addState(state); history.addState(state);
@ -166,7 +166,7 @@ public class HistoryUtilsTest {
calculatorEditor = EditorState.create("", 1); calculatorEditor = EditorState.create("", 1);
state = HistoryState.newInstance(calculatorEditor, calculatorDisplay); state = HistoryState.create(calculatorEditor, calculatorDisplay);
state.setSaved(true); state.setSaved(true);
state.setTime(date.getTime()); state.setTime(date.getTime());
history.addState(state); history.addState(state);
@ -175,17 +175,17 @@ public class HistoryUtilsTest {
calculatorEditor = EditorState.create("4+5/35sin(41)+dfdsfsdfs", 0); calculatorEditor = EditorState.create("4+5/35sin(41)+dfdsfsdfs", 0);
state = HistoryState.newInstance(calculatorEditor, calculatorDisplay); state = HistoryState.create(calculatorEditor, calculatorDisplay);
state.setSaved(true); state.setSaved(true);
state.setTime(date.getTime()); state.setTime(date.getTime());
history.addState(state); history.addState(state);
String xml = HistoryUtils.toXml(history.getStates()); String xml = History.toXml(history.getStates());
assertEquals(toXml2, xml); assertEquals(toXml2, xml);
final List<HistoryState> fromXml = new ArrayList<HistoryState>(); final List<HistoryState> fromXml = new ArrayList<HistoryState>();
final HistoryHelper<HistoryState> historyFromXml = SimpleHistoryHelper.newInstance(); final HistoryHelper<HistoryState> historyFromXml = SimpleHistoryHelper.newInstance();
HistoryUtils.fromXml(xml, fromXml); History.fromXml(xml, fromXml);
for (HistoryState historyState : fromXml) { for (HistoryState historyState : fromXml) {
historyFromXml.addState(historyState); historyFromXml.addState(historyState);
} }