This commit is contained in:
serso 2012-10-10 16:13:58 +04:00
parent cbbd8ea1e0
commit 9e237c1a2c
15 changed files with 1500 additions and 1362 deletions

View File

@ -65,7 +65,7 @@ public class CalculatorEditorImpl implements CalculatorEditor {
setViewState(newViewState, true); setViewState(newViewState, true);
} }
private void setViewState(CalculatorEditorViewState newViewState, boolean fireEvent) { private void setViewState(@NotNull CalculatorEditorViewState newViewState, boolean fireEvent) {
synchronized (viewLock) { synchronized (viewLock) {
final CalculatorEditorViewState oldViewState = this.lastViewState; final CalculatorEditorViewState oldViewState = this.lastViewState;
@ -109,7 +109,7 @@ public class CalculatorEditorImpl implements CalculatorEditor {
private CalculatorEditorViewState newSelectionViewState(int newSelection) { private CalculatorEditorViewState newSelectionViewState(int newSelection) {
if (this.lastViewState.getSelection() != newSelection) { if (this.lastViewState.getSelection() != newSelection) {
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, newSelection); final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, newSelection);
setViewState(result); setViewState(result, false);
return result; return result;
} else { } else {
return this.lastViewState; return this.lastViewState;
@ -262,7 +262,7 @@ public class CalculatorEditorImpl implements CalculatorEditor {
selection = correctSelection(selection, this.lastViewState.getText()); selection = correctSelection(selection, this.lastViewState.getText());
final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, selection); final CalculatorEditorViewState result = CalculatorEditorViewStateImpl.newSelection(this.lastViewState, selection);
setViewState(result); setViewState(result, false);
return result; return result;
} }
} }

View File

@ -66,5 +66,13 @@ public class CalculatorEventHolder {
} }
return sameSequence; return sameSequence;
} }
public boolean isNewAfterSequence() {
return newEventData.isAfterSequence(lastEventData);
}
public boolean isNewSameOrAfterSequence() {
return isSameSequence() || isNewAfterSequence();
}
} }
} }

View File

@ -30,4 +30,11 @@ public interface CalculatorHistory extends HistoryHelper<CalculatorHistoryState>
@NotNull @NotNull
CalculatorHistoryState addSavedState(@NotNull CalculatorHistoryState historyState); CalculatorHistoryState addSavedState(@NotNull CalculatorHistoryState historyState);
@NotNull
List<CalculatorHistoryState> getStates();
@NotNull
List<CalculatorHistoryState> getStates(boolean includeIntermediateStates);
} }

View File

