Sunflower v2.7.0版本的 MD5 值为:0696e8ce118febedd4bd019622cb23b1

以下内容为反编译后的 QrScanActivity.java 源代码,内容仅作参考


package im.grnuohmoqd.ui.hui.discovery;

import android.content.Context;
import android.content.Intent;
import android.hardware.Camera;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.URLUtil;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.king.zxing.CaptureHelper;
import com.king.zxing.OnCaptureCallback;
import com.king.zxing.ViewfinderView;
import com.king.zxing.util.CodeUtils;
import im.grnuohmoqd.messenger.AndroidUtilities;
import im.grnuohmoqd.messenger.FileLog;
import im.grnuohmoqd.messenger.LocaleController;
import im.grnuohmoqd.messenger.MessagesController;
import im.grnuohmoqd.messenger.R;
import im.grnuohmoqd.messenger.SharedConfig;
import im.grnuohmoqd.messenger.browser.Browser;
import im.grnuohmoqd.tgnet.RequestDelegate;
import im.grnuohmoqd.tgnet.TLObject;
import im.grnuohmoqd.tgnet.TLRPC;
import im.grnuohmoqd.ui.ProfileActivity;
import im.grnuohmoqd.ui.WebviewActivity;
import im.grnuohmoqd.ui.actionbar.BaseFragment;
import im.grnuohmoqd.ui.actionbar.Theme;
import im.grnuohmoqd.ui.components.toast.ToastUtils;
import im.grnuohmoqd.ui.hui.chats.NewProfileActivity;
import im.grnuohmoqd.ui.hui.contacts.AddContactsInfoActivity;
import im.grnuohmoqd.ui.hui.mine.QrCodeActivity;
import im.grnuohmoqd.ui.hviews.MryTextView;

public class QrScanActivity extends BaseFragment implements OnCaptureCallback {
    private static final int GALLERY_REQUEST_CODE = 2;
    private ImageView ivBackView;
    private ImageView ivFlash;
    private ImageView ivGallery;
    private LinearLayout llMyQrCode;
    private CaptureHelper mCaptureHelper;
    private Context mContext;
    private SurfaceView surfaceView;
    private TextView tvFlash;
    private TextView tvGallery;
    private ViewfinderView viewfinderView;

    @Override
    public boolean onFragmentCreate() {
        return super.onFragmentCreate();
    }

    @Override
    public void onResume() {
        super.onResume();
        this.mCaptureHelper.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        this.mCaptureHelper.onPause();
    }

    @Override
    public void onFragmentDestroy() {
        super.onFragmentDestroy();
        this.mCaptureHelper.onDestroy();
    }

    private void requestCameraPermissions() {
        if (Build.VERSION.SDK_INT < 23 || getParentActivity().checkSelfPermission("android.permission.CAMERA") == 0) {
            return;
        }
        try {
            getParentActivity().requestPermissions(new String[]{"android.permission.CAMERA"}, 20);
        } catch (Throwable unused) {
        }
    }

    @Override
    public View createView(Context context) {
        this.mContext = context;
        requestCameraPermissions();
        this.actionBar.setAddToContainer(false);
        this.fragmentView = LayoutInflater.from(this.mContext).inflate(R.layout.activity_qr_code_scan_layout, (ViewGroup) null, false);
        this.fragmentView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public final boolean onTouch(View view, MotionEvent motionEvent) {
                return QrScanActivity.this.lambda$createView$0$QrScanActivity(view, motionEvent);
            }
        });
        initView();
        return this.fragmentView;
    }

    public boolean lambda$createView$0$QrScanActivity(View view, MotionEvent motionEvent) {
        this.mCaptureHelper.onTouchEvent(motionEvent);
        return true;
    }

    private void initView() {
        this.surfaceView = (SurfaceView) this.fragmentView.findViewById(2131297260);
        ViewfinderView viewfinderView = (ViewfinderView) this.fragmentView.findViewById(2131297811);
        this.viewfinderView = viewfinderView;
        viewfinderView.setLabelText(LocaleController.getString("PutQrCodeInbox", R.string.PutQrCodeInbox));
        this.ivFlash = (ImageView) this.fragmentView.findViewById(R.id.flash_switch);
        this.tvFlash = (TextView) this.fragmentView.findViewById(R.id.tvFlash);
        this.ivGallery = (ImageView) this.fragmentView.findViewById(R.id.ivGallery);
        this.tvGallery = (TextView) this.fragmentView.findViewById(R.id.tvGallery);
        this.llMyQrCode = (LinearLayout) this.fragmentView.findViewById(R.id.ll_my_qr_code);
        ((MryTextView) this.fragmentView.findViewById(R.id.tv_my_qrcode)).setText(LocaleController.getString("MyQrCode", R.string.MyQRCode));
        this.ivFlash.setImageDrawable(Theme.createSimpleSelectorDrawable(getParentActivity(), R.mipmap.icon_flash, Theme.getColor(Theme.key_windowBackgroundWhite), Theme.getColor(Theme.key_windowBackgroundWhiteBlueIcon)));
        this.tvFlash.setTextColor(Theme.createColorStateList(Theme.getColor(Theme.key_windowBackgroundWhite), Theme.getColor(Theme.key_windowBackgroundWhiteBlueIcon)));
        this.tvFlash.setText(LocaleController.getString("FlashOn", R.string.FlashOn));
        this.ivGallery.setImageDrawable(Theme.createSimpleSelectorDrawable(getParentActivity(), R.mipmap.icon_album, Theme.getColor(Theme.key_windowBackgroundWhite), Theme.getColor(Theme.key_windowBackgroundWhiteBlueIcon)));
        this.tvGallery.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        this.tvGallery.setText(LocaleController.getString("Gallery", R.string.Gallery));
        ImageView imageView = (ImageView) this.fragmentView.findViewById(R.id.ivBack);
        this.ivBackView = imageView;
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
        layoutParams.setMargins(0, AndroidUtilities.statusBarHeight, 0, 0);
        this.ivBackView.setLayoutParams(layoutParams);
        this.ivBackView.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                QrScanActivity.this.lambda$initView$1$QrScanActivity(view);
            }
        });
        MryTextView mryTextView = (MryTextView) this.fragmentView.findViewById(R.id.tv_title);
        RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) mryTextView.getLayoutParams();
        layoutParams2.setMargins(0, AndroidUtilities.statusBarHeight, 0, 0);
        mryTextView.setLayoutParams(layoutParams2);
        CaptureHelper captureHelper = new CaptureHelper(getParentActivity(), this.surfaceView, this.viewfinderView, (View) null);
        this.mCaptureHelper = captureHelper;
        captureHelper.setOnCaptureCallback(this);
        this.mCaptureHelper.vibrate(true).playBeep(true).fullScreenScan(true).supportVerticalCode(false).supportLuminanceInvert(true).continuousScan(false);
        this.mCaptureHelper.onCreate();
        RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) this.llMyQrCode.getLayoutParams();
        int i = getParentActivity().getResources().getDisplayMetrics().widthPixels;
        layoutParams3.topMargin = (int) (((getParentActivity().getResources().getDisplayMetrics().heightPixels + (Math.min(i, r2) * 0.625f)) / 2.0f) + AndroidUtilities.dp(55.0f));
        this.llMyQrCode.setLayoutParams(layoutParams3);
        this.ivFlash.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                QrScanActivity.this.clickFlash(view);
            }
        });
        this.ivGallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                QrScanActivity.this.goGallery(view);
            }
        });
        this.llMyQrCode.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                QrScanActivity.this.goMyQrCode(view);
            }
        });
    }

    public void lambda$initView$1$QrScanActivity(View view) {
        finishFragment();
    }

    private void offFlash() {
        Camera camera = this.mCaptureHelper.getCameraManager().getOpenCamera().getCamera();
        Camera.Parameters parameters = camera.getParameters();
        parameters.setFlashMode("off");
        camera.setParameters(parameters);
    }

    private void openFlash() {
        Camera camera = this.mCaptureHelper.getCameraManager().getOpenCamera().getCamera();
        Camera.Parameters parameters = camera.getParameters();
        parameters.setFlashMode("torch");
        camera.setParameters(parameters);
    }

    public void clickFlash(View view) {
        if (view.isSelected()) {
            offFlash();
            view.setSelected(false);
            this.tvFlash.setSelected(false);
            this.tvFlash.setText(LocaleController.getString("FlashOn", R.string.FlashOn));
            return;
        }
        openFlash();
        view.setSelected(true);
        this.tvFlash.setSelected(true);
        this.tvFlash.setText(LocaleController.getString("FlashOff", R.string.FlashOff));
    }

    public void goGallery(View view) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") != 0) {
            getParentActivity().requestPermissions(new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 4);
            return;
        }
        Intent intent = new Intent();
        intent.setAction("android.intent.action.PICK");
        intent.setType("image/*");
        startActivityForResult(intent, 2);
    }

    public void goMyQrCode(View view) {
        presentFragment(new QrCodeActivity(getUserConfig().getClientUserId()));
    }

    @Override
    public boolean onBackPressed() {
        finishFragment(false);
        return false;
    }

    private void getUserInfo(TLRPC.User user) {
        TLRPC.TL_users_getFullUser tL_users_getFullUser = new TLRPC.TL_users_getFullUser();
        tL_users_getFullUser.id = getMessagesController().getInputUser(user);
        getConnectionsManager().bindRequestToGuid(getConnectionsManager().sendRequest(tL_users_getFullUser, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                QrScanActivity.this.lambda$getUserInfo$3$QrScanActivity(tLObject, tL_error);
            }
        }), this.classGuid);
    }

    public void lambda$getUserInfo$3$QrScanActivity(final TLObject tLObject, TLRPC.TL_error tL_error) {
        if (tL_error == null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    QrScanActivity.this.lambda$null$2$QrScanActivity(tLObject);
                }
            });
        } else {
            ToastUtils.show(R.string.NoUsernameFound);
        }
    }

    public void lambda$null$2$QrScanActivity(TLObject tLObject) {
        TLRPC.UserFull userFull = (TLRPC.UserFull) tLObject;
        getMessagesController().putUser(userFull.user, false);
        if (userFull.user == null) {
            return;
        }
        if (userFull.user.self || userFull.user.contact) {
            Bundle bundle = new Bundle();
            bundle.putInt("user_id", userFull.user.id);
            presentFragment(new NewProfileActivity(bundle), true);
        } else {
            Bundle bundle2 = new Bundle();
            bundle2.putInt("from_type", 1);
            presentFragment(new AddContactsInfoActivity(bundle2, userFull.user), true);
        }
    }

    private void getChatInfo(TLRPC.Chat chat) {
        TLRPC.TL_channels_getFullChannel tL_channels_getFullChannel = new TLRPC.TL_channels_getFullChannel();
        tL_channels_getFullChannel.channel = MessagesController.getInputChannel(chat);
        getConnectionsManager().bindRequestToGuid(getConnectionsManager().sendRequest(tL_channels_getFullChannel, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                QrScanActivity.this.lambda$getChatInfo$5$QrScanActivity(tLObject, tL_error);
            }
        }), this.classGuid);
    }

    public void lambda$getChatInfo$5$QrScanActivity(final TLObject tLObject, TLRPC.TL_error tL_error) {
        if (tL_error == null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    QrScanActivity.this.lambda$null$4$QrScanActivity(tLObject);
                }
            });
        }
    }

    public void lambda$null$4$QrScanActivity(TLObject tLObject) {
        TLRPC.TL_messages_chatFull tL_messages_chatFull = (TLRPC.TL_messages_chatFull) tLObject;
        getMessagesController().putChats(tL_messages_chatFull.chats, false);
        Bundle bundle = new Bundle();
        bundle.putInt("chat_id", tL_messages_chatFull.full_chat.id);
        ProfileActivity profileActivity = new ProfileActivity(bundle);
        profileActivity.setChatInfo(tL_messages_chatFull.full_chat);
        presentFragment(profileActivity, true);
    }

    public void parseQRCodeResult(String str) {
        String substring;
        String str2 = getMessagesController().sharePrefix + "&Key=";
        if (str.startsWith(str2) || str.startsWith("https://m12345.cc") || str.startsWith("http://m12345.cc")) {
            if (str.startsWith(str2)) {
                String str3 = new String(Base64.decode(str.substring(str2.length()).replace("%3D", "="), 0));
                String[] split = str3.split("#");
                String str4 = split[0].split("=")[1];
                String str5 = split[1].split("=")[1];
                if (str3.contains("Uname")) {
                    getMessagesController().openByUserName(split[2].split("=")[1], (BaseFragment) this, 1, true);
                    return;
                }
                TLRPC.TL_user tL_user = new TLRPC.TL_user();
                try {
                    tL_user.id = Integer.parseInt(str4);
                    tL_user.access_hash = Long.parseLong(str5);
                    getUserInfo(tL_user);
                    return;
                } catch (NumberFormatException e) {
                    FileLog.e("parse qr code err:" + e);
                    return;
                }
            }
            if (str.startsWith("http://m12345.cc")) {
                substring = str.substring(16);
            } else {
                substring = str.substring(17);
            }
            boolean startsWith = substring.startsWith("/g/");
            String str6 = new String(Base64.decode(substring.substring(substring.lastIndexOf("/") + 1), 0));
            if (startsWith) {
                getMessagesController().openByUserName(str6.substring(str6.lastIndexOf("/") + 1), (BaseFragment) this, 1, true);
                return;
            }
            String[] split2 = str6.substring(0, str6.length() - 4).split("&", 2);
            String str7 = split2[0];
            String str8 = split2[1];
            TLRPC.TL_user tL_user2 = new TLRPC.TL_user();
            try {
                tL_user2.id = Integer.parseInt(str7);
                tL_user2.access_hash = Long.parseLong(str8);
                getUserInfo(tL_user2);
                return;
            } catch (NumberFormatException e2) {
                FileLog.e("parse qr code err:" + e2);
                return;
            }
        }
        if (str.startsWith("https://m12345.cc/authtoken/")) {
            return;
        }
        if (URLUtil.isNetworkUrl(str)) {
            if (SharedConfig.customTabs) {
                presentFragment(new WebviewActivity(str, (String) null), true);
                return;
            } else {
                Browser.openUrl(getParentActivity(), str);
                return;
            }
        }
        presentFragment(new QrScanResultActivity(str), true);
    }

    @Override
    public void onActivityResultFragment(int i, int i2, Intent intent) {
        Uri data;
        if (i2 != -1 || i == 20 || i != 2 || (data = intent.getData()) == null) {
            return;
        }
        String parseQRCode = CodeUtils.parseQRCode(AndroidUtilities.getPath(data));
        if (parseQRCode != null) {
            parseQRCodeResult(parseQRCode);
        } else {
            ToastUtils.show(R.string.NoQRCode);
        }
    }

    @Override
    public boolean onResultCallback(String str) {
        parseQRCodeResult(str);
        return true;
    }
}