1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.javafx.ext.device.ios.sensors;
  26 
  27 import com.sun.glass.ui.ios.IosApplication;
  28 
  29 
  30 /**
  31  * The class IOSApplication provides the API for managing the IOS-specific aspects
  32  * of the application appearance, such as status bar appearance and orientation.
  33  */
  34 public class IOSApplication {
  35 
  36     private static IOSApplication INSTANCE = null;
  37 
  38     public static IOSApplication getSharedApplication() {
  39         synchronized (IOSApplication.class) {
  40             if (INSTANCE == null) INSTANCE = new IOSApplication();
  41             return INSTANCE;
  42         }
  43     }
  44 
  45 
  46     /**
  47      * Returns the visibility state of the status bar
  48      * @return <code>true</code> if the status bar is visible,
  49      *         <code>false</code> otherwise.
  50      */
  51     public boolean isStatusBarVisible() {
  52         return !IosApplication._getStatusBarHidden();
  53     }
  54 
  55 
  56     /**
  57      * Shows the status bar
  58      */
  59     public void showStatusBar() {
  60         IosApplication._setStatusBarHidden(false);
  61     }
  62 
  63 
  64     /**
  65      * Shows the status bar.
  66      * If the status bar was hidden, the transition can optionally be animated.
  67      * @param animation One of the constants in {@linkplain StatusBarAnimation}.
  68      */
  69     public void showStatusBarWithAnimation(final StatusBarAnimation animation) {
  70         IosApplication._setStatusBarHiddenWithAnimation(false, animation.ordinal());
  71     }
  72 
  73 
  74     /**
  75      * Hides the status bar.
  76      */
  77     public void hideStatusBar() {
  78         IosApplication._setStatusBarHidden(true);
  79     }
  80 
  81 
  82     /**
  83      * Hides the status bar.
  84      * If the status bar was visible, the transition can optionally be animated.
  85      * @param animation One of the constants in {@linkplain StatusBarAnimation}.
  86      */
  87     public void hideStatusBarWithAnimation(final StatusBarAnimation animation) {
  88         IosApplication._setStatusBarHiddenWithAnimation(true, animation.ordinal());
  89     }
  90 
  91 
  92     /**
  93      * Gets the status bar style.
  94      * @return one of the constants defined in {@linkplain StatusBarStyle}.
  95      */
  96     public StatusBarStyle getStatusBarStyle() {
  97         return StatusBarStyle.values()[IosApplication._getStatusBarStyle()];
  98     }
  99 
 100     /**
 101      * Sets the style of the application status bar,
 102      * with the possibility to animate the change of the style.
 103      * @param style         One of the styles defined in {@linkplain StatusBarStyle}.
 104      * @param animated      <code>true</code> if the style change should be animated,
 105      *                      <code>false</code> if the style change should be immediate.
 106      */
 107     public void setStatusBarStyleAnimated(final StatusBarStyle style, final boolean animated) {
 108         IosApplication._setStatusBarStyleAnimated(style.ordinal(), animated);
 109     }
 110 
 111 
 112     /**
 113      * Gets the status bar orientation.
 114      * @return one of the constants defined in {@linkplain StatusBarOrientation}.
 115      */
 116     public StatusBarOrientation getStatusBarOrientation() {
 117         return StatusBarOrientation.values()[IosApplication._getStatusBarOrientation() - 1];
 118     }
 119 
 120 
 121     /**
 122      * Sets the orientation of the application's status bar,
 123      * with the possibility to animate the transition to the new orientation.
 124      *
 125      * @param orientation   the status bar {@linkplain StatusBarOrientation orientation}.
 126      *                      The default orientation is {@linkplain javafx.ext.ios.StatusBarOrientation#PORTRAIT}.
 127      * @param animated      <code>true</code> if the orientation change should be animated,
 128      *                      <code>false</code> if the orientation change should be immediate.
 129      */
 130     public void setStatusBarOrientationAnimated(final StatusBarOrientation orientation, final boolean animated) {
 131         IosApplication._setStatusBarOrientationAnimated(orientation.value(), animated);
 132     }
 133 }