Skip to content

Commit ddfe809

Browse files
Merge pull request #89 from SimformSolutionsPvtLtd/develop
Develop to Main
2 parents 58308d1 + da3fd49 commit ddfe809

File tree

19 files changed

+249
-51
lines changed

19 files changed

+249
-51
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![](https://jitpack.io/v/SimformSolutionsPvtLtd/SSImagePicker.svg)](https://jitpack.io/#SimformSolutionsPvtLtd/SSImagePicker)
66
[![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21)
7-
[![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.9.23-blue.svg)](https://kotlinlang.org)
7+
[![Kotlin Version](https://img.shields.io/badge/Kotlin-v2.0.21-blue.svg)](https://kotlinlang.org)
88
[![Android Weekly](https://img.shields.io/badge/Android%20Weekly-%23473-orange)](https://androidweekly.net/issues/issue-473)
99
[![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-SSImagePicker-green.svg?style=flat )]( https://android-arsenal.com/details/1/8243 )
1010

@@ -19,6 +19,7 @@ using Camera with maximum size, extension, crop, rotate, zoom and compress featu
1919
* Support for
2020
new [Photo Picker](https://developer.android.com/training/data-storage/shared/photopicker) for
2121
Android 11+.
22+
* Dark theme support.
2223

2324
# :zap: Features :
2425

@@ -36,6 +37,7 @@ using Camera with maximum size, extension, crop, rotate, zoom and compress featu
3637
* Compress image
3738
* Customize entire Image Picker screen UI with your own options and style
3839
* New Photo picker for the Android 11+.
40+
* Edge-to-Edge Support ([Refer Here](https://developer.android.com/develop/ui/views/layout/edge-to-edge))
3941

4042
# 🎬Preview
4143

@@ -94,7 +96,7 @@ using Camera with maximum size, extension, crop, rotate, zoom and compress featu
9496

9597
```kotlin
9698
dependencies {
97-
implementation("com.github.SimformSolutionsPvtLtd:SSImagePicker:2.3")
99+
implementation("com.github.SimformSolutionsPvtLtd:SSImagePicker:2.4")
98100
}
99101
```
100102

@@ -163,6 +165,7 @@ imagePicker.open(PickerType.GALLERY)
163165
.compressImage(false)
164166
.maxImageSize(2)
165167
.extension(PickExtension.JPEG)
168+
.aspectRatio(AspectRatio(16, 8))
166169
imagePicker.open(PickerType.GALLERY)
167170
```
168171

@@ -202,12 +205,13 @@ imagePicker.open(PickerType.GALLERY)
202205

203206
# :pencil: Permissions
204207

205-
**SSImagePicker** Uses following permissions to display images. For
206-
system [Photo Picker](https://developer.android.com/training/data-storage/shared/photopicker) on
207-
Android 11+ no permission is required.
208+
**SSImagePicker** handles permissions automatically and follows modern Android best practices:
208209

209-
* API **21(Android 5)** to API **32(Android 12L)**: `android.permission.READ_EXTERNAL_STORAGE`
210-
* API **33(Android 13)** onwards: `android.permission.READ_MEDIA_IMAGES`
210+
* **API 21(Android 5) to API 29(Android 10)**: Requires `android.permission.READ_EXTERNAL_STORAGE` to access gallery images
211+
* **API 30(Android 11) to API 32(Android 12L)**: You can choose between two options:
212+
- **Traditional Gallery Picker**: Requires `android.permission.READ_EXTERNAL_STORAGE`
213+
- **System Photo Picker**: Available and **requires no permissions** (recommended for better user experience)
214+
* **API 33(Android 13) and above**: Uses the system [Photo Picker](https://developer.android.com/training/data-storage/shared/photopicker) API which **requires no permissions**
211215

212216
# :rocket: Migration
213217

app/src/main/java/com/ssimagepicker/app/ExtensionsUtils.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.ssimagepicker.app
22

33
import android.os.Build
4+
import android.view.View
5+
import androidx.appcompat.app.AppCompatActivity
46
import androidx.appcompat.widget.AppCompatImageView
7+
import androidx.core.view.ViewCompat
8+
import androidx.core.view.WindowInsetsCompat
59
import com.app.imagepickerlibrary.R
610
import com.bumptech.glide.Glide
711
import com.bumptech.glide.load.engine.DiskCacheStrategy
@@ -35,6 +39,23 @@ fun AppCompatImageView.loadImage(
3539
}
3640
}
3741

42+
//If you are using custom theming and need to change the status bar color,
43+
// it may not work unless you specify a particular view object, like a toolbar.
44+
fun AppCompatActivity.enableEdgeToEdge(view: View?) {
45+
view?.let {
46+
ViewCompat.setOnApplyWindowInsetsListener(it) { view, windowInsets ->
47+
val systemBarInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
48+
view.setPadding(
49+
systemBarInsets.left,
50+
systemBarInsets.top,
51+
systemBarInsets.right,
52+
0
53+
)
54+
windowInsets
55+
}
56+
}
57+
}
58+
3859
/**
3960
* Function to check if the system is at least android 11+
4061
*/

app/src/main/java/com/ssimagepicker/app/PickerOptions.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ssimagepicker.app
22

33
import android.os.Parcelable
4+
import com.app.imagepickerlibrary.model.AspectRatio
45
import com.app.imagepickerlibrary.model.PickExtension
56
import com.app.imagepickerlibrary.model.PickerType
67
import kotlinx.parcelize.Parcelize
@@ -21,7 +22,8 @@ data class PickerOptions(
2122
val isDoneIcon: Boolean,
2223
val openCropOptions: Boolean,
2324
val openSystemPicker: Boolean,
24-
val compressImage: Boolean
25+
val compressImage: Boolean,
26+
var aspectRatio: AspectRatio?
2527
) : Parcelable {
2628
companion object {
2729
fun default(): PickerOptions {
@@ -37,7 +39,8 @@ data class PickerOptions(
3739
isDoneIcon = true,
3840
openCropOptions = false,
3941
openSystemPicker = false,
40-
compressImage = false
42+
compressImage = false,
43+
aspectRatio = null
4144
)
4245
}
4346
}

app/src/main/java/com/ssimagepicker/app/ui/LaunchActivity.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
77
import androidx.databinding.DataBindingUtil
88
import com.ssimagepicker.app.R
99
import com.ssimagepicker.app.databinding.ActivityLaunchBinding
10+
import com.ssimagepicker.app.enableEdgeToEdge
1011

1112
class LaunchActivity : AppCompatActivity(), View.OnClickListener {
1213

@@ -16,6 +17,8 @@ class LaunchActivity : AppCompatActivity(), View.OnClickListener {
1617
super.onCreate(savedInstanceState)
1718
binding = DataBindingUtil.setContentView(this, R.layout.activity_launch)
1819
binding.clickHandler = this
20+
setUpToolbar()
21+
enableEdgeToEdge(binding.toolbar.root)
1922
}
2023

2124
override fun onClick(v: View) {
@@ -32,4 +35,11 @@ class LaunchActivity : AppCompatActivity(), View.OnClickListener {
3235
private fun <T> goToScreen(activity: Class<T>) {
3336
startActivity(Intent(this, activity))
3437
}
38+
39+
private fun setUpToolbar() {
40+
binding.toolbar.apply {
41+
title = this@LaunchActivity.title.toString()
42+
imageBackButton.visibility = View.GONE
43+
}
44+
}
3545
}

app/src/main/java/com/ssimagepicker/app/ui/MainActivity.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.app.imagepickerlibrary.ui.bottomsheet.SSPickerOptionsBottomSheet
1414
import com.ssimagepicker.app.PickerOptions
1515
import com.ssimagepicker.app.R
1616
import com.ssimagepicker.app.databinding.ActivityMainBinding
17+
import com.ssimagepicker.app.enableEdgeToEdge
1718
import com.ssimagepicker.app.isAtLeast11
1819

1920
/**
@@ -40,7 +41,9 @@ class MainActivity : AppCompatActivity(), View.OnClickListener,
4041
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
4142
title = getString(R.string.activity_demo)
4243
binding.clickHandler = this
44+
setUpToolbar()
4345
setUI(savedInstanceState)
46+
enableEdgeToEdge(binding.toolbar.root)
4447
}
4548

4649
private fun setUI(savedInstanceState: Bundle?) {
@@ -121,6 +124,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener,
121124
.compressImage(pickerOptions.compressImage)
122125
.maxImageSize(pickerOptions.maxPickSizeMB)
123126
.extension(pickerOptions.pickExtension)
127+
.aspectRatio(pickerOptions.aspectRatio)
124128
if (isAtLeast11()) {
125129
imagePicker.systemPicker(pickerOptions.openSystemPicker)
126130
}
@@ -153,4 +157,13 @@ class MainActivity : AppCompatActivity(), View.OnClickListener,
153157
outState.putParcelableArrayList(IMAGE_LIST, ArrayList(imageList))
154158
super.onSaveInstanceState(outState)
155159
}
160+
161+
private fun setUpToolbar() {
162+
binding.toolbar.apply {
163+
title = this@MainActivity.title.toString()
164+
clickListener = View.OnClickListener {
165+
onBackPressedDispatcher.onBackPressed()
166+
}
167+
}
168+
}
156169
}

app/src/main/java/com/ssimagepicker/app/ui/PickerOptionsBottomSheet.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class PickerOptionsBottomSheet : BottomSheetDialogFragment(), View.OnClickListen
150150
isDoneIcon = binding.doneSwitch.isChecked,
151151
openCropOptions = binding.openCropSwitch.isChecked,
152152
openSystemPicker = binding.systemPickerSwitch.isChecked,
153-
compressImage = binding.compressImageSwitch.isChecked
153+
compressImage = binding.compressImageSwitch.isChecked,
154+
aspectRatio = null
154155
)
155156
dismiss()
156157
mListener?.onPickerOptions(pickerOptions)

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,34 @@
1313
<androidx.constraintlayout.widget.ConstraintLayout
1414
android:layout_width="match_parent"
1515
android:layout_height="match_parent"
16-
android:paddingHorizontal="@dimen/_12sdp"
1716
tools:context=".ui.LaunchActivity">
1817

18+
<include
19+
android:id="@+id/toolbar"
20+
layout="@layout/toolbar_app"
21+
app:layout_constraintEnd_toEndOf="parent"
22+
app:layout_constraintStart_toStartOf="parent"
23+
app:layout_constraintTop_toTopOf="parent" />
24+
1925
<com.google.android.material.button.MaterialButton
2026
android:id="@+id/activity_button"
2127
style="@style/ButtonSelectorStyle"
2228
android:layout_marginTop="@dimen/_6sdp"
2329
android:onClick="@{clickHandler::onClick}"
2430
android:text="@string/activity_demo"
31+
android:layout_marginStart="@dimen/_12sdp"
32+
android:layout_marginEnd="@dimen/_12sdp"
2533
app:layout_constraintEnd_toEndOf="parent"
2634
app:layout_constraintStart_toStartOf="parent"
27-
app:layout_constraintTop_toTopOf="parent" />
35+
app:layout_constraintTop_toBottomOf="@id/toolbar" />
2836

2937
<com.google.android.material.button.MaterialButton
3038
android:id="@+id/fragment_button"
3139
style="@style/ButtonSelectorStyle"
3240
android:onClick="@{clickHandler::onClick}"
3341
android:text="@string/fragment_demo"
42+
android:layout_marginStart="@dimen/_12sdp"
43+
android:layout_marginEnd="@dimen/_12sdp"
3444
app:layout_constraintEnd_toEndOf="parent"
3545
app:layout_constraintStart_toStartOf="parent"
3646
app:layout_constraintTop_toBottomOf="@id/activity_button" />

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,31 @@
1313
<androidx.constraintlayout.widget.ConstraintLayout
1414
android:layout_width="match_parent"
1515
android:layout_height="match_parent"
16-
android:paddingHorizontal="@dimen/_12sdp"
1716
tools:context=".ui.MainActivity">
1817

18+
<include
19+
android:id="@+id/toolbar"
20+
layout="@layout/toolbar_app"
21+
app:layout_constraintEnd_toEndOf="parent"
22+
app:layout_constraintStart_toStartOf="parent"
23+
app:layout_constraintTop_toTopOf="parent" />
24+
1925
<com.google.android.material.button.MaterialButton
2026
android:id="@+id/open_picker_button"
2127
android:layout_marginTop="@dimen/_6sdp"
28+
android:layout_marginStart="@dimen/_12sdp"
29+
android:layout_marginEnd="@dimen/_12sdp"
2230
style="@style/ButtonSelectorStyle"
2331
android:onClick="@{clickHandler::onClick}"
2432
android:text="@string/open_image_picker"
2533
app:layout_constraintEnd_toEndOf="parent"
2634
app:layout_constraintStart_toStartOf="parent"
27-
app:layout_constraintTop_toTopOf="parent" />
35+
app:layout_constraintTop_toBottomOf="@id/toolbar" />
2836

2937
<com.google.android.material.button.MaterialButton
3038
android:id="@+id/open_sheet_button"
39+
android:layout_marginStart="@dimen/_12sdp"
40+
android:layout_marginEnd="@dimen/_12sdp"
3141
style="@style/ButtonSelectorStyle"
3242
android:onClick="@{clickHandler::onClick}"
3343
android:text="@string/open_picker_sheet"
@@ -37,6 +47,8 @@
3747

3848
<com.google.android.material.button.MaterialButton
3949
android:id="@+id/options_button"
50+
android:layout_marginStart="@dimen/_12sdp"
51+
android:layout_marginEnd="@dimen/_12sdp"
4052
style="@style/ButtonSelectorStyle"
4153
android:onClick="@{clickHandler::onClick}"
4254
android:text="@string/customize_picker_options"
@@ -49,6 +61,8 @@
4961
android:layout_width="0dp"
5062
android:layout_height="0dp"
5163
android:layout_marginTop="@dimen/_8sdp"
64+
android:layout_marginStart="@dimen/_12sdp"
65+
android:layout_marginEnd="@dimen/_12sdp"
5266
android:clipToPadding="false"
5367
android:orientation="vertical"
5468
android:paddingBottom="@dimen/_8sdp"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
5+
<data>
6+
7+
<variable
8+
name="clickListener"
9+
type="android.view.View.OnClickListener" />
10+
11+
<variable
12+
name="title"
13+
type="String" />
14+
</data>
15+
16+
<com.google.android.material.appbar.AppBarLayout
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content">
19+
20+
<com.google.android.material.appbar.MaterialToolbar
21+
android:layout_width="match_parent"
22+
android:layout_height="?attr/actionBarSize"
23+
android:background="@color/colorPrimary"
24+
app:contentInsetEnd="0dp"
25+
app:contentInsetStart="0dp">
26+
27+
<androidx.constraintlayout.widget.ConstraintLayout
28+
android:layout_width="match_parent"
29+
android:layout_height="match_parent">
30+
31+
<androidx.appcompat.widget.AppCompatImageView
32+
android:id="@+id/image_back_button"
33+
android:layout_width="@dimen/_24sdp"
34+
android:layout_height="@dimen/_24sdp"
35+
android:layout_marginStart="@dimen/_16sdp"
36+
android:onClick="@{clickListener::onClick}"
37+
android:src="@drawable/ic_arrow_back_ios"
38+
app:layout_constraintBottom_toBottomOf="parent"
39+
app:layout_constraintStart_toStartOf="parent"
40+
app:layout_constraintTop_toTopOf="parent" />
41+
42+
<TextView
43+
android:id="@+id/text_title"
44+
android:layout_width="0dp"
45+
android:layout_height="wrap_content"
46+
android:layout_marginStart="@dimen/_32sdp"
47+
android:includeFontPadding="false"
48+
android:text="@{title}"
49+
android:textAppearance="@style/ToolbarTitleTextAppearance"
50+
app:layout_constraintBottom_toBottomOf="parent"
51+
app:layout_constraintStart_toEndOf="@id/image_back_button"
52+
app:layout_constraintTop_toTopOf="parent" />
53+
54+
</androidx.constraintlayout.widget.ConstraintLayout>
55+
</com.google.android.material.appbar.MaterialToolbar>
56+
</com.google.android.material.appbar.AppBarLayout>
57+
</layout>

app/src/main/res/values-night/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
<color name="color_text">#FFFFFF</color>
44
<color name="color_bottom_sheet_bg">#222222</color>
55
<color name="button_stroke_color">@color/black</color>
6+
<color name="no_content_text_color">@color/white</color>
7+
<color name="picker_background">@color/white</color>
68
</resources>

0 commit comments

Comments
 (0)