-
-
Notifications
You must be signed in to change notification settings - Fork 53
fix: size wallpapers against the display's natural orientation #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,11 @@ package com.bnyro.wallpaper.util | |||||||
| import android.app.WallpaperManager | ||||||||
| import android.content.Context | ||||||||
| import android.graphics.Bitmap | ||||||||
| import android.hardware.display.DisplayManager | ||||||||
| import android.os.Build | ||||||||
| import android.util.DisplayMetrics | ||||||||
| import android.view.Display | ||||||||
| import android.view.Surface | ||||||||
| import android.view.WindowManager | ||||||||
| import androidx.annotation.RequiresApi | ||||||||
| import com.bnyro.wallpaper.enums.ResizeMethod | ||||||||
|
|
@@ -65,17 +68,35 @@ object WallpaperHelper { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /** The display size in its natural orientation, which is how a wallpaper is stored. */ | ||||||||
| private fun getMetrics(context: Context): Pair<Int, Int> { | ||||||||
| val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager | ||||||||
|
|
||||||||
| return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||||||||
| val (width, height) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||||||||
| windowManager.currentWindowMetrics.bounds.let { it.width() to it.height() } | ||||||||
| } else { | ||||||||
| val metrics = DisplayMetrics() | ||||||||
| @Suppress("DEPRECATION") | ||||||||
| windowManager.defaultDisplay.getMetrics(metrics) | ||||||||
| metrics.widthPixels to metrics.heightPixels | ||||||||
| } | ||||||||
|
|
||||||||
| return when (getDisplayRotation(context)) { | ||||||||
| Surface.ROTATION_90, Surface.ROTATION_270 -> height to width | ||||||||
| else -> width to height | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| private fun getDisplayRotation(context: Context): Int { | ||||||||
| val display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||||||||
| (context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager) | ||||||||
| .getDisplay(Display.DEFAULT_DISPLAY) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right, fixed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } else { | ||||||||
| @Suppress("DEPRECATION") | ||||||||
| (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay | ||||||||
| } | ||||||||
|
|
||||||||
| return display?.rotation ?: Surface.ROTATION_0 | ||||||||
| } | ||||||||
|
|
||||||||
| private fun resizeBitmapByPreference(context: Context, bitmap: Bitmap): Bitmap { | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a short comment here to explain what we're doing, e.g. as the one proposed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added~