FixableErrorsActivity

This commit is contained in:
serso 2016-01-31 20:46:47 +01:00
parent 5f4d545511
commit af43970d9b
41 changed files with 539 additions and 773 deletions

View File

@ -71,12 +71,11 @@
android:label="@string/c_history" /> android:label="@string/c_history" />
<activity <activity
android:name=".FixableMessagesDialog" android:name=".errors.FixableErrorsActivity"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:finishOnTaskLaunch="true" android:finishOnTaskLaunch="true"
android:label="@string/calculation_messages_dialog_title"
android:launchMode="singleTask" android:launchMode="singleTask"
android:theme="@style/Cpp.Theme.Material.Dialog" /> android:theme="@style/Cpp.Theme.Translucent" />
<activity <activity
android:name=".about.CalculatorAboutActivity" android:name=".about.CalculatorAboutActivity"

View File

@ -1,44 +0,0 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import javax.annotation.Nullable;
public abstract class AbstractFixableError implements FixableError {
@Nullable
private String fixCaption;
protected AbstractFixableError() {
}
protected AbstractFixableError(@Nullable String fixCaption) {
this.fixCaption = fixCaption;
}
@Nullable
@Override
public CharSequence getFixCaption() {
return fixCaption;
}
}

View File

@ -25,20 +25,17 @@ package org.solovyev.android.calculator;
import android.app.Application; import android.app.Application;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import jscl.NumeralBase;
import jscl.math.Generic;
import org.solovyev.android.calculator.errors.FixableErrorsActivity;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.common.msg.Message; import org.solovyev.common.msg.Message;
import java.util.List;
import java.util.concurrent.Executor;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
import jscl.NumeralBase; import java.util.concurrent.Executor;
import jscl.math.Generic;
public class AndroidCalculator implements Calculator, CalculatorEventListener, SharedPreferences.OnSharedPreferenceChangeListener { public class AndroidCalculator implements Calculator, CalculatorEventListener, SharedPreferences.OnSharedPreferenceChangeListener {
@ -160,7 +157,7 @@ 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(App.getApplication(), (List<Message>) data); FixableErrorsActivity.show(App.getApplication(), (List<Message>) data);
break; break;
case show_history: case show_history:
CalculatorActivityLauncher.showHistory(App.getApplication()); CalculatorActivityLauncher.showHistory(App.getApplication());

View File

@ -1,115 +0,0 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import jscl.AngleUnit;
import jscl.NumeralBase;
import org.solovyev.android.msg.AndroidMessage;
import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
/**
* User: serso
* Date: 11/17/12
* Time: 7:46 PM
*/
public class AndroidCalculatorPreferenceService implements CalculatorPreferenceService {
// one hour
private static final Long PREFERRED_PREFS_INTERVAL_TIME = 1000L * 60L * 60L;
@Nonnull
private final Application application;
public AndroidCalculatorPreferenceService(@Nonnull Application application) {
this.application = application;
}
@Override
public void checkPreferredPreferences(boolean force) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(application);
final Long currentTime = System.currentTimeMillis();
if (force || (Preferences.Calculations.showCalculationMessagesDialog.getPreference(prefs) && isTimeForCheck(currentTime, prefs))) {
final NumeralBase preferredNumeralBase = Preferences.Calculations.preferredNumeralBase.getPreference(prefs);
final NumeralBase numeralBase = Engine.Preferences.numeralBase.getPreference(prefs);
final AngleUnit preferredAngleUnits = Preferences.Calculations.preferredAngleUnits.getPreference(prefs);
final AngleUnit angleUnits = Engine.Preferences.angleUnit.getPreference(prefs);
final List<FixableMessage> messages = new ArrayList<FixableMessage>(2);
if (numeralBase != preferredNumeralBase) {
messages.add(new FixableMessage(application.getString(R.string.preferred_numeral_base_message, preferredNumeralBase.name(), numeralBase.name()), MessageType.warning, CalculatorFixableError.preferred_numeral_base));
}
if (angleUnits != preferredAngleUnits) {
messages.add(new FixableMessage(application.getString(R.string.preferred_angle_units_message, preferredAngleUnits.name(), angleUnits.name()), MessageType.warning, CalculatorFixableError.preferred_angle_units));
}
FixableMessagesDialog.showDialog(messages, application, true);
Preferences.Calculations.lastPreferredPreferencesCheck.putPreference(prefs, currentTime);
}
}
private boolean isTimeForCheck(@Nonnull Long currentTime, @Nonnull SharedPreferences preferences) {
final Long lastPreferredPreferencesCheckTime = Preferences.Calculations.lastPreferredPreferencesCheck.getPreference(preferences);
return currentTime - lastPreferredPreferencesCheckTime > PREFERRED_PREFS_INTERVAL_TIME;
}
@Override
public void setPreferredAngleUnits() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
setAngleUnits(Preferences.Calculations.preferredAngleUnits.getPreference(preferences));
}
@Override
public void setAngleUnits(@Nonnull AngleUnit angleUnit) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
Engine.Preferences.angleUnit.putPreference(preferences, angleUnit);
Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_angle_units_changed_to, MessageType.info, application, angleUnit.name()));
}
@Override
public void setPreferredNumeralBase() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
setNumeralBase(Preferences.Calculations.preferredNumeralBase.getPreference(preferences));
}
@Override
public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(application);
Engine.Preferences.numeralBase.putPreference(preferences, numeralBase);
Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_numeral_base_changed_to, MessageType.info, application, numeralBase.name()));
}
}

View File

@ -1,6 +1,8 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import dagger.Component; import dagger.Component;
import org.solovyev.android.calculator.errors.FixableErrorFragment;
import org.solovyev.android.calculator.errors.FixableErrorsActivity;
import org.solovyev.android.calculator.functions.EditFunctionFragment; import org.solovyev.android.calculator.functions.EditFunctionFragment;
import org.solovyev.android.calculator.functions.FunctionsFragment; import org.solovyev.android.calculator.functions.FunctionsFragment;
import org.solovyev.android.calculator.history.BaseHistoryFragment; import org.solovyev.android.calculator.history.BaseHistoryFragment;
@ -21,10 +23,13 @@ public interface AppComponent {
void inject(CalculatorOnscreenService service); void inject(CalculatorOnscreenService service);
void inject(BaseHistoryFragment fragment); void inject(BaseHistoryFragment fragment);
void inject(BaseDialogFragment fragment); void inject(BaseDialogFragment fragment);
void inject(FixableErrorFragment fragment);
void inject(EditFunctionFragment fragment); void inject(EditFunctionFragment fragment);
void inject(EditVariableFragment fragment); void inject(EditVariableFragment fragment);
void inject(EditHistoryFragment fragment); void inject(EditHistoryFragment fragment);
void inject(FunctionsFragment fragment); void inject(FunctionsFragment fragment);
void inject(VariablesFragment fragment); void inject(VariablesFragment fragment);
void inject(OperatorsFragment fragment); void inject(OperatorsFragment fragment);
void inject(CalculatorActivity activity);
void inject(FixableErrorsActivity activity);
} }

View File

