Preferences fixes

This commit is contained in:
Sergey Solovyev 2012-10-12 21:16:53 +04:00
parent 86b68f2562
commit 66d5d20465
3 changed files with 137 additions and 137 deletions

View File

@ -157,6 +157,8 @@ public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSh
CalculatorButtons.processButtons(true, theme, root); CalculatorButtons.processButtons(true, theme, root);
CalculatorButtons.toggleEqualsButton(preferences, activity); CalculatorButtons.toggleEqualsButton(preferences, activity);
CalculatorButtons.initMultiplicationButton(root);
NumeralBaseButtons.toggleNumericDigits(activity, preferences);
} }
private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) { private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {

View File

@ -1,134 +1,132 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.app.SherlockFragment;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 25.09.12 * Date: 25.09.12
* Time: 12:25 * Time: 12:25
*/ */
public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@NotNull @NotNull
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons(); private CalculatorPreferences.Gui.Theme theme;
@NotNull @NotNull
private CalculatorPreferences.Gui.Theme theme; private CalculatorFragmentHelper fragmentHelper;
@NotNull @Override
private CalculatorFragmentHelper fragmentHelper; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
public void onCreate(Bundle savedInstanceState) { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
super.onCreate(savedInstanceState);
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.calc_keyboard);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); fragmentHelper.onCreate(this);
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.calc_keyboard); preferences.registerOnSharedPreferenceChangeListener(this);
fragmentHelper.onCreate(this);
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
preferences.registerOnSharedPreferenceChangeListener(this);
}
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
@Override
} public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return fragmentHelper.onCreateView(this, inflater, container);
@Override }
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return fragmentHelper.onCreateView(this, inflater, container); @Override
} public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
@Override
public void onViewCreated(View root, Bundle savedInstanceState) { fragmentHelper.onViewCreated(this, root);
super.onViewCreated(root, savedInstanceState); }
fragmentHelper.onViewCreated(this, root);
} @Override
public void onResume() {
super.onResume();
@Override
public void onResume() { this.fragmentHelper.onResume(this);
super.onResume(); }
this.fragmentHelper.onResume(this); @Override
} public void onPause() {
this.fragmentHelper.onPause(this);
@Override
public void onPause() { super.onPause();
this.fragmentHelper.onPause(this); }
super.onPause(); @Override
} public void onDestroy() {
super.onDestroy();
@Override
public void onDestroy() { fragmentHelper.onDestroy(this);
super.onDestroy();
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
fragmentHelper.onDestroy(this); preferences.unregisterOnSharedPreferenceChangeListener(this);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); }
preferences.unregisterOnSharedPreferenceChangeListener(this);
/* 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
/* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
// IMPORTANT: this is workaround for probably android bug if (view != null) {
// currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually final DisplayMetrics dm = context.getResources().getDisplayMetrics();
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
if (view != null) { final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
final DisplayMetrics dm = context.getResources().getDisplayMetrics(); final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) { newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams(); view.setLayoutParams(newParams);
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);
@Override }
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); @Override
} public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key) ||
@Override CalculatorPreferences.Gui.hideNumeralBaseDigits.getKey().equals(key) ) {
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { NumeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) { }
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
} if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
CalculatorButtons.toggleEqualsButton(preferences, this.getActivity());
if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) { }
CalculatorButtons.toggleEqualsButton(preferences, this.getActivity());
} if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
CalculatorButtons.initMultiplicationButton(getView());
if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) { }
CalculatorButtons.initMultiplicationButton(getView()); }
}
}
@Nullable
private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
@Nullable return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
private static AndroidCalculatorDisplayView getCalculatorDisplayView() { }
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
} @NotNull
private Calculator getCalculator() {
@NotNull return CalculatorLocatorImpl.getInstance().getCalculator();
private Calculator getCalculator() { }
return CalculatorLocatorImpl.getInstance().getCalculator();
} @NotNull
private static CalculatorKeyboard getKeyboard() {
@NotNull return CalculatorLocatorImpl.getInstance().getKeyboard();
private static CalculatorKeyboard getKeyboard() { }
return CalculatorLocatorImpl.getInstance().getKeyboard(); }
}
}

View File

@ -13,7 +13,7 @@ import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
*/ */
public class NumeralBaseButtons { public class NumeralBaseButtons {
public synchronized void toggleNumericDigits(@NotNull Activity activity, @NotNull NumeralBase currentNumeralBase) { public static void toggleNumericDigits(@NotNull Activity activity, @NotNull NumeralBase currentNumeralBase) {
for (NumeralBase numeralBase : NumeralBase.values()) { for (NumeralBase numeralBase : NumeralBase.values()) {
if ( currentNumeralBase != numeralBase ) { if ( currentNumeralBase != numeralBase ) {
AndroidNumeralBase.valueOf(numeralBase).toggleButtons(false, activity); AndroidNumeralBase.valueOf(numeralBase).toggleButtons(false, activity);
@ -23,10 +23,10 @@ public class NumeralBaseButtons {
AndroidNumeralBase.valueOf(currentNumeralBase).toggleButtons(true, activity); AndroidNumeralBase.valueOf(currentNumeralBase).toggleButtons(true, activity);
} }
public synchronized void toggleNumericDigits(@NotNull Activity activity, @NotNull SharedPreferences preferences) { public static void toggleNumericDigits(@NotNull Activity activity, @NotNull SharedPreferences preferences) {
if (CalculatorPreferences.Gui.hideNumeralBaseDigits.getPreference(preferences)) { if (CalculatorPreferences.Gui.hideNumeralBaseDigits.getPreference(preferences)) {
final NumeralBase nb = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences); final NumeralBase nb = AndroidCalculatorEngine.Preferences.numeralBase.getPreference(preferences);
this.toggleNumericDigits(activity, nb); toggleNumericDigits(activity, nb);
} else { } else {
// set HEX to show all digits // set HEX to show all digits
AndroidNumeralBase.valueOf(NumeralBase.hex).toggleButtons(true, activity); AndroidNumeralBase.valueOf(NumeralBase.hex).toggleButtons(true, activity);