Show equals button preferences

This commit is contained in:
Sergey Solovyev 2012-04-21 15:06:27 +04:00
parent 2171d9dd2c
commit 39de2cbf8f
11 changed files with 56 additions and 20 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

View File

@ -3,5 +3,5 @@
<string name="c_auto_orientation_summary">If turned on calculator will change screen orientation automatically</string>
<string name="c_show_equals_button_title">Show equals button</string>
<string name="c_show_equals_button_summary">Preference hides or shows equals button</string>
<string name="c_show_equals_button_summary">If turned on equals button is shown</string>
</resources>

View File

@ -139,7 +139,14 @@
a:key="autoOrientation"
a:title="@string/c_auto_orientation_title"
a:summary="@string/c_auto_orientation_summary"
a:defaultValue="false"/>
a:defaultValue="true"/>
<android.preference.CheckBoxPreference
a:key="showEqualsButton"
a:title="@string/c_show_equals_button_title"
a:summary="@string/c_show_equals_button_summary"
a:defaultValue="true"/>
</PreferenceScreen>

View File

@ -183,21 +183,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
initMultiplicationButton();
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
// 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);
}
});
fixThemeParameters(true);
fixMargins(2, 2);
} else {
fixMargins(1, 1);
}
if (layout == CalculatorPreferences.Gui.Layout.simple) {
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);
@ -226,12 +214,33 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
numeralBaseButtons.addButtonId(R.id.sixDigitButton);
numeralBaseButtons.toggleNumericDigits(this, preferences);
toggleEqualsButton(preferences);
toggleOrientationChange(preferences);
preferences.registerOnSharedPreferenceChangeListener(this);
}
private void toggleButtonDirectionText(int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
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;
@ -250,7 +259,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
final View clearButton = findViewById(R.id.clearButton);
final View eraseButton = findViewById(R.id.eraseButton);
int orientation = getResources().getConfiguration().orientation;
int orientation = AndroidUtils.getScreenOrientation(this);
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
setMarginsForView(equalsButton, marginLeft, marginBottom);
setMarginsForView(calculatorModel.getDisplay(), marginLeft, marginBottom);
@ -673,8 +682,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
}
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
toggleOrientationChange(preferences);
if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
toggleEqualsButton(preferences);
}
if (CalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
@ -684,8 +693,28 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
if ( CalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
initMultiplicationButton();
}
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
toggleOrientationChange(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 DragButton button = (DragButton)findViewById(R.id.equalsButton);
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 1f));
calculatorModel.getDisplay().setBackgroundDrawable(null);
} else {
button.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 0f));
calculatorModel.getDisplay().setBackgroundDrawable(this.getResources().getDrawable(R.drawable.equals9));
}
fixThemeParameters(false);
}
}
private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {