Skip to content

Commit 0abb0b1

Browse files
committed
Add display metrics util
1 parent 9c51dc5 commit 0abb0b1

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ publish {
3131
userOrg = 'buffer'
3232
groupId = 'org.buffer.android'
3333
artifactId = 'android-utils'
34-
publishVersion = '0.4'
34+
publishVersion = '0.5'
3535
desc = 'An Android library for frequently used utility functions'
3636
website = 'https://github.com/bufferapp/android-utils'
3737
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.buffer.android.utils
2+
3+
import android.content.res.Resources
4+
import kotlin.math.roundToInt
5+
6+
object DisplayMetricsUtil {
7+
8+
fun dpToPx(dp: Int): Int {
9+
val density = Resources.getSystem().displayMetrics.density
10+
return (dp * density).roundToInt()
11+
}
12+
13+
fun dpToPx(dp: Float): Int {
14+
val density = Resources.getSystem().displayMetrics.density
15+
return (dp * density).roundToInt()
16+
}
17+
}

lib/src/main/res/values/strings.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
<resources>
2-
<string name="app_name">Android Utils</string>
3-
42
<string name="error_message_internet_connect">The internet connection appears to be offline.</string>
53
</resources>

0 commit comments

Comments
 (0)