@ -3,18 +3,18 @@ package org.solovyev.android.calculator.history;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.history.HistoryAction; import org.solovyev.common.history.HistoryAction;
import org.solovyev.common.history.HistoryHelper; import org.solovyev.common.history.HistoryHelper;
import org.solovyev.common.history.SimpleHistoryHelper; import org.solovyev.common.history.SimpleHistoryHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.solovyev.android.calculator.CalculatorEventType.display_state_changed; import static org.solovyev.android.calculator.CalculatorEventType.*;
import static org.solovyev.android.calculator.CalculatorEventType.editor_state_changed;
import static org.solovyev.android.calculator.CalculatorEventType.manual_calculation_requested;
/** /**
* User: Solovyev_S * User: Solovyev_S
@ -32,10 +32,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
private final List<CalculatorHistoryState> savedHistory = new ArrayList<CalculatorHistoryState>(); private final List<CalculatorHistoryState> savedHistory = new ArrayList<CalculatorHistoryState>();
@NotNull @NotNull
private volatile CalculatorEventData lastEventData = CalculatorUtils.createFirstEventDataId(); private final CalculatorEventHolder lastEventData = new CalculatorEventHolder(CalculatorUtils.createFirstEventDataId());
@NotNull
private final Object lastEventDataLock = new Object();
@Nullable @Nullable
private volatile CalculatorEditorViewState lastEditorViewState; private volatile CalculatorEditorViewState lastEditorViewState;
@ -114,6 +111,50 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
} }
} }
@NotNull
@Override
public List<CalculatorHistoryState> getStates(boolean includeIntermediateStates) {
if (includeIntermediateStates) {
return getStates();
} else {
final List<CalculatorHistoryState> states = getStates();
final List<CalculatorHistoryState> result = new LinkedList<CalculatorHistoryState>();
CalculatorHistoryState laterState = null;
for (CalculatorHistoryState state : CollectionsUtils.reversed(states)) {
if ( laterState != null ) {
final String laterEditorText = laterState.getEditorState().getText();
final String editorText = state.getEditorState().getText();
if ( laterEditorText != null && editorText != null && isIntermediate(laterEditorText, editorText)) {
// intermediate result => skip from add
} else {
result.add(0, state);
}
} else {
result.add(0, state);
}
laterState = state;
}
return result;
}
}
private boolean isIntermediate(@NotNull String laterEditorText,
@NotNull String editorText) {
if ( Math.abs(laterEditorText.length() - editorText.length()) <= 1 ) {
if ( laterEditorText.length() > editorText.length() ) {
return laterEditorText.startsWith(editorText);
} else {
return editorText.startsWith(laterEditorText);
}
}
return false;
}
@Override @Override
public void clear() { public void clear() {
synchronized (history) { synchronized (history) {
@ -186,27 +227,9 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
@Nullable Object data) { @Nullable Object data) {
if (calculatorEventType.isOfType(editor_state_changed, display_state_changed, manual_calculation_requested)) { if (calculatorEventType.isOfType(editor_state_changed, display_state_changed, manual_calculation_requested)) {
boolean sameSequence = false; final CalculatorEventHolder.Result result = lastEventData.apply(calculatorEventData);
boolean afterSequence = false;
boolean processEvent = false;
synchronized (this.lastEventDataLock) {
if (calculatorEventData.isAfter(this.lastEventData)) {
sameSequence = calculatorEventData.isSameSequence(this.lastEventData);
if (!sameSequence) {
afterSequence = calculatorEventData.isAfterSequence(this.lastEventData);
processEvent = afterSequence;
} else {
processEvent = true;
}
}
}
if (processEvent) {
this.lastEventData = calculatorEventData;
if (result.isNewAfter() && result.isNewSameOrAfterSequence() ) {
switch (calculatorEventType) { switch (calculatorEventType) {
case manual_calculation_requested: case manual_calculation_requested:
lastEditorViewState = (CalculatorEditorViewState) data; lastEditorViewState = (CalculatorEditorViewState) data;
@ -216,7 +239,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
lastEditorViewState = editorChangeData.getNewValue(); lastEditorViewState = editorChangeData.getNewValue();
break; break;
case display_state_changed: case display_state_changed:
if (sameSequence) { if (result.isSameSequence()) {
if (lastEditorViewState != null) { if (lastEditorViewState != null) {
final CalculatorEditorViewState editorViewState = lastEditorViewState; final CalculatorEditorViewState editorViewState = lastEditorViewState;
final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data; final CalculatorDisplayChangeEventData displayChangeData = (CalculatorDisplayChangeEventData) data;

View File

@ -0,0 +1,53 @@
package org.solovyev.android.calculator.history;
import junit.framework.Assert;
import org.jetbrains.annotations.NotNull;
import org.junit.BeforeClass;
import org.junit.Test;
import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl;
import org.solovyev.android.calculator.CalculatorEditorViewStateImpl;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.CalculatorTestUtils;
import java.util.List;
/**
* User: Solovyev_S
* Date: 10.10.12
* Time: 15:07
*/
public class CalculatorHistoryImplTest {
@BeforeClass
public static void setUp() throws Exception {
CalculatorTestUtils.staticSetUp();
}
@Test
public void testGetStates() throws Exception {
CalculatorHistory calculatorHistory = new CalculatorHistoryImpl(CalculatorLocatorImpl.getInstance().getCalculator());
addState(calculatorHistory, "1");
addState(calculatorHistory, "12");
addState(calculatorHistory, "123");
addState(calculatorHistory, "123+");
addState(calculatorHistory, "123+3");
addState(calculatorHistory, "");
addState(calculatorHistory, "2");
addState(calculatorHistory, "23");
addState(calculatorHistory, "235");
addState(calculatorHistory, "2355");
addState(calculatorHistory, "235");
addState(calculatorHistory, "2354");
addState(calculatorHistory, "23547");
final List<CalculatorHistoryState> states = calculatorHistory.getStates(false);
Assert.assertEquals(2, states.size());
Assert.assertEquals("23547", states.get(1).getEditorState().getText());
Assert.assertEquals("123+3", states.get(0).getEditorState().getText());
}
private void addState(@NotNull CalculatorHistory calculatorHistory, @NotNull String text) {
calculatorHistory.addState(CalculatorHistoryState.newInstance(CalculatorEditorViewStateImpl.newInstance(text, 3), CalculatorDisplayViewStateImpl.newDefaultInstance()));
}
}

