de.enough.polish.ui
Class SnapshotScreen

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by de.enough.polish.ui.Canvas
              extended by de.enough.polish.ui.Screen
                  extended by de.enough.polish.ui.SnapshotScreen
All Implemented Interfaces:
Animatable, Displayable, UiElement
Direct Known Subclasses:
CameraScreen

public class SnapshotScreen
extends Screen

A convenience screen for taking snapshots. This screen requires support of the MMAPI by the current target device!

 //#if polish.api.mmapi
    import de.enough.polish.ui.SnapshotScreen;
 //#endif
 ...
 //#if polish.api.mmapi
    //#style snapshotScreen
    SnapshotScreen screen = new SnapshotScreen("Snapshot");
 //#endif
 

Copyright Enough Software 2006 - 2009

 history
        Sep 8, 2006 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
 
Fields inherited from class de.enough.polish.ui.Screen
background, backgroundHeight, backgroundWidth, backgroundX, backgroundY, border, container, contentBackground, contentBackgroundAnchor, contentBackgroundHeight, contentBackgroundWidth, contentBgBorder, contentBorder, contentHeight, contentWidth, contentX, contentY, cssSelector, enableScreenChangeAnimation, fullScreenHeight, ignoreRepaintRequests, infoHeight, isAnimated, isInitRequested, isRepaintRequested, isScrollBackground, itemStateListener, keyPressedProcessed, keyReleasedProcessed, landscapeStyle, lastAnimateTime, lastInteractionTime, lastTriggeredCommand, menuBarHeight, originalScreenHeight, paintScrollBarOnRightSide, portraitStyle, previousScreenOverlayBackground, repaintPreviousScreen, screenHeight, screenStateListener, screenWidth, scrollBar, scrollBarVisible, style, subTitleHeight, title, titleHeight, triggerReleasedKeyCode, triggerReleasedTime, userEventRepaintRegion
 
Fields inherited from class de.enough.polish.ui.Canvas
_commands, DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Constructor Summary
SnapshotScreen(String title)
          Creates a new screen for taking screenshots.
SnapshotScreen(String title, Style style)
          Creates a new screen for taking screenshots.
 
Method Summary
protected  String createCssSelector()
          Retrieves the CSS selector for this screen.
 Command getCaptureCommand()
          Retrieves the command that has been set previously with setCaptureCommand
 Player getPlayer()
          Retrieves the player used for taking the snapshot.
 byte[] getSnapshot()
          Takes a snapshot in the default encoding.
 byte[] getSnapshot(String encoding)
          Takes a snapshot in the desired encoding/settings.
 Image getSnapshotImage()
          Takes a snapshot in the default encoding.
 Image getSnapshotImage(String encoding)
          Takes a snapshot in the desired encoding/settings.
 boolean handleKeyReleased(int keyCode, int gameAction)
          Handles the key-released event.
 void hideNotify()
          Unregisters this screen and notifies all items that they will not be shown anymore.
 boolean isAutofocus()
          Checks if the autofocus mode is enabled.
 boolean isBusy()
          Determines whether this snapshot screen is currently busy and should not be interrupted.
 boolean isSnapshotInProgress()
          Determines whether a snapshot is currently made
protected  void paintScreen(Graphics g)
          Paints the screen.
 void setAutofocus(boolean autofocus)
          Enables or disables the autofocus mode.
 void setCaptureCommand(Command cmdCapture)
          Sets the command that is used for capturing.
 void setCaptureCommand(Command cmdCapture)
          Sets the command that is used for capturing.
 void showNotify()
          Initialises this screen and informs all items about being painted soon.
 void stopSnapshot()
          Stops the snapshot and closes the snapshot player.
 void stopSnapshot(boolean removeInstanceVariables)
          Stops the snapshot and closes the snapshot player.
 
