Skip to content

Commit 3fbdc98

Browse files
authored
Merge pull request #131 from Mindinventory/develop
v1.4.3(31) Edge-to-edge support for android 15
2 parents 700cd88 + d3dd49b commit 3fbdc98

File tree

9 files changed

+83
-12
lines changed

9 files changed

+83
-12
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ plugins {
99

1010
android {
1111
namespace 'com.lassi.app'
12-
compileSdk 34
12+
compileSdk 35
1313
defaultConfig {
1414
applicationId "com.lassi.app"
1515
minSdk 21
16-
targetSdk 34
16+
targetSdk 35
1717
versionCode 1
1818
versionName "1.0"
1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

app/src/main/java/com/lassi/app/MainActivity.kt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import com.lassi.presentation.common.decoration.GridSpacingItemDecoration
2626
import com.lassi.presentation.cropper.CropImageView
2727
import java.io.File
2828
import java.util.Locale
29+
import androidx.core.net.toUri
30+
import androidx.core.view.ViewCompat
31+
import androidx.core.view.WindowCompat
32+
import androidx.core.view.WindowInsetsCompat
33+
import androidx.core.view.WindowInsetsControllerCompat
2934

3035
class MainActivity : AppCompatActivity(), View.OnClickListener {
3136
private var _binding: ActivityMainBinding? = null
@@ -35,9 +40,28 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
3540

3641
override fun onCreate(savedInstanceState: Bundle?) {
3742
super.onCreate(savedInstanceState)
43+
44+
// this thing ensures that the padding removed for the edge-to-edge support is not overridden again
45+
WindowCompat.setDecorFitsSystemWindows(window, false)
46+
47+
// this thing adds the black color to the text of status bar.
48+
WindowInsetsControllerCompat(window, window.decorView)
49+
.isAppearanceLightStatusBars = true
50+
3851
_binding = ActivityMainBinding.inflate(layoutInflater)
3952
binding.also {
4053
setContentView(it.root)
54+
// Apply system bar padding to root layout
55+
ViewCompat.setOnApplyWindowInsetsListener(it.root) { view, insets ->
56+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
57+
view.setPadding(
58+
view.paddingLeft,
59+
systemBars.top, // top padding for status bar
60+
view.paddingRight,
61+
systemBars.bottom // bottom padding for nav bar
62+
)
63+
insets
64+
}
4165
it.btnImagePicker.setOnClickListener(this)
4266
it.btnVideoPicker.setOnClickListener(this)
4367
it.btnAudioPicker.setOnClickListener(this)
@@ -337,9 +361,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
337361
try {
338362
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
339363
intent.addCategory("android.intent.category.DEFAULT")
340-
intent.data = Uri.parse(
341-
String.format("package:%s", applicationContext?.packageName)
342-
)
364+
intent.data =
365+
String.format("package:%s", applicationContext?.packageName).toUri()
343366
mPermissionSettingResult.launch(intent)
344367
} catch (e: Exception) {
345368
val intent = Intent()

lassi/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ group='com.github.Mindinventory'
1010

1111
android {
1212
namespace 'com.lassi'
13-
compileSdk 34
13+
compileSdk 35
1414
defaultConfig {
1515
minSdk 21
16-
targetSdk 34
17-
versionCode 30
18-
versionName "1.4.2"
16+
targetSdk 35
17+
versionCode 31
18+
versionName "1.4.3"
1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2020
vectorDrawables.useSupportLibrary = true
2121
multiDexEnabled true

lassi/src/main/java/com/lassi/presentation/cropper/BitmapUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ internal object BitmapUtils {
250250
)
251251
if (result == bitmap) {
252252
// corner case when all bitmap is selected, no worth optimizing for it
253-
result = bitmap.copy(bitmap.config, false)
253+
result = bitmap.copy(bitmap.config ?: Bitmap.Config.ARGB_8888, false)
254254
}
255255
// rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping
256256
if (degreesRotated % 90 != 0) {
@@ -614,7 +614,7 @@ internal object BitmapUtils {
614614
)
615615
}
616616
} catch (e: OutOfMemoryError) {
617-
result.recycle()
617+
result?.recycle()
618618
throw e
619619
}
620620
BitmapSampled(result, sampleSize)

lassi/src/main/java/com/lassi/presentation/cropper/CropImageView.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import android.widget.ProgressBar
2727
import androidx.annotation.RequiresApi
2828
import androidx.core.util.component1
2929
import androidx.core.util.component2
30+
import androidx.core.view.ViewCompat
31+
import androidx.core.view.WindowInsetsCompat
32+
import androidx.core.view.WindowInsetsControllerCompat
3033
import androidx.exifinterface.media.ExifInterface
3134
import com.lassi.R
3235
import com.lassi.presentation.cropper.CropOverlayView
@@ -1885,6 +1888,24 @@ class CropImageView @JvmOverloads constructor(
18851888
mProgressBar = v.findViewById(R.id.CropProgressBar)
18861889
mProgressBar.indeterminateTintList = ColorStateList.valueOf(options.progressBarColor)
18871890
setProgressBarVisibility()
1891+
1892+
// Gives the text of the status bar dark color
1893+
(context as? Activity)?.let { activity ->
1894+
WindowInsetsControllerCompat(activity.window, activity.window.decorView)
1895+
.isAppearanceLightStatusBars = true
1896+
}
1897+
// giving the padding according to the edge-to-edge support.
1898+
ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets ->
1899+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
1900+
1901+
v.setPadding(
1902+
v.paddingLeft,
1903+
systemBars.top,
1904+
v.paddingRight,
1905+
systemBars.bottom
1906+
)
1907+
insets
1908+
}
18881909
}
18891910

18901911
override fun onCropWindowChanged(inProgress: Boolean) {

lassi/src/main/java/com/lassi/presentation/mediadirectory/LassiMediaPickerActivity.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import android.webkit.MimeTypeMap
1414
import androidx.activity.result.contract.ActivityResultContracts
1515
import androidx.core.graphics.BlendModeColorFilterCompat
1616
import androidx.core.graphics.BlendModeCompat
17+
import androidx.core.view.ViewCompat
18+
import androidx.core.view.WindowCompat
19+
import androidx.core.view.WindowInsetsCompat
20+
import androidx.core.view.WindowInsetsControllerCompat
1721
import androidx.lifecycle.ViewModelProvider
1822
import androidx.lifecycle.lifecycleScope
1923
import com.lassi.R
@@ -140,6 +144,26 @@ class LassiMediaPickerActivity :
140144
supportActionBar?.setDisplayHomeAsUpEnabled(true)
141145
setThemeAttributes()
142146
initiateFragment()
147+
148+
// Gives the text of the status bar dark color
149+
WindowInsetsControllerCompat(window, window.decorView)
150+
.isAppearanceLightStatusBars = true
151+
152+
// this thing ensures that the padding removed for the edge-to-edge support is not overridden again
153+
WindowCompat.setDecorFitsSystemWindows(window, false)
154+
155+
// giving the padding according to the edge-to-edge support.
156+
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.root_layout_media_picker)) { view, insets ->
157+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
158+
view.setBackgroundColor(config.statusBarColor)
159+
view.setPadding(
160+
view.paddingLeft,
161+
systemBars.top,
162+
view.paddingRight,
163+
systemBars.bottom
164+
)
165+
insets
166+
}
143167
}
144168

145169
private fun setToolbarTitle(selectedMedias: ArrayList<MiMedia>) {

lassi/src/main/res/layout/activity_media_picker.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/root_layout_media_picker"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
78
android:orientation="vertical">

lassi/src/main/res/layout/crop_image_activity.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:fitsSystemWindows="false"
78
/>

lassi/src/main/res/layout/fragment_media_picker.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
6-
android:layout_height="match_parent">
6+
android:layout_height="match_parent"
7+
android:fitsSystemWindows="false">
78

89
<androidx.recyclerview.widget.RecyclerView
910
android:id="@+id/rvMedia"

0 commit comments

Comments
 (0)