diff options
4 files changed, 49 insertions, 19 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/OmemoActivity.java b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java index 3406d0c46..1ee2f9355 100644 --- a/src/main/java/de/pixart/messenger/ui/OmemoActivity.java +++ b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java @@ -29,6 +29,7 @@ public abstract class OmemoActivity extends XmppActivity { private Account mSelectedAccount; private String mSelectedFingerprint; + protected XmppUri mPendingFingerprintVerificationUri = null; @Override @@ -71,7 +72,7 @@ public abstract class OmemoActivity extends XmppActivity { copyOmemoFingerprint(mSelectedFingerprint); break; case R.id.verify_scan: - //new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC","QR_CODE")); + ScanActivity.scan(this); break; } return true; @@ -79,16 +80,16 @@ public abstract class OmemoActivity extends XmppActivity { @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { - /*IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); - if (scanResult != null && scanResult.getFormatName() != null) { - String data = scanResult.getContents(); - XmppUri uri = new XmppUri(data); + super.onActivityResult(requestCode, requestCode, intent); + if (requestCode == ScanActivity.REQUEST_SCAN_QR_CODE && resultCode == RESULT_OK) { + String result = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT); + XmppUri uri = new XmppUri(result == null ? "" : result); if (xmppConnectionServiceBound) { processFingerprintVerification(uri); } else { - this.mPendingFingerprintVerificationUri =uri; + this.mPendingFingerprintVerificationUri = uri; } - }*/ + } } protected abstract void processFingerprintVerification(XmppUri uri); @@ -123,7 +124,6 @@ public abstract class OmemoActivity extends XmppActivity { boolean undecidedNeedEnablement, CompoundButton.OnCheckedChangeListener onCheckedChangeListener) { - ContactKeyBinding binding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.contact_key, keys, true); if (Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509) { binding.key.setOnClickListener(v -> showX509Certificate(account, fingerprint)); @@ -177,9 +177,7 @@ public abstract class OmemoActivity extends XmppActivity { } else { binding.tglTrust.setVisibility(View.VISIBLE); binding.verifiedFingerprint.setVisibility(View.GONE); - binding.tglTrust.setOnClickListener(null); binding.tglTrust.setEnabled(false); - binding.tglTrust.setOnClickListener(toast); } } @@ -226,11 +224,11 @@ public abstract class OmemoActivity extends XmppActivity { private void showCertificateInformationDialog(Bundle bundle) { View view = getLayoutInflater().inflate(R.layout.certificate_information, null); final String not_available = getString(R.string.certicate_info_not_available); - TextView subject_cn = view.findViewById(R.id.subject_cn); - TextView subject_o = view.findViewById(R.id.subject_o); - TextView issuer_cn = view.findViewById(R.id.issuer_cn); - TextView issuer_o = view.findViewById(R.id.issuer_o); - TextView sha1 = view.findViewById(R.id.sha1); + TextView subject_cn = (TextView) view.findViewById(R.id.subject_cn); + TextView subject_o = (TextView) view.findViewById(R.id.subject_o); + TextView issuer_cn = (TextView) view.findViewById(R.id.issuer_cn); + TextView issuer_o = (TextView) view.findViewById(R.id.issuer_o); + TextView sha1 = (TextView) view.findViewById(R.id.sha1); subject_cn.setText(bundle.getString("subject_cn", not_available)); subject_o.setText(bundle.getString("subject_o", not_available)); @@ -244,4 +242,9 @@ public abstract class OmemoActivity extends XmppActivity { builder.setPositiveButton(R.string.ok, null); builder.create().show(); } + + @Override + public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { + ScanActivity.onRequestPermissionResult(this, requestCode, grantResults); + } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/ScanActivity.java b/src/main/java/de/pixart/messenger/ui/ScanActivity.java index d44f50512..7ca801948 100644 --- a/src/main/java/de/pixart/messenger/ui/ScanActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ScanActivity.java @@ -42,6 +42,7 @@ import android.view.TextureView; import android.view.TextureView.SurfaceTextureListener; import android.view.View; import android.view.WindowManager; +import android.widget.Toast; import com.google.zxing.BinaryBitmap; import com.google.zxing.DecodeHintType; @@ -67,6 +68,9 @@ import de.pixart.messenger.ui.widget.ScannerView; public final class ScanActivity extends Activity implements SurfaceTextureListener, ActivityCompat.OnRequestPermissionsResultCallback { public static final String INTENT_EXTRA_RESULT = "result"; + public static final int REQUEST_SCAN_QR_CODE = 0x0987; + private static final int REQUEST_CAMERA_PERMISSIONS_TO_SCAN = 0x6789; + private static final long VIBRATE_DURATION = 50L; private static final long AUTO_FOCUS_INTERVAL_MS = 2500L; private static boolean DISABLE_CONTINUOUS_AUTOFOCUS = Build.MODEL.equals("GT-I9100") // Galaxy S2 @@ -263,7 +267,30 @@ public final class ScanActivity extends Activity implements SurfaceTextureListen } private void postFinish() { - new Handler().postDelayed(() -> finish(), 50); + new Handler().postDelayed(this::finish, 50); + } + + public static void scan(Activity activity) { + if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { + Intent intent = new Intent(activity, ScanActivity.class); + activity.startActivityForResult(intent, REQUEST_SCAN_QR_CODE); + } else { + ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSIONS_TO_SCAN); + } + + } + + public static void onRequestPermissionResult(Activity activity, int requestCode, int[] grantResults) { + if (requestCode != REQUEST_CAMERA_PERMISSIONS_TO_SCAN) { + return; + } + if (grantResults.length > 0) { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + scan(activity); + } else { + Toast.makeText(activity, R.string.qr_code_scanner_needs_access_to_camera, Toast.LENGTH_SHORT).show(); + } + } } private final class AutoFocusRunnable implements Runnable { diff --git a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java index 3499b8f00..751c51f09 100644 --- a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java +++ b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java @@ -128,7 +128,7 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat if (hasPendingKeyFetches()) { Toast.makeText(this, R.string.please_wait_for_keys_to_be_fetched, Toast.LENGTH_SHORT).show(); } else { - //new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC","QR_CODE")); + ScanActivity.scan(this); return true; } } diff --git a/src/main/java/de/pixart/messenger/ui/VerifyOTRActivity.java b/src/main/java/de/pixart/messenger/ui/VerifyOTRActivity.java index ded1f90c7..47e991520 100644 --- a/src/main/java/de/pixart/messenger/ui/VerifyOTRActivity.java +++ b/src/main/java/de/pixart/messenger/ui/VerifyOTRActivity.java @@ -206,7 +206,7 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer } this.mode = intent.getIntExtra("mode", MODE_MANUAL_VERIFICATION); if (this.mode == MODE_SCAN_FINGERPRINT) { - // todo + // todo scan OTR fingerprint // new IntentIntegrator(this).initiateScan(); return false; } @@ -218,7 +218,7 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { - // todo + // todo onActivityResult OTR /*if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) { IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); if (scanResult != null && scanResult.getFormatName() != null) { |