javax.microedition.lcdui.Display Java Examples

The following examples show how to use javax.microedition.lcdui.Display. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Player.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
public static void play(Clip clip, int repeat) {
	if (repeat < -1) {
		throw new IllegalArgumentException("Repeat must be -1 or greater");
	}
	if (clip.getPriority() < priority) {
		return;
	}
	if (player != null) {
		player.close();
	}
	if (repeat != -1) {
		repeat++;
	}
	player = clip.getPlayer();
	player.setLoopCount(repeat);
	Display.getDisplay(null).vibrate(clip.getVibration());
	try {
		player.start();
	} catch (MediaException e) {
		e.printStackTrace();
	}
}
 
Example #2
Source File: AudioCanvas.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Implemented CommandListener method.
 */
public void commandAction(Command cmd, Displayable d) {
    if (cmd == backCommand) {
        if (infoMode) {
            infoMode = false;
            addCommand(infoCommand);
            repaint();
        } else {
            Display.getDisplay(midlet).setCurrent(returnScreen);
            pool.closeAllPlayers();
        }
        
    } else if (cmd == infoCommand) {
        infoMode = true;
        removeCommand(infoCommand);
        repaint();
    }
}
 
Example #3
Source File: Cottage360.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
protected void startApp() throws MIDletStateChangeException
{
	DeviceControl.setLights( 0, 100 );
	Display disp = Display.getDisplay( this );
	try
	{
		iCanvas = new PanoramaCanvas( Image.createImage(PHOTO_NAME), this );
		disp.setCurrent( iCanvas );
		iConnection = openAccelerationSensor();
		if (iConnection != null)
			iConnection.setDataListener( this, BUFFER_SIZE );
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
}
 
Example #4
Source File: Screen.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
public Screen(Display display) {
    super();
    this.setFullScreenMode(true);
    this.parentDisplay = display;

    updateOrientation();

    try {
        // Create background image
        this.background = Image.createImage("midlets/blogwriter/images/Background.png");
    } catch (IOException e) {
        this.parentDisplay.setCurrent(
                new Alert("Cannot create graphics."), this);
    }
    VirtualKeyboard.setVisibilityListener(this);
}
 
Example #5
Source File: FileStressBench.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
public void startApp() {
    Display display = Display.getDisplay(this);
    BouncyColors bouncyColors = new BouncyColors();
    display.setCurrent(bouncyColors);

    for (int i = 0; i < 16; i++) {
        Thread thread = new Thread(new Worker(), "T" + i);
        thread.setPriority(Thread.MIN_PRIORITY);
        thread.start();
      }

    Thread current = Thread.currentThread();
    current.setPriority(Thread.MAX_PRIORITY);

    while (true) {
        bouncyColors.repaint();

        try {
            Thread.sleep(16);
        } catch (InterruptedException e) {}
    }
}
 
Example #6
Source File: SocketStressBench.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
void runBenchmark() {
  Display display = Display.getDisplay(this);
  BouncyColors bouncyColors = new BouncyColors();
  display.setCurrent(bouncyColors);

  for (int i = 0; i < 16; i++) {
    Thread thread = new Thread(new Worker(), "T" + i);
    thread.setPriority(Thread.MIN_PRIORITY);
    thread.start();
  }

  Thread current = Thread.currentThread();
  current.setPriority(Thread.MAX_PRIORITY);

  while (true) {
    bouncyColors.repaint();
    try {
      Thread.sleep(16);
    } catch (InterruptedException e) {}
  }
}
 
Example #7
Source File: CldcMIDletStateListener.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called after a MIDlet is successfully activated. This is after
 * the startApp method is called.
 *
 * @param suite reference to the loaded suite
 * @param midlet reference to the MIDlet
 */
public void midletActivated(MIDletSuite suite, MIDlet midlet) {
    String className = midlet.getClass().getName();

    /*
     * JAMS UE feature: If a MIDlet has not set a current displayable
     * in its display by the time it has returned from startApp,
     * display the headless alert. The headless alert has been
     * set as the initial displayable but for the display but the
     * foreground has not been requested, to avoid displaying the
     * alert for MIDlet that do set a current displayable.
     */
    if (!previouslyActive) {
        previouslyActive = true;

        if (Display.getDisplay(midlet).getCurrent() == null) {
            displayContainer.requestForegroundForDisplay(className);
        }
    }

    midletControllerEventProducer.sendMIDletActiveNotifyEvent(
        suite.getID(), className);
}
 
Example #8
Source File: TOTPMIDlet.java    From totp-me with Apache License 2.0 6 votes vote down vote up
/**
 * Loads configuration and initializes token-refreshing timer.
 * 
 * @see javax.microedition.midlet.MIDlet#startApp()
 */
public void startApp() {
	try {
		loadProfiles();
		reorderProfiles();
		if (listProfiles.getSelectedIndex() < 0)
			listProfiles.setSelectedIndex(0, true);
		if (listProfiles.size() > 1) {
			Display.getDisplay(this).setCurrent(listProfiles);
		} else {
			loadSelectedProfile();
		}
		timer.schedule(refreshTokenTask, 0L, 1000L);
	} catch (Exception e) {
		debugErr("TOTPMIDlet.startApp() - " + e.getMessage());
		error(e);
	}
}
 
Example #9
Source File: MicroLoader.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
public void init() {
	Display.initDisplay();
	Graphics3D.initGraphics3D();
	File cacheDir = ContextHolder.getCacheDir();
	// Some phones return null here
	if (cacheDir != null && cacheDir.exists()) {
		for (File temp : cacheDir.listFiles()) {
			temp.delete();
		}
	}
	StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
			.permitNetwork()
			.penaltyLog()
			.build();
	StrictMode.setThreadPolicy(policy);
	params.load(false);
}
 
Example #10
Source File: MidletThread.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
static void destroyApp() {
	new Thread(() -> {
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		Process.killProcess(Process.myPid());
	}, "ForceDestroyTimer").start();
	Displayable current = ContextHolder.getActivity().getCurrent();
	if (current instanceof Canvas) {
		Canvas canvas = (Canvas) current;
		int keyCode = Canvas.convertKeyCode(Canvas.KEY_END);
		Display.postEvent(CanvasEvent.getInstance(canvas, CanvasEvent.KEY_PRESSED, keyCode));
		Display.postEvent(CanvasEvent.getInstance(canvas, CanvasEvent.KEY_RELEASED, keyCode));
	}
	instance.handler.obtainMessage(DESTROY, 1).sendToTarget();
}
 
Example #11
Source File: DisplayEventHandlerFactory.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a reference to the singleton display manager object.
 *
 * @param token security token with the MIDP permission "allowed"
 *
 * @return display manager reference.
 */
public static DisplayEventHandler
        getDisplayEventHandler(SecurityToken token) {

    token.checkIfPermissionAllowed(Permissions.MIDP);

    if (managerImpl != null) {
        return managerImpl;
    }

    /**
     * The display manager implementation is a private class of Display
     * and is create in the class init of Display, we need to call a
     * static method of display to get the class init to run, because
     * some classes need to get the display manager to create a display
     */
    try {
        // this will yield a null pointer exception on purpose
        Display.getDisplay(null);
    } catch (NullPointerException npe) {
        // this is normal for this case, do nothing
    }

    return managerImpl;
}
 
Example #12
Source File: ListItem.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param display For retrieving colors.
 * @param text1 Text 1 (e.g. top row text)
 * @param text2 Text 2 (e.g. bottom row text)
 * @param icon Image to use for icon. 
 * @param itemType Item type.
 */
public ListItem(Display display, String text1, String text2,
		Image icon, int itemType, int width, int height) {        	 
	if (Log.TEST) Log.note("[ListItem#ListItem]-->");
	this.display = display;
    this.text1 = text1;
    this.text2 = text2;
    this.icon = icon;
    this.itemType = itemType;
    this.height = height;
    this.width = width;
}
 
Example #13
Source File: VideoSourceSelector.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public void commandAction(Command cmd, Displayable d) {
    if (cmd == cmdOK) {
        String url = tf.getString();
        commitSelection(url);
    } else {
        Display.getDisplay(midlet).setCurrent(VideoSourceSelector.this);
    }
}
 
Example #14
Source File: VideoSourceSelector.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes and set visible the video canvas with the selected video
 * source.
 * 
 * @param input
 *            String as video http url or file path.
 */
private void commitSelection(String url) {
    try {
        VideoCanvas canvas = new VideoCanvas(midlet, returnList, url);
        canvas.prepareToPlay();
        Display.getDisplay(midlet).setCurrent(canvas);
    } catch (Exception e) {
        midlet.alertError("Cannot open connection: " + e.getMessage());
    }
}
 
Example #15
Source File: VideoSourceSelector.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public void commandAction(Command cmd, Displayable d) {
    if (cmd == SELECT_COMMAND) {
        int selection = getSelectedIndex();
        if (selection == 0) { // URL source selected
            Display.getDisplay(midlet).setCurrent(urlForm);
        } else if (selection == 1) { // JAR source selected
            // File name returned by the MediaFactory refers to the
            // "Video-Clip" application property...
            String videoFile = MediaFactory.getDefaultVideo().getFile();
            commitSelection(videoFile);
        }
    } else if (cmd == backCommand) {
        Display.getDisplay(midlet).setCurrent(returnList);
    }
}
 
Example #16
Source File: DestroyMIDlet.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public void startApp() {
    TestCanvas test = new TestCanvas();
    test.setFullScreenMode(true);
    Display.getDisplay(this).setCurrent(test);

    System.out.println("startApp" + (++started));

    maybePrintDone();
}
 
Example #17
Source File: BlogWriter.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public BlogWriter() {
    this.display = Display.getDisplay(this);
    // Crate login screen
    this.loginScreen = new LoginScreen(this.display);
    this.loginScreen.setParent(this);
    // Activate login screen
    this.display.setCurrent(this.loginScreen);
}
 
Example #18
Source File: ArtistItem.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param data The artist data of this item.
 * @param imageProvider Image provider for retrieving possible image.
 */
public ArtistItem(Display display, ArtistData data, ImageProvider imageProvider,
		int width){
	super(display, null, null, null, ListItem.TYPE_ONE_ROW | ListItem.TYPE_ICON_LEFT,
			width,
			ListItem.ICON_MAX_H + 2 * V_PAD);
	if (Log.TEST) Log.note("[ArtistItem#ArtistItem]-->");
	this.data = data;
	setText1(data.getName());
	setIcon(imageProvider.getImage(data.getImageFilename()));
}
 
Example #19
Source File: FavouriteItem.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param data The favourite data of this item.
 * @param imageProvider Image provider for retrieving possible image.
 */
public FavouriteItem(Display display, FavouriteData data, ImageProvider imageProvider,
		int width){
	super(display, null, null, null, ListItem.TYPE_TWO_ROW | ListItem.TYPE_ICON_LEFT,
			width,
			ListItem.ICON_MAX_H + 2 * V_PAD);
	if (Log.TEST) Log.note("[FavouriteItem#FavouriteItem]-->");
	this.data = data;
	setText1(data.getName());
	setText2(data.getSignificantSongs()[0]);
	setIcon(imageProvider.getImage(data.getImageFilename()));
	if(starImg == null){
		starImg = imageProvider.getImage(STAR_IMG_FILE);
	}
}
 
Example #20
Source File: ListItem.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws the item.
 * 
 * @param g Graphics context.
 * @param yOffset Y-offset to draw from.
 */
public void paint(Graphics g, final int yOffset) {
	if (Log.TEST) Log.note("[ListItem#paint]-->");
    int y = yOffset;
    if (Log.TEST) Log.note("[ListItem#paint] y: " + y);

    // First draw the underlying rect, and get color for text drawing
    if (selected) {
        g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_BACKGROUND));
        g.fillRect(0, y, width, height);
        g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_FOREGROUND));
    } else {
        g.setColor(display.getColor(Display.COLOR_FOREGROUND));
    }
    
    y += V_PAD;
    int x = H_PAD;
    
    int[] contentsRect = {x, y, width - 2 * H_PAD, height - 2 * V_PAD};

    drawContents(g, contentsRect );

    // Get border color
    if (selected) {
        g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_BORDER));
    } else {
       // g.setColor(display.getColor(Display.COLOR_BORDER));
        g.setColor(~display.getColor(Display.COLOR_BACKGROUND));
    }
    
    // Draw border
    g.drawLine(0, yOffset + height, width, yOffset + height);
    
    if (Log.TEST) Log.note("[ListItem#paint]<--");
}
 
