This commit is contained in:
Sergey Solovyev 2012-10-04 00:00:34 +04:00
parent e3f7fd5cb1
commit a49ca358af
9 changed files with 482 additions and 442 deletions

View File

@ -18,7 +18,7 @@
style="?fragmentTitleStyle"/> style="?fragmentTitleStyle"/>
<ScrollView a:layout_width="match_parent" <ScrollView a:layout_width="match_parent"
a:layout_height="match_parent"> a:layout_height="wrap_content">
<TextView <TextView
a:text="@string/c_faq_content" a:text="@string/c_faq_content"

View File

@ -218,5 +218,8 @@
In order to fix the problem we need some information about it. It\'s highly recommended to send crash report via email (after pressing \'Ok\' button you will see all sent data in the new window).\n\n In order to fix the problem we need some information about it. It\'s highly recommended to send crash report via email (after pressing \'Ok\' button you will see all sent data in the new window).\n\n
Do you want to send crash report? Do you want to send crash report?
</string> </string>
<string name="c_prefs_graph">Graph preferences</string>
<string name="c_show_complex_graph_summary">If checked complex graph will be plotted</string>
<string name="c_show_complex_graph_title">Show complex graph</string>
</resources> </resources>

View File

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

View File

@ -1,240 +1,247 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast; import android.widget.Toast;
import jscl.AngleUnit; import jscl.AngleUnit;
import jscl.NumeralBase; import jscl.NumeralBase;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.AndroidUtils; import org.solovyev.android.AndroidUtils;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.view.AngleUnitsButton; import org.solovyev.android.calculator.view.AngleUnitsButton;
import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.calculator.view.NumeralBasesButton;
import org.solovyev.android.view.ColorButton; import org.solovyev.android.view.ColorButton;
import org.solovyev.android.view.drag.DragButton; import org.solovyev.android.view.drag.DragButton;
import org.solovyev.android.view.drag.DragDirection; import org.solovyev.android.view.drag.DragDirection;
import org.solovyev.android.view.drag.SimpleOnDragListener; import org.solovyev.android.view.drag.SimpleOnDragListener;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
/** /**
* User: serso * User: serso
* Date: 9/28/12 * Date: 9/28/12
* Time: 12:06 AM * Time: 12:06 AM
*/ */
public final class CalculatorButtons { public final class CalculatorButtons {
private CalculatorButtons () { private CalculatorButtons () {
} }
public static void processButtons(boolean fixMagicFlames, public static void processButtons(boolean fixMagicFlames,
@NotNull CalculatorPreferences.Gui.Theme theme, @NotNull CalculatorPreferences.Gui.Theme theme,
@NotNull View root) { @NotNull View root) {
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) { if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
if (fixMagicFlames) { if (fixMagicFlames) {
// for metro themes we should turn off magic flames // for metro themes we should turn off magic flames
AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() { AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() {
@Override @Override
public void process(@NotNull ColorButton colorButton) { public void process(@NotNull ColorButton colorButton) {
colorButton.setDrawMagicFlame(false); colorButton.setDrawMagicFlame(false);
} }
}); });
} }
} }
} }
static void initMultiplicationButton(@NotNull View root) { static void initMultiplicationButton(@NotNull View root) {
final View multiplicationButton = root.findViewById(R.id.multiplicationButton); final View multiplicationButton = root.findViewById(R.id.multiplicationButton);
if ( multiplicationButton instanceof Button) { if ( multiplicationButton instanceof Button) {
((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign()); ((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
} }
} }
public static void toggleEqualsButton(@Nullable SharedPreferences preferences, public static void toggleEqualsButton(@Nullable SharedPreferences preferences,
@NotNull Activity activity) { @NotNull Activity activity) {
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences; preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
final boolean large = AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, activity.getResources().getConfiguration()); final boolean large = AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, activity.getResources().getConfiguration());
if (!large) { if (!large) {
if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT
|| !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) { || !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
final DragButton equalsButton = (DragButton)activity.findViewById(R.id.equalsButton); final DragButton equalsButton = (DragButton)activity.findViewById(R.id.equalsButton);
if (equalsButton != null) { if (equalsButton != null) {
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) { if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
equalsButton.setVisibility(View.VISIBLE); equalsButton.setVisibility(View.VISIBLE);
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView(); final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
if (calculatorDisplayView != null) { if (calculatorDisplayView != null) {
calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
} }
} else { } else {
equalsButton.setVisibility(View.GONE); equalsButton.setVisibility(View.GONE);
// mobile phones // mobile phones
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView(); final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
if (calculatorDisplayView != null) { if (calculatorDisplayView != null) {
calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(activity.getResources().getDrawable(R.drawable.equals9), null, null, null); calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(activity.getResources().getDrawable(R.drawable.equals9), null, null, null);
} }
} }
} }
} }
} }
} }
@Nullable @Nullable
private static AndroidCalculatorDisplayView getCalculatorDisplayView() { private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView(); return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
} }
/* /*
********************************************************************** **********************************************************************
* *
* STATIC CLASSES * STATIC CLASSES
* *
********************************************************************** **********************************************************************
*/ */
static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor { static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor {
@Override @Override
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) { public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
final boolean result; final boolean result;
if (dragDirection == DragDirection.left) { if (dragDirection == DragDirection.left) {
getKeyboard().roundBracketsButtonPressed(); getKeyboard().roundBracketsButtonPressed();
result = true; result = true;
} else { } else {
result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent); result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
} }
return result; return result;
} }
} }
@NotNull @NotNull
private static CalculatorKeyboard getKeyboard() { private static CalculatorKeyboard getKeyboard() {
return CalculatorLocatorImpl.getInstance().getKeyboard(); return CalculatorLocatorImpl.getInstance().getKeyboard();
} }
static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor { static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
@NotNull @NotNull
private Context context; private Context context;
VarsDragProcessor(Context context) { VarsDragProcessor(Context context) {
this.context = context; this.context = context;
} }
@Override @Override
public boolean processDragEvent(@NotNull DragDirection dragDirection, public boolean processDragEvent(@NotNull DragDirection dragDirection,
@NotNull DragButton dragButton, @NotNull DragButton dragButton,
@NotNull Point2d startPoint2d, @NotNull Point2d startPoint2d,
@NotNull MotionEvent motionEvent) { @NotNull MotionEvent motionEvent) {
boolean result = false; boolean result = false;
if (dragDirection == DragDirection.up) { if (dragDirection == DragDirection.up) {
CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay()); CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay());
result = true; result = true;
} }
return result; return result;
} }
} }
static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor { static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
@NotNull @NotNull
private final DigitButtonDragProcessor processor; private final DigitButtonDragProcessor processor;
@NotNull @NotNull
private final Context context; private final Context context;
AngleUnitsChanger(@NotNull Context context) { AngleUnitsChanger(@NotNull Context context) {
this.context = context; this.context = context;
this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard()); this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard());
} }
@Override @Override
public boolean processDragEvent(@NotNull DragDirection dragDirection, public boolean processDragEvent(@NotNull DragDirection dragDirection,
@NotNull DragButton dragButton, @NotNull DragButton dragButton,
@NotNull Point2d startPoint2d, @NotNull Point2d startPoint2d,
@NotNull MotionEvent motionEvent) { @NotNull MotionEvent motionEvent) {
boolean result = false; boolean result = false;
if (dragButton instanceof AngleUnitsButton) { if (dragButton instanceof AngleUnitsButton) {
if (dragDirection != DragDirection.left) { if (dragDirection != DragDirection.left) {
final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection); final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
if (directionText != null) { if (directionText != null) {
try { try {
final AngleUnit angleUnits = AngleUnit.valueOf(directionText); final AngleUnit angleUnits = AngleUnit.valueOf(directionText);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits); final AngleUnit oldAngleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(preferences);
if (oldAngleUnits != angleUnits) {
Toast.makeText(context, context.getString(R.string.c_angle_units_changed_to, angleUnits.name()), Toast.LENGTH_LONG).show(); AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
result = true; Toast.makeText(context, context.getString(R.string.c_angle_units_changed_to, angleUnits.name()), Toast.LENGTH_LONG).show();
} catch (IllegalArgumentException e) { }
Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText);
} result = true;
} } catch (IllegalArgumentException e) {
} else if (dragDirection == DragDirection.left) { Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText);
result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent); }
} }
} } else if (dragDirection == DragDirection.left) {
result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
return result; }
} }
}
return result;
static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor { }
}
@NotNull
private final Context context; static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
NumeralBasesChanger(@NotNull Context context) { @NotNull
this.context = context; private final Context context;
}
NumeralBasesChanger(@NotNull Context context) {
@Override this.context = context;
public boolean processDragEvent(@NotNull DragDirection dragDirection, }
@NotNull DragButton dragButton,
@NotNull Point2d startPoint2d, @Override
@NotNull MotionEvent motionEvent) { public boolean processDragEvent(@NotNull DragDirection dragDirection,
boolean result = false; @NotNull DragButton dragButton,
@NotNull Point2d startPoint2d,
if (dragButton instanceof NumeralBasesButton) { @NotNull MotionEvent motionEvent) {
final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection); boolean result = false;
if (directionText != null) {
try { if (dragButton instanceof NumeralBasesButton) {
final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection);
final NumeralBase numeralBase = NumeralBase.valueOf(directionText); if (directionText != null) {
try {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase); final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
Toast.makeText(context, context.getString(R.string.c_numeral_base_changed_to, numeralBase.name()), Toast.LENGTH_LONG).show(); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
result = true; final NumeralBase oldNumeralBase = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences);
} catch (IllegalArgumentException e) { if (oldNumeralBase != numeralBase) {
Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText); AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
}
} Toast.makeText(context, context.getString(R.string.c_numeral_base_changed_to, numeralBase.name()), Toast.LENGTH_LONG).show();
} }
return result; result = true;
} } catch (IllegalArgumentException e) {
} Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText);
} }
}
}
return result;
}
}
}

