Search in sources :

Example 1 with Point

use of com.example.verificationcodejavademo.model.Point in project captcha by anji-plus.

the class BlockPuzzleDialog method checkCaptcha.

private void checkCaptcha(double sliderXMoved) {
    Point point = new Point();
    point.setY(5.0);
    point.setX(sliderXMoved);
    String pointStr = new Gson().toJson(point);
    Map<String, Object> params = new HashMap<>();
    params.put("captchaType", "blockPuzzle");
    params.put("token", token);
    params.put("pointJson", AESUtil.encode(pointStr, key));
    JSONObject jsonObject = new JSONObject(params);
    RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
    RetrofitUtils.getServerApi().checkAsync(body).compose(RxHelper.observableIO2Main(mContext)).subscribe(new BaseObserver<CaptchaCheckIt>(mContext, false) {

        @Override
        public void onSuccess(CaptchaCheckIt data) {
            dragView.ok();
            loadCaptcha();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    dismiss();
                }
            }, 1500);
            if (mOnResultsListener != null) {
                String result = token + "---" + pointStr;
                mOnResultsListener.onResultsClick(AESUtil.encode(result, key));
            }
        }

        @Override
        public void onFailure(Throwable e, String errorMsg) {
            dragView.fail();
            // 刷新验证码
            loadCaptcha();
        }
    });
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson) Point(com.example.verificationcodejavademo.model.Point) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) CaptchaCheckIt(com.example.verificationcodejavademo.model.CaptchaCheckIt) RequestBody(okhttp3.RequestBody)

Example 2 with Point

use of com.example.verificationcodejavademo.model.Point in project captcha by anji-plus.

the class WordImageView method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        size--;
        Point point = new Point();
        point.setX(DisplayUtil.px2dip(getContext(), event.getX()));
        point.setY(DisplayUtil.px2dip(getContext(), event.getY()));
        mList.add(point);
        if (size > 0) {
            // 添加小圆点
            addTextView(event);
        } else if (size == 0) {
            addTextView(event);
            if (wordListenner != null) {
                wordListenner.onWord(new Gson().toJson(mList));
            }
        }
    }
    return true;
}
Also used : Gson(com.google.gson.Gson) Point(com.example.verificationcodejavademo.model.Point)

Aggregations

Point (com.example.verificationcodejavademo.model.Point)2 Gson (com.google.gson.Gson)2 CaptchaCheckIt (com.example.verificationcodejavademo.model.CaptchaCheckIt)1 HashMap (java.util.HashMap)1 RequestBody (okhttp3.RequestBody)1 JSONObject (org.json.JSONObject)1