Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

size-based MediaQueries should not use DisplayMetrics #38

Open
pfn opened this issue Sep 30, 2014 · 4 comments
Open

size-based MediaQueries should not use DisplayMetrics #38

pfn opened this issue Sep 30, 2014 · 4 comments

Comments

@pfn
Copy link

pfn commented Sep 30, 2014

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
Copy link
Author

pfn commented Oct 28, 2014

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

@pfn
Copy link
Author

pfn commented Nov 26, 2014

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

@stanch
Copy link
Collaborator

stanch commented Nov 27, 2014

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

@pfn
Copy link
Author

pfn commented Nov 27, 2014

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
#38 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants