static boolean hasValueOrEmpty(TypedArray ta, int index) { if (Build.VERSION.SDK_INT >= 22) { return ta.hasValueOrEmpty(index); } else { return ta.hasValue(index); } }
static boolean hasValueOrEmpty(TypedArray array, int index) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { return array.hasValueOrEmpty(index); } return array.hasValue(index); } }
final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.SearchView, defStyleAttr, defStyleRes); [...] // Prior to L MR1, the search hint icon defaulted to searchIcon. If the // style does not have an explicit value set, fall back to that. if (a.hasValueOrEmpty(R.styleable.SearchView_searchHintIcon)) { mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchHintIcon); } else { mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchIcon); }
@SuppressLint({"RestrictedApi", "ResourceType"}) private void init( @NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { if (Build.VERSION.SDK_INT == 23) { final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS, defStyleAttr, defStyleRes); try { final Transition enterTransition = getTransition(a.getResourceId(0, 0)); final Transition exitTransition; if (a.hasValueOrEmpty(1)) { exitTransition = getTransition(a.getResourceId(1, 0)); } else { exitTransition = enterTransition == null ? null : enterTransition.clone(); } setEnterTransition(enterTransition); setExitTransition(exitTransition); } finally { a.recycle(); } } }