public class CN extends CN1Constants
Modifier and Type | Field and Description |
---|---|
static int |
BASELINE
Alignment to the baseline constraint
|
static int |
BOTTOM
Box-orientation constant used to specify the bottom of a box.
|
static int |
CENTER
Indicates a Component center alignment
|
static int |
CENTER_BEHAVIOR_CENTER
Defines the behavior of the component placed in the center position of the layout, places the component in the center of
the space available to the center component.
|
static int |
CENTER_BEHAVIOR_CENTER_ABSOLUTE
Defines the behavior of the component placed in the center position of the layout, places the component in the center of
the surrounding container
|
static int |
CENTER_BEHAVIOR_SCALE
Defines the behavior of the component placed in the center position of the layout, by default it is scaled to the available space
|
static int |
CENTER_BEHAVIOR_TOTAL_BELOW
The center component takes up the entire screens and the sides are automatically placed on top of it thus creating
a layered effect
|
static String |
EAST
The east layout constraint (right of container).
|
static int |
FACE_MONOSPACE
Constant allowing us to author portable system fonts
|
static int |
FACE_PROPORTIONAL
Constant allowing us to author portable system fonts
|
static int |
FACE_SYSTEM
Constant allowing us to author portable system fonts
|
static int |
LEFT
Box-orientation constant used to specify the left side of a box.
|
static String |
NATIVE_ITALIC_BLACK
Constant for the italic black native font.
|
static String |
NATIVE_ITALIC_BOLD
Constant for the italic bold native font.
|
static String |
NATIVE_ITALIC_LIGHT
Constant for the italic light native font.
|
static String |
NATIVE_ITALIC_REGULAR
Constant for the italic regular native font.
|
static String |
NATIVE_ITALIC_THIN
Constant for the italic thin native font.
|
static String |
NATIVE_MAIN_BLACK
Constant for the main black native font.
|
static String |
NATIVE_MAIN_BOLD
Constant for the main bold native font.
|
static String |
NATIVE_MAIN_LIGHT
Constant for the main light native font.
|
static String |
NATIVE_MAIN_REGULAR
Constant for the main regular native font.
|
static String |
NATIVE_MAIN_THIN
Constant for the name of the main thin native font.
|
static String |
NORTH
The north layout constraint (top of container).
|
static int |
RIGHT
Box-orientation constant used to specify the right side of a box.
|
static int |
SIZE_LARGE
Constant allowing us to author portable system fonts
|
static int |
SIZE_MEDIUM
Constant allowing us to author portable system fonts
|
static int |
SIZE_SMALL
Constant allowing us to author portable system fonts
|
static String |
SOUTH
The south layout constraint (bottom of container).
|
static int |
STYLE_BOLD
Constant allowing us to author portable system fonts
|
static int |
STYLE_ITALIC
Constant allowing us to author portable system fonts
|
static int |
STYLE_PLAIN
Constant allowing us to author portable system fonts
|
static int |
STYLE_UNDERLINED
Constant allowing us to author portable system fonts
|
static int |
TOP
Box-orientation constant used to specify the top of a box.
|
static String |
WEST
The west layout constraint (left of container).
|
DENSITY_2HD, DENSITY_4K, DENSITY_560, DENSITY_HD, DENSITY_HIGH, DENSITY_LOW, DENSITY_MEDIUM, DENSITY_VERY_HIGH, DENSITY_VERY_LOW, GALLERY_ALL, GALLERY_ALL_MULTI, GALLERY_IMAGE, GALLERY_IMAGE_MULTI, GALLERY_VIDEO, GALLERY_VIDEO_MULTI, PICKER_TYPE_CALENDAR, PICKER_TYPE_DATE, PICKER_TYPE_DATE_AND_TIME, PICKER_TYPE_DURATION, PICKER_TYPE_DURATION_HOURS, PICKER_TYPE_DURATION_MINUTES, PICKER_TYPE_STRINGS, PICKER_TYPE_TIME, SMS_BOTH, SMS_INTERACTIVE, SMS_NOT_SUPPORTED, SMS_SEAMLESS
Modifier and Type | Method and Description |
---|---|
static void |
addDefaultHeader(String key,
String value)
Adds a header to the global default headers, this header will be implicitly added
to all requests going out from this point onwards.
|
static void |
addEdtErrorHandler(ActionListener e)
An error handler will receive an action event with the source exception from the EDT
once an error handler is installed the default Codename One error dialog will no longer appear
|
static void |
addMessageListener(ActionListener<MessageEvent> l)
Adds a listener to receive messages from the native platform.
|
static void |
addNetworkErrorListener(ActionListener<NetworkEvent> e)
Adds a generic listener to a network error that is invoked before the exception is propagated.
|
static void |
addNetworkProgressListener(ActionListener<NetworkEvent> al)
Adds a listener to be notified when progress updates
|
static void |
addToQueue(ConnectionRequest request)
Adds the given network connection to the queue of execution
|
static void |
addToQueueAndWait(ConnectionRequest request)
Identical to add to queue but waits until the request is processed in the queue,
this is useful for completely synchronous operations.
|
static void |
callSerially(Runnable r)
Causes the runnable to be invoked on the event dispatch thread.
|
static void |
callSeriallyAndWait(Runnable r)
Identical to callSerially with the added benefit of waiting for the Runnable method to complete.
|
static void |
callSeriallyAndWait(Runnable r,
int timeout)
Identical to callSerially with the added benefit of waiting for the Runnable method to complete.
|
static void |
callSeriallyOnIdle(Runnable r)
Causes the runnable to be invoked on the event dispatch thread when the event
dispatch thread is idle.
|
static boolean |
canDial()
Returns true if the device has dialing capabilities
|
static Boolean |
canExecute(String url)
Returns true if executing this URL should work, returns false if it will not
and null if this is unknown.
|
static boolean |
canForceOrientation()
Returns true if the device allows forcing the orientation via code, feature phones do not allow this
although some include a jad property allowing for this feature
|
static boolean |
canInstallOnHomescreen()
Checks to see if you can prompt the user to install the app on their homescreen.
|
static Image |
captureScreen()
Captures a screenshot of the screen.
|
static void |
clearStorage()
Deletes all the files in the application storage
|
static void |
clearStorageCache()
Storage is cached for faster access, however this might cause a problem with refreshing
objects since they are not cloned.
|
static int |
convertToPixels(float dipCount)
Converts the dips count to pixels, dips are roughly 1mm in length.
|
static int |
convertToPixels(float value,
byte unitType)
Converts from specified unit to pixels.
|
static int |
convertToPixels(float value,
byte unitType,
boolean horizontal)
Converts from specified unit to pixels.
|
static int |
convertToPixels(int dipCount,
boolean horizontal)
Converts the dips count to pixels, dips are roughly 1mm in length.
|
static Object |
createSoftWeakRef(Object o)
Creates a soft/weak reference to an object that allows it to be collected
yet caches it.
|
static InputStream |
createStorageInputStream(String name)
Creates an input stream to the given storage source file
|
static OutputStream |
createStorageOutputStream(String name)
Creates an output stream to the storage with the given name
|
static Thread |
createThread(Runnable r,
String name)
Start a Codename One thread that supports crash protection and similar Codename One features.
|
static void |
delete(String file)
Deletes the specific file or empty directory.
|
static void |
deleteStorageFile(String name)
Deletes the given file name from the storage
|
static void |
deregisterPush()
Stop receiving push notifications to this client application
|
static void |
dial(String phoneNumber)
Opens the device Dialer application with the given phone number
|
static void |
execute(String url)
Executes the given URL on the native platform
|
static boolean |
existsInFileSystem(String file)
Indicates whether a file exists
|
static boolean |
existsInStorage(String name)
Returns true if the given storage file exists
|
static void |
exitApplication()
Exits the application...
|
static boolean |
exitFullScreen()
Try to exit full-screen mode if the platform supports it.
|
static Object |
extractHardRef(Object o)
Extracts the hard reference from the soft/weak reference given
|
static void |
flushStorageCache()
Flush the storage cache allowing implementations that cache storage objects
to store
|
static String |
getAppHomePath()
The application home directory is a "safe place" to store files for this application in a portable way.
|
static String |
getCachesDir()
Returns a device specific directory designed for cache style files, or null if
hasCachesDir()
is false |
static Form |
getCurrentForm()
Return the form currently displayed on the screen or null if no form is
currently displayed.
|
static int |
getDeviceDensity()
Returns one of the density variables appropriate for this device, notice that
density doesn't always correspond to resolution and an implementation might
decide to change the density based on DPI constraints.
|
static int |
getDisplayHeight()
Return the height of the display
|
static int |
getDisplayWidth()
Return the width of the display
|
static int |
getDragStartPercentage()
This method allows us to manipulate the drag started detection logic.
|
static long |
getFileLastModifiedFile(String file)
Deprecated.
this API requires additional privacy permissions on iOS
and might cause problems with iOS submissions
|
static long |
getFileLength(String file)
Returns the length of the file
|
static long |
getFileSystemRootAvailableSpace(String root)
Returns the available space in the given root directory
|
static String[] |
getFileSystemRoots()
Returns the filesystem roots from which the structure of the file system
can be traversed
|
static long |
getFileSystemRootSizeBytes(String root)
Returns the size of the given root directory
|
static int |
getFileSystemRootType(String root)
Returns the type of the root often by guessing
|
static String |
getPlatformName()
Returns a 2-3 letter code representing the platform name for the platform override
|
static PluginSupport |
getPluginSupport()
Returns the plugin support object for the current platform.
|
static String |
getProperty(String key,
String defaultValue)
Returns the property from the underlying platform deployment or the default
value if no deployment values are supported.
|
static InputStream |
getResourceAsStream(String resource)
This method is essentially equivalent to cls.getResourceAsStream(String)
however some platforms might define unique ways in which to load resources
within the implementation.
|
static BrowserComponent |
getSharedJavascriptContext()
Gets a reference to an application-wide shared Javascript context that can be used for running
Javascript commands.
|
static int |
getSMSSupport()
Indicates the level of SMS support in the platform as one of:
CN1Constants.SMS_NOT_SUPPORTED (for desktop, tablet etc.),
CN1Constants.SMS_SEAMLESS (no UI interaction), CN1Constants.SMS_INTERACTIVE (with compose UI),
CN1Constants.SMS_BOTH .The sample below demonstrates the use case for this property: |
static boolean |
hasCachesDir()
Returns true if the device has a directory dedicated for "cache" files
|
static boolean |
hasCamera()
Returns true if the device has camera false otherwise.
|
static void |
invokeAndBlock(Runnable r)
Invokes runnable and blocks the current thread, if the current thread is the
EDT it will still be blocked in a way that doesn't break event dispatch .
|
static void |
invokeWithoutBlocking(Runnable r)
Invokes a Runnable with blocking disabled.
|
static <T> T |
invokeWithoutBlockingWithResultSync(RunnableWithResultSync<T> r)
Invokes a RunnableWithResultSync with blocking disabled.
|
static Boolean |
isDarkMode()
Returns true if the platform is in dark mode, null is returned for
unknown status
|
static boolean |
isDesktop()
Returns true if this is a desktop application
|
static boolean |
isDirectory(String file)
Indicates whether the given file is a directory
|
static boolean |
isEdt()
Returns true if we are currently in the event dispatch thread.
|
static boolean |
isEnableAsyncStackTraces()
Checks if async stack traces are enabled.
|
static boolean |
isFullScreenSupported()
Checks if this platform supports full-screen mode.
|
static boolean |
isHiddenFile(String file)
Indicates the hidden state of the file
|
static boolean |
isInFullScreenMode()
Checks if the app is currently running in full-screen mode.
|
static boolean |
isMinimized()
Indicates whether an application is minimized
|
static boolean |
isNativePickerTypeSupported(int pickerType)
Indicates whether the native picker dialog is supported for the given type
which can include one of PICKER_TYPE_DATE_AND_TIME, PICKER_TYPE_TIME, PICKER_TYPE_DATE
|
static boolean |
isNativeShareSupported()
Indicates if the underlying platform supports sharing capabilities
|
static boolean |
isPortrait()
Returns true if the device is currently in portrait mode
|
static boolean |
isScreenSaverDisableSupported()
Checks if the device supports disabling the screen display from dimming, allowing
the developer to keep the screen display on.
|
static boolean |
isSimulator()
Allows detecting development mode so debugging code and special cases can be used to simplify flow
|
static boolean |
isTablet()
Indicates whether the device is a tablet, notice that this is often a guess
|
static void |
killAndWait(ConnectionRequest request)
Kills the given request and waits until the request is killed if it is
being processed by one of the threads.
|
static String[] |
listFiles(String directory)
Lists the files within the given directory, returns relative file names and not
full file names.
|
static String[] |
listStorageEntries()
Lists the names of the storage files
|
static void |
lockOrientation(boolean portrait)
On devices that return true for canForceOrientation() this method can lock the device orientation
either to portrait or landscape mode
|
static void |
log(String s)
Prints to the log
|
static void |
log(Throwable s)
Prints to the log
|
static boolean |
minimizeApplication()
Minimizes the current application if minimization is supported by the platform (may fail).
|
static void |
mkdir(String directory)
Creates the given directory
|
static void |
onCanInstallOnHomescreen(Runnable r)
A callback fired when you are allowed to prompt the user to install the app on their homescreen.
|
static InputStream |
openFileInputStream(String file)
Opens an input stream to the given file
|
static OutputStream |
openFileOutputStream(String file)
Opens an output stream to the given file
|
static OutputStream |
openFileOutputStream(String file,
int offset)
Opens an output stream to the given file
|
static void |
openGallery(ActionListener response,
int type)
Opens the device gallery to pick an image or a video.
The method returns immediately and the response is sent asynchronously to the given ActionListener Object as the source value of the event (as a String) |
static void |
postMessage(MessageEvent message)
Posts a message to the native platform.
|
static boolean |
promptInstallOnHomescreen()
Prompts the user to install this app on their homescreen.
|
static Object |
readObjectFromStorage(String name)
Reads the object from the storage, returns null if the object isn't there
|
static void |
registerPush()
Register to receive push notification, invoke this method once (ever) to receive push
notifications.
|
static void |
removeEdtErrorHandler(ActionListener e)
An error handler will receive an action event with the source exception from the EDT
once an error handler is installed the default Codename One error dialog will no longer appear
|
static void |
removeMessageListener(ActionListener<MessageEvent> l)
Removes a listener from receiving messages from the native platform.
|
static void |
removeNetworkErrorListener(ActionListener<NetworkEvent> e)
Removes the given error listener
|
static void |
removeNetworkProgressListener(ActionListener<NetworkEvent> al)
Adds a listener to be notified when progress updates
|
static void |
renameFile(String file,
String newName)
Renames a file to the given name, expects the new name to be relative to the
current directory
|
static boolean |
requestFullScreen()
Try to enter full-screen mode if the platform supports it.
|
static void |
restoreMinimizedApplication()
Restore the minimized application if minimization is supported by the platform
|
static void |
restoreToBookmark()
Runs the last bookmark that was set using
setBookmark(java.lang.Runnable) |
static void |
scheduleBackgroundTask(Runnable r)
Allows executing a background task in a separate low priority thread.
|
static void |
sendLog()
Sends the log to your email account
|
static void |
sendMessage(String subject,
Message msg,
String... recipients)
Send an email using the platform mail client.
The code below demonstrates sending a simple message with attachments using the devices native email client: |
static void |
sendSMS(String phoneNumber,
String message)
Sends a SMS message to the given phone number
|
static void |
sendSMS(String phoneNumber,
String message,
boolean interactive)
Sends a SMS message to the given phone number, the code below demonstrates the logic
of detecting platform behavior for sending SMS.
|
static void |
setBookmark(Runnable bookmark)
Sets a bookmark that can restore the app to a particular state.
|
static void |
setDarkMode(Boolean darkMode)
Override the default dark mode setting
|
static void |
setDragStartPercentage(int dragStartPercentage)
This method allows us to manipulate the drag started detection logic.
|
static void |
setEnableAsyncStackTraces(boolean enable)
Enables or disables async stack traces.
|
static void |
setHiddenFile(String file,
boolean h)
Toggles the hidden state of the file
|
static Timer |
setInterval(int timeout,
Runnable r)
Convenience method to schedule a task to run on the EDT after periodms
repeating every periodms.
|
static void |
setProperty(String key,
String value)
Sets a local property to the application, this method has no effect on the
implementation code and only allows the user to override the logic of getProperty
for internal application purposes.
|
static void |
setScreenSaverEnabled(boolean e)
If isScreenSaverDisableSupported() returns true calling this method will
lock the screen display on
|
static Timer |
setTimeout(int timeout,
Runnable r)
Convenience method to schedule a task to run on the EDT after timeoutms.
|
static void |
share(String text,
String image,
String mimeType)
Share the required information using the platform sharing services.
|
static void |
share(String text,
String image,
String mimeType,
Rectangle sourceRect)
Share the required information using the platform sharing services.
|
static Object |
showNativePicker(int type,
Component source,
Object currentValue,
Object data)
Shows a native modal dialog allowing us to perform the picking for the given type
which can include one of PICKER_TYPE_DATE_AND_TIME, PICKER_TYPE_TIME, PICKER_TYPE_DATE
|
static Thread |
startThread(Runnable r,
String name)
Deprecated.
confusing name, use
createThread(java.lang.Runnable, java.lang.String) instead |
static int |
storageEntrySize(String name)
Returns the size in bytes of the given entry
|
static void |
unlockOrientation()
This is the reverse method for lock orientation allowing orientation lock to be disabled
|
static void |
updateNetworkThreadCount(int threadCount)
Sets the number of network threads and restarts the network threads
|
static void |
vibrate(int duration)
Vibrates the device for the given length of time, notice that this might ignore the time value completely
on some OS's where this level of control isn't supported e.g.
|
static boolean |
writeObjectToStorage(String name,
Object o)
Writes the given object to storage assuming it is an externalizable type
or one of the supported types.
|
public static final String NATIVE_MAIN_THIN
public static final String NATIVE_MAIN_LIGHT
public static final String NATIVE_MAIN_REGULAR
public static final String NATIVE_MAIN_BOLD
public static final String NATIVE_MAIN_BLACK
public static final String NATIVE_ITALIC_THIN
public static final String NATIVE_ITALIC_LIGHT
public static final String NATIVE_ITALIC_REGULAR
public static final String NATIVE_ITALIC_BOLD
public static final String NATIVE_ITALIC_BLACK
public static final int FACE_MONOSPACE
public static final int FACE_PROPORTIONAL
public static final int FACE_SYSTEM
public static final int SIZE_LARGE
public static final int SIZE_MEDIUM
public static final int SIZE_SMALL
public static final int STYLE_BOLD
public static final int STYLE_ITALIC
public static final int STYLE_UNDERLINED
public static final int STYLE_PLAIN
public static final String NORTH
public static final String SOUTH
public static final String WEST
public static final String EAST
public static final int CENTER
public static final int TOP
public static final int LEFT
public static final int BOTTOM
public static final int RIGHT
public static final int BASELINE
public static final int CENTER_BEHAVIOR_SCALE
public static final int CENTER_BEHAVIOR_CENTER
public static final int CENTER_BEHAVIOR_CENTER_ABSOLUTE
public static final int CENTER_BEHAVIOR_TOTAL_BELOW
public static void setBookmark(Runnable bookmark)
Runnable
that will be run when restoreToBookmark()
() } is called.
The primary purpose of this feature is live code refresh.
bookmark
- A Runnable
that can be run to restore the app to a particular point.public static void restoreToBookmark()
setBookmark(java.lang.Runnable)
public static int getDragStartPercentage()
public static Object createSoftWeakRef(Object o)
o
- object to cachepublic static Object extractHardRef(Object o)
o
- the reference returned by createSoftWeakRefpublic static boolean isEnableAsyncStackTraces()
callSerially(java.lang.Runnable)
calls will
be recorded, and logged in the case that there is an uncaught exception.
Currently this is only supported in the JavaSE/Simulator port.
setEnableAsyncStackTraces(boolean)
public static void setEnableAsyncStackTraces(boolean enable)
callSerially(java.lang.Runnable)
calls will
be recorded, and logged in the case that there is an uncaught exception.
Currently this is only supported in the JavaSE/Simulator port.
enable
- True to enable async stack traces.isEnableAsyncStackTraces()
public static void setDragStartPercentage(int dragStartPercentage)
dragStartPercentage
- percentage of the screen required to initiate dragpublic static void vibrate(int duration)
duration
- length of time to vibrate (might be ignored)public static boolean isEdt()
public static void callSerially(Runnable r)
r
- runnable (NOT A THREAD!) that will be invoked on the EDT serial to
the paint and key handling eventspublic static void callSeriallyOnIdle(Runnable r)
r
- runnable (NOT A THREAD!) that will be invoked on the EDT serial to
the paint and key handling eventspublic static void scheduleBackgroundTask(Runnable r)
r
- the task to perform in the backgroundpublic static void callSeriallyAndWait(Runnable r)
r
- runnable (NOT A THREAD!) that will be invoked on the EDT serial to
the paint and key handling eventsIllegalStateException
- if this method is invoked on the event dispatch thread (e.g. during
paint or event handling).public static void callSeriallyAndWait(Runnable r, int timeout)
r
- runnable (NOT A THREAD!) that will be invoked on the EDT serial to
the paint and key handling eventstimeout
- timeout duration, on timeout the method just returnsIllegalStateException
- if this method is invoked on the event dispatch thread (e.g. during
paint or event handling).public static void invokeAndBlock(Runnable r)
r
- runnable (NOT A THREAD!) that will be invoked synchroniously by this methodpublic static void invokeWithoutBlocking(Runnable r)
invokeAndBlock(java.lang.Runnable)
from inside this Runnable,
it will result in a BlockingDisallowedException
being thrown.r
- Runnable to be run immediately.BlockingDisallowedException
- If invokeAndBlock(java.lang.Runnable)
is attempted
anywhere in the Runnable.public static <T> T invokeWithoutBlockingWithResultSync(RunnableWithResultSync<T> r)
invokeAndBlock(java.lang.Runnable)
from inside this Runnable,
it will result in a BlockingDisallowedException
being thrown.r
- Runnable to be run immediately.BlockingDisallowedException
- If invokeAndBlock(java.lang.Runnable)
is attempted
anywhere in the Runnable.public static boolean minimizeApplication()
public static boolean isMinimized()
public static void restoreMinimizedApplication()
public static Form getCurrentForm()
public static int getDisplayWidth()
public static int getDisplayHeight()
public static int convertToPixels(int dipCount, boolean horizontal)
dipCount
- the dips that we will convert to pixelshorizontal
- indicates pixels in the horizontal planepublic static int convertToPixels(float value, byte unitType, boolean horizontal)
value
- The value to convert, expressed in unitType.unitType
- The unit type. One of Style.UNIT_TYPE_DIPS
, Style.UNIT_TYPE_PIXELS
,
Style.UNIT_TYPE_REM
, Style.UNIT_TYPE_SCREEN_PERCENTAGE
, Style.UNIT_TYPE_VH
,
Style.UNIT_TYPE_VW
, Style.UNIT_TYPE_VMIN
, Style.UNIT_TYPE_VMAX
horizontal
- Whether screen percentage units should be based on horitonzal or vertical percentage.public static int convertToPixels(float value, byte unitType)
value
- The value to convert, expressed in unitType.unitType
- The unit type. One of Style.UNIT_TYPE_DIPS
, Style.UNIT_TYPE_PIXELS
,
Style.UNIT_TYPE_REM
, Style.UNIT_TYPE_SCREEN_PERCENTAGE
, Style.UNIT_TYPE_VH
,
Style.UNIT_TYPE_VW
, Style.UNIT_TYPE_VMIN
, Style.UNIT_TYPE_VMAX
public static int convertToPixels(float dipCount)
dipCount
- the dips that we will convert to pixelspublic static InputStream getResourceAsStream(String resource)
resource
- relative/absolute URL based on the Java conventionpublic static void addEdtErrorHandler(ActionListener e)
e
- listener receiving the errorspublic static void removeEdtErrorHandler(ActionListener e)
e
- listener receiving the errorspublic static void exitApplication()
public static String getProperty(String key, String defaultValue)
The implementation should be responsible for the following keys to return reasonable valid values for the application:
key
- the key of the propertydefaultValue
- a default return valuepublic static void setProperty(String key, String value)
key
- key the key of the propertyvalue
- the value of the propertypublic static Boolean canExecute(String url)
Returns true if executing this URL should work, returns false if it will not and null if this is unknown.
url
- the url that would be executedpublic static void execute(String url)
Executes the given URL on the native platform
url
- the url to executepublic static int getDeviceDensity()
public static boolean isPortrait()
public static boolean requestFullScreen()
Currently only desktop and Javascript builds support full-screen mode; And Javascript only supports this on certain browsers. See the MDN Fullscreen API docs for a list of browsers that support full-screen.
When running in the simulator, full-screen is only supported for the desktop skin.
exitFullScreen()
,
isInFullScreenMode()
,
isFullScreenSupported()
public static boolean exitFullScreen()
Currently only desktop and Javascript builds support full-screen mode; And Javascript only supports this on certain browsers. See the MDN Fullscreen API docs for a list of browsers that support full-screen.
When running in the simulator, full-screen is only supported for the desktop skin.
requestFullScreen()
,
isInFullScreenMode()
,
isFullScreenSupported()
public static boolean isInFullScreenMode()
requestFullScreen()
,
exitFullScreen()
,
isFullScreenSupported()
public static boolean isFullScreenSupported()
requestFullScreen()
, exitFullScreen()
, and isInFullScreenMode()
methods
to enter and exit full-screen - and query the current state.
Currently only desktop and Javascript builds support full-screen mode; And Javascript only supports this on certain browsers. See the MDN Fullscreen API docs for a list of browsers that support full-screen.
When running in the simulator, full-screen is only supported for the desktop skin.
requestFullScreen()
,
exitFullScreen()
,
isInFullScreenMode()
public static boolean canForceOrientation()
public static void lockOrientation(boolean portrait)
portrait
- true to lock to portrait mode, false to lock to landscape modepublic static void unlockOrientation()
public static boolean isTablet()
public static boolean isDesktop()
public static boolean canDial()
public static Boolean isDarkMode()
public static void setDarkMode(Boolean darkMode)
darkMode
- can be set to null to reset to platform defaultpublic static void openGallery(ActionListener response, int type)
Opens the device gallery to pick an image or a video.
The method returns immediately and the response is sent asynchronously
to the given ActionListener Object as the source value of the event (as a String)
E.g. within the callback action performed call you can use this code: String path = (String) evt.getSource();
.
A more detailed sample of picking a video file can be seen here:
response
- a callback Object to retrieve the file pathtype
- one of the following CN1Constants.GALLERY_IMAGE
, CN1Constants.GALLERY_VIDEO
, CN1Constants.GALLERY_ALL
RuntimeException
- if this feature failed or unsupported on the platformpublic static String getPlatformName()
public static void dial(String phoneNumber)
phoneNumber
- public static int getSMSSupport()
Indicates the level of SMS support in the platform as one of:
CN1Constants.SMS_NOT_SUPPORTED
(for desktop, tablet etc.),
CN1Constants.SMS_SEAMLESS
(no UI interaction), CN1Constants.SMS_INTERACTIVE
(with compose UI),
CN1Constants.SMS_BOTH
.
The sample below demonstrates the use case for this property:
public static void sendSMS(String phoneNumber, String message) throws IOException
phoneNumber
- to send the smsmessage
- the content of the smsIOException
public static void sendSMS(String phoneNumber, String message, boolean interactive) throws IOException
Sends a SMS message to the given phone number, the code below demonstrates the logic of detecting platform behavior for sending SMS.
phoneNumber
- to send the smsmessage
- the content of the smsinteractive
- indicates the SMS should show a UI or should not show a UI if applicable see getSMSSupportIOException
getSMSSupport()
public static void share(String text, String image, String mimeType)
Since 6.0, there is native sharing support in the Javascript port using the navigator.share API. Currently (2019) this is only supported on Chrome for Android, and will only work if the app is accessed over https:.
text
- String to share.image
- file path to the image or nullmimeType
- type of the image or null if no image to sharepublic static boolean isNativeShareSupported()
Since 6.0, there is native sharing support in the Javascript port using the navigator.share API. Currently (2019) this is only supported on Chrome for Android, and will only work if the app is accessed over https:.
public static void share(String text, String image, String mimeType, Rectangle sourceRect)
text
- String to share.image
- file path to the image or nullmimeType
- type of the image or null if no image to sharesourceRect
- The source rectangle of the button that originated the share request. This is used on
some platforms to provide a hint as to where the share dialog overlay should pop up. Particularly,
on the iPad with iOS 8 and higher.public static void registerPush()
public static void deregisterPush()
public static Thread createThread(Runnable r, String name)
r
- runnable to run, NOTICE the thread MUST be explicitly started!name
- the name for the threadpublic static Thread startThread(Runnable r, String name)
createThread(java.lang.Runnable, java.lang.String)
insteadr
- runnable to run, NOTICE the thread MUST be explicitly started!name
- the name for the threadpublic static boolean isScreenSaverDisableSupported()
public static void setScreenSaverEnabled(boolean e)
e
- when set to true the screen saver will work as usual and when set to false the screen
will not turn off automaticallypublic static boolean hasCamera()
public static boolean isNativePickerTypeSupported(int pickerType)
pickerType
- the picker type constantpublic static Object showNativePicker(int type, Component source, Object currentValue, Object data)
type
- the picker type constantsource
- the source component (optional) the native dialog will be placed in relation to this
component if applicablecurrentValue
- the currently selected valuedata
- additional meta data specific to the picker type when applicablepublic static void log(String s)
s
- the stringpublic static void log(Throwable s)
s
- the exceptionpublic static void sendLog()
public static void sendMessage(String subject, Message msg, String... recipients)
Send an email using the platform mail client.
The code below demonstrates sending a simple message with attachments using the devices
native email client:
subject
- e-mail subjectmsg
- the Message to sendrecipients
- array of e-mail addressespublic static boolean isSimulator()
public static void addDefaultHeader(String key, String value)
key
- the key of the headervalue
- the value of the headerpublic static void addToQueueAndWait(ConnectionRequest request)
request
- the request object to addpublic static void addToQueue(ConnectionRequest request)
request
- network request for executionpublic static void killAndWait(ConnectionRequest request)
request
- public static void addNetworkErrorListener(ActionListener<NetworkEvent> e)
e
- callback will be invoked with the Exception as the source objectpublic static void removeNetworkErrorListener(ActionListener<NetworkEvent> e)
e
- callback to removepublic static void addNetworkProgressListener(ActionListener<NetworkEvent> al)
al
- action listenerpublic static void removeNetworkProgressListener(ActionListener<NetworkEvent> al)
al
- action listenerpublic static void updateNetworkThreadCount(int threadCount)
threadCount
- the new number of threadspublic static void clearStorageCache()
public static void flushStorageCache()
public static void deleteStorageFile(String name)
name
- the name of the storage filepublic static void clearStorage()
public static OutputStream createStorageOutputStream(String name) throws IOException
name
- the storage file nameIOException
public static InputStream createStorageInputStream(String name) throws IOException
name
- the name of the source fileIOException
public static boolean existsInStorage(String name)
name
- the storage file namepublic static String[] listStorageEntries()
public static int storageEntrySize(String name)
name
- the name of the entrypublic static boolean writeObjectToStorage(String name, Object o)
Writes the given object to storage assuming it is an externalizable type or one of the supported types.
The sample below demonstrates the usage and registration of the Externalizable
interface:
name
- store nameo
- object to storepublic static Object readObjectFromStorage(String name)
Reads the object from the storage, returns null if the object isn't there
The sample below demonstrates the usage and registration of the Externalizable
interface:
name
- name of the storepublic static String[] getFileSystemRoots()
public static int getFileSystemRootType(String root)
root
- the root whose type we are checkingpublic static String[] listFiles(String directory) throws IOException
directory
- the directory in which files should be listedIOException
public static long getFileSystemRootSizeBytes(String root)
root
- the root directory in the filesystempublic static long getFileSystemRootAvailableSpace(String root)
root
- the root directory in the filesystempublic static void mkdir(String directory)
directory
- the directory name to createpublic static void delete(String file)
file
- file or empty directory to deletepublic static boolean existsInFileSystem(String file)
file
- the file to checkpublic static boolean isHiddenFile(String file)
file
- filepublic static void setHiddenFile(String file, boolean h)
file
- fileh
- hidden statepublic static void renameFile(String file, String newName)
file
- absolute file namenewName
- relative new namepublic static long getFileLength(String file)
file
- filepublic static long getFileLastModifiedFile(String file)
public static boolean isDirectory(String file)
file
- filepublic static OutputStream openFileOutputStream(String file) throws IOException
file
- the fileIOException
public static InputStream openFileInputStream(String file) throws IOException
file
- the fileIOException
public static OutputStream openFileOutputStream(String file, int offset) throws IOException
file
- the fileoffset
- position in the fileIOException
public static String getAppHomePath()
The application home directory is a "safe place" to store files for this application in a portable way.
On some platforms such as Android & iOS this path may be visible only to the
application itself, other apps won't have permission to access this path.
The sample below uses the app home directory to save a file so we can share it using the ShareButton
:
public static boolean hasCachesDir()
public static String getCachesDir()
hasCachesDir()
is falsepublic static boolean canInstallOnHomescreen()
Best practice is to use onCanInstallOnHomescreen(java.lang.Runnable)
to be notified
when you are allowed to prompt the user for installation. Then call promptInstallOnHomescreen()
inside that method - or sometime after.
onCanInstallOnHomescreen(()->{
if (canInstallOnHomescreen()) {
if (promptInstallOnHomescreen()) {
// User accepted installation
} else {
// user rejected installation
}
}
});
https://developers.google.com/web/fundamentals/app-install-banners/promptInstallOnHomescreen()
,
onCanInstallOnHomescreen(java.lang.Runnable)
public static boolean promptInstallOnHomescreen()
canInstallOnHomescreen()
,
onCanInstallOnHomescreen(java.lang.Runnable)
public static void onCanInstallOnHomescreen(Runnable r)
r
- Runnable that will be run when/if you are permitted to prompt the user to install
the app on their homescreen.public static Image captureScreen()
public static void addMessageListener(ActionListener<MessageEvent> l)
In the Javascript port, javascript can send messages to the CN1 app by calling
window.dispatchEvent(new CustomEvent('cn1inbox', {detail:'The message', code: SOMEINTEGER}));
l
- The listener.public static void removeMessageListener(ActionListener<MessageEvent> l)
l
- The listener.public static void postMessage(MessageEvent message)
In the Javascript port these messages can be received in Javascript by adding an event listener for 'cn1outbox' events to the 'window' object. The message is contained in the event data "detail" key. And the code in the 'code' key.
message
- The message to send to the native platform.public static Timer setTimeout(int timeout, Runnable r)
timeout
- The timeout in milliseconds.r
- The task to run.setInterval(int, java.lang.Runnable)
public static Timer setInterval(int timeout, Runnable r)
timeout
- The delay and repeat in milliseconds.r
- The runnable to run on the EDT.setTimeout(int, java.lang.Runnable)
public static BrowserComponent getSharedJavascriptContext()
BrowserComponent
API.
When running on other platforms, this shared context will be an off-screen browser component.
Sample code allowing user to execute arbitrary Javascript code inside the shared context:
public static PluginSupport getPluginSupport()