From dad23681eda6b29fbb81eea2ace123b3002885c0 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Fri, 4 Oct 2019 16:09:59 -0500 Subject: [PATCH] Add QR code scanning to connect blasters 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. --- .idea/caches/build_file_checksums.ser | Bin 0 -> 538 bytes .idea/codeStyles/Project.xml | 29 ++++++++++ .idea/misc.xml | 15 +++-- app/build.gradle | 4 +- .../simplecoil/FullscreenActivity.java | 52 +++++++++++++++++- .../main/res/layout/activity_fullscreen.xml | 12 +++- app/src/main/res/values/strings.xml | 5 +- 7 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 .idea/caches/build_file_checksums.ser create mode 100644 .idea/codeStyles/Project.xml diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000000000000000000000000000000000000..80e714f217e35ae0d039dce56aa1f8a855d53fb3 GIT binary patch literal 538 zcmZ4UmVvdnh`~NNKUXg?FQq6yGexf?KR>5fFEb@IQ7^qHF(oHeub?PDD>b=9F91S2 zm1gFoxMk*~I%lLNXBU^|7Q2L-Ts|(GuF1r}l-a(W(##Th_( zR`y#54~r#SWM*J;W8likPfT%3OfJbU@?_vF$tX%K&dAS6sVJ~_U;qK0atKNES3g?ShC0*r|zT3L*WlTy5!@d#*ft>v0#2ip)6{HrGWTqCE!WC<^ zXVt!cAEvkexvj`!J=Yf{44V2G`MIh3DXFQ&@g+t1mHJQ%^bui>VagTRo}2v)n^;~p zaL#!1!>O)>K@gAXExmEV*S>Z;$^p?uIxJ@2xvtx5 Izd2R`0Ats^IsgCw literal 0 HcmV?d00001 diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 635999d..e0d5b93 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,26 +5,31 @@ - + diff --git a/app/build.gradle b/app/build.gradle index d611eed..3259ce2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java b/app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java index 7c14219..1bd0768 100644 --- a/app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java +++ b/app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java @@ -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; @@ -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; @@ -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() { @@ -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); @@ -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; } @@ -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) { @@ -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; @@ -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) { diff --git a/app/src/main/res/layout/activity_fullscreen.xml b/app/src/main/res/layout/activity_fullscreen.xml index 127733c..7229d98 100644 --- a/app/src/main/res/layout/activity_fullscreen.xml +++ b/app/src/main/res/layout/activity_fullscreen.xml @@ -46,11 +46,21 @@ android:layout_below="@id/reconnect_weapon_button" android:text="@string/connect_weapon_button" /> +