diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2ac5f2d..80dceec 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,15 +1,21 @@ - - - - + + + + + + + + + + android:value="barcode_ui"> + + + \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt index 99c0547..b490195 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AbstractProductView.kt @@ -2,10 +2,15 @@ package org.foxarmy.barcodescannerforemployees import android.app.Activity import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.util.Log import android.view.LayoutInflater import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.ContextCompat.startActivity import java.io.File class AbstractProductView: LinearLayout { @@ -15,7 +20,7 @@ class AbstractProductView: LinearLayout { private var categoryField: TextView private var unitField: TextView - constructor(activity: Activity, context: Context, productImageFile: String, productName: String, netWeight: Double, category: Int) : super(context) { + constructor(activity: Activity, context: Context, productImageHash: String, productName: String, netWeight: Double, category: Int) : super(context) { val inflater:LayoutInflater = activity.layoutInflater inflater.inflate(R.layout.abstract_product_view, this) @@ -26,14 +31,31 @@ class AbstractProductView: LinearLayout { categoryField = findViewById(R.id.categoryView) unitField = findViewById(R.id.unitView) - val picturesDir = File(context.filesDir, "pictures") - picturesDir.mkdirs() - val imageUri = getImageUri(activity, File(picturesDir, productImageFile)) - + val thumbnailsDir = File(context.cacheDir, "thumbnails") + thumbnailsDir.mkdirs() + val imageUri = getImageUri(activity, File(thumbnailsDir, "$productImageHash.webp")) + Log.d("QWERTYUIOP", "${productPicture.minimumWidth}x${productPicture.minimumHeight}") productPicture.setImageURI(imageUri) + productPicture.rotation = 90f + productPicture.setOnClickListener { + Log.d("QWERTYUIOP", productImageHash) + val fullscreenIntent = Intent(activity, FullscreenActivity::class.java) + val extras = Bundle() + extras.putString("imagehash", productImageHash) + fullscreenIntent.putExtras(extras) + startActivity(context, fullscreenIntent, extras) + } + productNameField.text = productName netWeightField.text = netWeight.toString() + //TODO: category and units + + findViewById(R.id.productLayout).setOnClickListener { + Log.d("QWERTYUIOP", "Clicked layout") + } + } + } \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AddProductFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AddProductFragment.kt index 988dfd1..c962c08 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/AddProductFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/AddProductFragment.kt @@ -1,6 +1,8 @@ package org.foxarmy.barcodescannerforemployees import android.content.ContentValues +import android.graphics.Bitmap +import android.graphics.BitmapFactory import android.os.Build import android.os.Bundle import android.util.Log @@ -10,6 +12,7 @@ import android.view.ViewGroup import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.RequiresApi +import androidx.core.graphics.scale import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import com.google.mlkit.vision.barcode.common.Barcode @@ -17,6 +20,7 @@ import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions import com.google.mlkit.vision.codescanner.GmsBarcodeScanning import org.foxarmy.barcodescannerforemployees.databinding.AddProductFragmentBinding import java.io.File +import java.io.FileOutputStream import java.nio.file.Files import java.nio.file.StandardCopyOption @@ -40,12 +44,20 @@ class AddProductFragment : Fragment() { return binding.root } - @RequiresApi(Build.VERSION_CODES.O) + @RequiresApi(Build.VERSION_CODES.R) val takePicture = registerForActivityResult(ActivityResultContracts.TakePicture()) { success: Boolean -> if (success) { //Move picture to a proper directory according to its calculated hash val tempfile = File(requireContext().filesDir, "image.png") - val imageHash = tempfile.inputStream().readBytes().toString(Charsets.UTF_8).md5() + val imageContent = tempfile.inputStream().readBytes() + val imageHash = imageContent.toString(Charsets.UTF_8).md5() + val thumbnailsDir = File(requireContext().cacheDir, "thumbnails") + thumbnailsDir.mkdirs() + val thumbnailFile = File(thumbnailsDir, "$imageHash.webp") + var img = BitmapFactory.decodeByteArray(imageContent, 0, imageContent.size) + img = img.scale(img.width/4,img.height/4) + img.compress(Bitmap.CompressFormat.WEBP_LOSSY, 25, FileOutputStream(thumbnailFile)) + pictureFile = File(picturesPath, "$imageHash.png") Files.move(tempfile.toPath(), pictureFile.toPath(), StandardCopyOption.REPLACE_EXISTING) tempfile.delete() @@ -56,7 +68,7 @@ class AddProductFragment : Fragment() { } } - @RequiresApi(Build.VERSION_CODES.O) + @RequiresApi(Build.VERSION_CODES.R) fun getPicture () { //Saving picture to a temp file for further hash calculation and moving to a proper directory val imageFile = File(requireContext().filesDir, "image.png") @@ -67,7 +79,7 @@ class AddProductFragment : Fragment() { takePicture.launch(imageUri) } - @RequiresApi(Build.VERSION_CODES.O) + @RequiresApi(Build.VERSION_CODES.R) val requestPermissionLauncher = registerForActivityResult( ActivityResultContracts.RequestPermission() @@ -104,7 +116,7 @@ class AddProductFragment : Fragment() { val values = ContentValues().apply { put(ProductContract.ProductEntry.PRODUCT_NAME, productName) put(ProductContract.ProductEntry.PRODUCT_NET_WEIGHT, netWeight.toString()) - put(ProductContract.ProductEntry.IMAGE_FILENAME, pictureFile.name) + put(ProductContract.ProductEntry.IMAGE_FILENAME, pictureFile.nameWithoutExtension) } db.insert(ProductContract.ProductEntry.TABLE_NAME, null, values) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/FullscreenActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/FullscreenActivity.kt new file mode 100644 index 0000000..f893817 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/FullscreenActivity.kt @@ -0,0 +1,43 @@ +package org.foxarmy.barcodescannerforemployees + +import android.app.Activity +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.util.Log +import android.widget.ImageView +import android.widget.LinearLayout +import org.foxarmy.barcodescannerforemployees.databinding.ActivityFullscreenBinding +import java.io.File + + +class FullscreenActivity : Activity() { + + private lateinit var binding: ActivityFullscreenBinding + private lateinit var fullscreenImageView: ImageView + private lateinit var fullscreenContentControls: LinearLayout + private val hideHandler = Handler(Looper.myLooper()!!) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.activity_fullscreen) + + fullscreenImageView = findViewById(R.id.fullscreenImageView) + + val extras = intent.extras + val imageHash = extras!!.get("imagehash") as String? //extras!!.getParcelable("imagehash") as String? + + + val picturesDir = File(filesDir, "pictures") + picturesDir.mkdirs() + Log.d("QWERTYUIOP", imageHash.toString()) + val fullscreenImageFile = File(picturesDir, "$imageHash.png") + // crash. change activity + fullscreenImageView.setImageURI(getImageUri(this, fullscreenImageFile)) + fullscreenImageView.setOnClickListener { + this.finish() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageFragment.kt index 3eb9e39..fcb5c13 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageFragment.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageFragment.kt @@ -2,6 +2,7 @@ package org.foxarmy.barcodescannerforemployees import android.os.Bundle import android.provider.BaseColumns +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -39,18 +40,22 @@ class StorageFragment : Fragment() { while(moveToNext()) { val productName = getString(getColumnIndexOrThrow(ProductContract.ProductEntry.PRODUCT_NAME)) val netWeight = getDouble(getColumnIndexOrThrow(ProductContract.ProductEntry.PRODUCT_NET_WEIGHT)) - val pictureFilename = getString(getColumnIndexOrThrow(ProductContract.ProductEntry.IMAGE_FILENAME)) + val productImageHash = getString(getColumnIndexOrThrow(ProductContract.ProductEntry.IMAGE_FILENAME)) - getView()?.findViewById(R.id.contentGridLayout)?.addView( - AbstractProductView( - requireActivity(), - requireContext(), - productImageFile = pictureFilename, - productName = productName, - netWeight = netWeight, - category = 1 - ) + + val abstractProduct = AbstractProductView( + requireActivity(), + requireContext(), + productImageHash, + productName, + netWeight, + 1 ) + getView()?.findViewById(R.id.contentGridLayout)?.addView(abstractProduct) + + abstractProduct.setOnClickListener { + Log.d("QWERTYUIOP", "Clicked view") + } // getView()?.findViewById(R.id.contentGridLayout)? } } diff --git a/app/src/main/res/layout/abstract_product_view.xml b/app/src/main/res/layout/abstract_product_view.xml index 9b63247..25ecef8 100644 --- a/app/src/main/res/layout/abstract_product_view.xml +++ b/app/src/main/res/layout/abstract_product_view.xml @@ -2,14 +2,15 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="200dp" - android:layout_height="200dp"> + android:layout_height="wrap_content" app:barrierMargin="1dp" android:clickable="false"> + android:layout_height="wrap_content" android:id="@+id/productLayout" android:outlineProvider="bounds" + android:background="#00FFFEFE" android:clickable="true"> @@ -19,8 +20,8 @@ android:layout_height="wrap_content" android:id="@+id/productNameView" app:layout_constraintTop_toBottomOf="@+id/productPicture" android:layout_marginTop="15dp" app:layout_constraintStart_toStartOf="parent" - android:layout_marginStart="25dp" android:fontFamily="monospace" android:textSize="20sp" - android:maxLines="2"/> + android:fontFamily="monospace" android:textSize="20sp" + android:maxLines="2" android:layout_marginStart="10dp"/> diff --git a/app/src/main/res/layout/activity_fullscreen.xml b/app/src/main/res/layout/activity_fullscreen.xml new file mode 100644 index 0000000..7ded621 --- /dev/null +++ b/app/src/main/res/layout/activity_fullscreen.xml @@ -0,0 +1,21 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 2164831..5a5e1bb 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -4,4 +4,6 @@ + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index e2337bb..db762c3 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -6,4 +6,8 @@ #FF039BE5 #FFBDBDBD #FF757575 + #FF01579B + #FF40C4FF + #FF00B0FF + #66000000 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0951f0e..2445f7a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,4 +17,8 @@ 1998 g Sample category + FullscreenActivity + Dummy Button + DUMMY\nCONTENT + Fullscreen image \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index cfdf948..682066f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,4 +3,12 @@ @color/gray_400 @color/light_blue_400 + + + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index a555978..6479b56 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -6,4 +6,12 @@ + + \ No newline at end of file