package jimm.ui; import java.util.*; import javax.microedition.lcdui.*; import DrawControls.*; import jimm.*; import jimm.cl.*; import jimm.ui.base.*; import jimm.ui.menu.*; public class SliderTask extends CanvasEx implements Runnable { /** *@author Rishat Shamsutdinov */ public static final int PERIOD = 7; //7 public static final int COUNT = 19; //9 private final static Timer sliderTimer = new Timer(); private TimerTask slider; private CanvasEx bgdScreen; private Image scrImg; private CanvasEx nextScreen; private int shiftX, shiftY, transY, transX; private int count = COUNT; private boolean stop; private int ftx, fty, x, y; public SliderTask(CanvasEx screen, CanvasEx bgdScreen, CanvasEx nextScreen, int tx, int ty, int dx, int dy, int x, int y) { try { scrImg = screen.paintOnImage(); } catch (OutOfMemoryError oome) { count = 0; } this.bgdScreen = bgdScreen; this.nextScreen = nextScreen; if (nextScreen instanceof Select && screen != nextScreen) { //ContactList //VirtualList-i dx += dx / COUNT; dy += dy / COUNT; } shiftX = -dx / COUNT; shiftY = -dy / COUNT; transX = tx; transY = ty; ftx = tx + dx; fty = ty + dy; this.x = x; this.y = y; } public SliderTask(CanvasEx screen, CanvasEx bgdScreen, CanvasEx nextScreen, int tx, int dx) { this(screen, bgdScreen, nextScreen, tx, 0, dx, 0, 0, 0); } public CanvasEx getNextScreen() { return nextScreen; } private synchronized void startSliding() { if (slider != null) { return; } slider = new TimerTask() { public void run() { Jimm.getDisplay().callSerially(SliderTask.this); } }; sliderTimer.schedule(slider, PERIOD, PERIOD); } private synchronized boolean check() { //System.out.println("TRS: "+transX+"; "+transY + " -> " + count); return (transX*(transX - shiftX) < 0 || transY*(transY - shiftY) < 0 || count-- <= 0); } public void run() { lock(); if (check()) { //transX = transY = 0; transX = ftx; transY = fty; stop = true; if (slider != null) { slider.cancel(); slider = null; } //screen = nextScreen; } else { transX -= shiftX; transY -= shiftY; } unlock(); //invalidate(); } private void switchScreen() { //if (nextScreen != bgdScreen && bgdScreen != null) { // bgdScreen.unlock(); //} //if (NativeCanvas.isActive(this) && this.equals(Jimm.getCurrentDisplay())) { Jimm.setDisplay(nextScreen); //} //System.out.println("===================="); nextScreen.unlock(); } public void beforShow() { startSliding(); } public void paint(GraphicsEx g) { //System.out.print("[Painting ...]"); if (bgdScreen != null) { paint(g); } if (scrImg != null) { g.drawImage(scrImg, x + transX, y + transY, Graphics.LEFT | Graphics. TOP); } if (stop) { stop = false; switchScreen(); } } protected void doKeyReaction(int keyCode, int actionCode, int type) { } }