numeral base/angle units button fix
This commit is contained in:
@@ -52,6 +52,8 @@ import java.util.List;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.simple_mobile;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -75,6 +77,12 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
|
||||
@Nonnull
|
||||
private String logTag = "CalculatorActivity";
|
||||
|
||||
@Nullable
|
||||
private AngleUnitsButton angleUnitsButton;
|
||||
|
||||
@Nullable
|
||||
private NumeralBasesButton clearButton;
|
||||
|
||||
protected AbstractCalculatorHelper() {
|
||||
}
|
||||
|
||||
@@ -151,12 +159,12 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
|
||||
equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EqualsDragProcessor(), dragPreferences), vibrator, preferences));
|
||||
}
|
||||
|
||||
final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.cpp_button_6);
|
||||
angleUnitsButton = getButton(root, R.id.cpp_button_6);
|
||||
if (angleUnitsButton != null) {
|
||||
angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.AngleUnitsChanger(activity), dragPreferences), vibrator, preferences));
|
||||
}
|
||||
|
||||
final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.cpp_button_clear);
|
||||
clearButton = getButton(root, R.id.cpp_button_clear);
|
||||
if (clearButton != null) {
|
||||
clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.NumeralBasesChanger(activity), dragPreferences), vibrator, preferences));
|
||||
}
|
||||
@@ -266,12 +274,22 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
|
||||
if (key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
|
||||
final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance());
|
||||
for (DragPreferencesChangeListener dragPreferencesChangeListener : dpclRegister.getListeners()) {
|
||||
dragPreferencesChangeListener.onDragPreferencesChange(dragPreferences);
|
||||
}
|
||||
}
|
||||
|
||||
if (angleUnit.isSameKey(key) || numeralBase.isSameKey(key)) {
|
||||
if (angleUnitsButton != null) {
|
||||
angleUnitsButton.setAngleUnit(angleUnit.getPreference(preferences));
|
||||
}
|
||||
|
||||
if (clearButton != null) {
|
||||
clearButton.setNumeralBase(numeralBase.getPreference(preferences));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroy(@Nonnull Activity activity) {
|
||||
|
@@ -36,6 +36,14 @@ import javax.annotation.Nullable;
|
||||
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.hideNumeralBaseDigits;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.showEqualsButton;
|
||||
import static org.solovyev.android.calculator.NumeralBaseButtons.toggleNumericDigits;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.angleUnit;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.multiplicationSign;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 25.09.12
|
||||
@@ -108,21 +116,6 @@ public class CalculatorKeyboardFragment extends SherlockFragment implements Shar
|
||||
|
||||
}
|
||||
|
||||
/* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @Nonnull 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);
|
||||
@@ -130,25 +123,15 @@ public class CalculatorKeyboardFragment extends SherlockFragment implements Shar
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key) ||
|
||||
CalculatorPreferences.Gui.hideNumeralBaseDigits.getKey().equals(key)) {
|
||||
NumeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
|
||||
if (numeralBase.isSameKey(key) || hideNumeralBaseDigits.isSameKey(key)) {
|
||||
toggleNumericDigits(this.getActivity(), preferences);
|
||||
}
|
||||
|
||||
if (AndroidCalculatorEngine.Preferences.angleUnit.getKey().equals(key) ||
|
||||
AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
// we should update state of angle units/numeral base button => we can achieve it by invalidating the whole view
|
||||
view.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
if (CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key)) {
|
||||
if (showEqualsButton.isSameKey(key)) {
|
||||
CalculatorButtons.toggleEqualsButton(preferences, this.getActivity());
|
||||
}
|
||||
|
||||
if (AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key)) {
|
||||
if (multiplicationSign.isSameKey(key)) {
|
||||
CalculatorButtons.initMultiplicationButton(getView());
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,10 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
|
||||
import static jscl.NumeralBase.hex;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.hideNumeralBaseDigits;
|
||||
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences.numeralBase;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/20/12
|
||||
@@ -48,12 +52,12 @@ public class NumeralBaseButtons {
|
||||
}
|
||||
|
||||
public static void toggleNumericDigits(@Nonnull Activity activity, @Nonnull SharedPreferences preferences) {
|
||||
if (CalculatorPreferences.Gui.hideNumeralBaseDigits.getPreference(preferences)) {
|
||||
final NumeralBase nb = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences);
|
||||
if (hideNumeralBaseDigits.getPreference(preferences)) {
|
||||
final NumeralBase nb = numeralBase.getPreference(preferences);
|
||||
toggleNumericDigits(activity, nb);
|
||||
} else {
|
||||
// set HEX to show all digits
|
||||
AndroidNumeralBase.valueOf(NumeralBase.hex).toggleButtons(true, activity);
|
||||
AndroidNumeralBase.valueOf(hex).toggleButtons(true, activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user