Commit 1d6a0b0f authored by Mygod's avatar Mygod

Use styling to fix #910

parent abcbc98c
...@@ -44,5 +44,8 @@ ...@@ -44,5 +44,8 @@
<item name="android:fadeScrollbars">true</item> <item name="android:fadeScrollbars">true</item>
<item name="android:scrollbars">vertical</item> <item name="android:scrollbars">vertical</item>
</style> </style>
<style name="NumberPickerStyle">
<item name="android:textSize">14sp</item>
</style>
</resources> </resources>
...@@ -4,25 +4,13 @@ import android.content.Context ...@@ -4,25 +4,13 @@ import android.content.Context
import android.content.res.TypedArray import android.content.res.TypedArray
import android.support.v7.preference.DialogPreference import android.support.v7.preference.DialogPreference
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.ContextThemeWrapper
import android.view.ViewGroup.LayoutParams import android.widget.NumberPicker
import android.widget.{EditText, NumberPicker}
import com.github.shadowsocks.R import com.github.shadowsocks.R
import com.github.shadowsocks.utils.Utils
class MyNumberPicker(private val context: Context, attrs: AttributeSet = null) extends NumberPicker(context, attrs) {
override def addView(child: View, index: Int, params: LayoutParams) {
super.addView(child, index, params)
child match {
case et: EditText => et.setTextSize(Utils.spToPx(context, 6))
case _ =>
}
}
}
class NumberPickerPreference(private val context: Context, attrs: AttributeSet = null) class NumberPickerPreference(private val context: Context, attrs: AttributeSet = null)
extends DialogPreference(context, attrs) with SummaryPreference { extends DialogPreference(context, attrs) with SummaryPreference {
private[preference] val picker = new MyNumberPicker(context) private[preference] val picker = new NumberPicker(new ContextThemeWrapper(context, R.style.NumberPickerStyle))
private var value: Int = _ private var value: Int = _
{ {
......
...@@ -77,10 +77,7 @@ object Utils { ...@@ -77,10 +77,7 @@ object Utils {
new String(Base64.encode(mdg.digest, 0)) new String(Base64.encode(mdg.digest, 0))
} }
def dpToPx(context: Context, dp: Int): Int = def dpToPx(context: Context, dp: Int): Int = Math.round(dp * context.getResources.getDisplayMetrics.density)
Math.round(dp * context.getResources.getDisplayMetrics.density)
def spToPx(context: Context, sp: Int): Int =
Math.round(sp * context.getResources.getDisplayMetrics.scaledDensity)
/* /*
* round or floor depending on whether you are using offsets(floor) or * round or floor depending on whether you are using offsets(floor) or
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment