large screen support + fix for numeral buttons

This commit is contained in:
Sergey Solovyev 2012-10-13 12:51:27 +04:00
parent 551cb3b2f7
commit a60e0caeb8
11 changed files with 468 additions and 229 deletions

View File

@ -1,51 +1,60 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="match_parent" a:layout_height="match_parent"
a:orientation="vertical"> a:orientation="vertical">
<LinearLayout a:layout_weight="1" <LinearLayout a:layout_weight="1"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="0dp"> a:layout_height="0dp">
<include layout="@layout/calc_left_button"/> <include layout="@layout/calc_left_button"/>
<include layout="@layout/calc_vars_button"/> <include layout="@layout/calc_erase_button"/>
<include layout="@layout/calc_copy_button"/> <include layout="@layout/calc_donate_button"/>
<include layout="@layout/calc_six_digit_button"/> <include layout="@layout/calc_seven_digit_button"/>
<include layout="@layout/calc_seven_digit_button"/> <include layout="@layout/calc_eight_digit_button"/>
<include layout="@layout/calc_eight_digit_button"/> <include layout="@layout/calc_nine_digit_button"/>
<include layout="@layout/calc_nine_digit_button"/> <include layout="@layout/calc_multiplication_button"/>
<include layout="@layout/calc_zero_digit_button"/> <include layout="@layout/calc_division_button"/>
<include layout="@layout/calc_multiplication_button"/> <include layout="@layout/calc_clear_button"/>
<include layout="@layout/calc_division_button"/> <include layout="@layout/calc_right_button"/>
<include layout="@layout/calc_equals_button"/>
<include layout="@layout/calc_operators_button"/> </LinearLayout>
<include layout="@layout/calc_donate_button"/>
<include layout="@layout/calc_right_button"/> <LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
</LinearLayout> a:layout_height="0dp">
<LinearLayout a:layout_weight="1" <include layout="@layout/calc_vars_button"/>
a:layout_width="match_parent" <include layout="@layout/calc_functions_button"/>
a:layout_height="0dp"> <include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_four_digit_button"/>
<include layout="@layout/calc_erase_button"/> <include layout="@layout/calc_five_digit_button"/>
<include layout="@layout/calc_functions_button"/> <include layout="@layout/calc_six_digit_button"/>
<include layout="@layout/calc_paste_button"/> <include layout="@layout/calc_plus_button"/>
<include layout="@layout/calc_one_digit_button"/> <include layout="@layout/calc_subtraction_button"/>
<include layout="@layout/calc_two_digit_button"/> <include layout="@layout/calc_copy_button"/>
<include layout="@layout/calc_three_digit_button"/> <include layout="@layout/calc_equals_button"/>
<include layout="@layout/calc_four_digit_button"/>
<include layout="@layout/calc_five_digit_button"/> </LinearLayout>
<include layout="@layout/calc_plus_button"/>
<include layout="@layout/calc_subtraction_button"/> <LinearLayout a:layout_weight="1"
<include layout="@layout/calc_round_brackets_button"/> a:layout_width="match_parent"
<include layout="@layout/calc_dot_button"/> a:layout_height="0dp">
<include layout="@layout/calc_history_button"/>
<include layout="@layout/calc_clear_button"/> <include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_operators_button"/>
</LinearLayout> <include layout="@layout/calc_dot_button"/>
<include layout="@layout/calc_one_digit_button"/>
<include layout="@layout/calc_two_digit_button"/>
<include layout="@layout/calc_three_digit_button"/>
<include layout="@layout/calc_zero_digit_button"/>
<include layout="@layout/calc_round_brackets_button"/>
<include layout="@layout/calc_paste_button"/>
<include layout="@layout/calc_history_button"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -14,7 +14,7 @@
<LinearLayout <LinearLayout
a:layout_height="0dp" a:layout_height="0dp"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_weight="5" a:layout_weight="3"
a:orientation="horizontal" a:orientation="horizontal"
a:baselineAligned="false"> a:baselineAligned="false">
@ -29,7 +29,7 @@
a:layout_height="0dp" a:layout_height="0dp"
a:layout_width="match_parent" a:layout_width="match_parent"
style="?paneStyle" style="?paneStyle"
a:layout_weight="3"/> a:layout_weight="1"/>
<LinearLayout a:id="@+id/displayContainer" <LinearLayout a:id="@+id/displayContainer"
a:layout_height="0dp" a:layout_height="0dp"
@ -51,7 +51,7 @@
<LinearLayout a:id="@+id/keyboardContainer" <LinearLayout a:id="@+id/keyboardContainer"
a:layout_height="0dp" a:layout_height="0dp"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_weight="1" a:layout_weight="2"
style="?paneStyleTransparent"/> style="?paneStyleTransparent"/>
</LinearLayout> </LinearLayout>

