Skip to content

Commit

Permalink
added room name QR code scanning and custom resolution/fps
Browse files Browse the repository at this point in the history
  • Loading branch information
mslavescu committed Feb 14, 2021
1 parent eb32ddf commit 61fdcbb
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 316 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
applicationId "org.ossdc.visionai"
minSdkVersion 16
targetSdkVersion 30
versionCode 2
versionName "1.1"
versionCode 3
versionName "1.3"
}
buildTypes {
release {
Expand Down Expand Up @@ -58,4 +58,6 @@ dependencies {
implementation files('libs/libjingle_peerconnection.jar')

implementation project(':usbserial')

implementation 'me.dm7.barcodescanner:zxing:1.9.13'
}
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" android:resource="@xml/usb_device_filter" />

</activity>

<activity android:name=".QRCodeScanningActivity"
android:label="@string/qr_code_scanner_activity">
</activity>
<service
android:name="org.ossdc.visionai.usb.UsbService"
android:enabled="true">
</service>
</application>

</manifest>
</manifest>
71 changes: 71 additions & 0 deletions app/src/main/java/org/ossdc/visionai/LauncherActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
*/
package org.ossdc.visionai;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
Expand All @@ -36,6 +41,9 @@

public class LauncherActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

private static final int ROOM_NAME_FROM_QR_CODE = 1;
public static final String QRCODE_RESULT = "QRCODE_RESULT";

SharedPreferences sp;

private String roomName;
Expand All @@ -45,6 +53,7 @@ public class LauncherActivity extends AppCompatActivity implements AdapterView.O
boolean hideLocalCamera = true;
private String robotMode = "OpenBot";
String[] ROBOT_MODES = { "OpenBot", "Neato", "SPARK Assistant"};
private String resFPS;

private static final String CHAR_LIST =
"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Expand Down Expand Up @@ -85,6 +94,7 @@ protected void onCreate(Bundle savedInstanceState) {
useDisplayArea = savedInstanceState.getBoolean("useDisplayArea",false);
hideLocalCamera = savedInstanceState.getBoolean("hideLocalCamera",false);
robotMode = savedInstanceState.getString("robotMode","OpenBot");
resFPS = savedInstanceState.getString("resFPS","2560,1440,30");
}
else
{
Expand All @@ -94,6 +104,7 @@ protected void onCreate(Bundle savedInstanceState) {
useDisplayArea = sp.getBoolean("useDisplayArea",false);
hideLocalCamera = sp.getBoolean("hideLocalCamera",false);
robotMode = sp.getString("robotMode","OpenBot");
resFPS = sp.getString("resFPS","2560,1440,30");
}

EditText roomNameField = findViewById(R.id.editTextTextPersonName);
Expand All @@ -102,13 +113,17 @@ protected void onCreate(Bundle savedInstanceState) {
Switch displayAreaSwitchField = findViewById(R.id.displayAreaSwitch);
Switch hideLocalCameraSwitchField = findViewById(R.id.hideLocalCameraSwitch);
Spinner robotModeField = findViewById(R.id.robotMode);
EditText resFPSField = findViewById(R.id.editTextResFPS);

backCameraSwitchField.setChecked(useBackCamera);
roomNameField.setText(roomName);
roomPasswordField.setText(roomPassword);
displayAreaSwitchField.setChecked(useDisplayArea);
hideLocalCameraSwitchField.setChecked(hideLocalCamera);
robotModeField.setSelection(Arrays.asList(ROBOT_MODES).indexOf(robotMode));
resFPSField.setText(resFPS);


}

@Override
Expand All @@ -120,20 +135,72 @@ public void onNothingSelected(AdapterView<?> arg0) {
// TODO - Custom Code
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case (ROOM_NAME_FROM_QR_CODE) : {
if (resultCode == Activity.RESULT_OK) {
roomName = data.getStringExtra(QRCODE_RESULT);

EditText roomNameField = findViewById(R.id.editTextTextPersonName);
roomNameField.setText(roomName);
}
break;
}
}
}

public void scanRoomQRCode(View view) {
launchActivity(QRCodeScanningActivity.class);
}

public void launchActivity(Class<?> clss) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
mClss = clss;
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA}, ZBAR_CAMERA_PERMISSION);
} else {
Intent intent = new Intent(this,clss);
startActivityForResult(intent, ROOM_NAME_FROM_QR_CODE);

}
}
private static final int ZBAR_CAMERA_PERMISSION = 1;
private Class<?> mClss;

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case ZBAR_CAMERA_PERMISSION:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if(mClss != null) {
Intent intent = new Intent(this, mClss);
startActivity(intent);
}
} else {
Toast.makeText(this, "Please grant camera permission to use the QR Scanner", Toast.LENGTH_SHORT).show();
}
return;
}
}
public void openRaceOSSDCActivity(View view) {
EditText roomNameField = findViewById(R.id.editTextTextPersonName);
EditText roomPasswordField = findViewById(R.id.editTextTextPassword);
Switch backCameraSwitchField = findViewById(R.id.backCameraSwitch);
Switch displayAreaSwitchField = findViewById(R.id.displayAreaSwitch);
Switch hideLocalCameraSwitchField = findViewById(R.id.hideLocalCameraSwitch);
Spinner robotModeField = findViewById(R.id.robotMode);
EditText resFPSField = findViewById(R.id.editTextResFPS);

useBackCamera = backCameraSwitchField.isChecked();
roomName = roomNameField.getText().toString();
roomPassword = roomPasswordField.getText().toString();
useDisplayArea = displayAreaSwitchField.isChecked();
hideLocalCamera = hideLocalCameraSwitchField.isChecked();
robotMode = ROBOT_MODES[robotModeField.getSelectedItemPosition()];
resFPS = resFPSField.getText().toString();

Intent intent = new Intent(this, RaceOSSDCActivity.class);
intent.putExtra("roomName", roomName);
Expand All @@ -142,6 +209,7 @@ public void openRaceOSSDCActivity(View view) {
intent.putExtra("useDisplayArea", useDisplayArea);
intent.putExtra("hideLocalCamera", hideLocalCamera);
intent.putExtra("robotMode", robotMode);
intent.putExtra("resFPS", resFPS);

sp=getSharedPreferences("SD", Context.MODE_PRIVATE);
SharedPreferences.Editor ed=sp.edit();
Expand All @@ -151,6 +219,7 @@ public void openRaceOSSDCActivity(View view) {
ed.putBoolean("useDisplayArea",useDisplayArea);
ed.putBoolean("hideLocalCamera",hideLocalCamera);
ed.putString("robotMode",robotMode);
ed.putString("resFPS",resFPS);

ed.commit();

Expand All @@ -166,6 +235,7 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putBoolean("useDisplayArea", useDisplayArea);
savedInstanceState.putBoolean("hideLocalCamera", hideLocalCamera);
savedInstanceState.putString("robotMode", robotMode);
savedInstanceState.putString("resFPS", resFPS);
}

@Override
Expand All @@ -177,5 +247,6 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
useDisplayArea = savedInstanceState.getBoolean("useDisplayArea");
hideLocalCamera = savedInstanceState.getBoolean("hideLocalCamera");
robotMode = savedInstanceState.getString("robotMode");
resFPS = savedInstanceState.getString("resFPS");
}
}
57 changes: 57 additions & 0 deletions app/src/main/java/org/ossdc/visionai/QRCodeScanningActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2021 Marius Slavescu - OSSDC.org. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ossdc.visionai;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.google.zxing.Result;

import me.dm7.barcodescanner.zxing.ZXingScannerView;

public class QRCodeScanningActivity extends Activity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;

@Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view
setContentView(mScannerView); // Set the scanner view as the content view
}

@Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}

@Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}

@Override
public void handleResult(Result rawResult) {
Intent resultIntent = new Intent();
resultIntent.putExtra(LauncherActivity.QRCODE_RESULT, rawResult.getText());
setResult(Activity.RESULT_OK, resultIntent);
finish();

}
}
Loading

0 comments on commit 61fdcbb

Please sign in to comment.