From a60e0caeb8688690de2e7ef4cc7aa87b6da4b1df Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Sat, 13 Oct 2012 12:51:27 +0400 Subject: [PATCH] large screen support + fix for numeral buttons --- .../res/layout-large-land/calc_keyboard.xml | 109 +++++---- .../res/layout-large-land/main_calculator.xml | 6 +- .../res/layout-large/calc_keyboard.xml | 130 +++++------ .../res/layout-large/main_calculator.xml | 2 +- .../res/layout-xlarge-land/calc_keyboard.xml | 51 ++++ .../layout-xlarge-land/main_calculator.xml | 57 +++++ .../calc_display.xml | 0 .../calc_editor.xml | 0 .../res/layout-xlarge/calc_keyboard.xml | 68 ++++++ .../res/layout-xlarge/main_calculator.xml | 57 +++++ .../calculator/AndroidNumeralBase.java | 217 +++++++++--------- 11 files changed, 468 insertions(+), 229 deletions(-) create mode 100644 calculatorpp/res/layout-xlarge-land/calc_keyboard.xml create mode 100644 calculatorpp/res/layout-xlarge-land/main_calculator.xml rename calculatorpp/res/{layout-large-land => layout-xlarge}/calc_display.xml (100%) rename calculatorpp/res/{layout-large-land => layout-xlarge}/calc_editor.xml (100%) create mode 100644 calculatorpp/res/layout-xlarge/calc_keyboard.xml create mode 100644 calculatorpp/res/layout-xlarge/main_calculator.xml diff --git a/calculatorpp/res/layout-large-land/calc_keyboard.xml b/calculatorpp/res/layout-large-land/calc_keyboard.xml index 7304e802..f97d39ec 100644 --- a/calculatorpp/res/layout-large-land/calc_keyboard.xml +++ b/calculatorpp/res/layout-large-land/calc_keyboard.xml @@ -1,51 +1,60 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/calculatorpp/res/layout-large-land/main_calculator.xml b/calculatorpp/res/layout-large-land/main_calculator.xml index 94d04dcb..cf894fea 100644 --- a/calculatorpp/res/layout-large-land/main_calculator.xml +++ b/calculatorpp/res/layout-large-land/main_calculator.xml @@ -14,7 +14,7 @@ @@ -29,7 +29,7 @@ a:layout_height="0dp" a:layout_width="match_parent" style="?paneStyle" - a:layout_weight="3"/> + a:layout_weight="1"/> diff --git a/calculatorpp/res/layout-large/calc_keyboard.xml b/calculatorpp/res/layout-large/calc_keyboard.xml index 29dd1bcc..7d9b9100 100644 --- a/calculatorpp/res/layout-large/calc_keyboard.xml +++ b/calculatorpp/res/layout-large/calc_keyboard.xml @@ -1,68 +1,64 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/calculatorpp/res/layout-large/main_calculator.xml b/calculatorpp/res/layout-large/main_calculator.xml index f9b4bd27..76b1a702 100644 --- a/calculatorpp/res/layout-large/main_calculator.xml +++ b/calculatorpp/res/layout-large/main_calculator.xml @@ -51,7 +51,7 @@ diff --git a/calculatorpp/res/layout-xlarge-land/calc_keyboard.xml b/calculatorpp/res/layout-xlarge-land/calc_keyboard.xml new file mode 100644 index 00000000..b7adc360 --- /dev/null +++ b/calculatorpp/res/layout-xlarge-land/calc_keyboard.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/calculatorpp/res/layout-xlarge-land/main_calculator.xml b/calculatorpp/res/layout-xlarge-land/main_calculator.xml new file mode 100644 index 00000000..94d04dcb --- /dev/null +++ b/calculatorpp/res/layout-xlarge-land/main_calculator.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/calculatorpp/res/layout-large-land/calc_display.xml b/calculatorpp/res/layout-xlarge/calc_display.xml similarity index 100% rename from calculatorpp/res/layout-large-land/calc_display.xml rename to calculatorpp/res/layout-xlarge/calc_display.xml diff --git a/calculatorpp/res/layout-large-land/calc_editor.xml b/calculatorpp/res/layout-xlarge/calc_editor.xml similarity index 100% rename from calculatorpp/res/layout-large-land/calc_editor.xml rename to calculatorpp/res/layout-xlarge/calc_editor.xml diff --git a/calculatorpp/res/layout-xlarge/calc_keyboard.xml b/calculatorpp/res/layout-xlarge/calc_keyboard.xml new file mode 100644 index 00000000..a40759e7 --- /dev/null +++ b/calculatorpp/res/layout-xlarge/calc_keyboard.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/calculatorpp/res/layout-xlarge/main_calculator.xml b/calculatorpp/res/layout-xlarge/main_calculator.xml new file mode 100644 index 00000000..f9b4bd27 --- /dev/null +++ b/calculatorpp/res/layout-xlarge/main_calculator.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidNumeralBase.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidNumeralBase.java index cdd5e4a6..ecdc65aa 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidNumeralBase.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/AndroidNumeralBase.java @@ -1,108 +1,109 @@ -package org.solovyev.android.calculator; - -import android.app.Activity; -import jscl.NumeralBase; -import org.jetbrains.annotations.NotNull; -import org.solovyev.android.calculator.units.CalculatorNumeralBase; -import org.solovyev.android.view.drag.DirectionDragButton; -import org.solovyev.android.view.drag.DragDirection; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * User: serso - * Date: 4/21/12 - * Time: 8:00 PM - */ -public enum AndroidNumeralBase { - - bin(CalculatorNumeralBase.bin) { - @NotNull - @Override - public List getButtonIds() { - return Arrays.asList(R.id.zeroDigitButton, R.id.oneDigitButton); - } - }, - - oct(CalculatorNumeralBase.oct) { - @NotNull - @Override - public List getButtonIds() { - final List result = new ArrayList(bin.getButtonIds()); - result.addAll(Arrays.asList(R.id.twoDigitButton, R.id.threeDigitButton, R.id.fourDigitButton, R.id.fiveDigitButton, R.id.sixDigitButton, R.id.sevenDigitButton)); - return result; - } - }, - - dec(CalculatorNumeralBase.dec) { - @NotNull - @Override - public List getButtonIds() { - final List result = new ArrayList(oct.getButtonIds()); - result.addAll(Arrays.asList(R.id.eightDigitButton, R.id.nineDigitButton)); - return result; - } - }, - - hex(CalculatorNumeralBase.hex) { - - @NotNull - private List specialHexButtonIds = Arrays.asList(R.id.oneDigitButton, R.id.twoDigitButton, R.id.threeDigitButton, R.id.fourDigitButton, R.id.fiveDigitButton, R.id.sixDigitButton); - - @NotNull - @Override - public List getButtonIds() { - return dec.getButtonIds(); - } - - @Override - protected void toggleButton(boolean show, @NotNull DirectionDragButton button) { - super.toggleButton(show, button); - if (specialHexButtonIds.contains(button.getId())) { - button.showDirectionText(show, DragDirection.left); - button.invalidate(); - } - } - }; - - @NotNull - private final CalculatorNumeralBase calculatorNumeralBase; - - private AndroidNumeralBase(@NotNull CalculatorNumeralBase calculatorNumeralBase) { - this.calculatorNumeralBase = calculatorNumeralBase; - } - - @NotNull - public abstract List getButtonIds(); - - public void toggleButtons(boolean show, @NotNull Activity activity) { - for (Integer buttonId : getButtonIds()) { - final DirectionDragButton button = (DirectionDragButton) activity.findViewById(buttonId); - if (button != null) { - toggleButton(show, button); - } - } - } - - protected void toggleButton(boolean show, @NotNull DirectionDragButton button) { - button.setShowText(show); - } - - @NotNull - public NumeralBase getNumeralBase() { - return calculatorNumeralBase.getNumeralBase(); - } - - @NotNull - public static AndroidNumeralBase valueOf(@NotNull NumeralBase nb) { - for (AndroidNumeralBase androidNumeralBase : values()) { - if (androidNumeralBase.calculatorNumeralBase.getNumeralBase() == nb) { - return androidNumeralBase; - } - } - - throw new IllegalArgumentException(nb + " is not supported numeral base!"); - } -} +package org.solovyev.android.calculator; + +import android.app.Activity; +import jscl.NumeralBase; +import org.jetbrains.annotations.NotNull; +import org.solovyev.android.calculator.units.CalculatorNumeralBase; +import org.solovyev.android.view.drag.DirectionDragButton; +import org.solovyev.android.view.drag.DragDirection; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * User: serso + * Date: 4/21/12 + * Time: 8:00 PM + */ +public enum AndroidNumeralBase { + + bin(CalculatorNumeralBase.bin) { + @NotNull + @Override + public List getButtonIds() { + return Arrays.asList(R.id.zeroDigitButton, R.id.oneDigitButton); + } + }, + + oct(CalculatorNumeralBase.oct) { + @NotNull + @Override + public List getButtonIds() { + final List result = new ArrayList(bin.getButtonIds()); + result.addAll(Arrays.asList(R.id.twoDigitButton, R.id.threeDigitButton, R.id.fourDigitButton, R.id.fiveDigitButton, R.id.sixDigitButton, R.id.sevenDigitButton)); + return result; + } + }, + + dec(CalculatorNumeralBase.dec) { + @NotNull + @Override + public List getButtonIds() { + final List result = new ArrayList(oct.getButtonIds()); + result.addAll(Arrays.asList(R.id.eightDigitButton, R.id.nineDigitButton)); + return result; + } + }, + + hex(CalculatorNumeralBase.hex) { + + @NotNull + private List specialHexButtonIds = Arrays.asList(R.id.oneDigitButton, R.id.twoDigitButton, R.id.threeDigitButton, R.id.fourDigitButton, R.id.fiveDigitButton, R.id.sixDigitButton); + + @NotNull + @Override + public List getButtonIds() { + return dec.getButtonIds(); + } + + @Override + protected void toggleButton(boolean show, @NotNull DirectionDragButton button) { + super.toggleButton(show, button); + if (specialHexButtonIds.contains(button.getId())) { + button.showDirectionText(show, DragDirection.left); + button.invalidate(); + } + } + }; + + @NotNull + private final CalculatorNumeralBase calculatorNumeralBase; + + private AndroidNumeralBase(@NotNull CalculatorNumeralBase calculatorNumeralBase) { + this.calculatorNumeralBase = calculatorNumeralBase; + } + + @NotNull + public abstract List getButtonIds(); + + public void toggleButtons(boolean show, @NotNull Activity activity) { + for (Integer buttonId : getButtonIds()) { + final DirectionDragButton button = (DirectionDragButton) activity.findViewById(buttonId); + if (button != null) { + toggleButton(show, button); + } + } + } + + protected void toggleButton(boolean show, @NotNull DirectionDragButton button) { + button.setShowText(show); + button.invalidate(); + } + + @NotNull + public NumeralBase getNumeralBase() { + return calculatorNumeralBase.getNumeralBase(); + } + + @NotNull + public static AndroidNumeralBase valueOf(@NotNull NumeralBase nb) { + for (AndroidNumeralBase androidNumeralBase : values()) { + if (androidNumeralBase.calculatorNumeralBase.getNumeralBase() == nb) { + return androidNumeralBase; + } + } + + throw new IllegalArgumentException(nb + " is not supported numeral base!"); + } +}