View File

@ -1,68 +1,64 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="match_parent" a:layout_height="match_parent"
a:orientation="vertical"> a:orientation="vertical">
<LinearLayout a:layout_weight="1" <LinearLayout a:layout_weight="1"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="0dp"> a:layout_height="0dp">
<include layout="@layout/calc_left_button"/> <include layout="@layout/calc_left_button"/>
<include layout="@layout/calc_erase_button"/> <include layout="@layout/calc_erase_button"/>
<include layout="@layout/calc_empty_button"/> <include layout="@layout/calc_seven_digit_button"/>
<include layout="@layout/calc_empty_button"/> <include layout="@layout/calc_eight_digit_button"/>
<include layout="@layout/calc_empty_button"/> <include layout="@layout/calc_nine_digit_button"/>
<include layout="@layout/calc_empty_button"/> <include layout="@layout/calc_multiplication_button"/>
<include layout="@layout/calc_clear_button"/> <include layout="@layout/calc_right_button"/>
<include layout="@layout/calc_right_button"/>
</LinearLayout>
</LinearLayout>
<LinearLayout a:layout_weight="1"
<LinearLayout a:layout_weight="1" a:layout_width="match_parent"
a:layout_width="match_parent" a:layout_height="0dp">
a:layout_height="0dp">
<include layout="@layout/calc_vars_button"/>
<include layout="@layout/calc_vars_button"/> <include layout="@layout/calc_clear_button"/>
<include layout="@layout/calc_copy_button"/> <include layout="@layout/calc_four_digit_button"/>
<include layout="@layout/calc_seven_digit_button"/> <include layout="@layout/calc_five_digit_button"/>
<include layout="@layout/calc_eight_digit_button"/> <include layout="@layout/calc_six_digit_button"/>
<include layout="@layout/calc_nine_digit_button"/> <include layout="@layout/calc_division_button"/>
<include layout="@layout/calc_multiplication_button"/> <include layout="@layout/calc_copy_button"/>
<include layout="@layout/calc_division_button"/>
<include layout="@layout/calc_equals_button"/> </LinearLayout>
</LinearLayout> <LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
<LinearLayout a:layout_weight="1" a:layout_height="0dp">
a:layout_width="match_parent"
a:layout_height="0dp"> <include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_equals_button"/>
<include layout="@layout/calc_functions_button"/> <include layout="@layout/calc_one_digit_button"/>
<include layout="@layout/calc_paste_button"/> <include layout="@layout/calc_two_digit_button"/>
<include layout="@layout/calc_four_digit_button"/> <include layout="@layout/calc_three_digit_button"/>
<include layout="@layout/calc_five_digit_button"/> <include layout="@layout/calc_plus_button"/>
<include layout="@layout/calc_six_digit_button"/> <include layout="@layout/calc_paste_button"/>
<include layout="@layout/calc_plus_button"/>
<include layout="@layout/calc_subtraction_button"/> </LinearLayout>
<include layout="@layout/calc_round_brackets_button"/>
<LinearLayout a:layout_weight="1"
</LinearLayout> a:layout_width="match_parent"
a:layout_height="0dp">
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent" <include layout="@layout/calc_operators_button"/>
a:layout_height="0dp"> <include layout="@layout/calc_donate_button"/>
<include layout="@layout/calc_round_brackets_button"/>
<include layout="@layout/calc_operators_button"/> <include layout="@layout/calc_zero_digit_button"/>
<include layout="@layout/calc_donate_button"/> <include layout="@layout/calc_dot_button"/>
<include layout="@layout/calc_one_digit_button"/> <include layout="@layout/calc_subtraction_button"/>
<include layout="@layout/calc_two_digit_button"/> <include layout="@layout/calc_history_button"/>
<include layout="@layout/calc_three_digit_button"/>
<include layout="@layout/calc_zero_digit_button"/> </LinearLayout>
<include layout="@layout/calc_dot_button"/>
<include layout="@layout/calc_history_button"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -51,7 +51,7 @@
<LinearLayout a:id="@+id/keyboardContainer" <LinearLayout a:id="@+id/keyboardContainer"
a:layout_height="0dp" a:layout_height="0dp"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_weight="1" a:layout_weight="2"
style="?paneStyleTransparent"/> style="?paneStyleTransparent"/>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical">
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/calc_left_button"/>
<include layout="@layout/calc_vars_button"/>
<include layout="@layout/calc_copy_button"/>
<include layout="@layout/calc_six_digit_button"/>
<include layout="@layout/calc_seven_digit_button"/>
<include layout="@layout/calc_eight_digit_button"/>
<include layout="@layout/calc_nine_digit_button"/>
<include layout="@layout/calc_zero_digit_button"/>
<include layout="@layout/calc_multiplication_button"/>
<include layout="@layout/calc_division_button"/>
<include layout="@layout/calc_equals_button"/>
<include layout="@layout/calc_operators_button"/>
<include layout="@layout/calc_donate_button"/>
<include layout="@layout/calc_right_button"/>
</LinearLayout>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/calc_erase_button"/>
<include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_paste_button"/>
<include layout="@layout/calc_one_digit_button"/>
<include layout="@layout/calc_two_digit_button"/>
<include layout="@layout/calc_three_digit_button"/>
<include layout="@layout/calc_four_digit_button"/>
<include layout="@layout/calc_five_digit_button"/>
<include layout="@layout/calc_plus_button"/>
<include layout="@layout/calc_subtraction_button"/>
<include layout="@layout/calc_round_brackets_button"/>
<include layout="@layout/calc_dot_button"/>
<include layout="@layout/calc_history_button"/>
<include layout="@layout/calc_clear_button"/>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,57 @@
<?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
-->
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_layout"
a:orientation="vertical"
style="?mainMultiPaneLayoutStyle">
<LinearLayout
a:layout_height="0dp"
a:layout_width="match_parent"
a:layout_weight="5"
a:orientation="horizontal"
a:baselineAligned="false">
<LinearLayout
a:layout_height="match_parent"
a:layout_width="0dp"
a:layout_weight="1"
a:orientation="vertical"
a:layout_gravity="center">
<LinearLayout a:id="@+id/editorContainer"
a:layout_height="0dp"
a:layout_width="match_parent"
style="?paneStyle"
a:layout_weight="3"/>
<LinearLayout a:id="@+id/displayContainer"
a:layout_height="0dp"
a:layout_width="match_parent"
style="?paneStyle"
a:layout_weight="1"/>
</LinearLayout>
<LinearLayout a:id="@+id/main_second_pane"
a:layout_height="match_parent"
a:layout_width="0dp"
a:layout_weight="1"
a:orientation="vertical"
style="?paneStyle"/>
</LinearLayout>
<LinearLayout a:id="@+id/keyboardContainer"
a:layout_height="0dp"
a:layout_width="match_parent"
a:layout_weight="1"
style="?paneStyleTransparent"/>
</LinearLayout>

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical">
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/calc_left_button"/>
<include layout="@layout/calc_erase_button"/>
<include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_clear_button"/>
<include layout="@layout/calc_right_button"/>
</LinearLayout>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/calc_vars_button"/>
<include layout="@layout/calc_copy_button"/>
<include layout="@layout/calc_seven_digit_button"/>
<include layout="@layout/calc_eight_digit_button"/>
<include layout="@layout/calc_nine_digit_button"/>
<include layout="@layout/calc_multiplication_button"/>
<include layout="@layout/calc_division_button"/>
<include layout="@layout/calc_equals_button"/>
</LinearLayout>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_paste_button"/>
<include layout="@layout/calc_four_digit_button"/>
<include layout="@layout/calc_five_digit_button"/>
<include layout="@layout/calc_six_digit_button"/>
<include layout="@layout/calc_plus_button"/>
<include layout="@layout/calc_subtraction_button"/>
<include layout="@layout/calc_round_brackets_button"/>
</LinearLayout>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/calc_operators_button"/>
<include layout="@layout/calc_donate_button"/>
<include layout="@layout/calc_one_digit_button"/>
<include layout="@layout/calc_two_digit_button"/>
<include layout="@layout/calc_three_digit_button"/>
<include layout="@layout/calc_zero_digit_button"/>
<include layout="@layout/calc_dot_button"/>
<include layout="@layout/calc_history_button"/>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,57 @@
<?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
-->
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_layout"
a:orientation="vertical"
style="?mainMultiPaneLayoutStyle">
<LinearLayout
a:layout_height="0dp"
a:layout_width="match_parent"
a:layout_weight="3"
a:orientation="horizontal"
a:baselineAligned="false">
<LinearLayout
a:layout_height="match_parent"
a:layout_width="0dp"
a:layout_weight="1"
a:orientation="vertical"
a:layout_gravity="center">
<LinearLayout a:id="@+id/editorContainer"
a:layout_height="0dp"
a:layout_width="match_parent"
style="?paneStyle"
a:layout_weight="4"/>
<LinearLayout a:id="@+id/displayContainer"
a:layout_height="0dp"
a:layout_width="match_parent"
style="?paneStyle"
a:layout_weight="1"/>
</LinearLayout>
<LinearLayout a:id="@+id/main_second_pane"
a:layout_height="match_parent"
a:layout_width="0dp"
a:layout_weight="1"
a:orientation="vertical"
style="?paneStyle"/>
</LinearLayout>
<LinearLayout a:id="@+id/keyboardContainer"
a:layout_height="0dp"
a:layout_width="match_parent"
a:layout_weight="1"
style="?paneStyleTransparent"/>
</LinearLayout>