Methods inherited from class de.enough.polish.ui.Screen
_keyPressed, _keyReleased, _keyRepeated, _pointerDragged, _pointerPressed, _pointerReleased, addCommand, addCommand, addCommand, addCommandSeparator, addCommandSeparator, addCommandsLayer, addPermanentNativeItem, addRelativeToContentRegion, addRepaintArea, addSubCommand, addSubCommand, adjustContentArea, animate, animate, calculateContentArea, callCommandListener, canScrollDown, canScrollUp, checkForRequestInit, clearItemCommands, closeMenu, commandAction, destroy, fireEvent, fireEventForTitleAndMenubar, focus, focus, focus, focus, focus, getAvailableHeight, getCommandItem, getCommandListener, getCommands, getCurrentIndex, getCurrentItem, getDefaultCommand, getItemAt, getKeyStates, getMenuBar, getNativeScreen, getPaintLock, getPolishTicker, getRootContainer, getRootItems, getScreenContentHeight, getScreenContentWidth, getScreenContentX, getScreenContentY, getScreenData, getScreenFullHeight, getScreenFullWidth, getScreenHeight, getScreenInitializerListener, getScreenStyle, getScrollBarWidth, getScrollDownBackgroundOffset, getScrollHeight, getScrollUpBackgroundOffset, getScrollYOffset, getStyle, getSubTitleItem, getTitle, getTitleHeight, getTitleItem, getUiEventListener, handleCommand, handleCommand, handleKeyPressed, handleKeyRepeated, handlePointerDragged, handlePointerDragged, handlePointerPressed, handlePointerReleased, handlePointerReleasedOutsideScreenArea, handlePointerTouchDown, handlePointerTouchUp, init, initContent, isActive, isGameActionFire, isInteracted, isKeyboardAccessible, isMenuOpened, isNativeUiShownFor, isSoftKey, isSoftKey, isSoftKeyLeft, isSoftKeyMiddle, isSoftKeyRight, notifyDefaultCommand, notifyFocusSet, notifyScreenStateChanged, notifyStateListener, paint, paintBackgroundAndBorder, paintMenuBar, paintScrollBar, paintTitleAndSubtitle, releaseResources, removeAllCommands, removeCommand, removeCommandsLayer, removeItemCommands, removePermanentNativeItem, removeSubCommand, requestInit, requestRepaint, requestRepaint, resetStyle, scrollRelative, scrollToBottom, setCommandListener, setCommandListener, setFullScreenMode, setInfo, setInfo, setItemCommands, setItemStateListener, setItemStateListener, setLastInteractionTime, setMenuBarStyle, setMenuItemStyle, setNativeScreen, setPolishTicker, setPolishTicker, setRootContainer, setScreenData, setScreenInitializerListener, setScreenOrientation, setScreenStateListener, setScrollYOffset, setStyle, setStyle, setSubTitle, setTitle, setTitle, setTitle, setTitle, setUiEventListener, sizeChanged, toString
 
Methods inherited from class de.enough.polish.ui.Canvas
_hideNotify, _hideNotifyExternal, _showNotify, getGameAction, getHeight, getKeyCode, getKeyName, getWidth, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotifyExternal, isDoubleBuffered, isShown, keyPressed, keyReleased, keyRepeated, pointerDragged, pointerPressed, pointerReleased, repaint, setTicker
 
Methods inherited from class javax.microedition.lcdui.Canvas
repaint, repaint, serviceRepaints
 
Methods inherited from class javax.microedition.lcdui.Displayable
getTicker, removeCommand, setTicker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SnapshotScreen

public SnapshotScreen(String title)
Creates a new screen for taking screenshots.

Parameters:
title - the title of the screen

SnapshotScreen

public SnapshotScreen(String title,
                      Style style)
Creates a new screen for taking screenshots.

Parameters:
title - the title of the screen
style - the style
Method Detail

isSnapshotInProgress

public boolean isSnapshotInProgress()
Determines whether a snapshot is currently made

Returns:
true when a this screen tries to create a snapshot at the moment.

hideNotify

public void hideNotify()
Description copied from class: Screen
Unregisters this screen and notifies all items that they will not be shown anymore.

Overrides:
hideNotify in class Screen

showNotify

public void showNotify()
Description copied from class: Screen
Initialises this screen and informs all items about being painted soon.

Overrides:
showNotify in class Screen

getSnapshotImage

public Image getSnapshotImage()
                       throws MediaException
Takes a snapshot in the default encoding.

Returns:
the image taken
Throws:
MediaException - when taking the snapshot fails
SecurityException - when the user does not allow the snapshot
See Also:
AsynchronousCommandListener, ThreadedCommandListener

getSnapshotImage

public Image getSnapshotImage(String encoding)
                       throws MediaException
Takes a snapshot in the desired encoding/settings. Attention: taking the snapshot is executed synchronously, so don't call this method within the device's event thread (commandAction, keyPressed, etc). You can safely call it from within commandAction if you use the AsysnchronousCommandListener.

Parameters:
encoding - the encoding and optionally size
Returns:
the image taken
Throws:
MediaException - when taking the snapshot fails
SecurityException - when the user does not allow the snapshot
See Also:
AsynchronousCommandListener, ThreadedCommandListener

