forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes mozilla-mobile#26245: refactor the WallpaperManager as several …
…WallpaperUseCases
- Loading branch information
1 parent
b3fa1b0
commit 99600c5
Showing
16 changed files
with
605 additions
and
449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.mozilla.fenix.ext | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.Matrix | ||
import android.view.View | ||
import android.widget.ImageView | ||
|
||
/** | ||
* This will scale the received [Bitmap] to the size of the [view]. It retains the bitmap's | ||
* original aspect ratio, but will shrink or enlarge it to fit the viewport. If bitmap does not | ||
* correctly fit the aspect ratio of the view, it will be shifted to prioritize the bottom-left | ||
* of the bitmap. | ||
*/ | ||
fun Bitmap.scaleToBottomOfView(view: ImageView) { | ||
val bitmap = this | ||
view.setImageBitmap(bitmap) | ||
view.scaleType = ImageView.ScaleType.MATRIX | ||
val matrix = Matrix() | ||
view.addOnLayoutChangeListener(object : View.OnLayoutChangeListener { | ||
override fun onLayoutChange( | ||
v: View?, | ||
left: Int, | ||
top: Int, | ||
right: Int, | ||
bottom: Int, | ||
oldLeft: Int, | ||
oldTop: Int, | ||
oldRight: Int, | ||
oldBottom: Int | ||
) { | ||
val viewWidth: Float = view.width.toFloat() | ||
val viewHeight: Float = view.height.toFloat() | ||
val bitmapWidth = bitmap.width | ||
val bitmapHeight = bitmap.height | ||
val widthScale = viewWidth / bitmapWidth | ||
val heightScale = viewHeight / bitmapHeight | ||
val scale = widthScale.coerceAtLeast(heightScale) | ||
matrix.postScale(scale, scale) | ||
// The image is translated to its bottom such that any pertinent information is | ||
// guaranteed to be shown. | ||
// Majority of this math borrowed from // https://medium.com/@tokudu/how-to-whitelist-strictmode-violations-on-android-based-on-stacktrace-eb0018e909aa | ||
// except that there is no need to translate horizontally in our case. | ||
matrix.postTranslate(0f, (viewHeight - bitmapHeight * scale)) | ||
view.imageMatrix = matrix | ||
view.removeOnLayoutChangeListener(this) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.