macroid icon indicating copy to clipboard operation
macroid copied to clipboard

size-based MediaQueries should not use DisplayMetrics

Open pfn opened this issue 11 years ago • 4 comments

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.

pfn avatar Sep 30 '14 15:09 pfn

Ugh, even display.getSize is adjusted for decoration... pos

pfn avatar Oct 28 '14 15:10 pfn

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)
  }

pfn avatar Nov 26 '14 23:11 pfn

Do you suggest to use this approach for all size queries?

stanch avatar Nov 27 '14 00:11 stanch

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.

pfn avatar Nov 27 '14 00:11 pfn