Example #21
Source File: GridItem.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
   * Draws the item.
   * 
   * @param g Graphics context.
   * @param viewX Top-left x-coordinate of the current view area (grid coordinates, not screen) 
   * @param viewY Top-left y-coordinate of the current view area (grid coordinates, not screen)
   */
  public void paint(Graphics g, int viewX, int viewY){
if (Log.TEST) Log.note("[GridItem#paint]-->");
  	// Calculate actual drawing coordinates from the view coordinates
int translatedX = x - viewX;
  	int translatedY = y - viewY;
  	
      // First draw the underlying rectangle, and get color for text drawing
      if (selected) {
          g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_BACKGROUND));
          // Draw highlighted background
          g.fillRect(translatedX, translatedY, width, height);
          g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_BORDER));
          // Draw border
          g.drawRect(translatedX, translatedY, width, height);
          // Set color for text drawing
          g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_FOREGROUND));
      } else {
      	//g.setColor(display.getColor(Display.COLOR_BORDER));
      	//g.setColor(display.getColor(Display.COLOR_HIGHLIGHTED_FOREGROUND));
              g.setColor(~display.getColor(Display.COLOR_BACKGROUND));

      	// Draw border
      	g.drawRect(translatedX, translatedY, width, height);
      	// Set color for text drawing
          g.setColor(display.getColor(Display.COLOR_FOREGROUND));
      }
      
      drawContents(g, translatedX + V_PAD, translatedY + H_PAD,
      		width - 2 * H_PAD, height - 2 * V_PAD);
      }
 
