polishing metro theme

This commit is contained in:
Sergey Solovyev 2012-02-08 02:52:09 +04:00
parent 8239365688
commit c4a4e94a0f
4 changed files with 48 additions and 9 deletions

View File

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:a="http://schemas.android.com/apk/res/android"> <selector xmlns:a="http://schemas.android.com/apk/res/android">
<item a:state_focused="true"
a:drawable="@drawable/metro_button_focused"/>
<item a:state_pressed="true" <item a:state_pressed="true"
a:drawable="@drawable/metro_button_focused"/> a:drawable="@drawable/metro_button_pressed"/>
<item a:drawable="@drawable/metro_button_dark_shape"/> <item a:drawable="@drawable/metro_button_dark_shape"/>
</selector> </selector>

View File

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:a="http://schemas.android.com/apk/res/android"> <selector xmlns:a="http://schemas.android.com/apk/res/android">
<item a:state_focused="true"
a:drawable="@drawable/metro_button_focused"/>
<item a:state_pressed="true" <item a:state_pressed="true"
a:drawable="@drawable/metro_button_focused"/> a:drawable="@drawable/metro_button_pressed"/>
<item a:drawable="@drawable/metro_button_light_shape"/> <item a:drawable="@drawable/metro_button_light_shape"/>
</selector> </selector>

View File

@ -8,17 +8,20 @@ package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.SharedPreferences; import android.content.SharedPreferences;
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.text.ClipboardManager; import android.text.ClipboardManager;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.*; import android.view.*;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.google.ads.AdView; import com.google.ads.AdView;
import jscl.AngleUnit; import jscl.AngleUnit;
@ -228,9 +231,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(), dragPreferences), vibrator, preferences)); angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(), dragPreferences), vibrator, preferences));
} }
final NumeralBasesButton numeralBasesButton = (NumeralBasesButton) findViewById(R.id.clearButton); final NumeralBasesButton clearButton = (NumeralBasesButton) findViewById(R.id.clearButton);
if (numeralBasesButton != null) { if (clearButton != null) {
numeralBasesButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(), dragPreferences), vibrator, preferences)); clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(), dragPreferences), vibrator, preferences));
} }
final DragButton varsButton = (DragButton) findViewById(R.id.varsButton); final DragButton varsButton = (DragButton) findViewById(R.id.varsButton);
@ -256,11 +259,51 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
colorButton.setDrawMagicFlame(false); colorButton.setDrawMagicFlame(false);
} }
}); });
fixMargins(2, 2);
} else {
fixMargins(1, 1);
} }
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
} }
private void fixMargins(int marginLeft, int marginBottom) {
// sad but true
final View equalsButton = findViewById(R.id.equalsButton);
final View rightButton = findViewById(R.id.rightButton);
final View leftButton = findViewById(R.id.leftButton);
final View clearButton = findViewById(R.id.clearButton);
final View eraseButton = findViewById(R.id.eraseButton);
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
setMarginsForView(equalsButton, marginLeft, marginBottom);
setMarginsForView(calculatorModel.getDisplay(), marginLeft, marginBottom);
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
setMarginsForView(leftButton, marginLeft, marginBottom);
setMarginsForView(eraseButton, marginLeft, marginBottom);
setMarginsForView(clearButton, marginLeft, marginBottom);
setMarginsForView(rightButton, marginLeft, marginBottom);
// magic magic magic
setMarginsForView(calculatorModel.getDisplay(), 3 * marginLeft, marginBottom);
}
}
private void setMarginsForView(@NotNull View view, int marginLeft, int marginBottom) {
// 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
final DisplayMetrics dm = 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);
}
}
private class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor { private class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
private final DigitButtonDragProcessor processor = new DigitButtonDragProcessor(calculatorModel); private final DigitButtonDragProcessor processor = new DigitButtonDragProcessor(calculatorModel);