1 /* 2 * Copyright (c) 2010, 2015, 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 26 package com.sun.glass.ui.ios; 27 28 import com.sun.glass.ui.*; 29 import com.sun.glass.ui.CommonDialogs.ExtensionFilter; 30 import com.sun.glass.ui.CommonDialogs.FileChooserResult; 31 import java.io.File; 32 import java.nio.ByteBuffer; 33 import java.nio.IntBuffer; 34 import java.security.AccessController; 35 import java.security.PrivilegedAction; 36 import java.util.List; 37 38 public final class IosApplication extends Application { 39 40 private static native void _initIDs(); // init IDs for java callbacks from native 41 static { 42 AccessController.doPrivileged((PrivilegedAction<Void>) () -> { 43 Application.loadNativeLibrary(); 44 return null; 45 }); 46 _initIDs(); 47 } 48 49 /** 50 * @inheritDoc 51 */ 52 @Override 53 protected void runLoop(final Runnable launchable) { 54 ClassLoader ccl = IosApplication.class.getClassLoader(); 55 _runLoop(launchable, ccl); 56 } 57 private native void _runLoop(Runnable launchable, ClassLoader contextClassLoader); 58 59 /** 60 * @inheritDoc 61 */ 62 @Override 63 protected void finishTerminating() { 64 setEventThread(null); 65 super.finishTerminating(); 66 } 67 68 // Called from the native code 69 private void setEventThread() { 70 setEventThread(Thread.currentThread()); 71 } 72 73 /** 74 * @inheritDoc 75 */ 76 @Override 77 public Window createWindow(Window owner, Screen screen, int styleMask) { 78 return new IosWindow(owner, screen, styleMask); 79 } 80 81 /** 82 * @inheritDoc 83 */ 84 @Override 85 public Window createWindow(long parent) { 86 return new IosWindow(parent); 87 } 88 89 /** 90 * @inheritDoc 91 */ 92 @Override 93 public View createView() { 94 return new IosView(); 95 } 96 97 /** 98 * @inheritDoc 99 */ 100 @Override 101 public Cursor createCursor(int type) { 102 return new IosCursor(type); 103 } 104 105 /** 106 * @inheritDoc 107 * On iOS, there is no cursor. 108 */ 109 @Override 110 public Cursor createCursor(int x, int y, Pixels pixels) { 111 return new IosCursor(x, y, pixels); 112 } 113 114 @Override 115 protected void staticCursor_setVisible(boolean visible) { } 116 117 @Override 118 protected Size staticCursor_getBestSize(int width, int height) { 119 return null; 120 } 121 122 /** 123 * @inheritDoc 124 */ 125 @Override 126 public Pixels createPixels(int width, int height, ByteBuffer data) { 127 return new IosPixels(width, height, data); 128 } 129 130 /** 131 * @inheritDoc 132 */ 133 @Override 134 public Pixels createPixels(int width, int height, IntBuffer data) { 135 return new IosPixels(width, height, data); 136 } 137 138 @Override 139 public Pixels createPixels(int width, int height, IntBuffer data, float scalex, float scaley) { 140 return new IosPixels(width, height, data, scalex, scaley); 141 } 142 143 @Override 144 protected int staticPixels_getNativeFormat() { 145 return 0; 146 } 147 148 /** 149 * @inheritDoc 150 */ 151 @Override 152 public Robot createRobot() { 153 return new IosRobot(); 154 } 155 156 @Override 157 protected native double staticScreen_getVideoRefreshPeriod(); 158 159 @Override 160 protected native Screen[] staticScreen_getScreens(); 161 162 /** 163 * @inheritDoc 164 */ 165 @Override 166 public Timer createTimer(Runnable runnable) { 167 return new IosTimer(runnable); 168 } 169 170 @Override 171 protected int staticTimer_getMinPeriod() { 172 return IosTimer.getMinPeriod_impl(); 173 } 174 175 @Override 176 protected int staticTimer_getMaxPeriod() { 177 return IosTimer.getMaxPeriod_impl(); 178 } 179 180 @Override 181 protected FileChooserResult staticCommonDialogs_showFileChooser(Window owner, String folder, String filename, String title, int type, boolean multipleMode, ExtensionFilter[] extensionFilters, int defaultFilterIndex) { 182 return new FileChooserResult(); 183 } 184 185 @Override 186 protected File staticCommonDialogs_showFolderChooser(Window owner, String folder, String title) { 187 return null; 188 } 189 190 private native Object _enterNestedEventLoopImpl(); 191 private native void _leaveNestedEventLoopImpl(); 192 193 @Override 194 protected Object _enterNestedEventLoop() { 195 return _enterNestedEventLoopImpl(); 196 } 197 198 @Override 199 protected void _leaveNestedEventLoop(Object retValue) { 200 _leaveNestedEventLoopImpl(); 201 } 202 203 @Override 204 protected long staticView_getMultiClickTime() { 205 return IosView._getMultiClickTime(); 206 } 207 208 @Override 209 protected int staticView_getMultiClickMaxX() { 210 return IosView._getMultiClickMaxX(); 211 } 212 213 @Override 214 protected int staticView_getMultiClickMaxY() { 215 return IosView._getMultiClickMaxY(); 216 } 217 218 @Override 219 native protected void _invokeAndWait(Runnable runnable); 220 221 @Override 222 native protected void _invokeLater(Runnable runnable); 223 224 @Override 225 protected boolean _supportsTransparentWindows() { 226 return true; 227 } 228 229 @Override protected boolean _supportsUnifiedWindows() { 230 return false; 231 } 232 233 /** 234 * Hides / Shows iOS status bar. 235 * @param hidden 236 */ 237 public native static void _setStatusBarHidden(boolean hidden); 238 239 /** 240 * Hides / Shows iOS status bar, possibly animating transition. 241 * @param hidden 242 * @param animation - 0 none, 1 fade, 2 slide 243 */ 244 public native static void _setStatusBarHiddenWithAnimation(boolean hidden, int animation); 245 246 /** 247 * Adjust status bar orientation with animation. See iOS UIApplication developers 248 * documentation for details. 249 * @param interfaceOrientation 250 * @param animated 251 */ 252 public native static void _setStatusBarOrientationAnimated(int interfaceOrientation, boolean animated); 253 254 /** 255 * See iOS developers documentation. (UIApplication). 256 * @param statusBarStyle 257 * @param animated 258 */ 259 public native static void _setStatusBarStyleAnimated(int statusBarStyle, boolean animated); 260 261 /** 262 * Status bar visibility getter. 263 * @return true if hidden 264 */ 265 public native static boolean _getStatusBarHidden(); 266 267 /** 268 * See iOS developers documentation. 269 */ 270 public native static int _getStatusBarStyle(); 271 272 /** 273 * See iOS developers documentation. 274 */ 275 public native static int _getStatusBarOrientation(); 276 277 @Override 278 public boolean hasTouch() { 279 return true; 280 } 281 282 @Override 283 public boolean hasMultiTouch() { 284 return true; 285 } 286 287 @Override 288 protected native int _getKeyCodeForChar(char c); 289 }