This commit is contained in:
serso 2012-09-25 14:29:26 +04:00
parent cf322d04ee
commit c1e6389024
6 changed files with 127 additions and 159 deletions

View File

@ -13,8 +13,7 @@
<item name="android:layout_weight">1</item> <item name="android:layout_weight">1</item>
<item name="android:focusable">true</item> <item name="android:focusable">true</item>
<item name="android:background">@drawable/default_button_dark</item> <item name="android:background">@drawable/default_button_dark</item>
<item name="android:layout_marginLeft">1dp</item> <item name="android:layout_margin">0.5dp</item>
<item name="android:layout_marginBottom">1dp</item>
</style> </style>
<style name="editor_style" parent="editor_style_parent"> <style name="editor_style" parent="editor_style_parent">
@ -25,8 +24,9 @@
<style name="display_style" parent="display_style_parent"> <style name="display_style" parent="display_style_parent">
<item name="android:gravity">top|right</item> <item name="android:gravity">top|right</item>
<item name="android:layout_width">fill_parent</item> <item name="android:layout_width">match_parent</item>
<item name="android:layout_height">fill_parent</item> <item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">0.5dp</item>
</style> </style>
<style name="about_style" parent="about_style_parent"> <style name="about_style" parent="about_style_parent">

View File

@ -2,8 +2,6 @@
<style name="metro_digit_button_style" parent="button_style"> <style name="metro_digit_button_style" parent="button_style">
<item name="android:background">@drawable/metro_button_dark</item> <item name="android:background">@drawable/metro_button_dark</item>
<item name="android:layout_marginLeft">2dp</item>
<item name="android:layout_marginBottom">2dp</item>
</style> </style>
<style name="metro_control_button_style" parent="metro_digit_button_style"> <style name="metro_control_button_style" parent="metro_digit_button_style">

View File

@ -2,8 +2,6 @@
<style name="metro_digit_button_style" parent="button_style"> <style name="metro_digit_button_style" parent="button_style">
<item name="android:background">@drawable/metro_button_dark</item> <item name="android:background">@drawable/metro_button_dark</item>
<item name="android:layout_marginLeft">2dp</item>
<item name="android:layout_marginBottom">2dp</item>
</style> </style>
<style name="metro_control_button_style" parent="metro_digit_button_style"> <style name="metro_control_button_style" parent="metro_digit_button_style">

View File

@ -2,8 +2,6 @@
<style name="metro_digit_button_style" parent="button_style"> <style name="metro_digit_button_style" parent="button_style">
<item name="android:background">@drawable/metro_button_dark</item> <item name="android:background">@drawable/metro_button_dark</item>
<item name="android:layout_marginLeft">2dp</item>
<item name="android:layout_marginBottom">2dp</item>
</style> </style>
<style name="metro_control_button_style" parent="metro_digit_button_style"> <style name="metro_control_button_style" parent="metro_digit_button_style">

View File

@ -74,7 +74,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setLayout(preferences); setLayout(preferences);
CalculatorKeyboardFragment.fixThemeParameters(findViewById(R.id.main_layout), true, this, theme); CalculatorKeyboardFragment.fixThemeParameters(true, theme, this.getWindow().getDecorView());
final FragmentManager fragmentManager = getFragmentManager(); final FragmentManager fragmentManager = getFragmentManager();

View File

@ -8,7 +8,6 @@ import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator; import android.os.Vibrator;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.*; import android.view.*;
import android.widget.Button; import android.widget.Button;
@ -156,7 +155,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences); numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
fixThemeParameters(root, true, this.getActivity(), theme); fixThemeParameters(true, theme, this.getView());
toggleEqualsButton(preferences, this.getActivity(), theme, root); toggleEqualsButton(preferences, this.getActivity(), theme, root);
@ -172,45 +171,20 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
preferences.unregisterOnSharedPreferenceChangeListener(this); preferences.unregisterOnSharedPreferenceChangeListener(this);
} }
public static void fixThemeParameters(@NotNull View root, boolean fixMagicFlames, @NotNull Activity activity, @NotNull CalculatorPreferences.Gui.Theme theme) { public static void fixThemeParameters(boolean fixMagicFlames,
@NotNull CalculatorPreferences.Gui.Theme theme,
@NotNull View root) {
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) { if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
if (fixMagicFlames) { if (fixMagicFlames) {
// for metro themes we should turn off magic flames // for metro themes we should turn off magic flames
AndroidUtils.processViewsOfType(activity.getWindow().getDecorView(), ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() { AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() {
@Override @Override
public void process(@NotNull ColorButton colorButton) { public void process(@NotNull ColorButton colorButton) {
colorButton.setDrawMagicFlame(false); 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);
} }
} }
@ -221,7 +195,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
} }
} }
private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) { /* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
// IMPORTANT: this is workaround for probably android bug // 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 // currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
@ -234,7 +208,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
view.setLayoutParams(newParams); view.setLayoutParams(newParams);
} }
} }
} }*/
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
@ -338,7 +312,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
} }
} }
fixThemeParameters(root, false, activity, theme); fixThemeParameters(false, theme, root);
} }
} }