Search code examples
csstizen-wearable-sdktizen-web-app

Gear 2 (SM-380) doesn't support @media screen queries


I use the following media query in CSS and it works fine with Gear 2 Neo (SM-R381), but it doesn't work with an older Gear 2 (SM-R380). Do you have any idea why? Probably it's related to a difference in API level supported by these two devices? Any pointers are appreciated. Googling didn't help so far.

The styles are completely ignored by SM-R380, while honored by SM-R381.

@media screen and (max-width: 320px) {
/*
.ui-header {
    top: 0;
    height: 46px;
    padding: 0;
    border: 0;
}

.ui-footer {
    border: 0;
    padding: 0;
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
}

.ui-header > button, .ui-footer > button {
    height: 46px;
    padding: 0;
    line-height: 48px;
}

footer.ui-footer {
    height: 46px;
}
*/    
.icon-title {
    max-width:250px; 
 }

 .icon-title-menu {
     max-width:200px;
 }

. digit {
    width: 23px;
    height: 34px;
    float: left;
    margin-right: 1px;
    margin-left: 1px;
    background-size: 100%;
    background-repeat: no-repeat;
}

.colon {
    background-image: url(../img/14x51/colon.png);
    width: 8px;
    height: 40px;
 }

.token {
     margin-left:auto; 
     margin-right:auto; 
     margin-top:5%;
     width:154px;
    height:auto;    
 }

 .time {
    margin-left:auto; 
     margin-right:auto; 
     margin-top:5%;
    width:170px;
     height:auto;   
}

.pb {
    margin-left:auto; 
    margin-right:auto; 
    margin-top:27%; 
    width:64px; 
    height:64px; 
    background-size: 100%;"
    background-repeat: no-repeat;
}

}

Solution

  • After going back and forth with this and not getting a solution to make @media working on Gear 2 (SM-R380), I found a way around:

    1. Created two stylesheets- one for 320x320 screen, another for 360x480
    2. Added the following code to index.html just before </head> tag:

      <script type="text/javascript">
      
      function setStyle(kb) {
          var link = document.createElement( "link" );
          link.href = kb?"./css/style.css":"./css/style320.css";
          link.type = "text/css";
          link.rel = "stylesheet";
          link.media = "screen";
          document.getElementsByTagName( "head" )[0].appendChild( link );
      }
      
      tizen.systeminfo.getPropertyValue("DISPLAY", 
          function (disp) {
              if (disp.resolutionWidth <= 320) 
                  setStyle(false); 
              else
                  setStyle(true); 
          }, 
          function (err) {console.log("Can't read display props: " + err.message); setStyle(false);} 
      );              
      

      </script>

    Now it seems to be working and appstore has finally accepted the application.