/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  javax.microedition.lcdui.Alert
 *  javax.microedition.lcdui.AlertType
 *  javax.microedition.lcdui.Canvas
 *  javax.microedition.lcdui.Command
 *  javax.microedition.lcdui.CommandListener
 *  javax.microedition.lcdui.Display
 *  javax.microedition.lcdui.Displayable
 *  javax.microedition.lcdui.Graphics
 *  javax.microedition.midlet.MIDlet
 */
import java.util.Hashtable;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;

public final class hj
extends Canvas {
    private final MIDlet e;
    private static Hashtable h = new Hashtable();
    private static Hashtable i = new Hashtable();
    private gd c;
    private bq d;
    private pb f;
    private boolean g = true;
    public cq a = null;
    public cq b = null;

    public static cq a(Command command) {
        return (cq)i.get(command);
    }

    public final void b(cq cq2) {
        this.removeCommand(hj.c(cq2));
    }

    public final void a(cq cq2) {
        this.addCommand(hj.c(cq2));
    }

    public final void hideNotify() {
        this.c.p();
    }

    public final void showNotify() {
        this.c.o();
    }

    public final void a() {
        Display.getDisplay((MIDlet)this.e).setCurrent((Displayable)this);
    }

    public final void a(Runnable runnable) {
        Display.getDisplay((MIDlet)this.e).callSerially(runnable);
    }

    private void a(pb pb2) {
        this.c.b(pb2);
        System.currentTimeMillis();
    }

    public hj(MIDlet mIDlet) {
        this.e = mIDlet;
    }

    public final void keyRepeated(int n) {
        if (this.f == null || n != this.f.a) {
            this.f = this.a(n, true);
        }
        this.a(this.f);
    }

    public final void keyPressed(int n) {
        this.a(this.a(n, false));
    }

    public final void keyReleased(int n) {
        this.c.a(this.a(n, false));
    }

    public final void pointerPressed(int n, int n2) {
        this.c.a(this.d.a(0, n, n2));
    }

    public final void pointerReleased(int n, int n2) {
        this.c.a(this.d.a(1, n, n2));
    }

    public final void pointerDragged(int n, int n2) {
        this.c.a(this.d.a(2, n, n2));
    }

    public final void sizeChanged(int n, int n2) {
        if (this.c != null) {
            this.c.a(n, n2);
        }
    }

    private static Command c(cq cq2) {
        Command command = (Command)h.get(cq2);
        if (command == null) {
            command = new Command(cq2.g, cq2.h, cq2.i);
            h.put(cq2, command);
            i.put(command, cq2);
        }
        return command;
    }

    public final void paint(Graphics graphics) {
        if (this.g) {
            this.g = false;
            this.sizeChanged(this.getWidth(), this.getHeight());
        }
        this.c.a(new ht(graphics));
    }

    public final void a(gd gd2) {
        this.c = gd2;
        this.d = new bq();
        if (!lh.w) {
            this.setFullScreenMode(true);
        }
        if (lh.w) {
            this.setCommandListener(new br(gd2));
        }
    }

    /*
     * Enabled aggressive block sorting
     */
    private pb a(int n, boolean bl2) {
        int n2;
        int n3;
        block13: {
            block12: {
                n3 = lh.c(n);
                n2 = lh.k().b((Object)this, n3);
                if (n == -9999) break block12;
                if (lh.k().a((Object)this, n)) {
                    n2 = 7;
                    return new pb(n, n3, n2, bl2);
                }
                if (n == lh.h && !lh.w) {
                    n2 = 5;
                    return new pb(n, n3, n2, bl2);
                }
                if (n == lh.j && !lh.w) {
                    n2 = 6;
                    return new pb(n, n3, n2, bl2);
                }
                if (n == lh.g || n == lh.q) break block13;
                switch (n2) {
                    case 2: {
                        n2 = 3;
                        return new pb(n, n3, n2, bl2);
                    }
                    case 6: {
                        n2 = 2;
                        return new pb(n, n3, n2, bl2);
                    }
                    case 5: {
                        n2 = 4;
                        return new pb(n, n3, n2, bl2);
                    }
                    case 1: {
                        n2 = 1;
                        return new pb(n, n3, n2, bl2);
                    }
                }
            }
            n2 = 0;
            return new pb(n, n3, n2, bl2);
        }
        n2 = 8;
        return new pb(n, n3, n2, bl2);
    }

    public final void a(cq cq2, cq cq3) {
        if (lh.w) {
            if (cq2 == null && this.a != null) {
                this.b(this.a);
                this.a = null;
            } else if (cq2 != null && !cq2.equals(this.a)) {
                if (this.a != null) {
                    this.b(this.a);
                }
                this.a = cq2;
                this.a(this.a);
            }
            if (cq3 == null && this.b != null) {
                this.b(this.b);
                this.b = null;
                return;
            }
            if (cq3 != null && !cq3.equals(this.b)) {
                if (this.b != null) {
                    this.b(this.b);
                }
                this.b = cq3;
                this.a(this.b);
            }
        }
    }

    public final void a(String string, String string2, boolean bl2, cq[] cqArray, mt mt2) {
        if (!(Display.getDisplay((MIDlet)this.e).getCurrent() instanceof Alert)) {
            Alert alert = new Alert(string, string2, null, AlertType.ERROR);
            alert.setTimeout(-2);
            boolean bl3 = false;
            if (cqArray != null) {
                bl3 = true;
                for (int i = 0; i < cqArray.length; ++i) {
                    alert.addCommand(hj.c(cqArray[i]));
                }
            }
            if (bl2) {
                bl3 = true;
                alert.addCommand(hj.c(this.c.e));
            }
            if (bl3) {
                alert.setCommandListener((CommandListener)new br(mt2));
            }
            Display.getDisplay((MIDlet)this.e).setCurrent((Displayable)alert);
        }
    }
}

