Skip to content

Commit

Permalink
Fix depth wallpaper for android 15 QPR1 beta 3
Browse files Browse the repository at this point in the history
Credits: siavash79/PixelXpert@00dfa7c

Signed-off-by: DrDisagree <[email protected]>
  • Loading branch information
Mahmud0808 committed Nov 5, 2024
1 parent 7babf3f commit 3b1556f
Show file tree
Hide file tree
Showing 2 changed files with 326 additions and 217 deletions.
118 changes: 59 additions & 59 deletions app/src/main/java/com/drdisagree/iconify/services/RootProviderProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,74 +90,74 @@ class RootProviderProxy : Service() {
callback: IExtractSubjectCallback
) {
ensureEnvironment()
val tag = BitmapSubjectSegmenter::class.java.simpleName

try {
val bitmapSubjectSegmenter = BitmapSubjectSegmenter(applicationContext)

bitmapSubjectSegmenter
.segmentSubject(
input,
object : SegmentResultListener {
override fun onStart() {
callback.onStart(getString(R.string.depth_wallpaper_subject_extraction_started))
}

override fun onSuccess(result: Bitmap?) {
try {
val tempFile = File.createTempFile(
"depth_wallpaper_fg",
".png"
)

val outputStream = FileOutputStream(tempFile)
result!!.compress(Bitmap.CompressFormat.PNG, 100, outputStream)

outputStream.close()
result.recycle()

val isSuccess = FileUtils.moveToIconifyHiddenDir(
tempFile.absolutePath,
resultPath
)

tempFile.delete()

callback.onResult(
isSuccess,
if (isSuccess) {
getString(R.string.depth_wallpaper_subject_extraction_success)
} else {
getString(R.string.depth_wallpaper_subject_extraction_failed)
}
)
} catch (throwable: Throwable) {
Log.e(
TAG,
"BitmapSubjectSegmenter - onSuccess: $throwable"
)

callback.onResult(
false,
bitmapSubjectSegmenter.segmentSubject(
input,
object : SegmentResultListener {
override fun onStart() {
callback.onStart(getString(R.string.depth_wallpaper_subject_extraction_started))
}

override fun onSuccess(result: Bitmap?) {
try {
val tempFile = File.createTempFile(
"depth_wallpaper_fg",
".png"
)

val outputStream = FileOutputStream(tempFile)
result!!.compress(Bitmap.CompressFormat.PNG, 100, outputStream)

outputStream.close()
result.recycle()

val isSuccess = FileUtils.moveToIconifyHiddenDir(
tempFile.absolutePath,
resultPath
)

tempFile.delete()

callback.onResult(
isSuccess,
if (isSuccess) {
getString(R.string.depth_wallpaper_subject_extraction_success)
} else {
getString(R.string.depth_wallpaper_subject_extraction_failed)
)
}
}
)
} catch (throwable: Throwable) {
Log.e(
TAG,
"$tag - onSuccess: $throwable"
)

callback.onResult(
false,
getString(R.string.depth_wallpaper_subject_extraction_failed)
)
}
}

override fun onFail() {
bitmapSubjectSegmenter.checkModelAvailability { moduleAvailabilityResponse: ModuleAvailabilityResponse? ->
callback.onResult(
false,
if (moduleAvailabilityResponse?.areModulesAvailable() == true) {
getString(R.string.depth_wallpaper_subject_extraction_failed)
} else {
getString(R.string.depth_wallpaper_missing_ai_model)
}
)
}
override fun onFail() {
bitmapSubjectSegmenter.checkModelAvailability { moduleAvailabilityResponse: ModuleAvailabilityResponse? ->
callback.onResult(
false,
if (moduleAvailabilityResponse?.areModulesAvailable() == true) {
getString(R.string.depth_wallpaper_subject_extraction_failed)
} else {
getString(R.string.depth_wallpaper_missing_ai_model)
}
)
}
})
}
})
} catch (throwable: Throwable) {
Log.e(TAG, "BitmapSubjectSegmenter - segmentSubject: $throwable")
Log.e(TAG, "$tag - segmentSubject: $throwable")

callback.onResult(
false,
Expand Down
Loading

0 comments on commit 3b1556f

Please sign in to comment.