Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting multiple screens #67

Open
zserge opened this issue May 6, 2016 · 1 comment
Open

Supporting multiple screens #67

zserge opened this issue May 6, 2016 · 1 comment

Comments

@zserge
Copy link
Collaborator

zserge commented May 6, 2016

People often ask how Anvil supports multiple screens. Currently it only provides an isPortrait helper.
All "media queries" (in terms of CSS) end up with checking current Configuration, which can be retrieved from Resources assiciated with the current Context:

if (getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
  // portrait layout
} else {
 // landscape layout
}

To keep Anvil simple we can remove isPortrait and make users write media queries manually. Or we can find a minimal subset of media queries to satisfy most needs.

Configuration allows you to detect:

  • Orientation (landscape, portrait)
  • Screen size category (small, normal, large, xlarge)
  • Screen DPI
  • Screen physical size in inches
  • Screen geometry (square, normal, long, or specific aspect ratio)

From the above I find the most practical to detect orientation and to tell normal (phone) layouts from large (tablet) layouts. This means that isPortrait is here to stay, but the screen size could be checked with different functions:

  • isTablet(), isTv(), isPhone()
  • isLarge(), isXLarge()
  • displaySize() that would returns size in inches, e.g. if (displaySize() > 6.5) { tablet(); } else { phone(); }

etc, etc. What are your thoughts?

P.S. Anko supports lots of configuration media queries - https://github.com/Kotlin/anko/blob/master/doc/ADVANCED.md#configuration-qualifiers while Scaloid supports only a few - https://github.com/pocorall/scaloid/blob/master/scaloid-common/src/main/st/org/scaloid/util/Configuration.scala

@ElectricCookie
Copy link

ElectricCookie commented Aug 25, 2016

Would love to see some included utilities. I would say that a function returning a simple enum of type

enum SCREEN_SIZE{ 
    TABLET_PORTRAIT,
    TABLET_LANDSCAPE,
    PHONE_PORTRAIT , 
    PHONE_LANDSCAPE,
    TV_LANDSCAPE 
    TV_PORTRAIT // Even possible?
}

is enough for most layouts, since you could then even perform a switch-case with fallthrough and default. For other use cases I would introduce a helper which returns the AspectRatio.

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

No branches or pull requests

2 participants