View File

@ -7,4 +7,7 @@
<string name="c_hide_numeral_base_digits_title">Не показывать цифры из других систем счисления</string> <string name="c_hide_numeral_base_digits_title">Не показывать цифры из других систем счисления</string>
<string name="c_hide_numeral_base_digits_summary">Если включено, то цифры из других систем счисления не будут показаны</string> <string name="c_hide_numeral_base_digits_summary">Если включено, то цифры из других систем счисления не будут показаны</string>
<string name="prefs_history_show_intermediate_calculations_title">Показывать промежуточные вычисления на экране истории</string>
<string name="prefs_history_show_intermediate_calculations_summary">Если включено, то все вычисления будут показаны на экране истории</string>
</resources> </resources>

View File

@ -7,4 +7,7 @@
<string name="c_hide_numeral_base_digits_title">Hide numeral base digits</string> <string name="c_hide_numeral_base_digits_title">Hide numeral base digits</string>
<string name="c_hide_numeral_base_digits_summary">If turned on numeral base digits of other numeral bases will be hidden</string> <string name="c_hide_numeral_base_digits_summary">If turned on numeral base digits of other numeral bases will be hidden</string>
<string name="prefs_history_show_intermediate_calculations_title">Show intermediate calculations in history</string>
<string name="prefs_history_show_intermediate_calculations_summary">If turned on all calculations will be shown on history screen</string>
</resources> </resources>

View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:range="http://schemas.android.com/apk/res-auto">
<PreferenceScreen
a:title="@string/c_prefs_appearance_category">
<org.solovyev.android.ads.AdViewPreference a:layout="@layout/admob_pref"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_color_display_key"
a:summary="@string/c_calc_color_display_summary"
a:title="@string/c_calc_color_display_title"
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_haptic_feedback_key"
a:summary="@string/c_calc_haptic_feedback_summary"
a:title="@string/c_calc_haptic_feedback_title"
a:defaultValue="false"/>
<ListPreference a:key="@string/p_calc_haptic_feedback_duration_key"
a:title="@string/p_calc_haptic_feedback_duration_title"
a:entries="@array/p_calc_haptic_feedback_duration_names"
a:summary="@string/p_calc_haptic_feedback_duration_summary"
a:entryValues="@array/p_calc_haptic_feedback_duration_values"/>
<ListPreference a:key="@string/p_calc_multiplication_sign_key"
a:title="@string/c_calc_multiplication_sign"
a:entries="@array/p_multiplication_sign_values"
a:summary="@string/c_calc_multiplication_sign_summary"
a:entryValues="@array/p_multiplication_sign_values"/>
<ListPreference a:key="@string/p_calc_theme_key"
a:title="@string/c_calc_theme"
a:entries="@array/p_theme_names"
a:summary="@string/c_calc_theme_summary"
a:entryValues="@array/p_theme_values"/>
<ListPreference a:key="@string/p_calc_layout_key"
a:title="@string/c_calc_layout"
a:entries="@array/p_layout_names"
a:summary="@string/c_calc_layout_summary"
a:entryValues="@array/p_layout_values"/>
<org.solovyev.android.prefs.FloatRangeSeekBarPreference
a:key="@string/p_drag_distance_key"
a:title="@string/c_swipe_distance"
a:summary="@string/c_swipe_distance_summary"
a:text=" pxs"
a:defaultValue="35;350"
range:step="10"
range:boundaries="10;500"/>
<!-- <org.solovyev.android.prefs.FloatRangeSeekBarPreference
a:key="@string/p_drag_duration_key"
a:title="Duration of drag event"
a:text=" ms"
a:defaultValue="40;2500"
range:steps="10"
range:boundaries="5;4000"/>
<org.solovyev.android.prefs.FloatRangeSeekBarPreference
a:key="@string/p_drag_angle_key"
a:title="Angle of drag event"
a:text=" degrees"
a:defaultValue="0;45"
range:steps="5"
range:boundaries="0;45"/>-->
<android.preference.CheckBoxPreference
a:key="autoOrientation"
a:title="@string/c_auto_orientation_title"
a:summary="@string/c_auto_orientation_summary"
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="showEqualsButton"
a:title="@string/c_show_equals_button_title"
a:summary="@string/c_show_equals_button_summary"
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="hideNumeralBaseDigits"
a:title="@string/c_hide_numeral_base_digits_title"
a:summary="@string/c_hide_numeral_base_digits_summary"
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="history_show_intermediate_calculations"
a:title="@string/prefs_history_show_intermediate_calculations_title"
a:summary="@string/prefs_history_show_intermediate_calculations_summary"/>
</PreferenceScreen>
</PreferenceScreen>

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:range="http://schemas.android.com/apk/res-auto">
<PreferenceScreen a:title="@string/c_prefs_calculations_category">
<org.solovyev.android.ads.AdViewPreference a:layout="@layout/admob_pref"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_round_result_key"
a:summary="@string/c_calc_round_result_summary"
a:title="@string/c_calc_round_result_title"
a:defaultValue="true"/>
<org.solovyev.android.prefs.IntegerPickerDialogPreference
a:key="@string/p_calc_result_precision_key"
a:title="@string/p_calc_result_precision_title"
a:summary="@string/c_calc_result_precision_summary"
a:defaultValue="5"
range:boundaries="0;16"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_science_notation_key"
a:summary="@string/c_calc_science_notation_summary"
a:title="@string/c_calc_science_notation_title"
a:defaultValue="false"/>
<ListPreference a:key="@string/p_calc_grouping_separator_key"
a:title="@string/c_calc_grouping_separator"
a:entries="@array/p_grouping_separator_names"
a:summary="@string/c_calc_grouping_separator_summary"
a:entryValues="@array/p_grouping_separator_values"/>
<ListPreference a:key="@string/p_calc_angle_units_key"
a:title="@string/c_calc_angle_units"
a:entries="@array/p_angle_units_names"
a:summary="@string/c_angle_units_summary"
a:entryValues="@array/p_angle_units"/>
<ListPreference a:key="@string/p_calc_numeral_bases_key"
a:title="@string/c_calc_numeral_bases"
a:entries="@array/p_numeral_bases_names"
a:summary="@string/c_numeral_bases_summary"
a:entryValues="@array/p_numeral_bases"/>
<org.solovyev.android.prefs.IntegerPickerDialogPreference
a:key="@string/p_calc_max_calculation_time_key"
a:title="@string/p_calc_max_calculation_time_title"
a:summary="@string/p_calc_max_calculation_time_summary"
a:defaultValue="5"
range:boundaries="3;1000"/>
</PreferenceScreen>
</PreferenceScreen>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android">
<PreferenceScreen
a:title="@string/c_prefs_other_category">
<org.solovyev.android.ads.AdViewPreference a:layout="@layout/admob_pref"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_show_release_notes_key"
a:summary="@string/c_calc_show_release_notes_summary"
a:title="@string/c_calc_show_release_notes_title"
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_use_back_button_as_prev_key"
a:summary="@string/c_calc_use_back_button_as_prev_summary"
a:title="@string/c_calc_use_back_button_as_prev_title"
a:defaultValue="false"/>
<Preference
a:key="@string/p_clear_billing_info_key"
a:summary="@string/c_clear_billing_info_summary"
a:title="@string/c_clear_billing_info_title"/>
</PreferenceScreen>
</PreferenceScreen>

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android">
xmlns:range="http://schemas.android.com/apk/res-auto">
<Preference <Preference
a:key="@string/p_calc_ad_free_key" a:key="@string/p_calc_ad_free_key"
@ -12,167 +11,4 @@
<org.solovyev.android.ads.AdViewPreference a:layout="@layout/admob_pref"/> <org.solovyev.android.ads.AdViewPreference a:layout="@layout/admob_pref"/>
<PreferenceScreen a:title="@string/c_prefs_calculations_category">
<org.solovyev.android.ads.AdViewPreference a:layout="@layout/admob_pref"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_round_result_key"
a:summary="@string/c_calc_round_result_summary"
a:title="@string/c_calc_round_result_title"
a:defaultValue="true"/>
<org.solovyev.android.prefs.IntegerPickerDialogPreference
a:key="@string/p_calc_result_precision_key"
a:title="@string/p_calc_result_precision_title"
a:summary="@string/c_calc_result_precision_summary"
a:defaultValue="5"
range:boundaries="0;16"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_science_notation_key"
a:summary="@string/c_calc_science_notation_summary"
a:title="@string/c_calc_science_notation_title"
a:defaultValue="false"/>
<ListPreference a:key="@string/p_calc_grouping_separator_key"
a:title="@string/c_calc_grouping_separator"
a:entries="@array/p_grouping_separator_names"
a:summary="@string/c_calc_grouping_separator_summary"
a:entryValues="@array/p_grouping_separator_values"/>
<ListPreference a:key="@string/p_calc_angle_units_key"
a:title="@string/c_calc_angle_units"
a:entries="@array/p_angle_units_names"
a:summary="@string/c_angle_units_summary"
a:entryValues="@array/p_angle_units"/>
<ListPreference a:key="@string/p_calc_numeral_bases_key"
a:title="@string/c_calc_numeral_bases"
a:entries="@array/p_numeral_bases_names"
a:summary="@string/c_numeral_bases_summary"
a:entryValues="@array/p_numeral_bases"/>
<org.solovyev.android.prefs.IntegerPickerDialogPreference
a:key="@string/p_calc_max_calculation_time_key"
a:title="@string/p_calc_max_calculation_time_title"
a:summary="@string/p_calc_max_calculation_time_summary"
a:defaultValue="5"
range:boundaries="3;1000"/>
</PreferenceScreen>
<PreferenceScreen
a:title="@string/c_prefs_appearance_category">
<org.solovyev.android.ads.AdViewPreference a:layout="@layout/admob_pref"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_color_display_key"
a:summary="@string/c_calc_color_display_summary"
a:title="@string/c_calc_color_display_title"
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_haptic_feedback_key"
a:summary="@string/c_calc_haptic_feedback_summary"
a:title="@string/c_calc_haptic_feedback_title"
a:defaultValue="false"/>
<ListPreference a:key="@string/p_calc_haptic_feedback_duration_key"
a:title="@string/p_calc_haptic_feedback_duration_title"
a:entries="@array/p_calc_haptic_feedback_duration_names"
a:summary="@string/p_calc_haptic_feedback_duration_summary"
a:entryValues="@array/p_calc_haptic_feedback_duration_values"/>
<ListPreference a:key="@string/p_calc_multiplication_sign_key"
a:title="@string/c_calc_multiplication_sign"
a:entries="@array/p_multiplication_sign_values"
a:summary="@string/c_calc_multiplication_sign_summary"
a:entryValues="@array/p_multiplication_sign_values"/>
<ListPreference a:key="@string/p_calc_theme_key"
a:title="@string/c_calc_theme"
a:entries="@array/p_theme_names"
a:summary="@string/c_calc_theme_summary"
a:entryValues="@array/p_theme_values"/>
<ListPreference a:key="@string/p_calc_layout_key"
a:title="@string/c_calc_layout"
a:entries="@array/p_layout_names"
a:summary="@string/c_calc_layout_summary"
a:entryValues="@array/p_layout_values"/>
<org.solovyev.android.prefs.FloatRangeSeekBarPreference
a:key="@string/p_drag_distance_key"
a:title="@string/c_swipe_distance"
a:summary="@string/c_swipe_distance_summary"
a:text=" pxs"
a:defaultValue="35;350"
range:step="10"
range:boundaries="10;500"/>
<!-- <org.solovyev.android.prefs.FloatRangeSeekBarPreference
a:key="@string/p_drag_duration_key"
a:title="Duration of drag event"
a:text=" ms"
a:defaultValue="40;2500"
range:steps="10"
range:boundaries="5;4000"/>
<org.solovyev.android.prefs.FloatRangeSeekBarPreference
a:key="@string/p_drag_angle_key"
a:title="Angle of drag event"
a:text=" degrees"
a:defaultValue="0;45"
range:steps="5"
range:boundaries="0;45"/>-->
<android.preference.CheckBoxPreference
a:key="autoOrientation"
a:title="@string/c_auto_orientation_title"
a:summary="@string/c_auto_orientation_summary"
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="showEqualsButton"
a:title="@string/c_show_equals_button_title"
a:summary="@string/c_show_equals_button_summary"
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="hideNumeralBaseDigits"
a:title="@string/c_hide_numeral_base_digits_title"
a:summary="@string/c_hide_numeral_base_digits_summary"
a:defaultValue="true"/>
</PreferenceScreen>
<PreferenceScreen
a:title="@string/c_prefs_other_category">
<org.solovyev.android.ads.AdViewPreference a:layout="@layout/admob_pref"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_show_release_notes_key"
a:summary="@string/c_calc_show_release_notes_summary"
a:title="@string/c_calc_show_release_notes_title"
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="@string/p_calc_use_back_button_as_prev_key"
a:summary="@string/c_calc_use_back_button_as_prev_summary"
a:title="@string/c_calc_use_back_button_as_prev_title"
a:defaultValue="false"/>
<Preference
a:key="@string/p_clear_billing_info_key"
a:summary="@string/c_clear_billing_info_summary"
a:title="@string/c_clear_billing_info_title"/>
</PreferenceScreen>
</PreferenceScreen> </PreferenceScreen>

