allow scanning vicc configuration with QR code
This commit is contained in:
@@ -97,6 +97,7 @@
|
||||
<orderEntry type="library" exported="" name="support-v4-23.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="recyclerview-v7-23.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-23.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="core-3.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-vector-drawable-23.2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="zxing-android-embedded-3.2.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="design-23.2.1" level="project" />
|
||||
|
||||
@@ -34,5 +34,6 @@ dependencies {
|
||||
compile 'com.android.support:design:23.2.1'
|
||||
|
||||
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
|
||||
compile 'com.google.zxing:core:3.2.1'
|
||||
compile group: 'com.madgag.spongycastle', name: 'core', version: '1.51.0.0'
|
||||
}
|
||||
|
||||
@@ -27,6 +27,14 @@
|
||||
<activity
|
||||
android:name="com.vsmartcard.acardemulator.SettingsActivity"
|
||||
android:label="@string/action_settings" >
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data
|
||||
android:scheme="@string/scheme_vicc" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service android:name="com.vsmartcard.acardemulator.SimulatorService"
|
||||
|
||||
@@ -21,9 +21,12 @@ package com.vsmartcard.acardemulator;
|
||||
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
@@ -32,9 +35,13 @@ import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.SwitchPreference;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
/**
|
||||
* A {@link PreferenceActivity} that presents a set of application settings. On
|
||||
* handset devices, settings are presented as a single list. On tablets,
|
||||
@@ -185,7 +192,16 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
|
||||
bindPreferenceSummaryToValue(findPreference("hostname"));
|
||||
bindPreferenceSummaryToValue(findPreference("port"));
|
||||
|
||||
Preference scan = findPreference("scan");
|
||||
scan.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new IntentIntegrator(getActivity()).initiateScan();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
@@ -195,6 +211,55 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
||||
switch(requestCode) {
|
||||
case IntentIntegrator.REQUEST_CODE:
|
||||
if (resultCode != RESULT_CANCELED) {
|
||||
handleScannedURI(Uri.parse(scanResult.getContents()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleScannedURI(Uri uri) {
|
||||
try {
|
||||
String h, p;
|
||||
h = uri.getHost();
|
||||
int _p = uri.getPort();
|
||||
if (_p < 0) {
|
||||
_p = SimulatorService.DEFAULT_PORT;
|
||||
}
|
||||
p = Integer.toString(_p);
|
||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SP.edit().putString("hostname", h).apply();
|
||||
SP.edit().putString("port", p).apply();
|
||||
SP.edit().putString("emulator", getString(R.string.vicc)).apply();
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content,
|
||||
new VICCPreferenceFragment()).commit();
|
||||
} catch (Exception e) {
|
||||
Snackbar.make(this.getCurrentFocus(), "Could not import configuration", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Intent intent = getIntent();
|
||||
// Check to see that the Activity started due to a configuration URI
|
||||
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||
Uri uri = intent.getData();
|
||||
handleScannedURI(uri);
|
||||
super.onNewIntent(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
// onResume gets called after this to handle the intent
|
||||
setIntent(intent);
|
||||
}
|
||||
}
|
||||
@@ -47,5 +47,6 @@
|
||||
<string name="vicc_config_info">If you choose the virtual smart card (VICC) as emulator, you need to start the it on your computer with the `--reversed` flag and configure the connection parameters here accordingly.</string>
|
||||
<string name="hint_vicc_port">VICC Port</string>
|
||||
<string name="hint_vicc_hostname">VICC Hostname</string>
|
||||
<string name="scheme_vicc">vicc</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -59,6 +59,12 @@
|
||||
android:data="https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html" />
|
||||
</Preference>
|
||||
|
||||
<Preference
|
||||
android:title="Scan Configuration"
|
||||
android:summary="Scan QR code to import VICC's hostname and port."
|
||||
android:key="scan">
|
||||
</Preference>
|
||||
|
||||
<EditTextPreference
|
||||
android:key="hostname"
|
||||
android:defaultValue="10.0.2.2"
|
||||
|
||||
@@ -221,6 +221,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SP.edit().putString("hostname", h).apply();
|
||||
SP.edit().putString("port", p).apply();
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content,
|
||||
new VPCDPreferenceFragment()).commit();
|
||||
} catch (Exception e) {
|
||||
Snackbar.make(this.getCurrentFocus(), "Could not import configuration", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
|
||||
Reference in New Issue
Block a user