File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
cocos/platform/android/java/src/org/cocos2dx/lib Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -546,6 +546,16 @@ public void run() {
546
546
}
547
547
}
548
548
549
+ private static int displayMetricsToDPI (DisplayMetrics metrics )
550
+ {
551
+ if (metrics .xdpi != metrics .ydpi ) {
552
+ Log .w (Cocos2dxHelper .TAG , "xdpi != ydpi, use (xdpi + ydpi)/2 instead." );
553
+ return (int ) ((metrics .xdpi + metrics .ydpi ) / 2.0 );
554
+ } else {
555
+ return (int )metrics .xdpi ;
556
+ }
557
+ }
558
+
549
559
public static int getDPI ()
550
560
{
551
561
if (sActivity != null )
@@ -557,8 +567,15 @@ public static int getDPI()
557
567
Display d = wm .getDefaultDisplay ();
558
568
if (d != null )
559
569
{
570
+ try {
571
+ Method getRealMetrics = d .getClass ().getMethod ("getRealMetrics" , metrics .getClass ());
572
+ getRealMetrics .invoke (d , metrics );
573
+ return displayMetricsToDPI (metrics );
574
+ } catch (Exception e ) {
575
+ e .printStackTrace ();
576
+ }
560
577
d .getMetrics (metrics );
561
- return ( int )( metrics . density * 160.0f );
578
+ return displayMetricsToDPI ( metrics );
562
579
}
563
580
}
564
581
}
You can’t perform that action at this time.
0 commit comments