Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Casanowow Life for love
VLC-Android
Commits
1416c017
Commit
1416c017
authored
Aug 10, 2012
by
Edward Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Util: Add dp/px conversion functions
These are a bit of a pain to find :(
parent
66061cb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
vlc-android/src/org/videolan/vlc/Util.java
vlc-android/src/org/videolan/vlc/Util.java
+22
-0
No files found.
vlc-android/src/org/videolan/vlc/Util.java
View file @
1416c017
...
...
@@ -36,7 +36,11 @@ import java.util.Properties;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.net.Uri
;
import
android.util.DisplayMetrics
;
import
android.util.TypedValue
;
import
android.view.Display
;
import
android.view.View
;
import
android.view.WindowManager
;
import
android.widget.Toast
;
public
class
Util
{
...
...
@@ -194,6 +198,24 @@ public class Util {
:
R
.
drawable
.
background_item2
);
}
public
static
int
convertPxToDp
(
int
px
)
{
WindowManager
wm
=
(
WindowManager
)
VLCApplication
.
getAppContext
().
getSystemService
(
Context
.
WINDOW_SERVICE
);
Display
display
=
wm
.
getDefaultDisplay
();
DisplayMetrics
metrics
=
new
DisplayMetrics
();
display
.
getMetrics
(
metrics
);
float
logicalDensity
=
metrics
.
density
;
int
dp
=
Math
.
round
(
px
/
logicalDensity
);
return
dp
;
}
public
static
int
convertDpToPx
(
int
dp
)
{
return
Math
.
round
(
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_DIP
,
dp
,
VLCApplication
.
getAppResources
().
getDisplayMetrics
())
);
}
public
static
boolean
isGingerbreadOrLater
()
{
return
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
android
.
os
.
Build
.
VERSION_CODES
.
GINGERBREAD
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment