Skip to content

Instantly share code, notes, and snippets.

@kapodamy
Created December 6, 2020 01:25
Show Gist options
  • Save kapodamy/7964b5b01b1d5011cd4ae4be03dce10a to your computer and use it in GitHub Desktop.
Save kapodamy/7964b5b01b1d5011cd4ae4be03dce10a to your computer and use it in GitHub Desktop.
TypedArray.getChangingConfigurations() for kitkat (API 19) or older versions
import android.content.res.TypedArray;
import android.util.TypedValue;
public final class TypedArrayCompat {
/**
* Return a mask of the configuration parameters for which the values in
* this typed array may change.
* Designed for API <21
*
* @return Returns a mask of the changing configuration parameters, as
* defined by {@link android.content.pm.ActivityInfo}.
* @see android.content.pm.ActivityInfo
*/
public static int getChangingConfigurations(TypedArray typedArray) {
int changingConfig = 0;
final int N = typedArray.length();
for (int i = 0; i < N; i++) {
final TypedValue value = typedArray.peekValue(i);
if (value == null || value.type == TypedValue.TYPE_NULL) {
continue;
}
changingConfig |= value.changingConfigurations;
}
return changingConfig;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment