Skip to content
Permalink
Browse files
Updated project with barcodeView rather than using an intent.
  • Loading branch information
upcharlie committed Mar 9, 2019
1 parent 07acf38 commit 4a87784664c4ff09ad095544a52d6143f659f59d
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 50 deletions.
@@ -25,6 +25,7 @@
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden"
tools:replace="android:screenOrientation" />

</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
@@ -7,83 +7,127 @@ import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.BeepManager;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.journeyapps.barcodescanner.BarcodeCallback;
import com.journeyapps.barcodescanner.BarcodeResult;
import com.journeyapps.barcodescanner.BarcodeView;
import com.journeyapps.barcodescanner.CaptureManager;
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
import com.journeyapps.barcodescanner.camera.CameraSettings;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Scanner;

public class MainActivity extends AppCompatActivity
{
private Button scanner;

public BeepManager beep;
public static android.support.v4.app.FragmentManager fragman;
private DecoratedBarcodeView barcodeView = null;
CaptureManager capture;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
barcodeView = (DecoratedBarcodeView) findViewById(R.id.barcode_scanner);
barcodeView.getViewFinder().setVisibility(View.VISIBLE);
barcodeView.setStatusText("");
barcodeView.getBarcodeView();

BarcodeCallback callback = new BarcodeCallback()
{
@Override
public void barcodeResult(BarcodeResult result)
{
if (result.getText() != null) {
scanner(result);
}
}

@Override
public void possibleResultPoints(List<ResultPoint> resultPoints)
{

}
};

barcodeView.decodeContinuous(callback);

//setContentView(barcodeView);
if (android.os.Build.VERSION.SDK_INT > 9)
{
StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
}

scanner = (Button) findViewById(R.id.scan);
scanner.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
scan();
}
});
scan();
@Override
protected void onResume() {
super.onResume();
barcodeView.resume();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
protected void onPause() {
super.onPause();
barcodeView.pause();
}

@Override
protected void onDestroy() {
super.onDestroy();
capture.onDestroy();
}


@Override
protected void onSaveInstanceState(Bundle outState) {
Log.d("onSaveInstanceState", "onSaveInstanceState: .");
super.onSaveInstanceState(outState);
capture.onSaveInstanceState(outState);
}

protected void scanner(BarcodeResult result)
{
beep = new BeepManager(this);
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
String resultString = result.getContents();
if (resultString != null)
if (result != null)
{
if (result.getContents() == null)
if (result.getText() == null)
{
Toast.makeText(this, "Scanning Cancelled", Toast.LENGTH_LONG).show();

}
else
{
String text = "https://ziemni.me/rwp/scanner.php?qr=" + result.getContents();
String text = "https://ziemni.me/rwp/scanner.php?qr=" + result.getText();
System.out.println(text);

String textReturn = readWeb(text.toLowerCase());
if (errorCheck(textReturn) == "Success!")
String errorCheckedText = errorCheck(textReturn);
if (errorCheckedText == "Success!")
{
beep.playBeepSound();
//beep.playBeepSound();
}
Toast.makeText(this, errorCheck(textReturn), Toast.LENGTH_LONG).show();

scan();
Toast.makeText(this, errorCheckedText, Toast.LENGTH_LONG).show();
}
}
else
{
super.onActivityResult(requestCode, resultCode, data);
}
}

public String errorCheck(String hashed)
@@ -133,19 +177,6 @@ public class MainActivity extends AppCompatActivity
return toastMessage;
}

public void scan()
{
final Activity activity = this;
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.setPrompt("");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(false);
integrator.setOrientationLocked(false);
integrator.initiateScan();
}

public String readWeb(String text)
{
try (Scanner scanner = new Scanner(new URL(text).openStream(), StandardCharsets.UTF_8.toString()))
@@ -5,18 +5,31 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="QR Scanner" />
android:id="@+id/room"
android:layout_width="match_parent"
android:layout_height="84dp"
android:text="RoomID" />

<com.journeyapps.barcodescanner.DecoratedBarcodeView
android:id="@+id/barcode_scanner"
android:text=""
android:layout_width="match_parent"
android:layout_height="327dp">

</com.journeyapps.barcodescanner.DecoratedBarcodeView>

<Button
android:id="@+id/scan"
<android.widget.TextClock
android:id="@+id/digitalClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCAN"/>
android:layout_height="84dp"
android:layout_alignParentEnd="true"
android:format12Hour="@null"
android:format24Hour="k:mm:ss"
android:textSize="48dp"
android:textStyle="bold"
android:timeZone="GMT+0000" />

</LinearLayout>
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

0 comments on commit 4a87784

Please sign in to comment.