| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.util; |
| 18 |
|
| 19 |
import android.content.res.Resources; |
| 20 |
import android.view.Display; |
| 21 |
|
| 22 |
import com.android.internal.R; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class DisplayUtils { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public static int getDisplayUniqueIdConfigIndex(Resources res, String displayUniqueId) { |
| 41 |
int index = -1; |
| 42 |
if (displayUniqueId == null || displayUniqueId.isEmpty()) { |
| 43 |
return index; |
| 44 |
} |
| 45 |
final String[] ids = res.getStringArray(R.array.config_displayUniqueIdArray); |
| 46 |
final int size = ids.length; |
| 47 |
for (int i = 0; i < size; i++) { |
| 48 |
if (displayUniqueId.equals(ids[i])) { |
| 49 |
index = i; |
| 50 |
break; |
| 51 |
} |
| 52 |
} |
| 53 |
return index; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public static Display.Mode getMaximumResolutionDisplayMode(Display.Mode[] modes) { |
| 60 |
if (modes == null || modes.length == 0) { |
| 61 |
return null; |
| 62 |
} |
| 63 |
int maxWidth = 0; |
| 64 |
Display.Mode target = null; |
| 65 |
for (Display.Mode mode : modes) { |
| 66 |
if (mode.getPhysicalWidth() > maxWidth) { |
| 67 |
maxWidth = mode.getPhysicalWidth(); |
| 68 |
target = mode; |
| 69 |
} |
| 70 |
} |
| 71 |
return target; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public static float getPhysicalPixelDisplaySizeRatio( |
| 78 |
int physicalWidth, int physicalHeight, int currentWidth, int currentHeight) { |
| 79 |
if (physicalWidth == currentWidth && physicalHeight == currentHeight) { |
| 80 |
return 1f; |
| 81 |
} |
| 82 |
final float widthRatio = (float) currentWidth / physicalWidth; |
| 83 |
final float heightRatio = (float) currentHeight / physicalHeight; |
| 84 |
return Math.min(widthRatio, heightRatio); |
| 85 |
} |
| 86 |
} |