StartConversationActivity: Scan QR codes via UriHandlerActivity

This commit is contained in:
Marc Schink 2017-12-10 11:44:10 +01:00
parent 75e16d0f54
commit d5f8a4dacb
3 changed files with 30 additions and 19 deletions

View File

@ -60,7 +60,6 @@
<activity
android:name=".ui.UriHandlerActivity"
android:label="@string/title_activity_start_conversation"
android:theme="@android:style/Theme.NoDisplay"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

View File

@ -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) {

View File

@ -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);
}
}