导航菜单

页面标题

页面副标题

AdaModal v1.4.0 - QRScanActivity.java 源代码

正在查看: AdaModal v1.4.0 应用的 QRScanActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.common.fine.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import cn.bingoogolapple.qrcode.core.QRCodeView;
import cn.bingoogolapple.qrcode.core.ScanBoxView;
import cn.bingoogolapple.qrcode.zxing.ZXingView;
import com.blankj.utilcode.constant.PermissionConstants;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.common.fine.R;
import java.util.Timer;
import java.util.TimerTask;

public class QRScanActivity extends AppCompatActivity implements QRCodeView.Delegate {
    public static final String EXTRA_CONTENT = "EXTRA_CONTENT";
    private static final long SCAN_TIME_OUT = 30000;
    private String mAmbientBrightnessTip;
    private Timer mFinishTimer;
    private TimerTask mFishTask;
    private ImageView mFlashTogger;
    private boolean mIsFlashOn = false;
    private ZXingView mZXingView;

    @Override
    public void onScanQRCodeOpenCameraError() {
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_zxing);
        ActionBar supportActionBar = getSupportActionBar();
        if (supportActionBar != null) {
            supportActionBar.setDisplayHomeAsUpEnabled(true);
        }
        this.mAmbientBrightnessTip = getString(R.string.qr_tips_too_dark);
        this.mZXingView = (ZXingView) findViewById(R.id.zxing_view);
        this.mFlashTogger = (ImageView) findViewById(R.id.button_flash);
        this.mZXingView.setDelegate(this);
        this.mFishTask = new TimerTask() {
            @Override
            public void run() {
                ToastUtils.showShort(R.string.qr_tip_scan_timeout);
                QRScanActivity.this.finish();
            }
        };
        this.mFlashTogger.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                QRScanActivity.this.lambda$onCreate$0(view);
            }
        });
    }

    public void lambda$onCreate$0(View view) {
        switchFlashLight();
    }

    private void switchFlashLight() {
        if (this.mIsFlashOn) {
            this.mZXingView.closeFlashlight();
            this.mFlashTogger.setImageResource(R.drawable.ic_flash_off);
        } else {
            this.mZXingView.openFlashlight();
            this.mFlashTogger.setImageResource(R.drawable.ic_flash_on);
        }
        this.mIsFlashOn = !this.mIsFlashOn;
    }

    @Override
    protected void onStart() {
        super.onStart();
        startCameraAndSpot();
    }

    private void startCameraAndSpot() {
        PermissionUtils.permission(PermissionConstants.CAMERA).callback(new PermissionUtils.SimpleCallback() {
            @Override
            public void onDenied() {
            }

            @Override
            public void onGranted() {
                QRScanActivity.this.mIsFlashOn = false;
                QRScanActivity.this.mFlashTogger.setVisibility(8);
                QRScanActivity.this.mZXingView.startCamera();
                QRScanActivity.this.mZXingView.startSpotAndShowRect();
                QRScanActivity.this.mFinishTimer = new Timer();
                QRScanActivity.this.mFinishTimer.schedule(QRScanActivity.this.mFishTask, QRScanActivity.SCAN_TIME_OUT);
            }
        }).request();
    }

    @Override
    protected void onStop() {
        this.mZXingView.stopCamera();
        this.mFinishTimer.cancel();
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        this.mZXingView.onDestroy();
        super.onDestroy();
    }

    @Override
    public void onScanQRCodeSuccess(String str) {
        vibrate();
        Intent intent = new Intent();
        intent.putExtra(EXTRA_CONTENT, str);
        setResult(-1, intent);
        finish();
    }

    @Override
    public void onCameraAmbientBrightnessChanged(boolean z) {
        String tipText = this.mZXingView.getScanBoxView().getTipText();
        ScanBoxView scanBoxView = this.mZXingView.getScanBoxView();
        int i = 0;
        if (z) {
            if (!tipText.contains(this.mAmbientBrightnessTip)) {
                scanBoxView.setTipText(tipText + this.mAmbientBrightnessTip);
            }
        } else {
            if (tipText.contains(this.mAmbientBrightnessTip)) {
                scanBoxView.setTipText(tipText.substring(0, tipText.indexOf(this.mAmbientBrightnessTip)));
            }
            if (!this.mIsFlashOn) {
                i = 8;
            }
        }
        if (this.mFlashTogger.getVisibility() != i) {
            this.mFlashTogger.setVisibility(i);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == 16908332) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(menuItem);
    }

    private void vibrate() {
        Vibrator vibrator = (Vibrator) getSystemService("vibrator");
        if (vibrator != null) {
            vibrator.vibrate(200L);
        }
    }
}