Java源码示例:javax.microedition.lcdui.Display

示例1
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();
	}
}
 
示例2
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);
}
 
示例3
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();
}
 
示例4
/**
 * 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;
}
 
示例5
/**
 * 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);
}
 
示例6
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) {}
  }
}
 
示例7
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) {}
    }
}
 
示例8
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);
}
 
示例9
/**
 * 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();
    }
}
 
示例10
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();
	}
}
 
示例11
/**
 * 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);
	}
}
 
示例12
/**
 * 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);
	}
   }
 
示例13
/**
   * 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);
      }
 
示例14
/**
 * 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;
}
 
示例15
/**
 * 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]<--");
}
 
示例16
/**
 * 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);
	}
}
 
示例17
/**
 * 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()));
}
 
示例18
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);
}
 
示例19
public void startApp() {
    TestCanvas test = new TestCanvas();
    test.setFullScreenMode(true);
    Display.getDisplay(this).setCurrent(test);

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

    maybePrintDone();
}
 
示例20
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);
    }
}
 
示例21
/**
 * 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());
    }
}
 
示例22
public void commandAction(Command cmd, Displayable d) {
    if (cmd == cmdOK) {
        String url = tf.getString();
        commitSelection(url);
    } else {
        Display.getDisplay(midlet).setCurrent(VideoSourceSelector.this);
    }
}
 
示例23
public void startApp() {
    if (display != null) {
        return;
    }

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

    showLinksView(session.getCategory());
}
 
示例24
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);
}
 
示例25
public void blitToScreen(int x, int y) {
	bufferGraphics.setColorAlpha(0);
	bufferGraphics.fillRect(0, 0, width, height);
	bufferGraphics.drawImage(image, x, y, 0);
	((Canvas) Display.getDisplay(null).getCurrent()).flushBuffer(buffer);
}
 
示例26
protected MIDlet() {
	Display.getDisplay(this); // init display for this instance
}
 
示例27
public static boolean isDisplayActive(Display display) {
    System.out.println("LCDUIUtils::isDisplayActive(Display) not implemented");
    return true;
}
 
示例28
public static void setDisplayStateListener(Display display, DisplayStateListener listener) {
    System.out.println("LCDUIUtils::setDisplayStateListener(Dispay,DisplayStateListener) not implemented");
}
 
示例29
public static void setCurrent(Display display, Displayable displayable, String str) {
    System.out.println("LCDUIUtil::setCurrent no implemente.");
}
 
示例30
EditScreen(Display display) {
    super(display);

    this.titleTextBox = new CanvasTextBox(this, "Title", TextField.ANY,
            this.maximumTextLength);
    this.titleTextBox.setTextEditorListener(this);
    if (!BlogWriter.isFullTouch() && !BlogWriter.isAshaPlatform()) {
        this.titleTextBox.setFocused(true);
    }
    this.contentTextBox = new CanvasTextBox(this, "Post", TextField.ANY,
            this.maximumTextLength, true);
    this.contentTextBox.setTextEditorListener(this);

    try {
        this.exitButton = new Button(this, "Exit", new Runnable() {

            public void run() {
                // When Exit is tapped, close the application
                removeItems();
                Display.getDisplay(parent).setCurrent(null);
                parent.notifyDestroyed();
            }
        });

        this.publishButton = new Button(this, "Publish", new Runnable() {

            public void run() {
                // Show alert when the Publish button is tapped
                parentDisplay.setCurrent(new Alert("Publish",
                        "Post published successfully.", null,
                        AlertType.INFO));
            }
        });
        this.publishButton.setEnabled(false);
    } catch (Exception ex) {
        this.parentDisplay.setCurrent(new Alert("Cannot create controls."),
                this);
    }

    // Set default position of items and buttons
    this.layoutControls();

    this.titleTextBox.setVisible(true);
    this.contentTextBox.setVisible(true);
}