diff --git a/calculatorpp/AndroidManifest.xml b/calculatorpp/AndroidManifest.xml index 72eaf288..d8c8ee64 100644 --- a/calculatorpp/AndroidManifest.xml +++ b/calculatorpp/AndroidManifest.xml @@ -1,72 +1,70 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/calculatorpp/res/layout-land/calc_keyboard.xml b/calculatorpp/res/layout-land/calc_keyboard.xml new file mode 100644 index 00000000..b93d1da5 --- /dev/null +++ b/calculatorpp/res/layout-land/calc_keyboard.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/calculatorpp/res/layout-land/main_calculator.xml b/calculatorpp/res/layout-land/main_calculator.xml index 9fd00589..c445eb00 100644 --- a/calculatorpp/res/layout-land/main_calculator.xml +++ b/calculatorpp/res/layout-land/main_calculator.xml @@ -1,118 +1,89 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/calculatorpp/res/layout-port/main_calculator.xml b/calculatorpp/res/layout/main_calculator.xml similarity index 93% rename from calculatorpp/res/layout-port/main_calculator.xml rename to calculatorpp/res/layout/main_calculator.xml index 5cc2d545..59de37ce 100644 --- a/calculatorpp/res/layout-port/main_calculator.xml +++ b/calculatorpp/res/layout/main_calculator.xml @@ -13,7 +13,7 @@ a:id="@+id/main_layout" a:orientation="vertical" a:layout_gravity="center" - a:background="#ff000000"> + a:background="@color/default_background"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 78c32c59..e05ab23c 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -14,6 +14,7 @@ import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.preference.PreferenceManager; +import android.support.v4.app.Fragment; import android.text.Html; import android.text.method.LinkMovementMethod; import android.util.Log; @@ -80,17 +81,17 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); final CalculatorEditorFragment editorFragment = new CalculatorEditorFragment(); - fragmentTransaction.add(R.id.editorContainer, editorFragment); + fragmentTransaction.add(R.id.editorContainer, editorFragment, "editor"); fragmentTransaction.commit(); fragmentTransaction = fragmentManager.beginTransaction(); final CalculatorDisplayFragment displayFragment = new CalculatorDisplayFragment(); - fragmentTransaction.add(R.id.displayContainer, displayFragment); + fragmentTransaction.add(R.id.displayContainer, displayFragment, "display"); fragmentTransaction.commit(); fragmentTransaction = fragmentManager.beginTransaction(); final CalculatorKeyboardFragment keyboardFragment = new CalculatorKeyboardFragment(); - fragmentTransaction.add(R.id.keyboardContainer, keyboardFragment); + fragmentTransaction.add(R.id.keyboardContainer, keyboardFragment, "keyboard"); fragmentTransaction.commit(); if (customTitleSupported) { diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java index 982d1132..02c96511 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java @@ -90,45 +90,59 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer setOnDragListeners(root, dragPreferences, preferences); final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor(getCalculator()), dragPreferences), vibrator, preferences); - ((DragButton) root.findViewById(R.id.historyButton)).setOnDragListener(historyOnDragListener); + final DragButton historyButton = getButton(root, R.id.historyButton); + if (historyButton != null) { + historyButton.setOnDragListener(historyOnDragListener); + } - ((DragButton) root.findViewById(R.id.subtractionButton)).setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() { - @Override - public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) { - if (dragDirection == DragDirection.down) { - CalculatorActivity.operatorsButtonClickHandler(getActivity(), dragButton); - return true; + final DragButton subtractionButton = getButton(root, R.id.subtractionButton); + if (subtractionButton != null) { + subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() { + @Override + public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) { + if (dragDirection == DragDirection.down) { + CalculatorActivity.operatorsButtonClickHandler(getActivity(), dragButton); + return true; + } + return false; } - return false; - } - }, dragPreferences), vibrator, preferences)); + }, dragPreferences), vibrator, preferences)); + } final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences); - ((DragButton) root.findViewById(R.id.rightButton)).setOnDragListener(toPositionOnDragListener); - ((DragButton) root.findViewById(R.id.leftButton)).setOnDragListener(toPositionOnDragListener); - final DragButton equalsButton = (DragButton) root.findViewById(R.id.equalsButton); + final DragButton rightButton = getButton(root, R.id.rightButton); + if (rightButton != null) { + rightButton.setOnDragListener(toPositionOnDragListener); + } + + final DragButton leftButton = getButton(root, R.id.leftButton); + if (leftButton != null) { + leftButton.setOnDragListener(toPositionOnDragListener); + } + + final DragButton equalsButton = getButton(root, R.id.equalsButton); if (equalsButton != null) { equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences)); } - final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) root.findViewById(R.id.sixDigitButton); + final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.sixDigitButton); if (angleUnitsButton != null) { angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(this.getActivity()), dragPreferences), vibrator, preferences)); } - final NumeralBasesButton clearButton = (NumeralBasesButton) root.findViewById(R.id.clearButton); + final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.clearButton); if (clearButton != null) { clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(this.getActivity()), dragPreferences), vibrator, preferences)); } - final DragButton varsButton = (DragButton) root.findViewById(R.id.varsButton); + final DragButton varsButton = getButton(root, R.id.varsButton); if (varsButton != null) { varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new VarsDragProcessor(this.getActivity()), dragPreferences), vibrator, preferences)); } - final DragButton roundBracketsButton = (DragButton) root.findViewById(R.id.roundBracketsButton); + final DragButton roundBracketsButton = getButton(root, R.id.roundBracketsButton); if (roundBracketsButton != null) { roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences)); } @@ -162,6 +176,11 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer initMultiplicationButton(); } + @Nullable + private T getButton(@NotNull View root, int buttonId) { + return (T) root.findViewById(buttonId); + } + @Override public void onDestroy() { super.onDestroy(); @@ -240,7 +259,10 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer } for (Integer dragButtonId : dragButtonIds) { - ((DragButton) root.findViewById(dragButtonId)).setOnDragListener(onDragListener); + final DragButton button = getButton(root, dragButtonId); + if (button != null) { + button.setOnDragListener(onDragListener); + } } } @@ -273,7 +295,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer } private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) { - final View v = root.findViewById(id); + final View v = getButton(root, id); if (v instanceof DirectionDragButton ) { final DirectionDragButton button = (DirectionDragButton)v; for (DragDirection dragDirection : dragDirections) {