Skip to content

Commit

Permalink
Add QR code scanning to connect blasters
Browse files Browse the repository at this point in the history
I generated the QR code at https://www.the-qrcode-generator.com/
and saved it to SVG. I opened it in GIMP using 100 pixels per
inch and specified a 1 inch sized image. I printed the result,
cut it out, and used some clear packing tape to get the QR code
onto the side of the blaster.
  • Loading branch information
Dees-Troy committed Oct 4, 2019
1 parent 24a2eef commit dad2368
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 13 deletions.
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.simplecoil.simplecoil"
minSdkVersion 21
targetSdkVersion 26
versionCode 11
versionName "1.10"
versionCode 12
versionName "1.11"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.CountDownTimer;
import android.os.Handler;
Expand Down Expand Up @@ -90,11 +91,15 @@
public class FullscreenActivity extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener {
private static final String TAG = "scmain";

private static final int REQUEST_ENABLE_BT = 1;
private static final int REQUEST_QR_SCAN = 2;

// For testing and debugging network only -- dumps you straight to the play game layout and allows you to switch teams without connecting a blaster
private static final boolean TEST_NETWORK = false;

private Button mReconnectButton = null;
private Button mConnectButton = null;
private Button mQRConnectButton = null;
private Button mDedicatedServerButton = null;
private Button mTeamMinusButton = null;
private Button mTeamPlusButton = null;
Expand Down Expand Up @@ -422,6 +427,22 @@ public void onClick(View v) {
}
}));
}
mQRConnectButton = findViewById(R.id.connect_qr_weapon_button);
if (mQRConnectButton != null) {
mQRConnectButton.setOnClickListener((new View.OnClickListener() {
public void onClick(View v) {
try {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes
startActivityForResult(intent, REQUEST_QR_SCAN);
} catch (Exception e) {
Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
startActivity(marketIntent);
}
}
}));
}
mDedicatedServerButton = findViewById(R.id.dedicated_server_button);
if (mDedicatedServerButton != null) {
mDedicatedServerButton.setOnClickListener((new View.OnClickListener() {
Expand Down Expand Up @@ -1635,6 +1656,30 @@ public void onReceive(Context context, Intent intent) {
}
};

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.e(TAG, "onActivityResult " + requestCode);
if (requestCode == REQUEST_QR_SCAN) {

if (resultCode == RESULT_OK) {
mDeviceAddress = data.getStringExtra("SCAN_RESULT");
if (mDeviceAddress != null && !mDeviceAddress.isEmpty()) {
Log.e(TAG, "Got QR: " + mDeviceAddress);
connectWeapon();
} else {
Log.e(TAG, "Did not get any good QR result");
}
}
if(resultCode == RESULT_CANCELED){
//handle cancel
Log.e(TAG, "QR cancel");
}
} else if (requestCode == REQUEST_ENABLE_BT) {
connectWeapon();
}
}

private void connectWeapon() {
if (TEST_NETWORK) {
RelativeLayout connectLayout = findViewById(R.id.connect_layout);
Expand Down Expand Up @@ -1678,7 +1723,6 @@ private void connectWeapon() {
Intent intentBtEnabled = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
// The REQUEST_ENABLE_BT constant passed to startActivityForResult() is a locally defined integer (which must be greater than 0), that the system passes back to you in your onActivityResult()
// implementation as the requestCode parameter.
int REQUEST_ENABLE_BT = 1;
startActivityForResult(intentBtEnabled, REQUEST_ENABLE_BT);
return;
}
Expand All @@ -1698,6 +1742,7 @@ private void connectWeapon() {
mConnectButton.setEnabled(false);
mReconnectButton.setEnabled(false);
mDedicatedServerButton.setEnabled(false);
mQRConnectButton.setEnabled(false);
mScanning = true;
TextView connectStatusTV = findViewById(R.id.connect_status_tv);
if (connectStatusTV != null) {
Expand Down Expand Up @@ -1754,6 +1799,7 @@ private void handleDisconnect() {
mConnectButton.setEnabled(true);
mReconnectButton.setEnabled(true);
mDedicatedServerButton.setEnabled(true);
mQRConnectButton.setEnabled(true);
TextView connectStatusTV = findViewById(R.id.connect_status_tv);
if (connectStatusTV != null) connectStatusTV.setText(R.string.connect_status_not_connected);
mLastShotCount = 0;
Expand Down Expand Up @@ -1846,10 +1892,10 @@ public void onReceive(Context context, Intent intent) {
} else if (BluetoothLeService.ID_DATA_AVAILABLE.equals(action)) {
mBlasterType = intent.getByteExtra(BluetoothLeService.EXTRA_DATA, BLASTER_TYPE_PISTOL);
if (mBlasterType == BLASTER_TYPE_RIFLE) {
Toast.makeText(getApplicationContext(), getString(R.string.rifle_detected_toast), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), getString(R.string.rifle_detected_toast, mDeviceAddress), Toast.LENGTH_LONG).show();
} else {
// We'll automatically assume that this is a pistol
Toast.makeText(getApplicationContext(), getString(R.string.pistol_detected_toast), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), getString(R.string.pistol_detected_toast, mDeviceAddress), Toast.LENGTH_LONG).show();
}
} else if (BluetoothLeService.CHARACTERISTIC_WRITE_FINISHED.equals(action)) {
if (mReloading == RELOADING_STATE_STARTED) {
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/res/layout/activity_fullscreen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@
android:layout_below="@id/reconnect_weapon_button"
android:text="@string/connect_weapon_button" />

<Button
android:id="@+id/connect_qr_weapon_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:layout_below="@id/connect_weapon_button"
android:text="@string/connect_qr_weapon_button" />

<TextView
android:id="@+id/connect_status_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/connect_weapon_button"
android:layout_below="@+id/connect_qr_weapon_button"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:text="@string/connect_status_not_connected"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<string name="reconnect_weapon_button">Reconnect Same Weapon Only</string>
<string name="connect_weapon_button">Connect Weapon</string>
<string name="connect_qr_weapon_button">Connect Weapon Using QR</string>
<string name="disconnect_weapon_button">Disconnect Weapon</string>
<string name="start_game_button">Start Game!</string>
<string name="end_game_button">End Game!</string>
Expand Down Expand Up @@ -98,8 +99,8 @@

<string name="please_wait">Please Wait</string>

<string name="pistol_detected_toast">Pistol Detected!</string>
<string name="rifle_detected_toast">Rifle Detected!</string>
<string name="pistol_detected_toast">Pistol Detected! (%1$s)</string>
<string name="rifle_detected_toast">Rifle Detected! (%1$s)</string>
<string name="grenade_paired_toast">Grenade Paired!</string>

<string name="dedicated_server_button">Dedicated Server</string>
Expand Down

0 comments on commit dad2368

Please sign in to comment.