Skip to content

Commit 025dd18

Browse files
committed
pinch zoom, flash, enhancement
1 parent e507023 commit 025dd18

10 files changed

Lines changed: 351 additions & 88 deletions

File tree

.idea/misc.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GeoTagImage/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ android {
2727
}
2828
}
2929

30+
buildFeatures {
31+
viewBinding = true
32+
}
33+
3034
compileOptions {
3135
sourceCompatibility JavaVersion.VERSION_17
3236
targetCompatibility JavaVersion.VERSION_17

GeoTagImage/src/main/java/com/dangiashish/GeoTagImage.kt

Lines changed: 213 additions & 79 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M3,2v12h3v9l7,-12L9,11l4,-9L3,2zM19,2h-2l-3.2,9h1.9l0.7,-2h3.2l0.7,2h1.9L19,2zM16.85,7.65L18,4l1.15,3.65h-2.3z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M3.27,3L2,4.27l5,5V13h3v9l3.58,-6.14L17.73,20 19,18.73 3.27,3zM17,10h-4l4,-8H7v2.18l8.46,8.46L17,10z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M7,2v11h3v9l7,-12h-4l4,-8z"/>
4+
5+
</vector>

GeoTagImage/src/main/res/layout/camera_layout.xml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
android:id="@+id/cameraContainer"
2828
android:layout_width="match_parent"
2929
android:layout_height="match_parent"
30+
android:fitsSystemWindows="true"
3031
android:background="#000">
3132

3233
<androidx.camera.view.PreviewView
@@ -35,9 +36,32 @@
3536
app:layout_constraintTop_toTopOf="parent"
3637
app:layout_constraintBottom_toBottomOf="parent"
3738
android:id="@+id/previewView"
39+
android:layout_width="0dp"
40+
android:layout_height="0dp"
41+
/>
42+
43+
<androidx.appcompat.widget.LinearLayoutCompat
44+
android:padding="20dp"
3845
android:layout_width="match_parent"
3946
android:layout_height="wrap_content"
40-
android:scaleType="fitCenter" />
47+
android:orientation="horizontal"
48+
app:layout_constraintStart_toStartOf="parent"
49+
app:layout_constraintEnd_toEndOf="parent"
50+
app:layout_constraintTop_toTopOf="parent"
51+
>
52+
53+
54+
<androidx.appcompat.widget.AppCompatImageView
55+
android:layout_width="wrap_content"
56+
android:layout_height="wrap_content"
57+
android:id="@+id/ivFlash"
58+
app:srcCompat="@drawable/baseline_flash_off_24"
59+
android:tint="@android:color/white"
60+
61+
/>
62+
63+
64+
</androidx.appcompat.widget.LinearLayoutCompat>
4165

4266
<LinearLayout
4367
android:orientation="vertical"
@@ -49,7 +73,6 @@
4973
android:paddingHorizontal="100dp"
5074
android:paddingBottom="15dp"
5175
android:layout_height="wrap_content"
52-
android:layout_alignParentBottom="true"
5376
>
5477

5578
<TextView
@@ -86,16 +109,14 @@
86109
android:layout_marginBottom="40dp"
87110
android:background="@android:color/transparent"
88111
android:src="@drawable/outline_close_24"
89-
android:tint="@android:color/white"
90-
android:layout_gravity="bottom|start" />
112+
android:tint="@android:color/white" />
91113

92114
<androidx.appcompat.widget.AppCompatImageView
93115
app:layout_constraintBottom_toBottomOf="parent"
94116
app:layout_constraintEnd_toEndOf="parent"
95117
android:id="@+id/btnFlip"
96118
android:layout_width="40dp"
97119
android:layout_height="40dp"
98-
android:layout_gravity="bottom|end"
99120
android:layout_marginBottom="40dp"
100121
android:layout_marginEnd="30dp"
101122
android:background="@android:color/transparent"
@@ -109,7 +130,6 @@
109130
android:id="@+id/btnCapture"
110131
android:layout_width="80dp"
111132
android:layout_height="80dp"
112-
android:layout_gravity="bottom|center_horizontal"
113133
android:layout_marginBottom="30dp">
114134

115135
<View

app/src/main/java/com/codebyashish/geotagimage/demo/BlankFragment.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ class BlankFragment : Fragment(), PermissionCallback {
9393
// initialize the GeoTagImage class object with context and callback
9494
geoTagImage = GeoTagImage(mContext as AppCompatActivity, permissionLauncher, cameraLauncher)
9595
geoTagImage.requestCameraAndLocationPermissions()
96-
geoTagImage.enableCameraX(false)
96+
97+
98+
99+
97100

98101
binding.ivCamera.setOnClickListener {
99102
geoTagImage.launchCamera(

app/src/main/java/com/codebyashish/geotagimage/demo/MainActivity.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import android.util.Log
3838
import android.view.View
3939
import android.widget.Toast
4040
import androidx.activity.addCallback
41+
import androidx.activity.enableEdgeToEdge
4142
import androidx.activity.result.ActivityResultLauncher
4243
import androidx.activity.result.contract.ActivityResultContracts
4344
import androidx.appcompat.app.AppCompatActivity
@@ -103,7 +104,6 @@ class MainActivity : AppCompatActivity(), PermissionCallback {
103104
// initialize the GeoTagImage class object with context and callback
104105
geoTagImage = GeoTagImage(this, permissionLauncher, cameraLauncher)
105106
geoTagImage.requestCameraAndLocationPermissions()
106-
geoTagImage.enableCameraX(false)
107107

108108

109109
// setOnClickListener on camera button.
@@ -205,6 +205,28 @@ class MainActivity : AppCompatActivity(), PermissionCallback {
205205
}
206206
}
207207

208+
binding.toggleCameraRatio.check(R.id.button_rat_2)
209+
binding.toggleCameraRatio.addOnButtonCheckedListener { group, checkedId, isChecked ->
210+
if (isChecked) {
211+
when (checkedId) {
212+
R.id.button_rat_1 -> {
213+
geoTagImage.setCameraAspectRatio(GeoTagImage.RATIO_1X1)
214+
}
215+
R.id.button_rat_2 -> {
216+
geoTagImage.setCameraAspectRatio(GeoTagImage.RATIO_4X3)
217+
}
218+
R.id.button_rat_3 -> {
219+
geoTagImage.setCameraAspectRatio(GeoTagImage.RATIO_16X9)
220+
}
221+
R.id.button_rat_4 -> {
222+
geoTagImage.setCameraAspectRatio(GeoTagImage.RATIO_FULL)
223+
}
224+
}
225+
}
226+
}
227+
228+
229+
208230
binding.toggleCamera.addOnButtonCheckedListener { group, checkedId, isChecked ->
209231
if (isChecked) {
210232
when (checkedId) {

app/src/main/res/layout/activity_main.xml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,72 @@
515515

516516
</com.google.android.material.card.MaterialCardView>
517517

518+
<!-- CardView for camera ratio -->
519+
<com.google.android.material.card.MaterialCardView
520+
android:layout_width="match_parent"
521+
android:layout_height="wrap_content"
522+
android:padding="8dp"
523+
app:cardUseCompatPadding="true">
524+
525+
<LinearLayout
526+
android:layout_width="match_parent"
527+
android:layout_height="wrap_content"
528+
android:orientation="vertical"
529+
android:padding="5dp">
530+
531+
<androidx.appcompat.widget.AppCompatTextView
532+
android:layout_width="wrap_content"
533+
android:layout_height="wrap_content"
534+
android:layout_margin="3dp"
535+
android:text="Set Camera Ratio : "
536+
android:textStyle="bold" />
537+
538+
<com.google.android.material.button.MaterialButtonToggleGroup
539+
android:id="@+id/toggle_camera_ratio"
540+
android:layout_width="match_parent"
541+
android:layout_height="0dp"
542+
android:layout_gravity="end"
543+
android:layout_weight="1"
544+
app:selectionRequired="true"
545+
app:singleSelection="true">
546+
547+
<com.google.android.material.button.MaterialButton
548+
android:id="@+id/button_rat_1"
549+
style="@style/Widget.Material3.Button.OutlinedButton"
550+
android:layout_width="wrap_content"
551+
android:layout_height="wrap_content"
552+
android:text="1:1"
553+
android:textSize="12sp" />
554+
555+
<com.google.android.material.button.MaterialButton
556+
android:id="@+id/button_rat_2"
557+
style="@style/Widget.Material3.Button.OutlinedButton"
558+
android:layout_width="wrap_content"
559+
android:layout_height="wrap_content"
560+
android:text="4:3"
561+
android:textSize="12sp" />
562+
563+
<com.google.android.material.button.MaterialButton
564+
android:id="@+id/button_rat_3"
565+
style="@style/Widget.Material3.Button.OutlinedButton"
566+
android:layout_width="wrap_content"
567+
android:layout_height="wrap_content"
568+
android:text="16:9"
569+
android:textSize="12sp" />
570+
571+
<com.google.android.material.button.MaterialButton
572+
android:id="@+id/button_rat_4"
573+
style="@style/Widget.Material3.Button.OutlinedButton"
574+
android:layout_width="wrap_content"
575+
android:layout_height="wrap_content"
576+
android:text="Full"
577+
android:textSize="12sp" />
578+
</com.google.android.material.button.MaterialButtonToggleGroup>
579+
580+
</LinearLayout>
581+
582+
</com.google.android.material.card.MaterialCardView>
583+
518584
</LinearLayout>
519585

520586
<androidx.appcompat.widget.AppCompatButton

0 commit comments

Comments
 (0)