| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.window; |
| 18 |
|
| 19 |
import static android.view.Display.INVALID_DISPLAY; |
| 20 |
|
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.app.ResourcesManager; |
| 24 |
import android.app.WindowConfiguration; |
| 25 |
import android.content.Context; |
| 26 |
import android.content.pm.ActivityInfo; |
| 27 |
import android.content.res.Configuration; |
| 28 |
import android.graphics.Canvas; |
| 29 |
import android.graphics.Rect; |
| 30 |
import android.os.IBinder; |
| 31 |
import android.view.Display; |
| 32 |
import android.view.WindowManager; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class ConfigurationHelper { |
| 41 |
private ConfigurationHelper() {} |
| 42 |
|
| 43 |
|
| 44 |
public static void freeTextLayoutCachesIfNeeded(int configDiff) { |
| 45 |
if ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0) { |
| 46 |
Canvas.freeTextLayoutCaches(); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public static boolean shouldUpdateResources(IBinder token, @Nullable Configuration config, |
| 64 |
@NonNull Configuration newConfig, @NonNull Configuration overrideConfig, |
| 65 |
boolean displayChanged, @Nullable Boolean configChanged) { |
| 66 |
|
| 67 |
if (config == null) { |
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
if (displayChanged) { |
| 73 |
return true; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
if (!ResourcesManager.getInstance().isSameResourcesOverrideConfig(token, overrideConfig)) { |
| 78 |
return true; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
if (shouldUpdateWindowMetricsBounds(config, newConfig)) { |
| 83 |
return true; |
| 84 |
} |
| 85 |
|
| 86 |
if (isDisplayRotationChanged(config, newConfig)) { |
| 87 |
return true; |
| 88 |
} |
| 89 |
return configChanged == null ? config.diff(newConfig) != 0 : configChanged; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public static boolean isDifferentDisplay(int displayId, int newDisplayId) { |
| 97 |
return newDisplayId != INVALID_DISPLAY && displayId != newDisplayId; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
private static boolean shouldUpdateWindowMetricsBounds(@NonNull Configuration currentConfig, |
| 110 |
@NonNull Configuration newConfig) { |
| 111 |
final Rect currentBounds = currentConfig.windowConfiguration.getBounds(); |
| 112 |
final Rect newBounds = newConfig.windowConfiguration.getBounds(); |
| 113 |
|
| 114 |
final Rect currentMaxBounds = currentConfig.windowConfiguration.getMaxBounds(); |
| 115 |
final Rect newMaxBounds = newConfig.windowConfiguration.getMaxBounds(); |
| 116 |
|
| 117 |
return !currentBounds.equals(newBounds) || !currentMaxBounds.equals(newMaxBounds); |
| 118 |
} |
| 119 |
|
| 120 |
private static boolean isDisplayRotationChanged(@NonNull Configuration config, |
| 121 |
@NonNull Configuration newConfig) { |
| 122 |
final int origRot = config.windowConfiguration.getDisplayRotation(); |
| 123 |
final int newRot = newConfig.windowConfiguration.getDisplayRotation(); |
| 124 |
if (newRot == WindowConfiguration.ROTATION_UNDEFINED |
| 125 |
|| origRot == WindowConfiguration.ROTATION_UNDEFINED) { |
| 126 |
return false; |
| 127 |
} |
| 128 |
return origRot != newRot; |
| 129 |
} |
| 130 |
} |