diff options
author | Adam Powell <adamp@google.com> | 2015-06-12 14:54:49 -0700 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2015-06-12 14:54:49 -0700 |
commit | bbd3eeb9e53707bcbf0cc540acd7bb566252a969 (patch) | |
tree | 31c7bb1cc1d70a73ddfb6f23c998f9e0dd5829f7 /core/java | |
parent | 54b65ff3004a1585867e8c3c4d267b381123e179 (diff) | |
download | frameworks_base-bbd3eeb9e53707bcbf0cc540acd7bb566252a969.zip frameworks_base-bbd3eeb9e53707bcbf0cc540acd7bb566252a969.tar.gz frameworks_base-bbd3eeb9e53707bcbf0cc540acd7bb566252a969.tar.bz2 |
Only read foreground attr for FrameLayouts for targetSdkVersion < M
Now that the android:foreground attribute is supported for all views
it turns out some existing apps were previously setting foreground or
applying styles with a foreground to unsupporting views even though
the values being set were not drawables. While this was silently
ignored before, now it results in app crashes.
The most expedient fix is to only support foreground on
non-FrameLayout views if the app sets targetSdkVersion to M or newer.
Bug 21646309
Change-Id: I8937f44988866e86e640555f4bbc5dd5b2e1cce1
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/view/View.java | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 0df8ea9..fd3ee4f 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -56,6 +56,8 @@ import android.graphics.Shader; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.hardware.display.DisplayManagerGlobal; +import android.os.Build; +import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -95,6 +97,7 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.widget.Checkable; +import android.widget.FrameLayout; import android.widget.ScrollBarDrawable; import static android.os.Build.VERSION_CODES.*; @@ -4274,23 +4277,33 @@ public class View implements Drawable.Callback, KeyEvent.Callback, PROVIDER_BACKGROUND)); break; case R.styleable.View_foreground: - setForeground(a.getDrawable(attr)); + if (targetSdkVersion >= VERSION_CODES.MNC || this instanceof FrameLayout) { + setForeground(a.getDrawable(attr)); + } break; case R.styleable.View_foregroundGravity: - setForegroundGravity(a.getInt(attr, Gravity.NO_GRAVITY)); + if (targetSdkVersion >= VERSION_CODES.MNC || this instanceof FrameLayout) { + setForegroundGravity(a.getInt(attr, Gravity.NO_GRAVITY)); + } break; case R.styleable.View_foregroundTintMode: - setForegroundTintMode(Drawable.parseTintMode(a.getInt(attr, -1), null)); + if (targetSdkVersion >= VERSION_CODES.MNC || this instanceof FrameLayout) { + setForegroundTintMode(Drawable.parseTintMode(a.getInt(attr, -1), null)); + } break; case R.styleable.View_foregroundTint: - setForegroundTintList(a.getColorStateList(attr)); + if (targetSdkVersion >= VERSION_CODES.MNC || this instanceof FrameLayout) { + setForegroundTintList(a.getColorStateList(attr)); + } break; case R.styleable.View_foregroundInsidePadding: - if (mForegroundInfo == null) { - mForegroundInfo = new ForegroundInfo(); + if (targetSdkVersion >= VERSION_CODES.MNC || this instanceof FrameLayout) { + if (mForegroundInfo == null) { + mForegroundInfo = new ForegroundInfo(); + } + mForegroundInfo.mInsidePadding = a.getBoolean(attr, + mForegroundInfo.mInsidePadding); } - mForegroundInfo.mInsidePadding = a.getBoolean(attr, - mForegroundInfo.mInsidePadding); break; case R.styleable.View_scrollIndicators: final int scrollIndicators = |