/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  android.app.AlertDialog
 *  android.app.AlertDialog$Builder
 *  android.app.ProgressDialog
 *  android.content.Context
 *  android.content.DialogInterface
 *  android.content.DialogInterface$OnClickListener
 *  android.content.SharedPreferences
 *  android.graphics.Bitmap
 *  android.graphics.Canvas
 *  android.graphics.Matrix
 *  android.graphics.Paint
 *  android.graphics.Paint$Cap
 *  android.graphics.Paint$Style
 *  android.graphics.Path
 *  android.os.Bundle
 *  android.os.Handler
 *  android.os.Message
 *  android.text.Editable
 *  android.util.Log
 *  android.view.MotionEvent
 *  android.view.SurfaceHolder
 *  android.view.SurfaceHolder$Callback
 *  android.view.SurfaceView
 *  android.widget.EditText
 *  android.widget.Toast
 *  java.lang.CharSequence
 *  java.lang.Object
 *  java.lang.Runnable
 *  java.lang.String
 *  java.lang.System
 *  java.lang.Thread
 *  java.util.ArrayList
 *  java.util.List
 */
package com.xinli.portalclient;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.EditText;
import android.widget.Toast;
import com.xinli.portalclient.MainActivity;
import com.xinli.portalclient.model.TouchPoint;
import java.util.ArrayList;
import java.util.List;

public class MySurfaceView
extends SurfaceView
implements SurfaceHolder.Callback,
Runnable {
    private static final int MAX_TOUCHPOINTS = 10;
    protected static final String TAG = "Client";
    public static final int TIME_IN_FRAME = 50;
    Canvas bakmCanvas;
    Bitmap bitmap;
    private int[] colors;
    private String keyvalue;
    final List<TouchPoint> list1;
    final List<TouchPoint> list2;
    Canvas mCanvas;
    private ProgressDialog mDialog;
    boolean mIsRunning;
    Paint mPaint;
    private Path[] mPath;
    boolean mRunning;
    SurfaceHolder mSurfaceHolder;
    private Handler mainHandler;
    MySurfaceView me;
    private float[] mposX;
    private float[] mposY;
    private boolean rememberPasswd;
    final List<ArrayList<TouchPoint>> resultList;
    private String sessionId;
    private SharedPreferences sp;
    private Paint[] touchPaints;

    public MySurfaceView(Context context) {
        super(context);
        this.mPaint = null;
        this.touchPaints = new Paint[10];
        this.colors = new int[10];
        this.mPath = new Path[10];
        this.mposX = new float[10];
        this.mposY = new float[10];
        this.mSurfaceHolder = null;
        this.mRunning = false;
        this.mCanvas = null;
        this.bakmCanvas = null;
        this.mIsRunning = false;
        this.list1 = new ArrayList();
        this.list2 = new ArrayList();
        this.resultList = new ArrayList();
        this.me = this;
    }

    public MySurfaceView(Context context, Bitmap bitmap, SharedPreferences sharedPreferences, Handler handler) {
        super(context);
        this.mPaint = null;
        this.touchPaints = new Paint[10];
        this.colors = new int[10];
        this.mPath = new Path[10];
        this.mposX = new float[10];
        this.mposY = new float[10];
        this.mSurfaceHolder = null;
        this.mRunning = false;
        this.mCanvas = null;
        this.bakmCanvas = null;
        this.mIsRunning = false;
        this.list1 = new ArrayList();
        this.list2 = new ArrayList();
        this.resultList = new ArrayList();
        this.me = this;
        this.setFocusable(true);
        this.setFocusableInTouchMode(true);
        this.mSurfaceHolder = this.getHolder();
        this.mSurfaceHolder.addCallback((SurfaceHolder.Callback)this);
        this.mCanvas = new Canvas();
        this.mPaint = new Paint();
        this.mPaint.setColor(-16777216);
        this.bitmap = bitmap;
        super.init();
        this.sp = sharedPreferences;
        this.mainHandler = handler;
    }

    private void drawBackground() {
        this.mCanvas = this.mSurfaceHolder.lockCanvas();
        Matrix matrix = new Matrix();
        Log.w((String)"\u6e05\u7a7a\u753b\u5e03=====drawBackground===", (String)(String.valueOf((int)this.getWidth()) + "\u00d7" + this.getHeight()));
        float f = (float)this.getWidth() / (float)this.bitmap.getWidth();
        float f2 = (float)this.getHeight() / (float)this.bitmap.getHeight();
        Log.w((String)"\u6e05\u7a7a\u753b\u5e03===drawBackground===client==", (String)(String.valueOf((int)this.getWidth()) + "\u00d7" + this.getHeight()));
        matrix.setScale(f, f2);
        matrix.postTranslate(0.0f, 0.0f);
        this.mCanvas.drawBitmap(this.bitmap, matrix, this.mPaint);
        this.mSurfaceHolder.unlockCanvasAndPost(this.mCanvas);
    }

    private void init() {
        this.colors[0] = -256;
        this.colors[1] = -256;
        this.colors[2] = -16711936;
        this.colors[3] = -256;
        this.colors[4] = -16711681;
        this.colors[5] = -65281;
        this.colors[6] = -12303292;
        this.colors[7] = -1;
        this.colors[8] = -3355444;
        this.colors[9] = -7829368;
        int n = 0;
        while (n < 10) {
            this.touchPaints[n] = new Paint();
            this.touchPaints[n].setColor(this.colors[n]);
            this.touchPaints[n].setAntiAlias(true);
            this.touchPaints[n].setStyle(Paint.Style.STROKE);
            this.touchPaints[n].setStrokeCap(Paint.Cap.ROUND);
            this.touchPaints[n].setStrokeWidth(25.0f);
            this.touchPaints[n].setDither(true);
            this.touchPaints[n].setShadowLayer(5.0f, 8.0f, 8.0f, this.colors[n]);
            this.mPath[n] = new Path();
            ++n;
        }
        return;
    }

    public String getKeyvalue() {
        return this.keyvalue;
    }

    public String getSessionId() {
        return this.sessionId;
    }

    /*
     * Unable to fully structure code
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public boolean onTouchEvent(MotionEvent var1) {
        var2_2 = ((MainActivity)this.getContext()).username.getText().toString();
        var3_3 = this.sp.getString(var2_2, "");
        this.rememberPasswd = false;
        Log.v((String)"Client", (String)var2_2);
        Log.v((String)"Client", (String)var3_3);
        if ("".equals((Object)var2_2) || var2_2 == null || "".equals((Object)var3_3) || var3_3 == null) {
            Toast.makeText((Context)this.getContext(), (CharSequence)"\u8bf7\u5148\u9009\u62e9\u5e10\u53f7", (int)10).show();
            return false;
        }
        var6_4 = var1.getPointerCount();
        switch (255 & var1.getAction()) lbl-1000: // 4 sources:
        {
            do {
                default: lbl-1000: // 3 sources:
                {
                    do {
                        Log.w((String)"\u4e00\u6b21\u7ed8\u5236\u7ed3\u675f", (String)"\u4e00\u6b21\u7ed8\u5236\u7ed3\u675f");
                        return true;
                        break;
                    } while (true);
                }
                break;
            } while (true);
            case 0: {
                Log.v((String)"Client", (String)"\u7b2c\u4e00\u4e2a\u70b9\u6309\u4e0b\u89e6\u6478\u5c4f");
                var44_5 = 0;
                do {
                    if (var44_5 < var6_4) ** GOTO lbl25
                    this.mPath[var1.getPointerId(-1 + var1.getPointerCount())].moveTo(var1.getX(), var1.getY());
                    this.mposX[var1.getPointerId((int)(-1 + var1.getPointerCount()))] = var1.getX();
                    this.mposY[var1.getPointerId((int)(-1 + var1.getPointerCount()))] = var1.getY();
                    ** GOTO lbl-1000
lbl25: // 1 sources:
                    var45_6 = (int)var1.getX(var44_5);
                    var46_7 = (int)var1.getY(var44_5);
                    Log.v((String)"Client", (String)("point(" + (var44_5 + 1) + ") action_down:(" + var45_6 + "," + var46_7 + ")"));
                    ++var44_5;
                } while (true);
            }
            case 5: {
                Log.v((String)"Client", (String)("\u67091\u4e2a\u70b9\u6309\u4e0b\u89e6\u6478\u5c4f.count:" + var1.getPointerCount() + "," + var1.getPointerId(-1 + var1.getPointerCount())));
                this.mPath[var1.getPointerId(-1 + var1.getPointerCount())].moveTo(var1.getX(var1.getPointerId(-1 + var1.getPointerCount())), var1.getY(var1.getPointerId(-1 + var1.getPointerCount())));
                this.mposX[var1.getPointerId((int)(-1 + var1.getPointerCount()))] = var1.getX(var1.getPointerId(-1 + var1.getPointerCount()));
                this.mposY[var1.getPointerId((int)(-1 + var1.getPointerCount()))] = var1.getY(var1.getPointerId(-1 + var1.getPointerCount()));
                ** GOTO lbl-1000
            }
            case 2: {
                Log.v((String)"Client", (String)("\u6709" + var6_4 + "\u4e2a\u70b9\u540c\u65f6\u79fb\u52a8"));
                var27_8 = 0;
                block10 : do {
                    if (var27_8 < var6_4) ** GOTO lbl49
                    var41_14 = 0;
                    do {
                        if (var41_14 >= var6_4) ** GOTO lbl-1000
                        this.mPath[var1.getPointerId(var41_14)].quadTo(this.mposX[var1.getPointerId(var41_14)], this.mposY[var1.getPointerId(var41_14)], var1.getX(var41_14), var1.getY(var41_14));
                        this.mposX[var1.getPointerId((int)var41_14)] = var1.getX(var41_14);
                        this.mposY[var1.getPointerId((int)var41_14)] = var1.getY(var41_14);
                        ++var41_14;
                    } while (true);
lbl49: // 1 sources:
                    var28_11 = (int)var1.getX(var27_8);
                    var29_9 = (int)var1.getY(var27_8);
                    var30_10 = new TouchPoint();
                    var30_10.setX(var28_11);
                    var30_10.setY(var29_9);
                    var30_10.setEventTime(var1.getEventTime());
                    new TouchPoint();
                    if (var27_8 != 0) ** GOTO lbl68
                    if (this.list1.size() == 0) break;
                    var38_12 = (TouchPoint)this.list1.get(-1 + this.list1.size());
                    if ((var30_10.getX() - var38_12.getX()) * (var30_10.getX() - var38_12.getX()) + (var30_10.getY() - var38_12.getY()) * (var30_10.getY() - var38_12.getY()) > 16) {
                        this.list1.add((Object)var30_10);
                        Log.v((String)"Client", (String)"------------\u79fb\u52a8\u8ddd\u79bb\u8d85\u8fc7\u9884\u8bbe\u8ddd\u79bb\uff0c\u52a0\u5165list1");
                    }
lbl62: // 7 sources:
                    do {
                        Log.v((String)"Client", (String)("point(" + (var27_8 + 1) + ") ACTION_MOVE:(" + var28_11 + "," + var29_9 + ")," + var1.getPointerId(var27_8)));
                        ++var27_8;
                        continue block10;
                        break;
                    } while (true);
                    break;
                } while (true);
                this.list1.add((Object)var30_10);
                ** GOTO lbl62
lbl68: // 1 sources:
                if (var27_8 != 1) ** GOTO lbl62
                if (this.list2.size() == 0) ** GOTO lbl75
                var34_13 = (TouchPoint)this.list2.get(-1 + this.list2.size());
                if ((var30_10.getX() - var34_13.getX()) * (var30_10.getX() - var34_13.getX()) + (var30_10.getY() - var34_13.getY()) * (var30_10.getY() - var34_13.getY()) > 16) {
                    this.list2.add((Object)var30_10);
                    Log.v((String)"Client", (String)"------------\u79fb\u52a8\u8ddd\u79bb\u8d85\u8fc7\u9884\u8bbe\u8ddd\u79bb\uff0c\u52a0\u5165list2");
                }
                ** GOTO lbl62
lbl75: // 1 sources:
                this.list2.add((Object)var30_10);
                ** continue;
            }
            case 6: {
                Log.v((String)"Client", (String)"\u67091\u4e2a\u70b9\u79bb\u5f00\u89e6\u6478\u5c4f");
                ** continue;
            }
            case 1: 
        }
        Log.v((String)"Client", (String)"\u6700\u540e\u4e00\u4e2a\u70b9\u79bb\u5f00\u89e6\u6478\u5c4f");
        var8_15 = 0;
        do {
            if (var8_15 >= var6_4) {
                Log.w((String)"\u753b\u56fe\u5b8c\u6bd5===", (String)(String.valueOf((int)this.getWidth()) + "\u00d7" + this.getHeight()));
                var13_18 = this.mainHandler.obtainMessage();
                if (this.list1.size() != 0 || this.list2.size() != 0) break;
                this.me.setFocusableInTouchMode(false);
                var20_19 = new AlertDialog.Builder(this.getContext());
                var20_19.setTitle((CharSequence)"\u6d88\u606f\u63d0\u793a");
                var20_19.setMessage((CharSequence)"\u89e6\u5c4f\u4e0d\u5408\u6cd5\uff01");
                var23_20 = new DialogInterface.OnClickListener(){

                    public void onClick(DialogInterface dialogInterface, int n) {
                        MySurfaceView.this.me.setFocusableInTouchMode(true);
                        dialogInterface.dismiss();
                    }
                };
                var20_19.setPositiveButton((CharSequence)"\u786e\u5b9a", var23_20);
                var20_19.create().show();
lbl95: // 2 sources:
                do {
                    var18_22 = 0;
                    do {
                        if (var18_22 >= 10) ** continue;
                        this.mPath[var18_22].reset();
                        ++var18_22;
                    } while (true);
                    break;
                } while (true);
            }
            var9_16 = (int)var1.getX(var8_15);
            var10_17 = (int)var1.getY(var8_15);
            Log.v((String)"Client", (String)("point(" + (var8_15 + 1) + ") ACTION_UP:(" + var9_16 + "," + var10_17 + ")"));
            ++var8_15;
        } while (true);
        Log.w((String)"\u753b\u56fe\u5b8c\u6bd5=2==", (String)(String.valueOf((int)this.getWidth()) + "\u00d7" + this.getHeight()));
        var13_18.what = 0;
        var15_21 = new Bundle();
        var15_21.putParcelableArrayList("list1", (ArrayList)this.list1);
        var15_21.putParcelableArrayList("list2", (ArrayList)this.list2);
        var15_21.putInt("picwidth", this.getWidth());
        var15_21.putInt("picheight", this.getHeight());
        Log.w((String)"\u753b\u56fe\u5b8c\u6bd5=3==", (String)(String.valueOf((int)this.getWidth()) + "\u00d7" + this.getHeight()));
        var13_18.setData(var15_21);
        this.mainHandler.sendMessage(var13_18);
        ** while (true)
    }

    /*
     * Unable to fully structure code
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     * Converted monitor instructions to comments
     * Lifted jumps to return sites
     */
    public void run() {
        block4 : do {
            if (!this.mIsRunning) {
                return;
            }
            var1_2 = System.currentTimeMillis();
            var9_4 = var3_6 = this.mSurfaceHolder;
            // MONITORENTER : var9_4
            this.mCanvas = this.mSurfaceHolder.lockCanvas();
            var5_5 = new Matrix();
            var5_5.setScale((float)this.getWidth() / (float)this.bitmap.getWidth(), (float)this.getHeight() / (float)this.bitmap.getHeight());
            var5_5.postTranslate(0.0f, 0.0f);
            if (this.mCanvas == null) ** GOTO lbl17
            this.mCanvas.drawBitmap(this.bitmap, var5_5, this.mPaint);
            var8_1 = 0;
            do {
                if (var8_1 >= 2) {
                    this.mSurfaceHolder.unlockCanvasAndPost(this.mCanvas);
lbl17: // 2 sources:
                    // MONITOREXIT : var9_4
                    var7_3 = (int)(System.currentTimeMillis() - var1_2);
                    do {
                        if (var7_3 > 50) continue block4;
                        var7_3 = (int)(System.currentTimeMillis() - var1_2);
                        Thread.yield();
                    } while (true);
                }
                this.mCanvas.drawPath(this.mPath[var8_1], this.touchPaints[var8_1]);
                ++var8_1;
            } while (true);
            break;
        } while (true);
    }

    public void setKeyvalue(String string2) {
        this.keyvalue = string2;
    }

    public void setSessionId(String string2) {
        this.sessionId = string2;
    }

    public void surfaceChanged(SurfaceHolder surfaceHolder, int n, int n2, int n3) {
        super.drawBackground();
    }

    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        super.drawBackground();
        this.mIsRunning = true;
        new Thread((Runnable)this).start();
    }

    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
        this.mIsRunning = false;
    }

}

