macroid
macroid copied to clipboard
size-based MediaQueries should not use DisplayMetrics
http://developer.android.com/reference/android/view/Display.html#getMetrics(android.util.DisplayMetrics)
widthPixels and heightPixels are adjusted for system decor. This is generally no good for maintaining compatibility with typical android size buckets (600dp for tablets, 720dp for large format tablets, etc).
A hack would be to display.getSize(p) metrics.widthPixels = p.x; etc.
Ugh, even display.getSize is adjusted for decoration... pos
I wrote this a while ago to emulate the -sw discriminator.
def sw(w: Int)(implicit ctx: AppContext) = {
import AndroidConversions._
val p = new Point
val d = ctx.get.systemService[WindowManager].getDefaultDisplay
if (Build.VERSION.SDK_INT >= 17) {
d.getRealSize(p)
} else if (Build.VERSION.SDK_INT >= 14) {
type RawSizeHack = {
def getRawWidth: Int
def getRawHeight: Int
}
val d2 = d.asInstanceOf[RawSizeHack]
p.x = d2.getRawWidth
p.y = d2.getRawHeight
} else {
p.x = d.getWidth
p.y = d.getHeight
}
MediaQuery(w <= p.x && w <= p.y)
}
Do you suggest to use this approach for all size queries?
I would, yes. It allows using similar size discriminators with normal android development.
Sent from my phone On Nov 26, 2014 4:44 PM, "Nick" [email protected] wrote:
Do you suggest to use this approach for all size queries?
— Reply to this email directly or view it on GitHub https://github.com/macroid/macroid/issues/38#issuecomment-64731225.