Example #22
Source File: GridItem.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param display Needed for color retrieval.
 * @param imageProvider Needed for image retrieval.
 */
public GridItem(Display display, ImageProvider imageProvider){
	this.display = display;
	if(starImg == null){
		starImg = imageProvider.getImage(STAR_IMG_FILE);
	}
   }
 
Example #23
Source File: Main.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public void startApp() {
    if (display != null) {
        return;
    }

    self = this;
    display = Display.getDisplay(this);

    showLinksView(session.getCategory());
}
 
Example #24
Source File: AudioRecorder.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
protected void startApp() throws MIDletStateChangeException {
	this.recordButton = new StringItem(null, "Start", Item.BUTTON);
	Command toggleRecordingCMD = new Command("Click", Command.ITEM, 1);
	this.recordButton.addCommand(toggleRecordingCMD);
	this.recordButton.setDefaultCommand(toggleRecordingCMD);
	this.recordButton.setItemCommandListener(this);

	this.form = new Form(null, new Item[] {
			new StringItem(null, "Audio Recorder"), this.recordButton });

	this.display = Display.getDisplay(this);
	this.display.setCurrent(this.form);
}
 
Example #25
Source File: TestHarness.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
public TestHarness(Display d) {
    display = d;
}
 
Example #26
Source File: GAFAMidlet.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
/** Creates the midlet and initiates the display. */
public GAFAMidlet() {
	display = Display.getDisplay(this);
}
 
Example #27
Source File: GAFAView.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
public GAFAView(CommandListener commandListener, Display display) {
	setTitle("GAFA APIs");
	myRectPosX = myGestureZonePosX = 5;
	myRectPosY = myGestureZonePosY = 5;
	myRectWidth = (short) (myGestureZoneWidth = 32);
	myRectHeight = (short) (myGestureZoneHeight = 32);
	mySquares = new Vector(10, 4);

	// Add commands
	exitCommand = new Command("Exit", Command.EXIT, 1);
	addCommand(exitCommand);
	setCommandListener(commandListener);

	// Create the first GestureInteractiveZone. The GestureInteractiveZone
	// class is used to define an
	// area of the screen that reacts to a set of specified gestures.
	// The parameter GESTURE_ALL means that we want events for all gestures.
	gizCanvas = new GestureInteractiveZone(
			GestureInteractiveZone.GESTURE_ALL);
	// Create the second interactive zone handling the DRAG gestures on the
	// rectangle area
	gizRectangle = new GestureInteractiveZone(
			GestureInteractiveZone.GESTURE_DRAG);
	gizRectangle.setRectangle(myRectPosX, myRectPosY, myRectWidth,
			myRectHeight);

	// Register the GestureInteractiveZones for myCanvas.
	if (GestureRegistrationManager.register(this, gizCanvas))
		System.out.println("Gestures for canvas added");
	if (GestureRegistrationManager.register(this, gizRectangle))
		System.out.println("Gestures for rect added");

	// Set this listener to a canvas or custom item
	GestureRegistrationManager.setListener(this, this);

	/*
	 * // Get system properties for fps and pps defaultFps = (short)
	 * Integer.parseInt(System
	 * .getProperty("com.nokia.mid.ui.frameanimator.fps")); defaultPps =
	 * (short) Integer.parseInt(System
	 * .getProperty("com.nokia.mid.ui.frameanimator.pps"));
	 */
	// Use default values
	maxFps = 0;
	maxPps = 0;

	// Create the frame animator for the rectangle
	rectAnimator = new FrameAnimator();
	// Initialize the frame animator
	rectAnimator.register(myRectPosX, myRectPosY, maxFps, maxPps,
			(FrameAnimatorListener) this);

	// Initialize the drag & drop counter used to store missing frame
	// increments
	dragCounterX = 0;
	dragCounterY = 0;
}
 
Example #28
Source File: BaseFormView.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
protected static void setDisplay(Displayable display) {
    Display.getDisplay(Main.getInstance()).setCurrent(display);
}
 
Example #29
Source File: BaseFormView.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
protected static void setItem(Item item) {
    Display.getDisplay(Main.getInstance()).setCurrentItem(item);
}
 
Example #30
Source File: GAFAControl.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
/** Separate initialization function for convenience. */
public void initialize() {
	display = Display.getDisplay(mainApp);
	myCanvas = new GAFAView(this, display);
	display.setCurrent(myCanvas);
}