From d5f8a4dacb666eb4a50aba148e493c10b259b13b Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Sun, 10 Dec 2017 11:44:10 +0100 Subject: [PATCH] StartConversationActivity: Scan QR codes via UriHandlerActivity --- src/main/AndroidManifest.xml | 1 - .../ui/StartConversationActivity.java | 22 +++------------- .../conversations/ui/UriHandlerActivity.java | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 55f41662f..3c17bf714 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -60,7 +60,6 @@ diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index ecc7a891d..8b36ce435 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -55,9 +55,6 @@ import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; -import com.google.zxing.integration.android.IntentIntegrator; -import com.google.zxing.integration.android.IntentResult; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -644,7 +641,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU showCreateConferenceDialog(); return true; case R.id.action_scan_qr_code: - new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC","QR_CODE")); + Intent intent = new Intent(this, UriHandlerActivity.class); + intent.setAction(UriHandlerActivity.ACTION_SCAN_QR_CODE); + startActivity(intent); return true; case R.id.action_hide_offline: mHideOfflineContacts = !item.isChecked(); @@ -682,20 +681,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { - if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) { - IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); - if (scanResult != null && scanResult.getFormatName() != null) { - String data = scanResult.getContents(); - Invite invite = new Invite(data); - if (xmppConnectionServiceBound) { - invite.invite(); - } else if (invite.getJid() != null) { - this.mPendingInvite = invite; - } else { - this.mPendingInvite = null; - } - } - } else if (resultCode == RESULT_OK) { + if (resultCode == RESULT_OK) { if (xmppConnectionServiceBound) { this.mPostponedActivityResult = null; if (requestCode == REQUEST_CREATE_CONFERENCE) { diff --git a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java index c725ec8cf..043bf247e 100644 --- a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java @@ -4,11 +4,17 @@ import android.app.Activity; import android.content.Intent; import android.net.Uri; +import com.google.zxing.integration.android.IntentIntegrator; +import com.google.zxing.integration.android.IntentResult; + +import java.util.Arrays; + import eu.siacs.conversations.persistance.DatabaseBackend; import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.xmpp.jid.Jid; public class UriHandlerActivity extends Activity { + public static final String ACTION_SCAN_QR_CODE = "scan_qr_code"; @Override public void onStart() { @@ -66,8 +72,28 @@ public class UriHandlerActivity extends Activity { case Intent.ACTION_VIEW: case Intent.ACTION_SENDTO: handleUri(data.getData()); + break; + case ACTION_SCAN_QR_CODE: + new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC", "QR_CODE")); + return; } finish(); } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent intent) { + if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) { + IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, + intent); + + if (scanResult != null && scanResult.getFormatName() != null) { + String data = scanResult.getContents(); + handleUri(Uri.parse(data)); + } + } + + finish(); + super.onActivityResult(requestCode, requestCode, intent); + } }