导航菜单

页面标题

页面副标题

St.John's v1.0.9 - GatePassQrcodeActivity.java 源代码

正在查看: St.John's v1.0.9 应用的 GatePassQrcodeActivity.java JAVA 源代码文件

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


package com.mcb.stjohnsemschool.activity;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;

public class GatePassQrcodeActivity extends AppCompatActivity {
    public static final int QRcodeWidth = 600;
    private Bitmap bitmap;
    String gatePassId;
    TextView gatePassTv;
    Intent intent;
    ProgressBar mProgressBar;
    TransparentProgressDialog mProgressbar;
    String nameStr = "Aadhya";
    ImageView qrCodeIv;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_gate_pass_qrcode);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setTitle("Pre Approved Gate Pass");
        init();
    }

    private void init() {
        this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
        this.qrCodeIv = (ImageView) findViewById(R.id.qr_code_iv);
        this.mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
        Intent intent = getIntent();
        this.intent = intent;
        this.gatePassId = intent.getStringExtra("gate_pass_id");
        if (this.intent.hasExtra(AppMeasurementSdk.ConditionalUserProperty.NAME)) {
            this.nameStr = this.intent.getStringExtra(AppMeasurementSdk.ConditionalUserProperty.NAME);
        }
        TextView textView = (TextView) findViewById(R.id.gate_pass_tv);
        this.gatePassTv = textView;
        textView.setText("" + this.gatePassId);
        new GenerateQrCodeResult().execute(new String[0]);
    }

    public class GenerateQrCodeResult extends AsyncTask<String, String, String> {
        Bitmap bitmap;

        public GenerateQrCodeResult() {
        }

        @Override
        protected void onPreExecute() {
            GatePassQrcodeActivity.this.qrCodeIv.setVisibility(8);
            GatePassQrcodeActivity.this.mProgressBar.setVisibility(0);
        }

        @Override
        public String doInBackground(String... strArr) {
            try {
                GatePassQrcodeActivity gatePassQrcodeActivity = GatePassQrcodeActivity.this;
                this.bitmap = gatePassQrcodeActivity.TextToImageEncode(gatePassQrcodeActivity.gatePassId);
                return null;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

        @Override
        public void onPostExecute(String str) {
            GatePassQrcodeActivity.this.mProgressBar.setVisibility(8);
            if (this.bitmap != null) {
                GatePassQrcodeActivity.this.qrCodeIv.setImageBitmap(this.bitmap);
            }
            GatePassQrcodeActivity.this.qrCodeIv.setVisibility(0);
        }
    }

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

    Bitmap TextToImageEncode(String str) throws WriterException {
        Resources resources;
        int i;
        try {
            MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
            BarcodeFormat barcodeFormat = BarcodeFormat.DATA_MATRIX;
            BitMatrix encode = multiFormatWriter.encode(str, BarcodeFormat.QR_CODE, QRcodeWidth, QRcodeWidth, null);
            int width = encode.getWidth();
            int height = encode.getHeight();
            int[] iArr = new int[width * height];
            for (int i2 = 0; i2 < height; i2++) {
                int i3 = i2 * width;
                for (int i4 = 0; i4 < width; i4++) {
                    int i5 = i3 + i4;
                    if (encode.get(i4, i2)) {
                        resources = getResources();
                        i = R.color.QRCodeBlackColor;
                    } else {
                        resources = getResources();
                        i = R.color.QRCodeWhiteColor;
                    }
                    iArr[i5] = resources.getColor(i);
                }
            }
            Bitmap createBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
            createBitmap.setPixels(iArr, 0, QRcodeWidth, 0, 0, width, height);
            return createBitmap;
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), e.getMessage(), 0).show();
            return null;
        }
    }
}