Fragments
This commit is contained in:
parent
5242d65e3a
commit
cf322d04ee
@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="match_parent"
|
||||||
a:id="@+id/ad_parent_view"
|
a:id="@+id/main_layout"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_gravity="center"
|
a:layout_gravity="center"
|
||||||
a:background="#ff000000">
|
a:background="#ff000000">
|
||||||
@ -20,12 +20,14 @@
|
|||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="0dp"/>
|
a:layout_height="0dp"/>
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
<LinearLayout a:layout_weight="1"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp">
|
||||||
|
|
||||||
<include layout="@layout/calc_equals_button"
|
<include layout="@layout/calc_equals_button"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_height="fill_parent"/>
|
a:layout_height="match_parent"/>
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/displayContainer"
|
<LinearLayout a:id="@+id/displayContainer"
|
||||||
a:layout_weight="4"
|
a:layout_weight="4"
|
||||||
@ -34,54 +36,9 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
<LinearLayout a:id="@+id/keyboardContainer"
|
||||||
|
a:layout_weight="5"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp"/>
|
||||||
|
|
||||||
<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_clear_button"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
|
||||||
|
|
||||||
<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_division_button"/>
|
|
||||||
<include layout="@layout/calc_erase_button"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
|
||||||
|
|
||||||
<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_plus_button"/>
|
|
||||||
<include layout="@layout/calc_copy_button"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
|
||||||
|
|
||||||
<include layout="@layout/calc_round_brackets_button"/>
|
|
||||||
<include layout="@layout/calc_zero_digit_button"/>
|
|
||||||
<include layout="@layout/calc_dot_button"/>
|
|
||||||
<include layout="@layout/calc_subtraction_button"/>
|
|
||||||
<include layout="@layout/calc_paste_button"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
|
||||||
|
|
||||||
<include layout="@layout/calc_left_button"/>
|
|
||||||
<include layout="@layout/calc_right_button"/>
|
|
||||||
<include layout="@layout/calc_vars_button"/>
|
|
||||||
<include layout="@layout/calc_functions_button"/>
|
|
||||||
<include layout="@layout/calc_history_button"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
69
calculatorpp/res/layout/calc_keyboard.xml
Normal file
69
calculatorpp/res/layout/calc_keyboard.xml
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?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_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_clear_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp">
|
||||||
|
|
||||||
|
<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_division_button"/>
|
||||||
|
<include layout="@layout/calc_erase_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp">
|
||||||
|
|
||||||
|
<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_plus_button"/>
|
||||||
|
<include layout="@layout/calc_copy_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_round_brackets_button"/>
|
||||||
|
<include layout="@layout/calc_zero_digit_button"/>
|
||||||
|
<include layout="@layout/calc_dot_button"/>
|
||||||
|
<include layout="@layout/calc_subtraction_button"/>
|
||||||
|
<include layout="@layout/calc_paste_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout a:layout_weight="1"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
a:layout_height="0dp">
|
||||||
|
|
||||||
|
<include layout="@layout/calc_left_button"/>
|
||||||
|
<include layout="@layout/calc_right_button"/>
|
||||||
|
<include layout="@layout/calc_vars_button"/>
|
||||||
|
<include layout="@layout/calc_functions_button"/>
|
||||||
|
<include layout="@layout/calc_history_button"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -12,22 +12,14 @@ import android.app.FragmentTransaction;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Vibrator;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
import jscl.AngleUnit;
|
|
||||||
import jscl.NumeralBase;
|
|
||||||
import net.robotmedia.billing.BillingController;
|
import net.robotmedia.billing.BillingController;
|
||||||
import net.robotmedia.billing.IBillingObserver;
|
import net.robotmedia.billing.IBillingObserver;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -35,29 +27,16 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.FontSizeAdjuster;
|
import org.solovyev.android.FontSizeAdjuster;
|
||||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
|
||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||||
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
|
||||||
import org.solovyev.android.calculator.view.CalculatorAdditionalTitle;
|
import org.solovyev.android.calculator.view.CalculatorAdditionalTitle;
|
||||||
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
|
||||||
import org.solovyev.android.calculator.view.OnDragListenerVibrator;
|
|
||||||
import org.solovyev.android.history.HistoryDragProcessor;
|
|
||||||
import org.solovyev.android.menu.ActivityMenu;
|
import org.solovyev.android.menu.ActivityMenu;
|
||||||
import org.solovyev.android.menu.LayoutActivityMenu;
|
import org.solovyev.android.menu.LayoutActivityMenu;
|
||||||
import org.solovyev.android.prefs.Preference;
|
import org.solovyev.android.prefs.Preference;
|
||||||
import org.solovyev.android.view.ColorButton;
|
import org.solovyev.android.view.ColorButton;
|
||||||
import org.solovyev.android.view.drag.*;
|
|
||||||
import org.solovyev.common.Announcer;
|
|
||||||
import org.solovyev.common.equals.EqualsTool;
|
import org.solovyev.common.equals.EqualsTool;
|
||||||
import org.solovyev.common.history.HistoryAction;
|
import org.solovyev.common.history.HistoryAction;
|
||||||
import org.solovyev.common.math.Point2d;
|
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.text.StringUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -68,23 +47,14 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
@Nullable
|
@Nullable
|
||||||
private IBillingObserver billingObserver;
|
private IBillingObserver billingObserver;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorPreferences.Gui.Theme theme;
|
private CalculatorPreferences.Gui.Theme theme;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorPreferences.Gui.Layout layout;
|
private CalculatorPreferences.Gui.Layout layout;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private Vibrator vibrator;
|
|
||||||
|
|
||||||
private boolean useBackAsPrev;
|
private boolean useBackAsPrev;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ActivityMenu<Menu, MenuItem> menu = LayoutActivityMenu.newInstance(R.menu.main_menu, CalculatorMenu.class);
|
private ActivityMenu<Menu, MenuItem> menu = LayoutActivityMenu.newInstance(R.menu.main_menu, CalculatorMenu.class);
|
||||||
|
|
||||||
@ -100,12 +70,12 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
CalculatorPreferences.setDefaultValues(preferences);
|
|
||||||
|
|
||||||
setTheme(preferences);
|
setTheme(preferences);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setLayout(preferences);
|
setLayout(preferences);
|
||||||
|
|
||||||
|
CalculatorKeyboardFragment.fixThemeParameters(findViewById(R.id.main_layout), true, this, theme);
|
||||||
|
|
||||||
final FragmentManager fragmentManager = getFragmentManager();
|
final FragmentManager fragmentManager = getFragmentManager();
|
||||||
|
|
||||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
@ -118,6 +88,11 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
fragmentTransaction.add(R.id.displayContainer, displayFragment);
|
fragmentTransaction.add(R.id.displayContainer, displayFragment);
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
|
|
||||||
|
fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
|
final CalculatorKeyboardFragment keyboardFragment = new CalculatorKeyboardFragment();
|
||||||
|
fragmentTransaction.add(R.id.keyboardContainer, keyboardFragment);
|
||||||
|
fragmentTransaction.commit();
|
||||||
|
|
||||||
if (customTitleSupported) {
|
if (customTitleSupported) {
|
||||||
try {
|
try {
|
||||||
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
|
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
|
||||||
@ -139,88 +114,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
// init billing controller
|
// init billing controller
|
||||||
BillingController.checkBillingSupported(this);
|
BillingController.checkBillingSupported(this);
|
||||||
|
|
||||||
vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
|
|
||||||
|
|
||||||
dpclRegister.clear();
|
|
||||||
|
|
||||||
final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, this);
|
|
||||||
|
|
||||||
setOnDragListeners(dragPreferences, preferences);
|
|
||||||
|
|
||||||
final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(getCalculator()), dragPreferences), vibrator, preferences);
|
|
||||||
((DragButton) findViewById(R.id.historyButton)).setOnDragListener(historyOnDragListener);
|
|
||||||
|
|
||||||
((DragButton) 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) {
|
|
||||||
operatorsButtonClickHandler(dragButton);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}, dragPreferences), vibrator, preferences));
|
|
||||||
|
|
||||||
|
|
||||||
final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences);
|
|
||||||
((DragButton) findViewById(R.id.rightButton)).setOnDragListener(toPositionOnDragListener);
|
|
||||||
((DragButton) findViewById(R.id.leftButton)).setOnDragListener(toPositionOnDragListener);
|
|
||||||
|
|
||||||
final DragButton equalsButton = (DragButton) findViewById(R.id.equalsButton);
|
|
||||||
if (equalsButton != null) {
|
|
||||||
equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences));
|
|
||||||
}
|
|
||||||
|
|
||||||
final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) findViewById(R.id.sixDigitButton);
|
|
||||||
if (angleUnitsButton != null) {
|
|
||||||
angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(), dragPreferences), vibrator, preferences));
|
|
||||||
}
|
|
||||||
|
|
||||||
final NumeralBasesButton clearButton = (NumeralBasesButton) findViewById(R.id.clearButton);
|
|
||||||
if (clearButton != null) {
|
|
||||||
clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(), dragPreferences), vibrator, preferences));
|
|
||||||
}
|
|
||||||
|
|
||||||
final DragButton varsButton = (DragButton) findViewById(R.id.varsButton);
|
|
||||||
if (varsButton != null) {
|
|
||||||
varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new VarsDragProcessor(), dragPreferences), vibrator, preferences));
|
|
||||||
}
|
|
||||||
|
|
||||||
final DragButton roundBracketsButton = (DragButton) findViewById(R.id.roundBracketsButton);
|
|
||||||
if ( roundBracketsButton != null ) {
|
|
||||||
roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
|
|
||||||
}
|
|
||||||
|
|
||||||
initMultiplicationButton();
|
|
||||||
|
|
||||||
fixThemeParameters(true);
|
|
||||||
|
|
||||||
if (layout == CalculatorPreferences.Gui.Layout.simple) {
|
|
||||||
toggleButtonDirectionText(R.id.oneDigitButton, false, DragDirection.up, DragDirection.down);
|
|
||||||
toggleButtonDirectionText(R.id.twoDigitButton, false, DragDirection.up, DragDirection.down);
|
|
||||||
toggleButtonDirectionText(R.id.threeDigitButton, false, DragDirection.up, DragDirection.down);
|
|
||||||
|
|
||||||
toggleButtonDirectionText(R.id.sixDigitButton, false, DragDirection.up, DragDirection.down);
|
|
||||||
toggleButtonDirectionText(R.id.sevenDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
|
||||||
toggleButtonDirectionText(R.id.eightDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
|
||||||
|
|
||||||
toggleButtonDirectionText(R.id.clearButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
|
||||||
|
|
||||||
toggleButtonDirectionText(R.id.fourDigitButton, false, DragDirection.down);
|
|
||||||
toggleButtonDirectionText(R.id.fiveDigitButton, false, DragDirection.down);
|
|
||||||
|
|
||||||
toggleButtonDirectionText(R.id.nineDigitButton, false, DragDirection.left);
|
|
||||||
|
|
||||||
toggleButtonDirectionText(R.id.multiplicationButton, false, DragDirection.left);
|
|
||||||
toggleButtonDirectionText(R.id.plusButton, false, DragDirection.down, DragDirection.up);
|
|
||||||
}
|
|
||||||
|
|
||||||
numeralBaseButtons.toggleNumericDigits(this, preferences);
|
|
||||||
|
|
||||||
toggleOrientationChange(preferences);
|
toggleOrientationChange(preferences);
|
||||||
|
|
||||||
// todo serso: continue
|
CalculatorKeyboardFragment.toggleEqualsButton(preferences, this, theme, findViewById(R.id.main_layout));
|
||||||
//toggleEqualsButton(preferences);
|
|
||||||
|
|
||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
@ -235,201 +131,6 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
|
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fixThemeParameters(boolean fixMagicFlames) {
|
|
||||||
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
|
|
||||||
|
|
||||||
if (fixMagicFlames) {
|
|
||||||
// for metro themes we should turn off magic flames
|
|
||||||
AndroidUtils.processViewsOfType(this.getWindow().getDecorView(), ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() {
|
|
||||||
@Override
|
|
||||||
public void process(@NotNull ColorButton colorButton) {
|
|
||||||
colorButton.setDrawMagicFlame(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fixMargins(2, 2);
|
|
||||||
} else {
|
|
||||||
fixMargins(1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toggleButtonDirectionText(int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
|
|
||||||
final View v = findViewById(id);
|
|
||||||
if (v instanceof DirectionDragButton ) {
|
|
||||||
final DirectionDragButton button = (DirectionDragButton)v;
|
|
||||||
for (DragDirection dragDirection : dragDirections) {
|
|
||||||
button.showDirectionText(showDirectionText, dragDirection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fixMargins(int marginLeft, int marginBottom) {
|
|
||||||
// sad but true
|
|
||||||
|
|
||||||
final View equalsButton = findViewById(R.id.equalsButton);
|
|
||||||
final View rightButton = findViewById(R.id.rightButton);
|
|
||||||
final View leftButton = findViewById(R.id.leftButton);
|
|
||||||
final View clearButton = findViewById(R.id.clearButton);
|
|
||||||
final View eraseButton = findViewById(R.id.eraseButton);
|
|
||||||
|
|
||||||
int orientation = AndroidUtils.getScreenOrientation(this);
|
|
||||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
||||||
setMarginsForView(equalsButton, marginLeft, marginBottom);
|
|
||||||
// todo serso: continue
|
|
||||||
//setMarginsForView(getCalculatorDisplayView(), marginLeft, marginBottom);
|
|
||||||
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
||||||
setMarginsForView(leftButton, marginLeft, marginBottom);
|
|
||||||
setMarginsForView(eraseButton, marginLeft, marginBottom);
|
|
||||||
setMarginsForView(clearButton, marginLeft, marginBottom);
|
|
||||||
setMarginsForView(rightButton, marginLeft, marginBottom);
|
|
||||||
// magic magic magic
|
|
||||||
// todo serso: continue
|
|
||||||
//setMarginsForView(getCalculatorDisplayView(), 3 * marginLeft, marginBottom);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setMarginsForView(@NotNull View view, int marginLeft, int marginBottom) {
|
|
||||||
// IMPORTANT: this is workaround for probably android bug
|
|
||||||
// currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
|
|
||||||
|
|
||||||
final DisplayMetrics dm = getResources().getDisplayMetrics();
|
|
||||||
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
|
|
||||||
final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
|
|
||||||
final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
|
|
||||||
newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
|
|
||||||
view.setLayoutParams(newParams);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
|
|
||||||
|
|
||||||
private final DigitButtonDragProcessor processor = new DigitButtonDragProcessor(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(CalculatorActivity.this);
|
|
||||||
|
|
||||||
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
|
|
||||||
|
|
||||||
Toast.makeText(CalculatorActivity.this, CalculatorActivity.this.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
|
|
||||||
|
|
||||||
Toast.makeText(CalculatorActivity.this, CalculatorActivity.this.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
|
||||||
|
|
||||||
@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(CalculatorActivity.this, CalculatorLocatorImpl.getInstance().getDisplay());
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void setOnDragListeners(@NotNull SimpleOnDragListener.Preferences dragPreferences, @NotNull SharedPreferences preferences) {
|
|
||||||
final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new DigitButtonDragProcessor(getKeyboard()), dragPreferences), vibrator, preferences);
|
|
||||||
|
|
||||||
final List<Integer> dragButtonIds = new ArrayList<Integer>();
|
|
||||||
final List<Integer> buttonIds = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
for (Field field : R.id.class.getDeclaredFields()) {
|
|
||||||
int modifiers = field.getModifiers();
|
|
||||||
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
|
|
||||||
try {
|
|
||||||
int viewId = field.getInt(R.id.class);
|
|
||||||
final View view = this.findViewById(viewId);
|
|
||||||
if (view instanceof DragButton) {
|
|
||||||
dragButtonIds.add(viewId);
|
|
||||||
}
|
|
||||||
if (view instanceof Button) {
|
|
||||||
buttonIds.add(viewId);
|
|
||||||
}
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
Log.e(R.id.class.getName(), e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Integer dragButtonId : dragButtonIds) {
|
|
||||||
((DragButton) findViewById(dragButtonId)).setOnDragListener(onDragListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private SimpleOnDragListener newOnDragListener(@NotNull SimpleOnDragListener.DragProcessor dragProcessor,
|
|
||||||
@NotNull SimpleOnDragListener.Preferences dragPreferences) {
|
|
||||||
final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences);
|
|
||||||
dpclRegister.addListener(onDragListener);
|
|
||||||
return onDragListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private synchronized void setLayout(@NotNull SharedPreferences preferences) {
|
private synchronized void setLayout(@NotNull SharedPreferences preferences) {
|
||||||
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||||
|
|
||||||
@ -512,9 +213,15 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@Override
|
||||||
public void elementaryButtonClickHandler(@NotNull View v) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
throw new UnsupportedOperationException("Not implemented yet!");
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
if (useBackAsPrev) {
|
||||||
|
getCalculator().doHistoryAction(HistoryAction.undo);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
@ -522,6 +229,85 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
getCalculator().evaluate();
|
getCalculator().evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
return this.menu.onCreateOptionsMenu(this, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
return menu.onOptionsItemSelected(this, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The font sizes in the layout files are specified for a HVGA display.
|
||||||
|
* Adjust the font sizes accordingly if we are running on a different
|
||||||
|
* display.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void adjustFontSize(@NotNull TextView view) {
|
||||||
|
float fontPixelSize = view.getTextSize();
|
||||||
|
Display display = getWindowManager().getDefaultDisplay();
|
||||||
|
int h = Math.min(display.getWidth(), display.getHeight());
|
||||||
|
float ratio = (float) h / HVGA_WIDTH_PIXELS;
|
||||||
|
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize * ratio);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
||||||
|
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
|
||||||
|
if (!theme.equals(newTheme) || !layout.equals(newLayout)) {
|
||||||
|
AndroidUtils.restartActivity(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
if (billingObserver != null) {
|
||||||
|
BillingController.unregisterObserver(billingObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
|
||||||
|
if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
|
||||||
|
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
|
||||||
|
toggleOrientationChange(preferences);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
|
||||||
|
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
|
||||||
|
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||||
|
} else {
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* BUTTON HANDLERS
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void elementaryButtonClickHandler(@NotNull View v) {
|
||||||
|
throw new UnsupportedOperationException("Not implemented yet!");
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void historyButtonClickHandler(@NotNull View v) {
|
public void historyButtonClickHandler(@NotNull View v) {
|
||||||
CalculatorActivityLauncher.showHistory(this);
|
CalculatorActivityLauncher.showHistory(this);
|
||||||
@ -585,6 +371,10 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
CalculatorActivityLauncher.showOperators(this);
|
CalculatorActivityLauncher.showOperators(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void operatorsButtonClickHandler(@NotNull Activity activity, @NotNull View view) {
|
||||||
|
CalculatorActivityLauncher.showOperators(activity);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public void varsButtonClickHandler(@NotNull View v) {
|
public void varsButtonClickHandler(@NotNull View v) {
|
||||||
CalculatorActivityLauncher.showVars(this);
|
CalculatorActivityLauncher.showVars(this);
|
||||||
@ -595,150 +385,4 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
CalculatorApplication.showDonationDialog(this);
|
CalculatorApplication.showDonationDialog(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
||||||
if (useBackAsPrev) {
|
|
||||||
getCalculator().doHistoryAction(HistoryAction.undo);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.onKeyDown(keyCode, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
return this.menu.onCreateOptionsMenu(this, menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
return menu.onOptionsItemSelected(this, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The font sizes in the layout files are specified for a HVGA display.
|
|
||||||
* Adjust the font sizes accordingly if we are running on a different
|
|
||||||
* display.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void adjustFontSize(@NotNull TextView view) {
|
|
||||||
float fontPixelSize = view.getTextSize();
|
|
||||||
Display display = getWindowManager().getDefaultDisplay();
|
|
||||||
int h = Math.min(display.getWidth(), display.getHeight());
|
|
||||||
float ratio = (float) h / HVGA_WIDTH_PIXELS;
|
|
||||||
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize * ratio);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
|
|
||||||
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
|
||||||
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
|
|
||||||
if (!theme.equals(newTheme) || !layout.equals(newLayout)) {
|
|
||||||
AndroidUtils.restartActivity(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
if (billingObserver != null) {
|
|
||||||
BillingController.unregisterObserver(billingObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
|
|
||||||
if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
|
|
||||||
dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
|
|
||||||
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
|
|
||||||
numeralBaseButtons.toggleNumericDigits(this, preferences);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
|
|
||||||
initMultiplicationButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
|
|
||||||
toggleOrientationChange(preferences);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
|
|
||||||
toggleEqualsButton(preferences);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toggleEqualsButton(@Nullable SharedPreferences preferences) {
|
|
||||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
|
|
||||||
|
|
||||||
|
|
||||||
if (AndroidUtils.getScreenOrientation(this) == Configuration.ORIENTATION_PORTRAIT || !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
|
||||||
final Display display = this.getWindowManager().getDefaultDisplay();
|
|
||||||
|
|
||||||
final DragButton button = (DragButton)findViewById(R.id.equalsButton);
|
|
||||||
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
|
|
||||||
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 1f));
|
|
||||||
if (display.getWidth() <= 480) {
|
|
||||||
// mobile phones
|
|
||||||
getCalculatorDisplayView().setBackgroundDrawable(null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 0f));
|
|
||||||
if (display.getWidth() <= 480) {
|
|
||||||
// mobile phones
|
|
||||||
getCalculatorDisplayView().setBackgroundDrawable(this.getResources().getDrawable(R.drawable.equals9));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fixThemeParameters(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private AndroidCalculatorDisplayView getCalculatorDisplayView() {
|
|
||||||
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
|
|
||||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
|
|
||||||
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
|
||||||
} else {
|
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initMultiplicationButton() {
|
|
||||||
final View multiplicationButton = findViewById(R.id.multiplicationButton);
|
|
||||||
if ( multiplicationButton instanceof Button) {
|
|
||||||
((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -4,7 +4,9 @@ import android.app.AlertDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -68,6 +70,10 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
return CalculatorSecurity.getPK();
|
return CalculatorSecurity.getPK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
CalculatorPreferences.setDefaultValues(preferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showDonationDialog(@NotNull final Context context) {
|
public static void showDonationDialog(@NotNull final Context context) {
|
||||||
|
@ -15,7 +15,9 @@ public class CalculatorDisplayFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.calc_display, null);
|
final View view = inflater.inflate(R.layout.calc_display, null);
|
||||||
|
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,497 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Vibrator;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.*;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
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.history.CalculatorHistoryState;
|
||||||
|
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.calculator.view.OnDragListenerVibrator;
|
||||||
|
import org.solovyev.android.history.HistoryDragProcessor;
|
||||||
|
import org.solovyev.android.view.ColorButton;
|
||||||
|
import org.solovyev.android.view.drag.*;
|
||||||
|
import org.solovyev.common.Announcer;
|
||||||
|
import org.solovyev.common.math.Point2d;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: Solovyev_S
|
||||||
|
* Date: 25.09.12
|
||||||
|
* Time: 12:25
|
||||||
|
*/
|
||||||
|
public class CalculatorKeyboardFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Vibrator vibrator;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private CalculatorPreferences.Gui.Theme theme;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private CalculatorPreferences.Gui.Layout layout;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
vibrator = (Vibrator) this.getActivity().getSystemService(Activity.VIBRATOR_SERVICE);
|
||||||
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||||
|
|
||||||
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||||
|
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
final View view = inflater.inflate(R.layout.calc_keyboard, null);
|
||||||
|
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(root, savedInstanceState);
|
||||||
|
|
||||||
|
dpclRegister.clear();
|
||||||
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||||
|
final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, this.getActivity());
|
||||||
|
|
||||||
|
setOnDragListeners(root, dragPreferences, preferences);
|
||||||
|
|
||||||
|
final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(getCalculator()), dragPreferences), vibrator, preferences);
|
||||||
|
((DragButton) root.findViewById(R.id.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;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, 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);
|
||||||
|
if (equalsButton != null) {
|
||||||
|
equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences));
|
||||||
|
}
|
||||||
|
|
||||||
|
final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) root.findViewById(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);
|
||||||
|
if (clearButton != null) {
|
||||||
|
clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(this.getActivity()), dragPreferences), vibrator, preferences));
|
||||||
|
}
|
||||||
|
|
||||||
|
final DragButton varsButton = (DragButton) root.findViewById(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);
|
||||||
|
if (roundBracketsButton != null) {
|
||||||
|
roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (layout == CalculatorPreferences.Gui.Layout.simple) {
|
||||||
|
toggleButtonDirectionText(root, R.id.oneDigitButton, false, DragDirection.up, DragDirection.down);
|
||||||
|
toggleButtonDirectionText(root, R.id.twoDigitButton, false, DragDirection.up, DragDirection.down);
|
||||||
|
toggleButtonDirectionText(root, R.id.threeDigitButton, false, DragDirection.up, DragDirection.down);
|
||||||
|
|
||||||
|
toggleButtonDirectionText(root, R.id.sixDigitButton, false, DragDirection.up, DragDirection.down);
|
||||||
|
toggleButtonDirectionText(root, R.id.sevenDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
||||||
|
toggleButtonDirectionText(root, R.id.eightDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
||||||
|
|
||||||
|
toggleButtonDirectionText(root, R.id.clearButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
|
||||||
|
|
||||||
|
toggleButtonDirectionText(root, R.id.fourDigitButton, false, DragDirection.down);
|
||||||
|
toggleButtonDirectionText(root, R.id.fiveDigitButton, false, DragDirection.down);
|
||||||
|
|
||||||
|
toggleButtonDirectionText(root, R.id.nineDigitButton, false, DragDirection.left);
|
||||||
|
|
||||||
|
toggleButtonDirectionText(root, R.id.multiplicationButton, false, DragDirection.left);
|
||||||
|
toggleButtonDirectionText(root, R.id.plusButton, false, DragDirection.down, DragDirection.up);
|
||||||
|
}
|
||||||
|
|
||||||
|
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
|
||||||
|
|
||||||
|
fixThemeParameters(root, true, this.getActivity(), theme);
|
||||||
|
|
||||||
|
toggleEqualsButton(preferences, this.getActivity(), theme, root);
|
||||||
|
|
||||||
|
initMultiplicationButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
|
||||||
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||||
|
|
||||||
|
preferences.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fixThemeParameters(@NotNull View root, boolean fixMagicFlames, @NotNull Activity activity, @NotNull CalculatorPreferences.Gui.Theme theme) {
|
||||||
|
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
|
||||||
|
|
||||||
|
if (fixMagicFlames) {
|
||||||
|
// for metro themes we should turn off magic flames
|
||||||
|
AndroidUtils.processViewsOfType(activity.getWindow().getDecorView(), ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() {
|
||||||
|
@Override
|
||||||
|
public void process(@NotNull ColorButton colorButton) {
|
||||||
|
colorButton.setDrawMagicFlame(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fixMargins(root, 2, 2, activity);
|
||||||
|
} else {
|
||||||
|
fixMargins(root, 1, 1, activity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fixMargins(@NotNull View root, int marginLeft, int marginBottom, @NotNull Activity activity) {
|
||||||
|
// sad but true
|
||||||
|
|
||||||
|
final View equalsButton = root.findViewById(R.id.equalsButton);
|
||||||
|
final View rightButton = root.findViewById(R.id.rightButton);
|
||||||
|
final View leftButton = root.findViewById(R.id.leftButton);
|
||||||
|
final View clearButton = root.findViewById(R.id.clearButton);
|
||||||
|
final View eraseButton = root.findViewById(R.id.eraseButton);
|
||||||
|
|
||||||
|
int orientation = AndroidUtils.getScreenOrientation(activity);
|
||||||
|
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
|
setMarginsForView(equalsButton, marginLeft, marginBottom, activity);
|
||||||
|
setMarginsForView(getCalculatorDisplayView(), marginLeft, marginBottom, activity);
|
||||||
|
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
|
setMarginsForView(leftButton, marginLeft, marginBottom, activity);
|
||||||
|
setMarginsForView(eraseButton, marginLeft, marginBottom, activity);
|
||||||
|
setMarginsForView(clearButton, marginLeft, marginBottom, activity);
|
||||||
|
setMarginsForView(rightButton, marginLeft, marginBottom, activity);
|
||||||
|
// magic magic magic
|
||||||
|
setMarginsForView(getCalculatorDisplayView(), 3 * marginLeft, marginBottom, activity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMultiplicationButton() {
|
||||||
|
final View multiplicationButton = getView().findViewById(R.id.multiplicationButton);
|
||||||
|
if ( multiplicationButton instanceof Button) {
|
||||||
|
((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
|
||||||
|
// IMPORTANT: this is workaround for probably android bug
|
||||||
|
// currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
|
||||||
|
|
||||||
|
if (view != null) {
|
||||||
|
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||||
|
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
|
||||||
|
final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
|
||||||
|
final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
|
||||||
|
newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
|
||||||
|
view.setLayoutParams(newParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void setOnDragListeners(@NotNull View root, @NotNull SimpleOnDragListener.Preferences dragPreferences, @NotNull SharedPreferences preferences) {
|
||||||
|
final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new DigitButtonDragProcessor(getKeyboard()), dragPreferences), vibrator, preferences);
|
||||||
|
|
||||||
|
final List<Integer> dragButtonIds = new ArrayList<Integer>();
|
||||||
|
final List<Integer> buttonIds = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
for (Field field : R.id.class.getDeclaredFields()) {
|
||||||
|
int modifiers = field.getModifiers();
|
||||||
|
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
|
||||||
|
try {
|
||||||
|
int viewId = field.getInt(R.id.class);
|
||||||
|
final View view = root.findViewById(viewId);
|
||||||
|
if (view instanceof DragButton) {
|
||||||
|
dragButtonIds.add(viewId);
|
||||||
|
}
|
||||||
|
if (view instanceof Button) {
|
||||||
|
buttonIds.add(viewId);
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
Log.e(R.id.class.getName(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Integer dragButtonId : dragButtonIds) {
|
||||||
|
((DragButton) root.findViewById(dragButtonId)).setOnDragListener(onDragListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private SimpleOnDragListener newOnDragListener(@NotNull SimpleOnDragListener.DragProcessor dragProcessor,
|
||||||
|
@NotNull SimpleOnDragListener.Preferences dragPreferences) {
|
||||||
|
final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences);
|
||||||
|
dpclRegister.addListener(onDragListener);
|
||||||
|
return onDragListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
|
if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
|
||||||
|
dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this.getActivity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
|
||||||
|
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
|
||||||
|
toggleEqualsButton(preferences, this.getActivity(), theme, getView());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
|
||||||
|
initMultiplicationButton();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
|
||||||
|
final View v = root.findViewById(id);
|
||||||
|
if (v instanceof DirectionDragButton ) {
|
||||||
|
final DirectionDragButton button = (DirectionDragButton)v;
|
||||||
|
for (DragDirection dragDirection : dragDirections) {
|
||||||
|
button.showDirectionText(showDirectionText, dragDirection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toggleEqualsButton(@Nullable SharedPreferences preferences,
|
||||||
|
@NotNull Activity activity,
|
||||||
|
@NotNull CalculatorPreferences.Gui.Theme theme,
|
||||||
|
@NotNull View root) {
|
||||||
|
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
|
||||||
|
|
||||||
|
if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT || !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
||||||
|
final Display display = activity.getWindowManager().getDefaultDisplay();
|
||||||
|
|
||||||
|
final DragButton button = (DragButton)activity.findViewById(R.id.equalsButton);
|
||||||
|
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
|
||||||
|
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 1f));
|
||||||
|
if (display.getWidth() <= 480) {
|
||||||
|
// mobile phones
|
||||||
|
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
|
||||||
|
if (calculatorDisplayView != null) {
|
||||||
|
calculatorDisplayView.setBackgroundDrawable(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 0f));
|
||||||
|
if (display.getWidth() <= 480) {
|
||||||
|
// mobile phones
|
||||||
|
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
|
||||||
|
if (calculatorDisplayView != null) {
|
||||||
|
calculatorDisplayView.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.equals9));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fixThemeParameters(root, false, activity, theme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
|
||||||
|
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Calculator getCalculator() {
|
||||||
|
return CalculatorLocatorImpl.getInstance().getCalculator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static CalculatorKeyboard getKeyboard() {
|
||||||
|
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* STATIC CLASSES
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
private 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
private 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final DigitButtonDragProcessor processor;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
private 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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
private 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);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user