Package com.googlecode.mgwt.ui.client.util.impl

Source Code of com.googlecode.mgwt.ui.client.util.impl.ResizeOrientationHandler

package com.googlecode.mgwt.ui.client.util.impl;

import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Window;
import com.googlecode.mgwt.dom.client.event.orientation.OrientationChangeEvent.ORIENTATION;
import com.googlecode.mgwt.ui.client.util.OrientationHandler;

public class ResizeOrientationHandler extends BaseOrientationHandler implements
    OrientationHandler {

  @Override
  public void doSetupOrientation() {

    if (!orientationEventSupported()) {
      Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
          ORIENTATION orientation = getOrientation();
          if (orientation != currentOrientation) {
            currentOrientation = orientation;
            fireOrientationChangedEvent(orientation);
          }
        }
      });
    } else {
      setupNativeBrowerOrientationHandler();
    }

  }

  private native static boolean orientationEventSupported()/*-{
    return "onorientationchange" in $wnd;
  }-*/;

  /**
   * Get the current orientation of the device
   *
   * @return the current orientation of the device
   */
  public ORIENTATION getOrientation() {
    if (!orientationSupport()) {
      int height = Window.getClientHeight();
      int width = Window.getClientWidth();

      if (width > height) {
        return ORIENTATION.LANDSCAPE;
      } else {
        return ORIENTATION.PORTRAIT;
      }
    } else {
      return getBrowserOrientation();
    }
  }

  private static native boolean orientationSupport() /*-{
    return "orientation" in $wnd;
  }-*/;
TOP

Related Classes of com.googlecode.mgwt.ui.client.util.impl.ResizeOrientationHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.