Saturday, July 7, 2012

mgwt and the viewport

This post is part of a series of blogposts that show the usage of  some mgwt / gwt-phonegap components.



If you are writing software for mobile phones you should know about the view port meta tag and what it can do for you.
There are different settings for the viewport that let you do different things.
Browsers on mobile phones are different from desktop browser in the sense that they have this notion of the viewport. The screen on an average mobile phone is not big enough to fit a normal webpage. This is why the viewport was invented. It allows mobile browsers to display webpages that are made for desktop devices by zooming and moving the viewport around.

If you don`t supply any information to the browser it will render your page zoomed out. It will try to give the user a good overview of the page so that he can decide on which part he needs to zoom in.
Normally text will not be readable.

You can control the initial scale, the maximum scale and the minimal scale of the viewport with a meta tag.

Setting an inital scale will set the value lets you control the zoom value at startup.
With mgwt it would look something like this:


   ViewPort viewPort = new MGWTSettings.ViewPort();
   //configure view port
   viewPort.setMinimumScale(0.2).setInitialScale(1.0).setMaximumScale(5);

   //create settings and set view port
   MGWTSettings settings = new MGWTSettings();
   settings.setViewPort(viewPort);

   //apply the setting e.g. create meta tag in page
   MGWT.applySettings(settings);


This code would result in a meta tag looking like this:
   <meta name="viewport" content="initial-scale=1.0,minimum-scale=0.2,maximum-scale=5">

If you are writing app you do not want the user to be able to zoom your app. The webpage should feel like a native app. This can be done by setting the initial screen scale to 1.0 and disabling scrolling.

With mgwt this would look like this:

   ViewPort viewPort = new MGWTSettings.ViewPort();
   viewPort.setUserScaleAble(false).setMinimumScale(1.0).setInitialScale(1.0).setMaximumScale(1.0);

   MGWTSettings settings = new MGWTSettings();
   settings.setViewPort(viewPort);
   settings.setPreventScrolling(true);

   MGWT.applySettings(settings);

This will create a meta tag that looks like this:
   <meta name="viewport" content="initial-scale=1.0,minimum-scale=1,maximum-scale=1,user-scalable=no">

Depending on what you are trying to do you need to set different values for the viewport.
mgwt gives you the freedom to set any value that make sense to you.

If you want to have the default settings for an app you can use a short handle like this:

   MGWT.applySettings(MGWTSettings.getAppSetting());


I hope gives you the necessary information to use viewport effectively to build your mobile app with mgwt.

As always feel free to leave any comments or suggestions.

7 comments:

  1. Thanks Daniel! That was a very good post... Thanks for all your great work.

    ReplyDelete
  2. I need to implement pinch to zoom for my InAppbrowser in android. I can acheive this by passing enableviewportscale=yes in iOs. Anything like that for android

    ReplyDelete
  3. Great,sometime we should do it , l like it, we should use the industrial intercom to protect us , such as the ip intercom, voip intercom and sip intercom.

    ReplyDelete
  4. Anyone can attempt writing on your behalf, however, the question is would you pay someone to do it for you without checking their credibility? Our firm has established itself as the most trustworthy assignments help firm in Australia and globally. Join these thousands of students and achieve high distinction in each and every one of your college tasks. This is the main reason why most students search for online assignment help australia over the internet and choose only the most proficient and trusted academic writing experts. So, if you are searching for quality assignment help singapore you can find it right here from the local experts.

    ReplyDelete
  5. Thanks for sharing such article. If any students wants case study assignment help then they can contact us. We are best assignment help provider in worldwide.

    ReplyDelete
  6. It is important to distinguish between practicalities, family circumstances, and personal preferences. The following authors discuss how to collect futanari sex doll from an older person's perspective.

    ReplyDelete