View File

@ -97,6 +97,12 @@ public final class CalculatorPreferences {
} }
} }
public static class Graph {
public static final Preference<Boolean> showComplexGraph = new BooleanPreference("show_complex_graph", 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();

View File

@ -29,10 +29,8 @@ public enum CalculatorFragmentType {
variables(CalculatorVarsFragment.class, R.layout.vars_fragment, R.string.c_vars), variables(CalculatorVarsFragment.class, R.layout.vars_fragment, R.string.c_vars),
functions(CalculatorFunctionsFragment.class, R.layout.math_entities_fragment, R.string.c_functions), functions(CalculatorFunctionsFragment.class, R.layout.math_entities_fragment, R.string.c_functions),
operators(CalculatorOperatorsFragment.class, R.layout.math_entities_fragment, R.string.c_operators), operators(CalculatorOperatorsFragment.class, R.layout.math_entities_fragment, R.string.c_operators),
plotter(CalculatorPlotFragment.class, R.layout.plot_fragment, R.string.c_plot), plotter(CalculatorPlotFragment.class, R.layout.plot_fragment, R.string.c_graph),
about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about), about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about),
// todo serso: rename and inflate ad
faq(CalculatorHelpFaqFragment.class, R.layout.help_faq_fragment, R.string.c_faq), faq(CalculatorHelpFaqFragment.class, R.layout.help_faq_fragment, R.string.c_faq),
hints(CalculatorHelpHintsFragment.class, R.layout.help_hints_fragment, R.string.c_hints), hints(CalculatorHelpHintsFragment.class, R.layout.help_hints_fragment, R.string.c_hints),
screens(CalculatorHelpScreensFragment.class, R.layout.help_screens_fragment, R.string.c_screens), screens(CalculatorHelpScreensFragment.class, R.layout.help_screens_fragment, R.string.c_screens),

View File

@ -163,7 +163,7 @@ public class AndroidCalculatorEngine implements CalculatorEngine, SharedPreferen
@Override @Override
public void init() { public void init() {
synchronized (lock) { synchronized (lock) {
calculatorEngine.init(); reset();
} }
} }

View File

@ -6,9 +6,11 @@
package org.solovyev.android.calculator.plot; package org.solovyev.android.calculator.plot;
import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -56,7 +58,8 @@ public class CalculatorPlotFragment extends SherlockFragment implements Calculat
private static final int DEFAULT_MAX_NUMBER = 10; private static final int DEFAULT_MAX_NUMBER = 10;
public static final String INPUT = "org.solovyev.android.calculator.CalculatorPlotActivity_input"; public static final String INPUT = "plotter_input";
private static final String PLOT_BOUNDARIES = "plot_boundaries";
public static final long EVAL_DELAY_MILLIS = 200; public static final long EVAL_DELAY_MILLIS = 200;
@ -74,7 +77,7 @@ public class CalculatorPlotFragment extends SherlockFragment implements Calculat
private Constant variable; private Constant variable;
@NotNull @NotNull
private final CalculatorFragmentHelper fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.plot_fragment, R.string.c_plot, false); private final CalculatorFragmentHelper fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.plot_fragment, R.string.c_graph, false);
@NotNull @NotNull
private final Executor plotExecutor = Executors.newSingleThreadExecutor(); private final Executor plotExecutor = Executors.newSingleThreadExecutor();
@ -113,6 +116,8 @@ public class CalculatorPlotFragment extends SherlockFragment implements Calculat
this.bgColor = getResources().getColor(android.R.color.transparent); this.bgColor = getResources().getColor(android.R.color.transparent);
prepareData(); prepareData();
} }
setRetainInstance(true);
} }
private void createInputFromDisplayState(@NotNull CalculatorDisplayViewState displayState) { private void createInputFromDisplayState(@NotNull CalculatorDisplayViewState displayState) {
@ -161,7 +166,25 @@ public class CalculatorPlotFragment extends SherlockFragment implements Calculat
this.fragmentHelper.onViewCreated(this, root); this.fragmentHelper.onViewCreated(this, root);
updateGraphicalView(root);
PlotBoundaries plotBoundaries = null;
/*if ( savedInstanceState != null ) {
final Object object = savedInstanceState.getSerializable(PLOT_BOUNDARIES);
if ( object instanceof PlotBoundaries) {
plotBoundaries = ((PlotBoundaries) object);
}
}*/
updateGraphicalView(root, plotBoundaries);
}
@Override
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
/*if (chart != null) {
out.putSerializable(PLOT_BOUNDARIES, new PlotBoundaries(chart.getRenderer()));
}*/
} }
@Override @Override
@ -172,7 +195,7 @@ public class CalculatorPlotFragment extends SherlockFragment implements Calculat
if ( !inputFromArgs ) { if ( !inputFromArgs ) {
createInputFromDisplayState(CalculatorLocatorImpl.getInstance().getDisplay().getViewState()); createInputFromDisplayState(CalculatorLocatorImpl.getInstance().getDisplay().getViewState());
updateGraphicalView(getView()); updateGraphicalView(getView(), null);
} }
} }
@ -183,11 +206,9 @@ public class CalculatorPlotFragment extends SherlockFragment implements Calculat
super.onPause(); super.onPause();
} }
private void updateGraphicalView(@NotNull View root) { private void updateGraphicalView(@NotNull View root, @Nullable PlotBoundaries plotBoundaries) {
if (input != null) { if (input != null) {
// todo serso setGraphicalView(root, plotBoundaries);
final Object lastNonConfigurationInstance = null;//getLastNonConfigurationInstance();
setGraphicalView(root, lastNonConfigurationInstance instanceof PlotBoundaries ? (PlotBoundaries) lastNonConfigurationInstance : null);
} else { } else {
Toast.makeText(this.getActivity(), "Plot is not possible!", Toast.LENGTH_LONG).show(); Toast.makeText(this.getActivity(), "Plot is not possible!", Toast.LENGTH_LONG).show();
} }
@ -282,6 +303,9 @@ public class CalculatorPlotFragment extends SherlockFragment implements Calculat
} }
private void updateDataSets(@NotNull final XYChart chart, long millisToWait) { private void updateDataSets(@NotNull final XYChart chart, long millisToWait) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
final boolean showComplexGraph = CalculatorPreferences.Graph.showComplexGraph.getPreference(preferences);
pendingOperation.setObject(new Runnable() { pendingOperation.setObject(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -405,7 +429,7 @@ public class CalculatorPlotFragment extends SherlockFragment implements Calculat
public void run() { public void run() {
final View view = getView(); final View view = getView();
if (view != null) { if (view != null) {
updateGraphicalView(view); updateGraphicalView(view, null);
} }
} }
}); });