View File

@ -114,8 +114,13 @@ public final class CalculatorPreferences {
public static final Preference<GraphLineColor> lineColorImag = StringPreference.newInstance("graph_line_color_imag", GraphLineColor.blue, GraphLineColor.class); public static final Preference<GraphLineColor> lineColorImag = StringPreference.newInstance("graph_line_color_imag", GraphLineColor.blue, GraphLineColor.class);
} }
public static class History {
public static final Preference<Boolean> showIntermediateCalculations = new BooleanPreference("history_show_intermediate_calculations", false);
}
static void setDefaultValues(@NotNull SharedPreferences preferences) {
static void setDefaultValues(@NotNull SharedPreferences preferences) {
if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) { if (!AndroidCalculatorEngine.Preferences.groupingSeparator.isSet(preferences)) {
final Locale locale = Locale.getDefault(); final Locale locale = Locale.getDefault();
if (locale != null) { if (locale != null) {
@ -163,6 +168,7 @@ public final class CalculatorPreferences {
applyDefaultPreference(preferences, Graph.interpolate); applyDefaultPreference(preferences, Graph.interpolate);
applyDefaultPreference(preferences, Graph.lineColorImag); applyDefaultPreference(preferences, Graph.lineColorImag);
applyDefaultPreference(preferences, Graph.lineColorReal); applyDefaultPreference(preferences, Graph.lineColorReal);
applyDefaultPreference(preferences, History.showIntermediateCalculations);
if ( !VibratorContainer.Preferences.hapticFeedbackEnabled.isSet(preferences) ) { if ( !VibratorContainer.Preferences.hapticFeedbackEnabled.isSet(preferences) ) {
VibratorContainer.Preferences.hapticFeedbackEnabled.putPreference(preferences, true); VibratorContainer.Preferences.hapticFeedbackEnabled.putPreference(preferences, true);

View File

@ -42,7 +42,10 @@ public class CalculatorPreferencesActivity extends SherlockPreferenceActivity im
//noinspection deprecation //noinspection deprecation
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
//noinspection deprecation //noinspection deprecation
addPreferencesFromResource(R.xml.calculations_preferences);
addPreferencesFromResource(R.xml.appearance_preferences);
addPreferencesFromResource(R.xml.plot_preferences); addPreferencesFromResource(R.xml.plot_preferences);
addPreferencesFromResource(R.xml.other_preferences);
final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY); final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
adFreePreference.setEnabled(false); adFreePreference.setEnabled(false);

View File

@ -12,7 +12,10 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.Calculator;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.R;
import org.solovyev.common.history.HistoryAction; import org.solovyev.common.history.HistoryAction;
import java.util.List; import java.util.List;
@ -117,6 +120,12 @@ public class AndroidCalculatorHistory implements CalculatorHistory {
return calculatorHistory.getStates(); return calculatorHistory.getStates();
} }
@NotNull
@Override
public List<CalculatorHistoryState> getStates(boolean includeIntermediateStates) {
return calculatorHistory.getStates(includeIntermediateStates);
}
@Override @Override
public void clear() { public void clear() {
calculatorHistory.clear(); calculatorHistory.clear();

View File

@ -6,8 +6,10 @@
package org.solovyev.android.calculator.history; package org.solovyev.android.calculator.history;
import android.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.CalculatorLocatorImpl; import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.CalculatorPreferences;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.about.CalculatorFragmentType; import org.solovyev.android.calculator.about.CalculatorFragmentType;
@ -33,7 +35,8 @@ public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment
@NotNull @NotNull
@Override @Override
protected List<CalculatorHistoryState> getHistoryItems() { protected List<CalculatorHistoryState> getHistoryItems() {
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getStates()); final boolean showIntermediateCalculations = CalculatorPreferences.History.showIntermediateCalculations.getPreference(PreferenceManager.getDefaultSharedPreferences(getActivity()));
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getStates(showIntermediateCalculations));
} }
@Override @Override