diff --git a/res/layout-land/main_calculator.xml b/res/layout-land/main_calculator.xml index 73b165db..3baa3a22 100644 --- a/res/layout-land/main_calculator.xml +++ b/res/layout-land/main_calculator.xml @@ -52,10 +52,12 @@ a:layout_height="fill_parent" a:layout_weight="4"/> - - - + @@ -50,7 +50,7 @@ - + diff --git a/res/layout-port/main_cellphone.xml b/res/layout-port/main_cellphone.xml index 2f2fd2c4..ce391ffd 100644 --- a/res/layout-port/main_cellphone.xml +++ b/res/layout-port/main_cellphone.xml @@ -34,7 +34,7 @@ - + @@ -44,7 +44,7 @@ - + diff --git a/res/layout/calc_clear_button.xml b/res/layout/calc_clear_button.xml index 302afc60..f8541dac 100644 --- a/res/layout/calc_clear_button.xml +++ b/res/layout/calc_clear_button.xml @@ -6,10 +6,12 @@ ~ or visit http://se.solovyev.org --> - \ No newline at end of file diff --git a/res/layout/calc_six_digit_button.xml b/res/layout/calc_six_digit_button.xml index 12ed26c4..170391d6 100644 --- a/res/layout/calc_six_digit_button.xml +++ b/res/layout/calc_six_digit_button.xml @@ -9,7 +9,8 @@ \ No newline at end of file diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index c7b9c407..86e98354 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -22,6 +22,7 @@ import android.view.*; import android.widget.EditText; import android.widget.TextView; import jscl.AngleUnit; +import jscl.NumeralBase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.math.MathType; @@ -114,8 +115,14 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) findViewById(R.id.sixDigitButton); if (angleUnitsButton != null) { - final OnDragListener varsOnDragListener = new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(), dragPreferences), vibrator, preferences); - angleUnitsButton.setOnDragListener(varsOnDragListener); + final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(), dragPreferences), vibrator, preferences); + angleUnitsButton.setOnDragListener(onDragListener); + } + + final NumeralBasesButton numeralBasesButton = (NumeralBasesButton) findViewById(R.id.clearButton); + if (numeralBasesButton != null) { + final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(), dragPreferences), vibrator, preferences); + numeralBasesButton.setOnDragListener(onDragListener); } final DragButton varsButton = (DragButton) findViewById(R.id.varsButton); @@ -161,6 +168,39 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh } } + private class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor { + + @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(CalculatorActivity.this); + final SharedPreferences.Editor editor = preferences.edit(); + editor.putString(CalculatorEngine.NUMERAL_BASES_P_KEY, numeralBase.name()); + editor.commit(); + + result = true; + } catch (IllegalArgumentException e) { + Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText); + } + } + } + + return result; + } + } + + private class VarsDragProcessor implements SimpleOnDragListener.DragProcessor { @Override diff --git a/src/main/java/org/solovyev/android/view/widgets/NumeralBasesButton.java b/src/main/java/org/solovyev/android/view/widgets/NumeralBasesButton.java new file mode 100644 index 00000000..5d8f81c2 --- /dev/null +++ b/src/main/java/org/solovyev/android/view/widgets/NumeralBasesButton.java @@ -0,0 +1,43 @@ +/* + * 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 + */ + +package org.solovyev.android.view.widgets; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Paint; +import android.text.TextPaint; +import android.util.AttributeSet; +import org.jetbrains.annotations.NotNull; +import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.model.CalculatorEngine; + +/** + * User: serso + * Date: 12/8/11 + * Time: 2:22 AM + */ +public class NumeralBasesButton extends DirectionDragButton { + + public NumeralBasesButton(Context context, @NotNull AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void initDirectionTextPaint(@NotNull Paint basePaint, + @NotNull DirectionTextData directionTextData, + @NotNull Resources resources) { + super.initDirectionTextPaint(basePaint, directionTextData, resources); + + final TextPaint directionTextPaint = directionTextData.getPaint(); + if (CalculatorEngine.instance.getEngine().getNumeralBase().name().equals(directionTextData.getText())) { + directionTextPaint.setColor(resources.getColor(R.color.selected_angle_unit_text_color)); + } else { + directionTextPaint.setColor(resources.getColor(R.color.default_text_color)); + directionTextPaint.setAlpha(getDefaultDirectionTextAlpha()); + } + } +}