View File

@ -37,7 +37,7 @@ public final class PlotUtils {
@NotNull Generic expression, @NotNull Generic expression,
@NotNull Constant variable, @NotNull Constant variable,
@NotNull MyXYSeries realSeries, @NotNull MyXYSeries realSeries,
@NotNull MyXYSeries imagSeries, @Nullable MyXYSeries imagSeries,
boolean addExtra, boolean addExtra,
int numberOfSteps) throws ArithmeticException { int numberOfSteps) throws ArithmeticException {
@ -72,7 +72,7 @@ public final class PlotUtils {
prevX = x; prevX = x;
} }
boolean needToCalculateImagY = imagSeries.needToAdd(step, x); boolean needToCalculateImagY = imagSeries != null && imagSeries.needToAdd(step, x);
if (needToCalculateImagY) { if (needToCalculateImagY) {
y = prepareY(c.imaginaryPart()); y = prepareY(c.imaginaryPart());
if (y != null) { if (y != null) {
@ -86,7 +86,7 @@ public final class PlotUtils {
} }
} }
} else { } else {
boolean needToCalculateImagY = imagSeries.needToAdd(step, x); boolean needToCalculateImagY = imagSeries != null && imagSeries.needToAdd(step, x);
if (needToCalculateImagY) { if (needToCalculateImagY) {
final Complex c = calculatorExpression(expression, variable, x); final Complex c = calculatorExpression(expression, variable, x);
Double y = prepareY(c.imaginaryPart()); Double y = prepareY(c.imaginaryPart());