summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.idea/deploymentTargetDropDown.xml17
-rw-r--r--app/build.gradle9
-rw-r--r--app/src/main/AndroidManifest.xml5
-rw-r--r--app/src/main/java/com/jopek/lectordecodi/MainActivity.java7
-rw-r--r--app/src/main/java/com/jopek/lectordecodi/ui/barcode_gen/BarcodeGenFragment.java27
-rw-r--r--app/src/main/java/com/jopek/lectordecodi/ui/reader/ReaderFragment.java46
-rw-r--r--app/src/main/res/layout/fragment_barcode_gen.xml36
-rw-r--r--app/src/main/res/layout/fragment_reader.xml33
8 files changed, 152 insertions, 28 deletions
diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 0000000..c5171d1
--- /dev/null
+++ b/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="deploymentTargetDropDown">
+ <runningDeviceTargetSelectedWithDropDown>
+ <Target>
+ <type value="RUNNING_DEVICE_TARGET" />
+ <deviceKey>
+ <Key>
+ <type value="SERIAL_NUMBER" />
+ <value value="290c726c731c7ece" />
+ </Key>
+ </deviceKey>
+ </Target>
+ </runningDeviceTargetSelectedWithDropDown>
+ <timeTargetWasSelectedWithDropDown value="2022-09-22T09:40:42.975900Z" />
+ </component>
+</project> \ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index e945c07..4e93c0c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -36,12 +36,13 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
- implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
+ implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
api "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
- implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
- implementation 'androidx.navigation:navigation-fragment:2.3.5'
- implementation 'androidx.navigation:navigation-ui:2.3.5'
+ implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
+ implementation 'androidx.navigation:navigation-fragment:2.5.2'
+ implementation 'androidx.navigation:navigation-ui:2.5.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
+ implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
} \ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index deb8751..56d55cb 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,6 +11,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.LectorDeCodi"
+ android:hardwareAccelerated="true"
tools:targetApi="31">
<activity
android:name=".MainActivity"
@@ -23,6 +24,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity
+ android:name="com.journeyapps.barcodescanner.CaptureActivity"
+ android:screenOrientation="fullSensor"
+ tools:replace="screenOrientation" />
</application>
</manifest> \ No newline at end of file
diff --git a/app/src/main/java/com/jopek/lectordecodi/MainActivity.java b/app/src/main/java/com/jopek/lectordecodi/MainActivity.java
index f40a08f..95cfb87 100644
--- a/app/src/main/java/com/jopek/lectordecodi/MainActivity.java
+++ b/app/src/main/java/com/jopek/lectordecodi/MainActivity.java
@@ -29,13 +29,6 @@ public class MainActivity extends AppCompatActivity {
setContentView(binding.getRoot());
setSupportActionBar(binding.appBarMain.toolbar);
- //binding.appBarMain.fab.setOnClickListener(new View.OnClickListener() {
- // @Override
- // public void onClick(View view) {
- // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
- // .setAction("Action", null).show();
- // }
- //});
DrawerLayout drawer = binding.drawerLayout;
NavigationView navigationView = binding.navView;
// Passing each menu ID as a set of Ids because each
diff --git a/app/src/main/java/com/jopek/lectordecodi/ui/barcode_gen/BarcodeGenFragment.java b/app/src/main/java/com/jopek/lectordecodi/ui/barcode_gen/BarcodeGenFragment.java
index e087d5e..7ccda24 100644
--- a/app/src/main/java/com/jopek/lectordecodi/ui/barcode_gen/BarcodeGenFragment.java
+++ b/app/src/main/java/com/jopek/lectordecodi/ui/barcode_gen/BarcodeGenFragment.java
@@ -1,20 +1,30 @@
package com.jopek.lectordecodi.ui.barcode_gen;
+import android.graphics.Bitmap;
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.EditText;
+import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
+import com.google.zxing.BarcodeFormat;
import com.jopek.lectordecodi.databinding.FragmentBarcodeGenBinding;
+import com.journeyapps.barcodescanner.BarcodeEncoder;
public class BarcodeGenFragment extends Fragment {
private FragmentBarcodeGenBinding binding;
+ private EditText etInput;
+ private ImageView img;
+ private Button btnGen;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
@@ -24,8 +34,21 @@ public class BarcodeGenFragment extends Fragment {
binding = FragmentBarcodeGenBinding.inflate(inflater, container, false);
View root = binding.getRoot();
- final TextView textView = binding.textGallery;
- barcodeGenViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
+ etInput = binding.plainTextInput;
+ img = binding.barcodeImg;
+ btnGen = binding.btnGenBarcode;
+
+ btnGen.setOnClickListener(v -> {
+ try {
+ BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
+ Bitmap bitmap = barcodeEncoder.encodeBitmap(String.valueOf(etInput.getText()), BarcodeFormat.EAN_13, 400, 400);
+ Log.d("maks", "onCreateView: " + bitmap);
+ img.setImageBitmap(bitmap);
+ } catch(Exception e) {
+
+ }
+ });
+
return root;
}
diff --git a/app/src/main/java/com/jopek/lectordecodi/ui/reader/ReaderFragment.java b/app/src/main/java/com/jopek/lectordecodi/ui/reader/ReaderFragment.java
index c0a7237..87d9615 100644
--- a/app/src/main/java/com/jopek/lectordecodi/ui/reader/ReaderFragment.java
+++ b/app/src/main/java/com/jopek/lectordecodi/ui/reader/ReaderFragment.java
@@ -1,20 +1,44 @@
package com.jopek.lectordecodi.ui.reader;
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
import android.widget.TextView;
+import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
+import com.jopek.lectordecodi.R;
import com.jopek.lectordecodi.databinding.FragmentReaderBinding;
+import com.journeyapps.barcodescanner.ScanContract;
+import com.journeyapps.barcodescanner.ScanOptions;
public class ReaderFragment extends Fragment {
private FragmentReaderBinding binding;
+ private final String TAG = "maks";
+ private TextView tvRead;
+ private Button bStartRead;
+ private Button bCopyCode;
+ private String readCode = "";
+
+ // Register the launcher and result handler
+ private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
+ result -> {
+ if(result.getContents() == null) {
+ tvRead.setText("Reading code failed");
+ } else {
+ readCode = result.getContents();
+ tvRead.setText("Readed: " + readCode);
+ }
+ });
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
@@ -24,9 +48,25 @@ public class ReaderFragment extends Fragment {
binding = FragmentReaderBinding.inflate(inflater, container, false);
View root = binding.getRoot();
- binding.textHome2.setText("Tescik Home2");
- final TextView textView = binding.textHome;
- readerViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
+ tvRead = root.findViewById(R.id.read_from_code);
+ bStartRead = root.findViewById(R.id.start_read);
+ bCopyCode = root.findViewById(R.id.copy_read_from_code);
+
+ bStartRead.setOnClickListener(view -> {
+ ScanOptions options = new ScanOptions();
+ options.setDesiredBarcodeFormats(ScanOptions.ALL_CODE_TYPES);
+ options.setPrompt("Scan a QbaRCode");
+ options.setCameraId(0); // Use a specific camera of the device
+ options.setBeepEnabled(false);
+ options.setBarcodeImageEnabled(true);
+ options.setOrientationLocked(false);
+ barcodeLauncher.launch(options);
+ });
+ bCopyCode.setOnClickListener(view -> {
+ ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
+ ClipData clip = ClipData.newPlainText("label", readCode);
+ clipboard.setPrimaryClip(clip);
+ });
return root;
}
diff --git a/app/src/main/res/layout/fragment_barcode_gen.xml b/app/src/main/res/layout/fragment_barcode_gen.xml
index 8c9c474..caec265 100644
--- a/app/src/main/res/layout/fragment_barcode_gen.xml
+++ b/app/src/main/res/layout/fragment_barcode_gen.xml
@@ -7,9 +7,43 @@
tools:context=".ui.barcode_gen.BarcodeGenFragment">
<TextView
- android:id="@+id/text_gallery"
+ android:id="@id/plain_text_input_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:text="Gimme text to encode in barcode"
+ android:textAlignment="center"
+ android:layout_marginTop="40dp"
+ android:textSize="20sp"
+ app:layout_constraintStart_toEndOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+ <EditText
+ android:labelFor="@+id/plain_text_input_label"
+ android:id="@+id/plain_text_input"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="text"
+ android:layout_marginTop="80dp"
+ app:layout_constraintStart_toEndOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+ <Button
+ android:id="@+id/btn_gen_barcode"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Generate Barcode"
+ android:layout_marginTop="160dp"
+ app:layout_constraintStart_toEndOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <ImageView
+ android:id="@+id/barcode_img"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
diff --git a/app/src/main/res/layout/fragment_reader.xml b/app/src/main/res/layout/fragment_reader.xml
index 7b27f13..7a0c900 100644
--- a/app/src/main/res/layout/fragment_reader.xml
+++ b/app/src/main/res/layout/fragment_reader.xml
@@ -6,27 +6,38 @@
android:layout_height="match_parent"
tools:context=".ui.reader.ReaderFragment">
- <TextView
- android:id="@+id/text_home2"
- android:layout_width="match_parent"
+ <Button
+ android:id="@+id/start_read"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginTop="8dp"
- android:layout_marginEnd="8dp"
+ android:layout_marginTop="80dp"
+ app:layout_constraintStart_toEndOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
- android:textAlignment="center"
- android:textSize="20sp" />
+ android:text="Scan QbaRCode"/>
<TextView
- android:id="@+id/text_home"
+ android:id="@+id/read_from_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
- android:textSize="20sp"
+ android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
+ app:layout_constraintTop_toTopOf="parent"
+ />
+ <Button
+ android:id="@+id/copy_read_from_code"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="80dp"
+ app:layout_constraintStart_toEndOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ android:text="Copy"/>
</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file