getSnapshot

public byte[] getSnapshot()
                   throws MediaException
Takes a snapshot in the default encoding. Attention: taking the snapshot is executed synchronously, so don't call this method within the device's event thread (commandAction, keyPressed, etc). You can safely call it from within commandAction if you use the AsysnchronousCommandListener.

Returns:
the image data
Throws:
MediaException - when taking the snapshot fails
SecurityException - when the user does not allow the snapshot
See Also:
AsynchronousCommandListener, ThreadedCommandListener

getSnapshot

public byte[] getSnapshot(String encoding)
                   throws MediaException
Takes a snapshot in the desired encoding/settings. Attention: taking the snapshot is executed synchronously, so don't call this method within the device's event thread (commandAction, keyPressed, etc). You can safely call it from within commandAction if you use the AsysnchronousCommandListener.

Parameters:
encoding - the encoding and optionally size
Returns:
the image data
Throws:
MediaException - when taking the snapshot fails
SecurityException - when the user does not allow the snapshot
See Also:
AsynchronousCommandListener, ThreadedCommandListener

setAutofocus

public void setAutofocus(boolean autofocus)
Enables or disables the autofocus mode. Note that autofocusing is only supported for devices with the camera supplements of the Advanced Media API (JSR 234).

Parameters:
autofocus - true when the autofocus mode should be enabled

isAutofocus

public boolean isAutofocus()
Checks if the autofocus mode is enabled. Note that autofocusing is only supported for devices with the camera supplements of the Advanced Media API (JSR 234).

Returns:
true when the autofocus mode should be enabled and when JSR 234 is supported

paintScreen

protected void paintScreen(Graphics g)
Description copied from class: Screen
Paints the screen. This method also needs to set the protected variables paintScrollIndicator, paintScrollIndicatorUp and paintScrollIndicatorDown.

Overrides:
paintScreen in class Screen
Parameters:
g - the graphics on which the screen should be painted
See Also:
Screen.contentX, Screen.contentY, Screen.contentWidth, Screen.contentHeight, Screen.paintScrollIndicator, Screen.paintScrollIndicatorUp, Screen.paintScrollIndicatorDown

createCssSelector

protected String createCssSelector()
Description copied from class: Screen
Retrieves the CSS selector for this screen. The CSS selector is used for the dynamic assignment of styles - that is the styles are assigned by the usage of the screen and not by a predefined style-name. With the #style preprocessing command styles are set in a static way, this method yields in a faster GUI and is recommended. When in a style-sheet dynamic styles are used, e.g. "form>p", than the selector of the screen is needed. This abstract method needs only be implemented, when dynamic styles are used: #ifdef polish.useDynamicStyles

Specified by:
createCssSelector in class Screen
Returns:
the name of the appropriate CSS Selector for this screen.

stopSnapshot

public void stopSnapshot()
Stops the snapshot and closes the snapshot player.


stopSnapshot

public void stopSnapshot(boolean removeInstanceVariables)
Stops the snapshot and closes the snapshot player.

Parameters:
removeInstanceVariables - true when instance variables of VideoControl and player should be removed

getPlayer

public Player getPlayer()
Retrieves the player used for taking the snapshot.

Returns:
the player

handleKeyReleased

public boolean handleKeyReleased(int keyCode,
                                 int gameAction)
Description copied from class: Screen
Handles the key-released event. Please note, that implementation should first try to handle the given key-code, before the game-action is processed.

Overrides:
handleKeyReleased in class Screen
Parameters:
keyCode - the code of the released key, e.g. Canvas.KEY_NUM2
gameAction - the corresponding game-action, e.g. Canvas.UP
Returns:
true when the key-event was processed

getCaptureCommand

public Command getCaptureCommand()
Retrieves the command that has been set previously with setCaptureCommand

Returns:
the capture command, can be null

setCaptureCommand

public void setCaptureCommand(Command cmdCapture)
Sets the command that is used for capturing. This command is automatically added to this screen as well.

Parameters:
cmdCapture - the capture command to set, use null to remove it

setCaptureCommand

public void setCaptureCommand(Command cmdCapture)
Sets the command that is used for capturing. This command is automatically added to this screen as well.

Parameters:
cmdCapture - the capture command to set, use null to remove it

isBusy

public boolean isBusy()
Determines whether this snapshot screen is currently busy and should not be interrupted. This is case when it is currently taking a snapshot or when it is currently initializing.

Returns:
true when this screen is busy.