diff --git a/app/src/main/java/com/example/android_hit/FragmentTwibbon.kt b/app/src/main/java/com/example/android_hit/FragmentTwibbon.kt index 57272afd5544051085322b46fae2139095c5c381..e9ef312d09be3df64e12ac5720c756913bcc63c9 100644 --- a/app/src/main/java/com/example/android_hit/FragmentTwibbon.kt +++ b/app/src/main/java/com/example/android_hit/FragmentTwibbon.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.content.IntentFilter +import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.ImageFormat @@ -95,9 +96,14 @@ class FragmentTwibbon : Fragment() { val buffer = image.planes[0].buffer val bytes = ByteArray(buffer.remaining()) buffer.get(bytes) - val bitmap = BitmapFactory.decodeByteArray(bytes,0,bytes.size) - val rotatebitmap = rotateBitmap(bitmap) - displayCapturedImage(rotatebitmap) + var bitmap = BitmapFactory.decodeByteArray(bytes,0,bytes.size) + val orientation = resources.configuration.orientation + if(orientation == Configuration.ORIENTATION_PORTRAIT){ + bitmap = rotateBitmap90(bitmap) + }else{ + bitmap = rotateBitmap180(bitmap) + } + displayCapturedImage(bitmap) image.close() cameraProvider.unbindAll() } @@ -131,11 +137,16 @@ class FragmentTwibbon : Fragment() { binding.imageView.visibility = View.VISIBLE } - fun rotateBitmap(bitmap: Bitmap): Bitmap { + fun rotateBitmap90(bitmap: Bitmap): Bitmap { val matrix = Matrix() matrix.postRotate(90f) return Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true) } + fun rotateBitmap180(bitmap: Bitmap): Bitmap { + val matrix = Matrix() + matrix.postRotate(180f) + return Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true) + } override fun onDestroyView() { super.onDestroyView() _binding = null diff --git a/app/src/main/res/layout-land/fragment_twibbon.xml b/app/src/main/res/layout-land/fragment_twibbon.xml new file mode 100644 index 0000000000000000000000000000000000000000..723cced1c5ab4383714bb57a5432e8f95627f87f --- /dev/null +++ b/app/src/main/res/layout-land/fragment_twibbon.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent" + android:layout_height="match_parent" + tools:context=".FragmentTwibbon"> + + + <FrameLayout + android:id="@+id/frameLayout" + android:layout_width="300dp" + android:layout_height="300dp" + android:layout_marginEnd="24dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + <androidx.camera.view.PreviewView + android:id="@+id/previewView" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + + <ImageView + android:id="@+id/imageView" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:scaleType="centerCrop" + android:visibility="gone" /> + + <ImageView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:src="@drawable/twibbon_frame" /> + </FrameLayout> + + <ImageButton + android:id="@+id/capture" + android:layout_width="60sp" + android:layout_height="60sp" + android:layout_alignParentBottom="true" + android:layout_centerHorizontal="true" + android:background="?attr/selectableItemBackgroundBorderless" + android:scaleType="centerCrop" + android:src="@drawable/rounded_button" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/frameLayout" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + + <ImageButton + android:id="@+id/retakeButton" + android:layout_width="60sp" + android:layout_height="60sp" + android:layout_alignParentBottom="true" + android:background="?attr/selectableItemBackgroundBorderless" + android:src="@drawable/baseline_refresh_24" + android:visibility="gone" + app:layout_constraintEnd_toStartOf="@+id/frameLayout" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toBottomOf="@id/capture"/> + + +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_twibbon.xml b/app/src/main/res/layout/fragment_twibbon.xml index 2dd0881ffe8cf9583e06bf3dcb6b910b39695760..df0b146dd85a6501b71d6d92a8a3472b42024c08 100644 --- a/app/src/main/res/layout/fragment_twibbon.xml +++ b/app/src/main/res/layout/fragment_twibbon.xml @@ -9,11 +9,12 @@ <FrameLayout android:id="@+id/frameLayout" - android:layout_width="match_parent" - android:layout_height="500dp" + android:layout_width="400dp" + android:layout_height="400dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"> + app:layout_constraintTop_toTopOf="parent" + android:layout_marginTop="30dp"> <androidx.camera.view.PreviewView android:id="@+id/previewView" @@ -30,7 +31,7 @@ <ImageView android:layout_width="match_parent" android:layout_height="match_parent" - android:src="@drawable/twibbon" /> + android:src="@drawable/twibbon_frame" /> </FrameLayout> <ImageButton