@ -6,8 +6,8 @@ import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MenuItem; import android.view.MenuItem;
import org.solovyev.android.calculator.entities.Category;
import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import org.solovyev.android.calculator.entities.BaseEntitiesFragment;
import org.solovyev.android.calculator.entities.Category;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -38,9 +38,13 @@ public class BaseActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
ui.onPreCreate(this); ui.onPreCreate(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
inject(((CalculatorApplication) getApplication()).getComponent());
ui.onCreate(this); ui.onCreate(this);
} }
protected void inject(@Nonnull AppComponent component) {
}
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -80,7 +84,6 @@ public class BaseActivity extends AppCompatActivity {
super.onPause(); super.onPause();
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();

View File

@ -20,7 +20,7 @@ import javax.inject.Inject;
public abstract class BaseDialogFragment extends DialogFragment { public abstract class BaseDialogFragment extends DialogFragment {
@Inject @Inject
SharedPreferences preferences; protected SharedPreferences preferences;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -38,10 +38,12 @@ public abstract class BaseDialogFragment extends DialogFragment {
final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(preferences); final Preferences.Gui.Theme theme = Preferences.Gui.getTheme(preferences);
final Context context = getActivity(); final Context context = getActivity();
final LayoutInflater inflater = LayoutInflater.from(context); final LayoutInflater inflater = LayoutInflater.from(context);
final View view = onCreateDialogView(context, inflater, savedInstanceState);
final int spacing = context.getResources().getDimensionPixelSize(R.dimen.cpp_dialog_spacing);
final AlertDialog.Builder b = new AlertDialog.Builder(context, theme.alertDialogTheme); final AlertDialog.Builder b = new AlertDialog.Builder(context, theme.alertDialogTheme);
final View view = onCreateDialogView(context, inflater, savedInstanceState);
if (view != null) {
final int spacing = context.getResources().getDimensionPixelSize(R.dimen.cpp_dialog_spacing);
b.setView(view, spacing, spacing, spacing, spacing); b.setView(view, spacing, spacing, spacing, spacing);
}
onPrepareDialog(b); onPrepareDialog(b);
final AlertDialog dialog = b.create(); final AlertDialog dialog = b.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() { dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@ -58,7 +60,7 @@ public abstract class BaseDialogFragment extends DialogFragment {
protected abstract void onPrepareDialog(@NonNull AlertDialog.Builder builder); protected abstract void onPrepareDialog(@NonNull AlertDialog.Builder builder);
@NonNull @Nullable
protected abstract View onCreateDialogView(@NonNull Context context, @NonNull LayoutInflater inflater, @Nullable Bundle savedInstanceState); protected abstract View onCreateDialogView(@NonNull Context context, @NonNull LayoutInflater inflater, @Nullable Bundle savedInstanceState);
protected void setError(@NonNull TextInputLayout textInput, @StringRes int error, Object... errorArgs) { protected void setError(@NonNull TextInputLayout textInput, @StringRes int error, Object... errorArgs) {

View File

@ -71,6 +71,11 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
private boolean useBackAsPrev; private boolean useBackAsPrev;
@Inject
PreferredPreferences preferredPreferences;
@Inject
Keyboard keyboard;
public CalculatorActivity() { public CalculatorActivity() {
super(0, TAG); super(0, TAG);
} }
@ -154,7 +159,7 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final Preferences.Gui.Layout layout = Preferences.Gui.layout.getPreferenceNoError(preferences); final Preferences.Gui.Layout layout = Preferences.Gui.layout.getPreferenceNoError(preferences);
ui.setLayoutId(layout.getLayoutId()); ui.setLayoutId(layout.layoutId);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -188,15 +193,21 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
Locator.getInstance().getPreferenceService().checkPreferredPreferences(false); preferredPreferences.check(this, false);
if (App.isMonkeyRunner(this)) { if (App.isMonkeyRunner(this)) {
Locator.getInstance().getKeyboard().buttonPressed("123"); keyboard.buttonPressed("123");
Locator.getInstance().getKeyboard().buttonPressed("+"); keyboard.buttonPressed("+");
Locator.getInstance().getKeyboard().buttonPressed("321"); keyboard.buttonPressed("321");
} }
} }
@Override
protected void inject(@Nonnull AppComponent component) {
super.inject(component);
component.inject(this);
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private boolean hasPermanentMenuKey() { private boolean hasPermanentMenuKey() {
return ViewConfiguration.get(this).hasPermanentMenuKey(); return ViewConfiguration.get(this).hasPermanentMenuKey();
@ -206,11 +217,6 @@ public class CalculatorActivity extends BaseActivity implements SharedPreference
return findViewById(R.id.main_second_pane) != null; return findViewById(R.id.main_second_pane) != null;
} }
@Nonnull
private AndroidCalculator getCalculator() {
return ((AndroidCalculator) Locator.getInstance().getCalculator());
}
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {

View File

@ -36,12 +36,14 @@ import jscl.math.Generic;
import jscl.math.function.Constant; import jscl.math.function.Constant;
import org.solovyev.android.Activities; import org.solovyev.android.Activities;
import org.solovyev.android.calculator.about.CalculatorAboutActivity; import org.solovyev.android.calculator.about.CalculatorAboutActivity;
import org.solovyev.android.calculator.errors.FixableError;
import org.solovyev.android.calculator.errors.FixableErrorsActivity;
import org.solovyev.android.calculator.functions.CppFunction; import org.solovyev.android.calculator.functions.CppFunction;
import org.solovyev.android.calculator.functions.EditFunctionFragment; import org.solovyev.android.calculator.functions.EditFunctionFragment;
import org.solovyev.android.calculator.functions.FunctionsActivity; import org.solovyev.android.calculator.functions.FunctionsActivity;
import org.solovyev.android.calculator.history.CalculatorHistoryActivity; import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
import org.solovyev.android.calculator.operators.OperatorsActivity;
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity; import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
import org.solovyev.android.calculator.operators.OperatorsActivity;
import org.solovyev.android.calculator.plot.CalculatorPlotActivity; import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
import org.solovyev.android.calculator.plot.CalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotter;
import org.solovyev.android.calculator.preferences.PreferencesActivity; import org.solovyev.android.calculator.preferences.PreferencesActivity;
@ -55,6 +57,7 @@ import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -169,7 +172,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
builder.withParameter(constant.getName()); builder.withParameter(constant.getName());
} }
} }
EditFunctionFragment.showDialog(builder.build(), context); EditFunctionFragment.show(builder.build(), context);
} else { } else {
getNotifier().showMessage(R.string.empty_function_error, MessageType.error); getNotifier().showMessage(R.string.empty_function_error, MessageType.error);
} }
@ -217,14 +220,6 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
context.startActivity(intent); context.startActivity(intent);
} }
public static void showCalculationMessagesDialog(@Nonnull Context context, @Nonnull List<Message> messages) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (Preferences.Calculations.showCalculationMessagesDialog.getPreference(prefs)) {
FixableMessagesDialog.showDialogForMessages(messages, context, true);
}
}
public static void showEvaluationError(@Nonnull Context context, @Nonnull final String errorMessage) { public static void showEvaluationError(@Nonnull Context context, @Nonnull final String errorMessage) {
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

View File

@ -94,6 +94,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
@Inject @Inject
ErrorReporter errorReporter; ErrorReporter errorReporter;
@Inject
PreferredPreferences preferredPreferences;
@Override @Override
public void onCreate() { public void onCreate() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
@ -123,7 +126,7 @@ public class CalculatorApplication extends android.app.Application implements Sh
engine, engine,
new AndroidCalculatorNotifier(this), new AndroidCalculatorNotifier(this),
errorReporter, errorReporter,
new AndroidCalculatorPreferenceService(this), preferredPreferences,
keyboard, keyboard,
new AndroidCalculatorPlotter(this, new CalculatorPlotterImpl(calculator)) new AndroidCalculatorPlotter(this, new CalculatorPlotterImpl(calculator))
); );

View File

@ -55,7 +55,7 @@ public final class CalculatorButtons {
public static void fixButtonsTextSize(@Nonnull Preferences.Gui.Theme theme, public static void fixButtonsTextSize(@Nonnull Preferences.Gui.Theme theme,
@Nonnull Preferences.Gui.Layout layout, @Nonnull Preferences.Gui.Layout layout,
@Nonnull View root) { @Nonnull View root) {
if (!layout.isOptimized()) { if (!layout.optimized) {
final ScreenMetrics metrics = App.getScreenMetrics(); final ScreenMetrics metrics = App.getScreenMetrics();
final boolean portrait = metrics.isInPortraitMode(); final boolean portrait = metrics.isInPortraitMode();
@ -85,7 +85,7 @@ public final class CalculatorButtons {
@Nonnull Activity activity) { @Nonnull Activity activity) {
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences; preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
final boolean large = App.isLargeScreen() && Preferences.Gui.getLayout(preferences).isOptimized(); final boolean large = App.isLargeScreen() && Preferences.Gui.getLayout(preferences).optimized;
if (!large) { if (!large) {
if (Views.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT if (Views.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT

View File

@ -50,7 +50,7 @@ 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.optimized) {
fragmentUi = new FragmentUi(R.layout.cpp_app_display_mobile, R.string.result); fragmentUi = new FragmentUi(R.layout.cpp_app_display_mobile, R.string.result);
} else { } else {
fragmentUi = new FragmentUi(R.layout.cpp_app_display, R.string.result); fragmentUi = new FragmentUi(R.layout.cpp_app_display, R.string.result);

View File

@ -80,7 +80,7 @@ public class CalculatorEditorFragment extends Fragment {
((CalculatorApplication) getActivity().getApplication()).getComponent().inject(this); ((CalculatorApplication) getActivity().getApplication()).getComponent().inject(this);
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences); final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences);
if (!layout.isOptimized()) { if (!layout.optimized) {
fragmentUi = new FragmentUi(R.layout.cpp_app_editor_mobile, R.string.editor); fragmentUi = new FragmentUi(R.layout.cpp_app_editor_mobile, R.string.editor);
} else { } else {
fragmentUi = new FragmentUi(R.layout.cpp_app_editor, R.string.editor); fragmentUi = new FragmentUi(R.layout.cpp_app_editor, R.string.editor);

View File

@ -78,7 +78,6 @@ public class CalculatorImpl implements Calculator {
private volatile long lastPreferenceCheck = 0L; private volatile long lastPreferenceCheck = 0L;
public CalculatorImpl(@Nonnull Bus bus, @Nonnull Executor eventExecutor) { public CalculatorImpl(@Nonnull Bus bus, @Nonnull Executor eventExecutor) {
this.eventExecutor = eventExecutor; this.eventExecutor = eventExecutor;
bus.register(this); bus.register(this);
@ -287,7 +286,7 @@ public class CalculatorImpl implements Calculator {
if (currentTime - lastPreferenceCheck > PREFERENCE_CHECK_INTERVAL) { if (currentTime - lastPreferenceCheck > PREFERENCE_CHECK_INTERVAL) {
lastPreferenceCheck = currentTime; lastPreferenceCheck = currentTime;
Locator.getInstance().getPreferenceService().checkPreferredPreferences(false); Locator.getInstance().getPreferenceService().check(false);
} }
} }

View File

@ -54,7 +54,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
final SharedPreferences preferences = App.getPreferences(); final SharedPreferences preferences = App.getPreferences();
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences); final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(preferences);
if (!layout.isOptimized()) { if (!layout.optimized) {
ui = new FragmentUi(R.layout.cpp_app_keyboard_mobile); ui = new FragmentUi(R.layout.cpp_app_keyboard_mobile);
} else { } else {
ui = new FragmentUi(R.layout.cpp_app_keyboard); ui = new FragmentUi(R.layout.cpp_app_keyboard);

View File

@ -32,7 +32,7 @@ public interface CalculatorLocator {
@Nonnull Engine engine, @Nonnull Engine engine,
@Nonnull CalculatorNotifier notifier, @Nonnull CalculatorNotifier notifier,
@Nonnull ErrorReporter errorReporter, @Nonnull ErrorReporter errorReporter,
@Nonnull CalculatorPreferenceService preferenceService, @Nonnull PreferredPreferences preferenceService,
@Nonnull Keyboard keyboard, @Nonnull Keyboard keyboard,
@Nonnull CalculatorPlotter plotter); @Nonnull CalculatorPlotter plotter);
@ -55,5 +55,5 @@ public interface CalculatorLocator {
CalculatorPlotter getPlotter(); CalculatorPlotter getPlotter();
@Nonnull @Nonnull
CalculatorPreferenceService getPreferenceService(); PreferredPreferences getPreferenceService();
} }

View File

@ -84,7 +84,7 @@ public final class CalculatorMessages {
} }
@Nonnull @Nonnull
static MessageType toMessageType(int messageLevel) { public static MessageType toMessageType(int messageLevel) {
if (messageLevel < info.getMessageLevel()) { if (messageLevel < info.getMessageLevel()) {
return info; return info;
} else if (messageLevel < warning.getMessageLevel()) { } else if (messageLevel < warning.getMessageLevel()) {

View File

@ -1,46 +0,0 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import javax.annotation.Nonnull;
import jscl.AngleUnit;
import jscl.NumeralBase;
/**
* User: serso
* Date: 11/17/12
* Time: 7:45 PM
*/
public interface CalculatorPreferenceService {
void setPreferredAngleUnits();
void setAngleUnits(@Nonnull AngleUnit angleUnit);
void setPreferredNumeralBase();
void setNumeralBase(@Nonnull NumeralBase numeralBase);
void checkPreferredPreferences(boolean force);
}

View File

@ -67,7 +67,7 @@ public class DisplayView extends AutoResizeTextView {
return; return;
} }
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(App.getPreferences()); final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(App.getPreferences());
if (!layout.isOptimized()) { if (!layout.optimized) {
setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.cpp_display_text_size_mobile)); setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.cpp_display_text_size_mobile));
} }
setOnClickListener(new CalculatorDisplayOnClickListener((FragmentActivity) context)); setOnClickListener(new CalculatorDisplayOnClickListener((FragmentActivity) context));

View File

@ -1,40 +0,0 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import java.io.Serializable;
import javax.annotation.Nullable;
/**
* User: serso
* Date: 12/2/12
* Time: 10:21 PM
*/
public interface FixableError extends Serializable {
@Nullable
CharSequence getFixCaption();
void fix();
}

View File

@ -1,109 +0,0 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import android.os.Parcel;
import android.os.Parcelable;
import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* User: serso
* Date: 11/17/12
* Time: 6:54 PM
*/
public class FixableMessage implements Parcelable {
public static final Creator<FixableMessage> CREATOR = new Creator<FixableMessage>() {
@Override
public FixableMessage createFromParcel(@Nonnull Parcel in) {
return FixableMessage.fromParcel(in);
}
@Override
public FixableMessage[] newArray(int size) {
return new FixableMessage[size];
}
};
@Nonnull
private final String message;
@Nonnull
private final MessageType messageType;
@Nullable
private final FixableError fixableError;
public FixableMessage(@Nonnull Message message) {
this.message = message.getLocalizedMessage();
final int messageLevel = message.getMessageLevel().getMessageLevel();
this.messageType = CalculatorMessages.toMessageType(messageLevel);
this.fixableError = CalculatorFixableError.getErrorByMessageCode(message.getMessageCode());
}
public FixableMessage(@Nonnull String message,
@Nonnull MessageType messageType,
@Nullable FixableError fixableError) {
this.message = message;
this.messageType = messageType;
this.fixableError = fixableError;
}
@Nonnull
private static FixableMessage fromParcel(@Nonnull Parcel in) {
final String message = in.readString();
final MessageType messageType = (MessageType) in.readSerializable();
final FixableError fixableError = (FixableError) in.readSerializable();
return new FixableMessage(message, messageType, fixableError);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@Nonnull Parcel out, int flags) {
out.writeString(message);
out.writeSerializable(messageType);
out.writeSerializable(fixableError);
}
@Nonnull
public String getMessage() {
return message;
}
@Nonnull
public MessageType getMessageType() {
return messageType;
}
@Nullable
public FixableError getFixableError() {
return fixableError;
}
}

View File

@ -1,275 +0,0 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import org.solovyev.common.msg.Message;
import org.solovyev.common.text.Strings;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
/**
* User: serso
* Date: 11/17/12
* Time: 3:37 PM
*/
public class FixableMessagesDialog extends ActionBarActivity {
private static final String INPUT = "input";
@Nonnull
private Input input = new Input(Collections.<FixableMessage>emptyList(), false);
public FixableMessagesDialog() {
}
public static void showDialogForMessages(@Nonnull List<Message> messages,
@Nonnull Context context,
boolean showCheckbox) {
if (!messages.isEmpty()) {
final Intent intent = new Intent(context, FixableMessagesDialog.class);
intent.putExtra(INPUT, Input.fromMessages(messages, showCheckbox));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
public static void showDialog(@Nonnull List<FixableMessage> messages,
@Nonnull Context context,
boolean showCheckbox) {
if (!messages.isEmpty()) {
final Intent intent = new Intent(context, FixableMessagesDialog.class);
intent.putExtra(INPUT, new Input(messages, showCheckbox));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cpp_fixable_messages_dialog);
final Intent intent = getIntent();
if (intent != null) {
parseIntent(intent);
}
final CheckBox doNotShowCalculationMessagesCheckbox = (CheckBox) findViewById(R.id.cpp_do_not_show_fixable_messages_checkbox);
if (input.isShowCheckbox()) {
doNotShowCalculationMessagesCheckbox.setVisibility(View.VISIBLE);
} else {
doNotShowCalculationMessagesCheckbox.setVisibility(View.GONE);
}
final Button closeButton = (Button) findViewById(R.id.close_button);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (doNotShowCalculationMessagesCheckbox.isChecked()) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(FixableMessagesDialog.this);
Preferences.Calculations.showCalculationMessagesDialog.putPreference(prefs, false);
}
FixableMessagesDialog.this.finish();
}
});
}
private void parseIntent(@Nonnull Intent intent) {
final Input input = intent.getParcelableExtra(INPUT);
if (input != null) {
this.input = input;
onInputChanged();
}
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
private void onInputChanged() {
final ViewGroup viewGroup = (ViewGroup) findViewById(R.id.cpp_fixable_messages_container);
viewGroup.removeAllViews();
final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final List<FixableMessage> messages = input.getMessages();
for (final FixableMessage message : messages) {
final View view = layoutInflater.inflate(R.layout.cpp_fixable_messages_dialog_message, null);
final TextView calculationMessagesTextView = (TextView) view.findViewById(R.id.cpp_fixable_messages_text_view);
calculationMessagesTextView.setText(message.getMessage());
final Button fixButton = (Button) view.findViewById(R.id.cpp_fix_button);
final FixableError fixableError = message.getFixableError();
if (fixableError == null) {
fixButton.setVisibility(View.GONE);
fixButton.setOnClickListener(null);
} else {
fixButton.setVisibility(View.VISIBLE);
fixButton.setOnClickListener(new FixErrorOnClickListener(messages, message));
final CharSequence fixCaption = fixableError.getFixCaption();
if (!Strings.isEmpty(fixCaption)) {
fixButton.setText(fixCaption);
}
}
viewGroup.addView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
}
@Override
protected void onNewIntent(@Nonnull Intent intent) {
super.onNewIntent(intent);
parseIntent(intent);
}
private static final class Input implements Parcelable {
public static final Creator<Input> CREATOR = new Creator<Input>() {
@Override
public Input createFromParcel(@Nonnull Parcel in) {
return Input.fromParcel(in);
}
@Override
public Input[] newArray(int size) {
return new Input[size];
}
};
@Nonnull
private List<FixableMessage> messages = new ArrayList<FixableMessage>();
private boolean showCheckbox;
private Input(@Nonnull List<FixableMessage> messages, boolean showCheckbox) {
this.messages = messages;
this.showCheckbox = showCheckbox;
}
@Nonnull
private static Input fromParcel(@Nonnull Parcel in) {
final List<FixableMessage> messages = new ArrayList<FixableMessage>();
boolean showCheckbox = in.readInt() == 1;
in.readTypedList(messages, FixableMessage.CREATOR);
return new Input(messages, showCheckbox);
}
@Nonnull
public static Input fromMessages(@Nonnull List<Message> messages, boolean showCheckbox) {
final List<FixableMessage> stringMessages = new ArrayList<FixableMessage>(messages.size());
for (Message message : messages) {
stringMessages.add(new FixableMessage(message));
}
return new Input(stringMessages, showCheckbox);
}
@Nonnull
public List<FixableMessage> getMessages() {
return messages;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@Nonnull Parcel out, int flags) {
out.writeInt(showCheckbox ? 1 : 0);
out.writeTypedList(messages);
}
public boolean isShowCheckbox() {
return showCheckbox;
}
}
private class FixErrorOnClickListener implements View.OnClickListener {
@Nonnull
private final List<FixableMessage> messages;
@Nonnull
private final FixableMessage currentMessage;
public FixErrorOnClickListener(@Nonnull List<FixableMessage> messages,
@Nonnull FixableMessage message) {
this.messages = messages;
this.currentMessage = message;
}
@Override
public void onClick(View v) {
final List<FixableMessage> filteredMessages = new ArrayList<FixableMessage>(messages.size() - 1);
for (FixableMessage message : messages) {
if (message.getFixableError() == null) {
filteredMessages.add(message);
} else if (message.getFixableError() != currentMessage.getFixableError()) {
filteredMessages.add(message);
}
}
currentMessage.getFixableError().fix();
if (!filteredMessages.isEmpty()) {
FixableMessagesDialog.this.input = new Input(filteredMessages, FixableMessagesDialog.this.input.showCheckbox);
onInputChanged();
} else {
FixableMessagesDialog.this.finish();
}
}
}
}

View File

@ -41,7 +41,7 @@ public class Locator implements CalculatorLocator {
@Nonnull @Nonnull
private ErrorReporter errorReporter = new SystemErrorReporter(); private ErrorReporter errorReporter = new SystemErrorReporter();
@Nonnull @Nonnull
private CalculatorPreferenceService calculatorPreferenceService; private PreferredPreferences preferredPreferences;
@Nonnull @Nonnull
private CalculatorPlotter calculatorPlotter; private CalculatorPlotter calculatorPlotter;
@ -59,7 +59,7 @@ public class Locator implements CalculatorLocator {
@Nonnull Engine engine, @Nonnull Engine engine,
@Nonnull CalculatorNotifier notifier, @Nonnull CalculatorNotifier notifier,
@Nonnull ErrorReporter errorReporter, @Nonnull ErrorReporter errorReporter,
@Nonnull CalculatorPreferenceService preferenceService, @Nonnull PreferredPreferences preferenceService,
@Nonnull Keyboard keyboard, @Nonnull Keyboard keyboard,
@Nonnull CalculatorPlotter plotter) { @Nonnull CalculatorPlotter plotter) {
@ -67,7 +67,7 @@ public class Locator implements CalculatorLocator {
this.engine = engine; this.engine = engine;
this.calculatorNotifier = notifier; this.calculatorNotifier = notifier;
this.errorReporter = errorReporter; this.errorReporter = errorReporter;
this.calculatorPreferenceService = preferenceService; this.preferredPreferences = preferenceService;
this.calculatorPlotter = plotter; this.calculatorPlotter = plotter;
this.keyboard = keyboard; this.keyboard = keyboard;
@ -115,7 +115,7 @@ public class Locator implements CalculatorLocator {
@Nonnull @Nonnull
@Override @Override
public CalculatorPreferenceService getPreferenceService() { public PreferredPreferences getPreferenceService() {
return this.calculatorPreferenceService; return this.preferredPreferences;
} }
} }

View File

@ -60,6 +60,9 @@ public final class Preferences {
} }
static void setDefaultValues(@Nonnull SharedPreferences preferences) { static void setDefaultValues(@Nonnull SharedPreferences preferences) {
// renew value after each application start
Gui.showFixableErrorDialog.putDefault(preferences);
Gui.lastPreferredPreferencesCheck.putDefault(preferences);
if (!Engine.Preferences.groupingSeparator.isSet(preferences)) { if (!Engine.Preferences.groupingSeparator.isSet(preferences)) {
final Locale locale = Locale.getDefault(); final Locale locale = Locale.getDefault();
@ -116,10 +119,6 @@ public final class Preferences {
applyDefaultPreference(preferences, Onscreen.theme); applyDefaultPreference(preferences, Onscreen.theme);
applyDefaultPreference(preferences, Widget.theme); applyDefaultPreference(preferences, Widget.theme);
// renew value after each application start
Calculations.showCalculationMessagesDialog.putDefault(preferences);
Calculations.lastPreferredPreferencesCheck.putDefault(preferences);
} }
private static void applyDefaultPreference(@Nonnull SharedPreferences preferences, @Nonnull Preference<?> preference) { private static void applyDefaultPreference(@Nonnull SharedPreferences preferences, @Nonnull Preference<?> preference) {
@ -236,11 +235,9 @@ public final class Preferences {
public static class Calculations { public static class Calculations {
public static final Preference<Boolean> calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true); public static final Preference<Boolean> calculateOnFly = BooleanPreference.of("calculations_calculate_on_fly", true);
public static final Preference<Boolean> showCalculationMessagesDialog = BooleanPreference.of("show_calculation_messages_dialog", true);
public static final Preference<NumeralBase> preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", Engine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class); public static final Preference<NumeralBase> preferredNumeralBase = StringPreference.ofEnum("preferred_numeral_base", Engine.Preferences.numeralBase.getDefaultValue(), NumeralBase.class);
public static final Preference<AngleUnit> preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", Engine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class); public static final Preference<AngleUnit> preferredAngleUnits = StringPreference.ofEnum("preferred_angle_units", Engine.Preferences.angleUnit.getDefaultValue(), AngleUnit.class);
public static final Preference<Long> lastPreferredPreferencesCheck = LongPreference.of("preferred_preferences_check_time", 0L);
} }
@ -258,6 +255,8 @@ public final class Preferences {
public static final Preference<Boolean> preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true); public static final Preference<Boolean> preventScreenFromFading = BooleanPreference.of("preventScreenFromFading", true);
public static final Preference<Boolean> colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true); public static final Preference<Boolean> colorDisplay = BooleanPreference.of("org.solovyev.android.calculator.CalculatorModel_color_display", true);
public static final Preference<Long> hapticFeedback = NumberToStringPreference.of("hapticFeedback", 60L, Long.class); public static final Preference<Long> hapticFeedback = NumberToStringPreference.of("hapticFeedback", 60L, Long.class);
public static final Preference<Boolean> showFixableErrorDialog = BooleanPreference.of("gui.showFixableErrorDialog", true);
public static final Preference<Long> lastPreferredPreferencesCheck = LongPreference.of("gui.lastPreferredPreferencesCheck", 0L);
@Nonnull @Nonnull
public static Theme getTheme(@Nonnull SharedPreferences preferences) { public static Theme getTheme(@Nonnull SharedPreferences preferences) {
@ -332,37 +331,23 @@ public final class Preferences {
} }
public enum Layout { public enum Layout {
main_calculator(R.layout.main_calculator, R.string.p_layout_calculator, true), main_calculator(R.layout.main_calculator, true),
main_calculator_mobile(R.layout.main_calculator_mobile, R.string.p_layout_calculator_mobile, false), main_calculator_mobile(R.layout.main_calculator_mobile, false),
// not used anymore // not used anymore
@Deprecated @Deprecated
main_cellphone(R.layout.main_calculator, 0, true), main_cellphone(R.layout.main_calculator, true),
simple(R.layout.main_calculator, R.string.p_layout_simple, true), simple(R.layout.main_calculator, true),
simple_mobile(R.layout.main_calculator_mobile, R.string.p_layout_simple_mobile, false); simple_mobile(R.layout.main_calculator_mobile, false);
private final int layoutId; public final int layoutId;
private final int nameResId; public final boolean optimized;
private final boolean optimized;
Layout(int layoutId, int nameResId, boolean optimized) { Layout(int layoutId, boolean optimized) {
this.layoutId = layoutId; this.layoutId = layoutId;
this.nameResId = nameResId;
this.optimized = optimized; this.optimized = optimized;
} }
public int getLayoutId() {
return layoutId;
}
public int getNameResId() {
return nameResId;
}
public boolean isOptimized() {
return optimized;
}
} }
public static final class TextColor { public static final class TextColor {

View File

@ -0,0 +1,117 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import jscl.AngleUnit;
import jscl.NumeralBase;
import org.solovyev.android.calculator.errors.FixableError;
import org.solovyev.android.calculator.errors.FixableErrorType;
import org.solovyev.android.calculator.errors.FixableErrorsActivity;
import org.solovyev.android.msg.AndroidMessage;
import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import static org.solovyev.android.calculator.Preferences.Gui.lastPreferredPreferencesCheck;
@Singleton
public class PreferredPreferences {
// one hour
private static final Long PREFERRED_PREFS_INTERVAL_TIME = 1000L * 60L * 60L;
@Inject
Application application;
@Inject
SharedPreferences preferences;
@Inject
public PreferredPreferences() {
}
public void check(boolean force) {
check(application, force);
}
public void check(@Nonnull Context context, boolean force) {
final long now = System.currentTimeMillis();
if (!force) {
if (!Preferences.Gui.showFixableErrorDialog.getPreference(preferences)) {
// user has disabled calculation message dialogs until the next session
return;
}
if (!shouldCheck(now)) {
return;
}
}
final NumeralBase preferredNumeralBase = Preferences.Calculations.preferredNumeralBase.getPreference(preferences);
final NumeralBase numeralBase = Engine.Preferences.numeralBase.getPreference(preferences);
final AngleUnit preferredAngleUnits = Preferences.Calculations.preferredAngleUnits.getPreference(preferences);
final AngleUnit angleUnits = Engine.Preferences.angleUnit.getPreference(preferences);
final ArrayList<FixableError> messages = new ArrayList<>(2);
if (numeralBase != preferredNumeralBase) {
messages.add(new FixableError(application.getString(R.string.preferred_numeral_base_message, preferredNumeralBase.name(), numeralBase.name()), MessageType.warning, FixableErrorType.preferred_numeral_base));
}
if (angleUnits != preferredAngleUnits) {
messages.add(new FixableError(application.getString(R.string.preferred_angle_units_message, preferredAngleUnits.name(), angleUnits.name()), MessageType.warning, FixableErrorType.preferred_angle_units));
}
FixableErrorsActivity.show(context, messages);
lastPreferredPreferencesCheck.putPreference(preferences, now);
}
private boolean shouldCheck(long now) {
final long lastCheckTime = lastPreferredPreferencesCheck.getPreference(preferences);
return now - lastCheckTime > PREFERRED_PREFS_INTERVAL_TIME;
}
public void setPreferredAngleUnits() {
setAngleUnits(Preferences.Calculations.preferredAngleUnits.getPreference(preferences));
}
public void setAngleUnits(@Nonnull AngleUnit angleUnit) {
Engine.Preferences.angleUnit.putPreference(preferences, angleUnit);
Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_angle_units_changed_to, MessageType.info, application, angleUnit.name()));
}
public void setPreferredNumeralBase() {
setNumeralBase(Preferences.Calculations.preferredNumeralBase.getPreference(preferences));
}
public void setNumeralBase(@Nonnull NumeralBase numeralBase) {
Engine.Preferences.numeralBase.putPreference(preferences, numeralBase);
Locator.getInstance().getNotifier().showMessage(new AndroidMessage(R.string.c_numeral_base_changed_to, MessageType.info, application, numeralBase.name()));
}
}

View File

@ -0,0 +1,87 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator.errors;
import android.os.Parcel;
import android.os.Parcelable;
import org.solovyev.android.calculator.CalculatorMessages;
import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class FixableError implements Parcelable {
public static final Creator<FixableError> CREATOR = new Creator<FixableError>() {
@Override
public FixableError createFromParcel(@Nonnull Parcel in) {
return new FixableError(in);
}
@Override
public FixableError[] newArray(int size) {
return new FixableError[size];
}
};
@Nonnull
public final String message;
@Nonnull
public final MessageType messageType;
@Nullable
public final FixableErrorType error;
private FixableError(@Nonnull Parcel in) {
message = in.readString();
messageType = MessageType.values()[in.readInt()];
final int errorOrdinal = in.readInt();
error = errorOrdinal == -1 ? null : FixableErrorType.values()[errorOrdinal];
}
public FixableError(@Nonnull Message message) {
this.message = message.getLocalizedMessage();
final int messageLevel = message.getMessageLevel().getMessageLevel();
this.messageType = CalculatorMessages.toMessageType(messageLevel);
this.error = FixableErrorType.getErrorByCode(message.getMessageCode());
}
public FixableError(@Nonnull String message,
@Nonnull MessageType messageType,
@Nullable FixableErrorType error) {
this.message = message;
this.messageType = messageType;
this.error = error;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@Nonnull Parcel out, int flags) {
out.writeString(message);
out.writeInt(messageType.ordinal());
out.writeInt(error == null ? -1 : error.ordinal());
}
}

View File

@ -0,0 +1,98 @@
package org.solovyev.android.calculator.errors;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.*;
import javax.annotation.Nonnull;
import javax.inject.Inject;
public class FixableErrorFragment extends BaseDialogFragment {
static final String FRAGMENT_TAG = "fixable-error";
@Nonnull
private static final String ARG_ERROR = "error";
@Inject
PreferredPreferences preferredPreferences;
private FixableError error;
@Nullable
private FixableErrorsActivity activity;
@Nonnull
private static FixableErrorFragment create(@Nonnull FixableError error) {
final FixableErrorFragment fragment = new FixableErrorFragment();
final Bundle args = new Bundle(1);
args.putParcelable(ARG_ERROR, error);
fragment.setArguments(args);
return fragment;
}
public static void show(@Nonnull FixableError error, @Nonnull FragmentManager fm) {
App.showDialog(create(error), FRAGMENT_TAG, fm);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = (FixableErrorsActivity) activity;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
error = getArguments().getParcelable(ARG_ERROR);
Check.isNotNull(error);
}
@Override
protected void inject(@NonNull AppComponent component) {
super.inject(component);
component.inject(this);
}
@Override
protected void onPrepareDialog(@NonNull AlertDialog.Builder builder) {
builder.setMessage(error.message);
builder.setNeutralButton(R.string.cpp_dont_show_again, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Preferences.Gui.showFixableErrorDialog.putPreference(preferences, false);
dismiss();
}
});
builder.setNegativeButton(R.string.close, null);
if (error.error != null) {
builder.setPositiveButton(R.string.fix, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
error.error.fix(preferredPreferences);
dismiss();
}
});
}
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
if (activity != null) {
activity.onDialogClosed();
activity = null;
}
}
@Nullable
@Override
protected View onCreateDialogView(@NonNull Context context, @NonNull LayoutInflater inflater, @Nullable Bundle savedInstanceState) {
return null;
}
}

View File

@ -20,65 +20,56 @@
* Site: http://se.solovyev.org * Site: http://se.solovyev.org
*/ */
package org.solovyev.android.calculator; package org.solovyev.android.calculator.errors;
import jscl.AngleUnit; import jscl.AngleUnit;
import jscl.text.msg.Messages; import jscl.text.msg.Messages;
import org.solovyev.android.calculator.PreferredPreferences;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/** public enum FixableErrorType {
* User: serso
* Date: 11/17/12
* Time: 7:30 PM
*/
public enum CalculatorFixableError implements FixableError {
must_be_rad(Messages.msg_23, Messages.msg_24, Messages.msg_25) { must_be_rad(Messages.msg_23, Messages.msg_24, Messages.msg_25) {
@Override @Override
public void fix() { public void fix(@Nonnull PreferredPreferences preferences) {
Locator.getInstance().getPreferenceService().setAngleUnits(AngleUnit.rad); preferences.setAngleUnits(AngleUnit.rad);
} }
}, },
preferred_numeral_base() { preferred_numeral_base() {
@Override @Override
public void fix() { public void fix(@Nonnull PreferredPreferences preferences) {
Locator.getInstance().getPreferenceService().setPreferredNumeralBase(); preferences.setPreferredNumeralBase();
} }
}, },
preferred_angle_units() { preferred_angle_units() {
@Override @Override
public void fix() { public void fix(@Nonnull PreferredPreferences preferences) {
Locator.getInstance().getPreferenceService().setPreferredAngleUnits(); preferences.setPreferredAngleUnits();
} }
}; };
@Nonnull @Nonnull
private final List<String> messageCodes; private final List<String> messageCodes;
CalculatorFixableError(@Nullable String... messageCodes) { FixableErrorType(@Nullable String... messageCodes) {
this.messageCodes = messageCodes == null || messageCodes.length == 0 ? java.util.Collections.<String>emptyList() : Arrays.asList(messageCodes); this.messageCodes = messageCodes == null || messageCodes.length == 0 ? java.util.Collections.<String>emptyList() : Arrays.asList(messageCodes);
} }
@Nullable @Nullable
public static CalculatorFixableError getErrorByMessageCode(@Nonnull String messageCode) { public static FixableErrorType getErrorByCode(@Nonnull String code) {
for (CalculatorFixableError fixableError : values()) { for (FixableErrorType type : values()) {
if (fixableError.messageCodes.contains(messageCode)) { if (type.messageCodes.contains(code)) {
return fixableError; return type;
} }
} }
return null; return null;
} }
public abstract void fix(@Nonnull PreferredPreferences preferences);
@Nullable
@Override
public CharSequence getFixCaption() {
return null;
}
} }

View File

@ -0,0 +1,118 @@
/*
* Copyright 2013 serso aka se.solovyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Contact details
*
* Email: se.solovyev@gmail.com
* Site: http://se.solovyev.org
*/
package org.solovyev.android.calculator.errors;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import org.solovyev.android.Activities;
import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.common.msg.Message;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
public class FixableErrorsActivity extends AppCompatActivity {
public static final String EXTRA_ERRORS = "errors";
public static final String STATE_ERRORS = "errors";
@Inject
SharedPreferences preferences;
private ArrayList<FixableError> errors;
public static void show(@Nonnull Context context, @Nonnull List<Message> messages) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (Preferences.Gui.showFixableErrorDialog.getPreference(preferences)) {
final ArrayList<FixableError> errors = new ArrayList<>();
for (Message message : messages) {
errors.add(new FixableError(message));
}
show(context, errors);
}
}
public static void show(@Nonnull Context context, @Nonnull ArrayList<FixableError> errors) {
final Intent intent = new Intent(context, FixableErrorsActivity.class);
intent.putExtra(EXTRA_ERRORS, errors);
Activities.addIntentFlags(intent, false, context);
context.startActivity(intent);
}
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
if (state != null) {
errors = state.getParcelableArrayList(STATE_ERRORS);
} else {
final Intent intent = getIntent();
errors = intent.getParcelableArrayListExtra(EXTRA_ERRORS);
}
if (errors == null) {
finish();
return;
}
((CalculatorApplication) getApplication()).getComponent().inject(this);
if (state == null) {
showNextError();
}
}
@Override
protected void onSaveInstanceState(@Nonnull Bundle out) {
super.onSaveInstanceState(out);
out.putParcelableArrayList(STATE_ERRORS, errors);
}
public void showNextError() {
if (errors.isEmpty()) {
finish();
return;
}
if (!Preferences.Gui.showFixableErrorDialog.getPreference(preferences)) {
finish();
return;
}
final FixableError fixableError = errors.remove(0);
FixableErrorFragment.show(fixableError, getSupportFragmentManager());
}
public void onDialogClosed() {
final Fragment fragment = getSupportFragmentManager().findFragmentByTag(FixableErrorFragment.FRAGMENT_TAG);
if (fragment == null) {
// activity is closing
return;
}
showNextError();
}
}

View File

@ -100,23 +100,23 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
return fragment; return fragment;
} }
public static void showDialog(@Nonnull FragmentActivity activity) { public static void show(@Nonnull FragmentActivity activity) {
EditFunctionFragment.showDialog(null, activity.getSupportFragmentManager()); EditFunctionFragment.show(null, activity.getSupportFragmentManager());
} }
public static void showDialog(@Nullable CppFunction function, @Nonnull Context context) { public static void show(@Nullable CppFunction function, @Nonnull Context context) {
if (!(context instanceof FunctionsActivity)) { if (!(context instanceof FunctionsActivity)) {
final Intent intent = new Intent(context, FunctionsActivity.class); final Intent intent = new Intent(context, FunctionsActivity.class);
Activities.addIntentFlags(intent, false, context); Activities.addIntentFlags(intent, false, context);
intent.putExtra(FunctionsActivity.EXTRA_FUNCTION, function); intent.putExtra(FunctionsActivity.EXTRA_FUNCTION, function);
context.startActivity(intent); context.startActivity(intent);
} else { } else {
EditFunctionFragment.showDialog(function, ((FunctionsActivity) context).getSupportFragmentManager()); EditFunctionFragment.show(function, ((FunctionsActivity) context).getSupportFragmentManager());
} }
} }
public static void showDialog(@Nullable CppFunction input, @Nonnull FragmentManager fm) { public static void show(@Nullable CppFunction function, @Nonnull FragmentManager fm) {
App.showDialog(create(input), "function-editor", fm); App.showDialog(create(function), "function-editor", fm);
} }
@Override @Override

View File

@ -60,7 +60,7 @@ public class FunctionsActivity extends BaseActivity {
final Bundle extras = getIntent().getExtras(); final Bundle extras = getIntent().getExtras();
final CppFunction function = extras != null ? (CppFunction) extras.getParcelable(EXTRA_FUNCTION) : null; final CppFunction function = extras != null ? (CppFunction) extras.getParcelable(EXTRA_FUNCTION) : null;
if (function != null) { if (function != null) {
EditFunctionFragment.showDialog(function, this); EditFunctionFragment.show(function, this);
} }
} }
} }

View File

@ -71,7 +71,7 @@ public class FunctionsFragment extends BaseEntitiesFragment<Function> {
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
EditFunctionFragment.showDialog(getActivity()); EditFunctionFragment.show(getActivity());
} }
}); });
return view; return view;
@ -95,7 +95,7 @@ public class FunctionsFragment extends BaseEntitiesFragment<Function> {
return true; return true;
case R.string.c_edit: case R.string.c_edit:
if (function instanceof IFunction) { if (function instanceof IFunction) {
EditFunctionFragment.showDialog(CppFunction.builder((IFunction) function).build(), activity.getSupportFragmentManager()); EditFunctionFragment.show(CppFunction.builder((IFunction) function).build(), activity.getSupportFragmentManager());
} }
return true; return true;
case R.string.c_remove: case R.string.c_remove:

View File

@ -66,7 +66,7 @@ enum CalculatorLayout {
@Nonnull @Nonnull
static CalculatorLayout fromGuiLayout(@Nonnull Preferences.Gui.Layout layout) { static CalculatorLayout fromGuiLayout(@Nonnull Preferences.Gui.Layout layout) {
if (layout.isOptimized()) { if (layout.optimized) {
return optimized; return optimized;
} else { } else {
return big_buttons; return big_buttons;

View File

@ -46,7 +46,7 @@ enum CalculatorMode {
@Override @Override
protected void apply(@Nonnull SharedPreferences preferences) { protected void apply(@Nonnull SharedPreferences preferences) {
final Preferences.Gui.Layout layout = Preferences.Gui.layout.getPreference(preferences); final Preferences.Gui.Layout layout = Preferences.Gui.layout.getPreference(preferences);
if (layout.isOptimized()) { if (layout.optimized) {
Preferences.Gui.layout.putPreference(preferences, Preferences.Gui.Layout.simple); Preferences.Gui.layout.putPreference(preferences, Preferences.Gui.Layout.simple);
} else { } else {
Preferences.Gui.layout.putPreference(preferences, Preferences.Gui.Layout.simple_mobile); Preferences.Gui.layout.putPreference(preferences, Preferences.Gui.Layout.simple_mobile);
@ -62,7 +62,7 @@ enum CalculatorMode {
@Override @Override
protected void apply(@Nonnull SharedPreferences preferences) { protected void apply(@Nonnull SharedPreferences preferences) {
final Preferences.Gui.Layout layout = Preferences.Gui.layout.getPreference(preferences); final Preferences.Gui.Layout layout = Preferences.Gui.layout.getPreference(preferences);
if (layout.isOptimized()) { if (layout.optimized) {
Preferences.Gui.layout.putPreference(preferences, main_calculator); Preferences.Gui.layout.putPreference(preferences, main_calculator);
} else { } else {
Preferences.Gui.layout.putPreference(preferences, main_calculator_mobile); Preferences.Gui.layout.putPreference(preferences, main_calculator_mobile);

View File

@ -175,7 +175,7 @@
<style name="WizardButtons" parent="BaseWizardButtons" /> <style name="WizardButtons" parent="BaseWizardButtons" />
<style name="PrimaryButton" parent="MaterialButton"></style> <style name="PrimaryButton" parent="MaterialButton"/>
<style name="WizardFragment"> <style name="WizardFragment">
<item name="android:layout_width">match_parent</item> <item name="android:layout_width">match_parent</item>
@ -328,18 +328,14 @@
<item name="background">@color/cpp_material_actionbar</item> <item name="background">@color/cpp_material_actionbar</item>
<item name="android:background">@color/cpp_material_actionbar</item> <item name="android:background">@color/cpp_material_actionbar</item>
<item name="backgroundStacked">@color/cpp_material_actionbar</item> <item name="backgroundStacked">@color/cpp_material_actionbar</item>
<item name="android:backgroundStacked">@color/cpp_material_actionbar</item>
<item name="backgroundSplit">@color/cpp_material_actionbar</item> <item name="backgroundSplit">@color/cpp_material_actionbar</item>
<item name="android:backgroundSplit">@color/cpp_material_actionbar</item>
</style> </style>
<style name="CppActionBar.Light" parent="CppActionBar"> <style name="CppActionBar.Light" parent="CppActionBar">
<item name="background">@color/cpp_material_actionbar_light</item> <item name="background">@color/cpp_material_actionbar_light</item>
<item name="android:background">@color/cpp_material_actionbar_light</item> <item name="android:background">@color/cpp_material_actionbar_light</item>
<item name="backgroundStacked">@color/cpp_material_actionbar_light</item> <item name="backgroundStacked">@color/cpp_material_actionbar_light</item>
<item name="android:backgroundStacked">@color/cpp_material_actionbar_light</item>
<item name="backgroundSplit">@color/cpp_material_actionbar_light</item> <item name="backgroundSplit">@color/cpp_material_actionbar_light</item>
<item name="android:backgroundSplit">@color/cpp_material_actionbar_light</item>
</style> </style>
<dimen name="list_item_text_size">16sp</dimen> <dimen name="list_item_text_size">16sp</dimen>

View File

@ -235,5 +235,6 @@
<string name="cpp_clear_history">Clear</string> <string name="cpp_clear_history">Clear</string>
<string name="cpp_new_in_version">New in %1$s version</string> <string name="cpp_new_in_version">New in %1$s version</string>
<string name="cpp_release_notes_choose_theme">Do you want to try new Material themes? Choose them from the list:</string> <string name="cpp_release_notes_choose_theme">Do you want to try new Material themes? Choose them from the list:</string>
<string name="cpp_dont_show_again">Don\'t show again</string>
<string name="cpp_system_language">System language</string> <string name="cpp_system_language">System language</string>
</resources> </resources>

View File

@ -40,6 +40,15 @@
<item name="android:listDivider">@drawable/divider_dark</item> <item name="android:listDivider">@drawable/divider_dark</item>
</style> </style>
<style name="Cpp.Theme.Translucent" parent="Cpp.Theme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
</style>
<style name="Cpp.Theme.Dialog" parent="@style/Theme.AppCompat.Dialog"> <style name="Cpp.Theme.Dialog" parent="@style/Theme.AppCompat.Dialog">
<item name="colorPrimary">@color/cpp_metro_button</item> <item name="colorPrimary">@color/cpp_metro_button</item>
<item name="colorPrimaryDark">@color/cpp_metro_button_dark</item> <item name="colorPrimaryDark">@color/cpp_metro_button_dark</item>

View File

@ -70,17 +70,6 @@
a:summary="@string/c_show_equals_button_summary" a:summary="@string/c_show_equals_button_summary"
a:title="@string/c_show_equals_button_title" /> a:title="@string/c_show_equals_button_title" />
<android.preference.CheckBoxPreference
a:defaultValue="true"
a:key="hideNumeralBaseDigits"
a:summary="@string/c_hide_numeral_base_digits_summary"
a:title="@string/c_hide_numeral_base_digits_title" />
<android.preference.CheckBoxPreference
a:key="history_show_intermediate_calculations"
a:summary="@string/prefs_history_show_intermediate_calculations_summary"
a:title="@string/prefs_history_show_intermediate_calculations_title" />
<android.preference.CheckBoxPreference <android.preference.CheckBoxPreference
a:key="preventScreenFromFading" a:key="preventScreenFromFading"
a:summary="@string/prefs_prevent_screen_from_fading_summary" a:summary="@string/prefs_prevent_screen_from_fading_summary"

View File

@ -84,9 +84,4 @@
a:summary="@string/p_calculations_calculate_on_fly_summary" a:summary="@string/p_calculations_calculate_on_fly_summary"
a:title="@string/p_calculations_calculate_on_fly_title" /> a:title="@string/p_calculations_calculate_on_fly_title" />
<android.preference.CheckBoxPreference
a:key="show_calculation_messages_dialog"
a:summary="@string/p_show_calculation_messages_dialog_summary"
a:title="@string/p_show_calculation_messages_dialog_title" />
</PreferenceScreen> </PreferenceScreen>

View File

@ -36,7 +36,7 @@ import java.util.concurrent.Executor;
public class AbstractCalculatorTest { public class AbstractCalculatorTest {
protected void setUp() throws Exception { protected void setUp() throws Exception {
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class)); Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(PreferredPreferences.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
Locator.getInstance().getEngine().init(new Executor() { Locator.getInstance().getEngine().init(new Executor() {
@Override @Override
public void execute(Runnable command) { public void execute(Runnable command) {

View File

@ -57,7 +57,7 @@ public class CalculatorTestUtils {
public static void staticSetUp() throws Exception { public static void staticSetUp() throws Exception {
App.init(new CalculatorApplication(), new Languages(new RoboSharedPreferences(new HashMap<String, Map<String, Object>>(), "test", 0))); App.init(new CalculatorApplication(), new Languages(new RoboSharedPreferences(new HashMap<String, Map<String, Object>>(), "test", 0)));
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class)); Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(PreferredPreferences.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
Locator.getInstance().getEngine().init(new Executor() { Locator.getInstance().getEngine().init(new Executor() {
@Override @Override
public void execute(Runnable command) { public void execute(Runnable command) {
@ -72,7 +72,7 @@ public class CalculatorTestUtils {
} }
public static void staticSetUp(@Nullable Context context) throws Exception { public static void staticSetUp(@Nullable Context context) throws Exception {
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class)); Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(PreferredPreferences.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
Locator.getInstance().getEngine().init(new Executor() { Locator.getInstance().getEngine().init(new Executor() {
@Override @Override
public void execute(Runnable command) { public void execute(Runnable command) {