Matrix support
This commit is contained in:
parent
08af58b18a
commit
de52ca4512
@ -37,6 +37,9 @@
|
||||
|
||||
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
||||
|
||||
<!-- todo serso: strings-->
|
||||
<activity android:label="@string/c_plot_graph" android:name=".matrix.CalculatorMatrixActivity"/>
|
||||
|
||||
<!-- settings must use action bar icon-->
|
||||
<activity android:icon="@drawable/icon_action_bar" android:label="@string/c_settings" android:name=".plot.CalculatorPlotPreferenceActivity"/>
|
||||
|
||||
|
@ -1,17 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
~ For more information, please, contact se.solovyev@gmail.com
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/varsButton"
|
||||
c:directionTextScale="0.5"
|
||||
c:textUp="+π"
|
||||
a:text="π,…"
|
||||
a:textStyle="italic"
|
||||
a:onClick="varsButtonClickHandler"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
~ For more information, please, contact se.solovyev@gmail.com
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/varsButton"
|
||||
c:directionTextScale="0.5"
|
||||
c:textUp="+π"
|
||||
c:textDown="+m"
|
||||
a:text="π,…"
|
||||
a:textStyle="italic"
|
||||
a:onClick="varsButtonClickHandler"
|
||||
style="?controlButtonStyle"/>
|
35
calculatorpp/res/layout/matrix_edit_fragment.xml
Normal file
35
calculatorpp/res/layout/matrix_edit_fragment.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:id="@+id/main_fragment_layout"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_width="match_parent"
|
||||
style="?fragmentLayoutStyle">
|
||||
|
||||
<LinearLayout a:layout_height="wrap_content"
|
||||
a:layout_width="match_parent"
|
||||
a:gravity="center">
|
||||
|
||||
<TextView a:layout_height="wrap_content"
|
||||
a:layout_width="wrap_content"
|
||||
a:text="Rows"/>
|
||||
|
||||
<org.solovyev.android.view.Picker a:id="@+id/matrix_rows_count_picker"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="wrap_content"/>
|
||||
|
||||
<TextView a:layout_height="wrap_content"
|
||||
a:layout_width="wrap_content"
|
||||
a:text="Columns"/>
|
||||
|
||||
<org.solovyev.android.view.Picker a:id="@+id/matrix_cols_count_picker"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_width="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TableLayout a:id="@+id/matrix_layout"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_width="match_parent"/>
|
||||
|
||||
</LinearLayout>
|
12
calculatorpp/res/layout/matrix_edit_fragment_item.xml
Normal file
12
calculatorpp/res/layout/matrix_edit_fragment_item.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_width="match_parent">
|
||||
|
||||
<EditText a:id="@+id/matrix_element_edittext"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_width="match_parent"
|
||||
a:text="test"/>
|
||||
|
||||
</LinearLayout>
|
@ -1,238 +1,243 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
||||
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
||||
import org.solovyev.android.view.ColorButton;
|
||||
import org.solovyev.android.view.drag.DragButton;
|
||||
import org.solovyev.android.view.drag.DragDirection;
|
||||
import org.solovyev.android.view.drag.SimpleOnDragListener;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/28/12
|
||||
* Time: 12:06 AM
|
||||
*/
|
||||
public final class CalculatorButtons {
|
||||
|
||||
private CalculatorButtons () {
|
||||
}
|
||||
|
||||
|
||||
public static void processButtons(boolean fixMagicFlames,
|
||||
@NotNull CalculatorPreferences.Gui.Theme theme,
|
||||
@NotNull View root) {
|
||||
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
|
||||
|
||||
if (fixMagicFlames) {
|
||||
// for metro themes we should turn off magic flames
|
||||
AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() {
|
||||
@Override
|
||||
public void process(@NotNull ColorButton colorButton) {
|
||||
colorButton.setDrawMagicFlame(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void initMultiplicationButton(@NotNull View root) {
|
||||
final View multiplicationButton = root.findViewById(R.id.multiplicationButton);
|
||||
if ( multiplicationButton instanceof Button) {
|
||||
((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void toggleEqualsButton(@Nullable SharedPreferences preferences,
|
||||
@NotNull Activity activity) {
|
||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
|
||||
|
||||
final boolean large = AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, activity.getResources().getConfiguration());
|
||||
|
||||
if (!large) {
|
||||
if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT
|
||||
|| !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
||||
|
||||
final DragButton equalsButton = (DragButton)activity.findViewById(R.id.equalsButton);
|
||||
if (equalsButton != null) {
|
||||
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
|
||||
equalsButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
equalsButton.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
|
||||
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC CLASSES
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
||||
final boolean result;
|
||||
|
||||
if (dragDirection == DragDirection.left) {
|
||||
getKeyboard().roundBracketsButtonPressed();
|
||||
result = true;
|
||||
} else {
|
||||
result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static CalculatorKeyboard getKeyboard() {
|
||||
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
||||
}
|
||||
|
||||
static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
||||
|
||||
@NotNull
|
||||
private Context context;
|
||||
|
||||
VarsDragProcessor(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
||||
@NotNull DragButton dragButton,
|
||||
@NotNull Point2d startPoint2d,
|
||||
@NotNull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
if (dragDirection == DragDirection.up) {
|
||||
CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay());
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
|
||||
|
||||
@NotNull
|
||||
private final DigitButtonDragProcessor processor;
|
||||
|
||||
@NotNull
|
||||
private final Context context;
|
||||
|
||||
AngleUnitsChanger(@NotNull Context context) {
|
||||
this.context = context;
|
||||
this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
||||
@NotNull DragButton dragButton,
|
||||
@NotNull Point2d startPoint2d,
|
||||
@NotNull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
if (dragButton instanceof AngleUnitsButton) {
|
||||
if (dragDirection != DragDirection.left) {
|
||||
final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
|
||||
if (directionText != null) {
|
||||
try {
|
||||
|
||||
final AngleUnit angleUnits = AngleUnit.valueOf(directionText);
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
final AngleUnit oldAngleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(preferences);
|
||||
if (oldAngleUnits != angleUnits) {
|
||||
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
|
||||
|
||||
Toast.makeText(context, context.getString(R.string.c_angle_units_changed_to, angleUnits.name()), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
result = true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText);
|
||||
}
|
||||
}
|
||||
} else if (dragDirection == DragDirection.left) {
|
||||
result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
|
||||
|
||||
@NotNull
|
||||
private final Context context;
|
||||
|
||||
NumeralBasesChanger(@NotNull Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
||||
@NotNull DragButton dragButton,
|
||||
@NotNull Point2d startPoint2d,
|
||||
@NotNull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
if (dragButton instanceof NumeralBasesButton) {
|
||||
final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection);
|
||||
if (directionText != null) {
|
||||
try {
|
||||
|
||||
final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
final NumeralBase oldNumeralBase = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences);
|
||||
if (oldNumeralBase != numeralBase) {
|
||||
AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
|
||||
|
||||
Toast.makeText(context, context.getString(R.string.c_numeral_base_changed_to, numeralBase.name()), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
result = true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.matrix.CalculatorMatrixActivity;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
||||
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
||||
import org.solovyev.android.view.ColorButton;
|
||||
import org.solovyev.android.view.drag.DragButton;
|
||||
import org.solovyev.android.view.drag.DragDirection;
|
||||
import org.solovyev.android.view.drag.SimpleOnDragListener;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/28/12
|
||||
* Time: 12:06 AM
|
||||
*/
|
||||
public final class CalculatorButtons {
|
||||
|
||||
private CalculatorButtons () {
|
||||
}
|
||||
|
||||
|
||||
public static void processButtons(boolean fixMagicFlames,
|
||||
@NotNull CalculatorPreferences.Gui.Theme theme,
|
||||
@NotNull View root) {
|
||||
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
|
||||
|
||||
if (fixMagicFlames) {
|
||||
// for metro themes we should turn off magic flames
|
||||
AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() {
|
||||
@Override
|
||||
public void process(@NotNull ColorButton colorButton) {
|
||||
colorButton.setDrawMagicFlame(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void initMultiplicationButton(@NotNull View root) {
|
||||
final View multiplicationButton = root.findViewById(R.id.multiplicationButton);
|
||||
if ( multiplicationButton instanceof Button) {
|
||||
((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void toggleEqualsButton(@Nullable SharedPreferences preferences,
|
||||
@NotNull Activity activity) {
|
||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
|
||||
|
||||
final boolean large = AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, activity.getResources().getConfiguration());
|
||||
|
||||
if (!large) {
|
||||
if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT
|
||||
|| !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
||||
|
||||
final DragButton equalsButton = (DragButton)activity.findViewById(R.id.equalsButton);
|
||||
if (equalsButton != null) {
|
||||
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
|
||||
equalsButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
equalsButton.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
|
||||
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC CLASSES
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
||||
final boolean result;
|
||||
|
||||
if (dragDirection == DragDirection.left) {
|
||||
getKeyboard().roundBracketsButtonPressed();
|
||||
result = true;
|
||||
} else {
|
||||
result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static CalculatorKeyboard getKeyboard() {
|
||||
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
||||
}
|
||||
|
||||
static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
||||
|
||||
@NotNull
|
||||
private Context context;
|
||||
|
||||
VarsDragProcessor(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
||||
@NotNull DragButton dragButton,
|
||||
@NotNull Point2d startPoint2d,
|
||||
@NotNull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
if (dragDirection == DragDirection.up) {
|
||||
CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay());
|
||||
result = true;
|
||||
} else if ( dragDirection == DragDirection.down ) {
|
||||
context.startActivity(new Intent(context, CalculatorMatrixActivity.class));
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
|
||||
|
||||
@NotNull
|
||||
private final DigitButtonDragProcessor processor;
|
||||
|
||||
@NotNull
|
||||
private final Context context;
|
||||
|
||||
AngleUnitsChanger(@NotNull Context context) {
|
||||
this.context = context;
|
||||
this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
||||
@NotNull DragButton dragButton,
|
||||
@NotNull Point2d startPoint2d,
|
||||
@NotNull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
if (dragButton instanceof AngleUnitsButton) {
|
||||
if (dragDirection != DragDirection.left) {
|
||||
final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
|
||||
if (directionText != null) {
|
||||
try {
|
||||
|
||||
final AngleUnit angleUnits = AngleUnit.valueOf(directionText);
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
final AngleUnit oldAngleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(preferences);
|
||||
if (oldAngleUnits != angleUnits) {
|
||||
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
|
||||
|
||||
Toast.makeText(context, context.getString(R.string.c_angle_units_changed_to, angleUnits.name()), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
result = true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText);
|
||||
}
|
||||
}
|
||||
} else if (dragDirection == DragDirection.left) {
|
||||
result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
|
||||
|
||||
@NotNull
|
||||
private final Context context;
|
||||
|
||||
NumeralBasesChanger(@NotNull Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection,
|
||||
@NotNull DragButton dragButton,
|
||||
@NotNull Point2d startPoint2d,
|
||||
@NotNull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
if (dragButton instanceof NumeralBasesButton) {
|
||||
final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection);
|
||||
if (directionText != null) {
|
||||
try {
|
||||
|
||||
final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
final NumeralBase oldNumeralBase = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences);
|
||||
if (oldNumeralBase != numeralBase) {
|
||||
AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
|
||||
|
||||
Toast.makeText(context, context.getString(R.string.c_numeral_base_changed_to, numeralBase.name()), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
result = true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +1,80 @@
|
||||
package org.solovyev.android.calculator.about;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorEditorFragment;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.help.CalculatorHelpFaqFragment;
|
||||
import org.solovyev.android.calculator.help.CalculatorHelpHintsFragment;
|
||||
import org.solovyev.android.calculator.help.CalculatorHelpScreensFragment;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 03.10.12
|
||||
* Time: 11:30
|
||||
*/
|
||||
public enum CalculatorFragmentType {
|
||||
|
||||
editor(CalculatorEditorFragment.class, R.layout.calc_editor, R.string.editor),
|
||||
//display(CalculatorHistoryFragment.class, "history", R.layout.history_fragment, R.string.c_history),
|
||||
//keyboard(CalculatorHistoryFragment.class, "history", R.layout.history_fragment, R.string.c_history),
|
||||
history(CalculatorHistoryFragment.class, R.layout.history_fragment, R.string.c_history),
|
||||
saved_history(CalculatorSavedHistoryFragment.class, R.layout.history_fragment, R.string.c_saved_history),
|
||||
variables(CalculatorVarsFragment.class, R.layout.vars_fragment, R.string.c_vars),
|
||||
functions(CalculatorFunctionsFragment.class, R.layout.math_entities_fragment, R.string.c_functions),
|
||||
operators(CalculatorOperatorsFragment.class, R.layout.math_entities_fragment, R.string.c_operators),
|
||||
plotter(CalculatorPlotFragment.class, R.layout.plot_fragment, R.string.c_graph),
|
||||
about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about),
|
||||
faq(CalculatorHelpFaqFragment.class, R.layout.help_faq_fragment, R.string.c_faq),
|
||||
hints(CalculatorHelpHintsFragment.class, R.layout.help_hints_fragment, R.string.c_hints),
|
||||
screens(CalculatorHelpScreensFragment.class, R.layout.help_screens_fragment, R.string.c_screens),
|
||||
release_notes(CalculatorReleaseNotesFragment.class, R.layout.release_notes_fragment, R.string.c_release_notes);
|
||||
|
||||
@NotNull
|
||||
private Class<? extends Fragment> fragmentClass;
|
||||
|
||||
private final int defaultLayoutId;
|
||||
|
||||
private int defaultTitleResId;
|
||||
|
||||
private CalculatorFragmentType(@NotNull Class<? extends Fragment> fragmentClass,
|
||||
int defaultLayoutId,
|
||||
int defaultTitleResId) {
|
||||
this.fragmentClass = fragmentClass;
|
||||
this.defaultLayoutId = defaultLayoutId;
|
||||
this.defaultTitleResId = defaultTitleResId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFragmentTag() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
public int getDefaultTitleResId() {
|
||||
return defaultTitleResId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Class<? extends Fragment> getFragmentClass() {
|
||||
return fragmentClass;
|
||||
}
|
||||
|
||||
public int getDefaultLayoutId() {
|
||||
return defaultLayoutId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String createSubFragmentTag(@NotNull String subFragmentTag) {
|
||||
return this.getFragmentTag() + "_" + subFragmentTag;
|
||||
}
|
||||
}
|
||||
package org.solovyev.android.calculator.about;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorEditorFragment;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.help.CalculatorHelpFaqFragment;
|
||||
import org.solovyev.android.calculator.help.CalculatorHelpHintsFragment;
|
||||
import org.solovyev.android.calculator.help.CalculatorHelpScreensFragment;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
|
||||
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
|
||||
import org.solovyev.android.calculator.matrix.CalculatorMatrixEditFragment;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 03.10.12
|
||||
* Time: 11:30
|
||||
*/
|
||||
public enum CalculatorFragmentType {
|
||||
|
||||
editor(CalculatorEditorFragment.class, R.layout.calc_editor, R.string.editor),
|
||||
//display(CalculatorHistoryFragment.class, "history", R.layout.history_fragment, R.string.c_history),
|
||||
//keyboard(CalculatorHistoryFragment.class, "history", R.layout.history_fragment, R.string.c_history),
|
||||
history(CalculatorHistoryFragment.class, R.layout.history_fragment, R.string.c_history),
|
||||
saved_history(CalculatorSavedHistoryFragment.class, R.layout.history_fragment, R.string.c_saved_history),
|
||||
variables(CalculatorVarsFragment.class, R.layout.vars_fragment, R.string.c_vars),
|
||||
functions(CalculatorFunctionsFragment.class, R.layout.math_entities_fragment, R.string.c_functions),
|
||||
operators(CalculatorOperatorsFragment.class, R.layout.math_entities_fragment, R.string.c_operators),
|
||||
plotter(CalculatorPlotFragment.class, R.layout.plot_fragment, R.string.c_graph),
|
||||
about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about),
|
||||
faq(CalculatorHelpFaqFragment.class, R.layout.help_faq_fragment, R.string.c_faq),
|
||||
hints(CalculatorHelpHintsFragment.class, R.layout.help_hints_fragment, R.string.c_hints),
|
||||
screens(CalculatorHelpScreensFragment.class, R.layout.help_screens_fragment, R.string.c_screens),
|
||||
|
||||
// todo serso: strings
|
||||
matrix_edit(CalculatorMatrixEditFragment.class, R.layout.matrix_edit_fragment, R.string.c_screens),
|
||||
release_notes(CalculatorReleaseNotesFragment.class, R.layout.release_notes_fragment, R.string.c_release_notes);
|
||||
|
||||
@NotNull
|
||||
private Class<? extends Fragment> fragmentClass;
|
||||
|
||||
private final int defaultLayoutId;
|
||||
|
||||
private int defaultTitleResId;
|
||||
|
||||
private CalculatorFragmentType(@NotNull Class<? extends Fragment> fragmentClass,
|
||||
int defaultLayoutId,
|
||||
int defaultTitleResId) {
|
||||
this.fragmentClass = fragmentClass;
|
||||
this.defaultLayoutId = defaultLayoutId;
|
||||
this.defaultTitleResId = defaultTitleResId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFragmentTag() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
public int getDefaultTitleResId() {
|
||||
return defaultTitleResId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Class<? extends Fragment> getFragmentClass() {
|
||||
return fragmentClass;
|
||||
}
|
||||
|
||||
public int getDefaultLayoutId() {
|
||||
return defaultLayoutId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String createSubFragmentTag(@NotNull String subFragmentTag) {
|
||||
return this.getFragmentTag() + "_" + subFragmentTag;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package org.solovyev.android.calculator.matrix;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.os.Bundle;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentActivity;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 12.10.12
|
||||
* Time: 10:56
|
||||
*/
|
||||
public class CalculatorMatrixActivity extends CalculatorFragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||
getActivityHelper().setFragment(this, CalculatorFragmentType.matrix_edit, null, R.id.main_layout);
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package org.solovyev.android.calculator.matrix;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TableLayout;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorFragment;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||
import org.solovyev.android.view.IntegerRange;
|
||||
import org.solovyev.android.view.Picker;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 12.10.12
|
||||
* Time: 10:41
|
||||
*/
|
||||
public class CalculatorMatrixEditFragment extends CalculatorFragment implements Picker.OnChangedListener<Integer> {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private static final int MAX_COUNT = 10;
|
||||
private static final int MIN_COUNT = 2;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTRUCTORS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
public CalculatorMatrixEditFragment() {
|
||||
super(CalculatorFragmentType.matrix_edit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
final Picker<Integer> matrixRowsCountPicker = (Picker<Integer>) root.findViewById(R.id.matrix_rows_count_picker);
|
||||
initPicker(matrixRowsCountPicker);
|
||||
final Picker<Integer> matrixColsCountPicker = (Picker<Integer>) root.findViewById(R.id.matrix_cols_count_picker);
|
||||
initPicker(matrixColsCountPicker);
|
||||
|
||||
getMatrixTable(root);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private TableLayout getMatrixTable(@NotNull View root) {
|
||||
return (TableLayout) root.findViewById(R.id.matrix_layout);
|
||||
}
|
||||
|
||||
private void initPicker(@NotNull Picker<Integer> picker) {
|
||||
picker.setRange(new IntegerRange(MIN_COUNT, MAX_COUNT, 1, 2, null));
|
||||
picker.setOnChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(@NotNull Picker picker, @NotNull Integer value) {
|
||||
switch (picker.getId()) {
|
||||
case R.id.matrix_rows_count_picker:
|
||||
onRowsCountChange(value);
|
||||
break;
|
||||
case R.id.matrix_cols_count_picker:
|
||||
onColsCountChange(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void onColsCountChange(@NotNull Integer cols) {
|
||||
final TableLayout matrixTable = getMatrixTable(getView());
|
||||
}
|
||||
|
||||
private void onRowsCountChange(@NotNull Integer rows) {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user