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_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_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> </resources>

View File

@ -139,7 +139,14 @@
a:key="autoOrientation" a:key="autoOrientation"
a:title="@string/c_auto_orientation_title" a:title="@string/c_auto_orientation_title"
a:summary="@string/c_auto_orientation_summary" 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> </PreferenceScreen>

View File

@ -183,19 +183,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
initMultiplicationButton(); initMultiplicationButton();
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) { fixThemeParameters(true);
// 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);
}
if (layout == CalculatorPreferences.Gui.Layout.simple) { if (layout == CalculatorPreferences.Gui.Layout.simple) {
toggleButtonDirectionText(R.id.oneDigitButton, false, DragDirection.up, DragDirection.down); toggleButtonDirectionText(R.id.oneDigitButton, false, DragDirection.up, DragDirection.down);
@ -226,11 +214,32 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
numeralBaseButtons.addButtonId(R.id.sixDigitButton); numeralBaseButtons.addButtonId(R.id.sixDigitButton);
numeralBaseButtons.toggleNumericDigits(this, preferences); numeralBaseButtons.toggleNumericDigits(this, preferences);
toggleEqualsButton(preferences);
toggleOrientationChange(preferences); toggleOrientationChange(preferences);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
} }
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) { private void toggleButtonDirectionText(int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
final View v = findViewById(id); final View v = findViewById(id);
if (v instanceof DirectionDragButton ) { if (v instanceof DirectionDragButton ) {
@ -250,7 +259,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
final View clearButton = findViewById(R.id.clearButton); final View clearButton = findViewById(R.id.clearButton);
final View eraseButton = findViewById(R.id.eraseButton); final View eraseButton = findViewById(R.id.eraseButton);
int orientation = getResources().getConfiguration().orientation; int orientation = AndroidUtils.getScreenOrientation(this);
if (orientation == Configuration.ORIENTATION_PORTRAIT) { if (orientation == Configuration.ORIENTATION_PORTRAIT) {
setMarginsForView(equalsButton, marginLeft, marginBottom); setMarginsForView(equalsButton, marginLeft, marginBottom);
setMarginsForView(calculatorModel.getDisplay(), 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); useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
} }
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) { if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
toggleOrientationChange(preferences); toggleEqualsButton(preferences);
} }
if (CalculatorEngine.Preferences.numeralBase.getKey().equals(key)) { if (CalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
@ -684,6 +693,26 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
if ( CalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) { if ( CalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
initMultiplicationButton(); 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) { private void toggleOrientationChange(@Nullable SharedPreferences preferences) {