View File

@ -1,108 +1,109 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import jscl.NumeralBase; import jscl.NumeralBase;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.units.CalculatorNumeralBase; import org.solovyev.android.calculator.units.CalculatorNumeralBase;
import org.solovyev.android.view.drag.DirectionDragButton; import org.solovyev.android.view.drag.DirectionDragButton;
import org.solovyev.android.view.drag.DragDirection; import org.solovyev.android.view.drag.DragDirection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
* User: serso * User: serso
* Date: 4/21/12 * Date: 4/21/12
* Time: 8:00 PM * Time: 8:00 PM
*/ */
public enum AndroidNumeralBase { public enum AndroidNumeralBase {
bin(CalculatorNumeralBase.bin) { bin(CalculatorNumeralBase.bin) {
@NotNull @NotNull
@Override @Override
public List<Integer> getButtonIds() { public List<Integer> getButtonIds() {
return Arrays.asList(R.id.zeroDigitButton, R.id.oneDigitButton); return Arrays.asList(R.id.zeroDigitButton, R.id.oneDigitButton);
} }
}, },
oct(CalculatorNumeralBase.oct) { oct(CalculatorNumeralBase.oct) {
@NotNull @NotNull
@Override @Override
public List<Integer> getButtonIds() { public List<Integer> getButtonIds() {
final List<Integer> result = new ArrayList<Integer>(bin.getButtonIds()); final List<Integer> result = new ArrayList<Integer>(bin.getButtonIds());
result.addAll(Arrays.asList(R.id.twoDigitButton, R.id.threeDigitButton, R.id.fourDigitButton, R.id.fiveDigitButton, R.id.sixDigitButton, R.id.sevenDigitButton)); result.addAll(Arrays.asList(R.id.twoDigitButton, R.id.threeDigitButton, R.id.fourDigitButton, R.id.fiveDigitButton, R.id.sixDigitButton, R.id.sevenDigitButton));
return result; return result;
} }
}, },
dec(CalculatorNumeralBase.dec) { dec(CalculatorNumeralBase.dec) {
@NotNull @NotNull
@Override @Override
public List<Integer> getButtonIds() { public List<Integer> getButtonIds() {
final List<Integer> result = new ArrayList<Integer>(oct.getButtonIds()); final List<Integer> result = new ArrayList<Integer>(oct.getButtonIds());
result.addAll(Arrays.asList(R.id.eightDigitButton, R.id.nineDigitButton)); result.addAll(Arrays.asList(R.id.eightDigitButton, R.id.nineDigitButton));
return result; return result;
} }
}, },
hex(CalculatorNumeralBase.hex) { hex(CalculatorNumeralBase.hex) {
@NotNull @NotNull
private List<Integer> specialHexButtonIds = Arrays.asList(R.id.oneDigitButton, R.id.twoDigitButton, R.id.threeDigitButton, R.id.fourDigitButton, R.id.fiveDigitButton, R.id.sixDigitButton); private List<Integer> specialHexButtonIds = Arrays.asList(R.id.oneDigitButton, R.id.twoDigitButton, R.id.threeDigitButton, R.id.fourDigitButton, R.id.fiveDigitButton, R.id.sixDigitButton);
@NotNull @NotNull
@Override @Override
public List<Integer> getButtonIds() { public List<Integer> getButtonIds() {
return dec.getButtonIds(); return dec.getButtonIds();
} }
@Override @Override
protected void toggleButton(boolean show, @NotNull DirectionDragButton button) { protected void toggleButton(boolean show, @NotNull DirectionDragButton button) {
super.toggleButton(show, button); super.toggleButton(show, button);
if (specialHexButtonIds.contains(button.getId())) { if (specialHexButtonIds.contains(button.getId())) {
button.showDirectionText(show, DragDirection.left); button.showDirectionText(show, DragDirection.left);
button.invalidate(); button.invalidate();
} }
} }
}; };
@NotNull @NotNull
private final CalculatorNumeralBase calculatorNumeralBase; private final CalculatorNumeralBase calculatorNumeralBase;
private AndroidNumeralBase(@NotNull CalculatorNumeralBase calculatorNumeralBase) { private AndroidNumeralBase(@NotNull CalculatorNumeralBase calculatorNumeralBase) {
this.calculatorNumeralBase = calculatorNumeralBase; this.calculatorNumeralBase = calculatorNumeralBase;
} }
@NotNull @NotNull
public abstract List<Integer> getButtonIds(); public abstract List<Integer> getButtonIds();
public void toggleButtons(boolean show, @NotNull Activity activity) { public void toggleButtons(boolean show, @NotNull Activity activity) {
for (Integer buttonId : getButtonIds()) { for (Integer buttonId : getButtonIds()) {
final DirectionDragButton button = (DirectionDragButton) activity.findViewById(buttonId); final DirectionDragButton button = (DirectionDragButton) activity.findViewById(buttonId);
if (button != null) { if (button != null) {
toggleButton(show, button); toggleButton(show, button);
} }
} }
} }
protected void toggleButton(boolean show, @NotNull DirectionDragButton button) { protected void toggleButton(boolean show, @NotNull DirectionDragButton button) {
button.setShowText(show); button.setShowText(show);
} button.invalidate();
}
@NotNull
public NumeralBase getNumeralBase() { @NotNull
return calculatorNumeralBase.getNumeralBase(); public NumeralBase getNumeralBase() {
} return calculatorNumeralBase.getNumeralBase();
}
@NotNull
public static AndroidNumeralBase valueOf(@NotNull NumeralBase nb) { @NotNull
for (AndroidNumeralBase androidNumeralBase : values()) { public static AndroidNumeralBase valueOf(@NotNull NumeralBase nb) {
if (androidNumeralBase.calculatorNumeralBase.getNumeralBase() == nb) { for (AndroidNumeralBase androidNumeralBase : values()) {
return androidNumeralBase; if (androidNumeralBase.calculatorNumeralBase.getNumeralBase() == nb) {
} return androidNumeralBase;
} }
}
throw new IllegalArgumentException(nb + " is not supported numeral base!");
} throw new IllegalArgumentException(nb + " is not supported numeral base!");
} }
}