下面列出了怎么用androidx.annotation.BoolRes的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 获取 Boolean
* @param id resource identifier
* @return Boolean
*/
public static boolean getBoolean(@BoolRes final int id) {
try {
return DevUtils.getContext().getResources().getBoolean(id);
} catch (Exception e) {
LogPrintUtils.eTag(TAG, e, "getBoolean");
}
return false;
}
public boolean resolveBoolRes(@BoolRes int resId) {
if (resId != 0) {
Boolean cached = mResourceCache.get(resId);
if (cached != null) {
return cached;
}
boolean result = mResources.getBoolean(resId);
mResourceCache.put(resId, result);
return result;
}
return false;
}
public boolean resolveBoolAttr(@AttrRes int attrResId, @BoolRes int defResId) {
TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId});
try {
return a.getBoolean(0, resolveBoolRes(defResId));
} finally {
a.recycle();
}
}
@Override
Boolean getPreferenceDefaultValue(@BoolRes int defaultValueKey) {
Resources resources = context.getResources();
return resources.getBoolean(defaultValueKey);
}
public void setChipIconVisible(@BoolRes int id) {
setChipIconVisible(context.getResources().getBoolean(id));
}
/** @deprecated Use {@link ChipDrawable#setChipIconVisible(int)} instead. */
@Deprecated
public void setChipIconEnabledResource(@BoolRes int id) {
setChipIconVisible(id);
}
public void setCloseIconVisible(@BoolRes int id) {
setCloseIconVisible(context.getResources().getBoolean(id));
}
/** @deprecated Use {@link ChipDrawable#setCloseIconVisible(int)} instead. */
@Deprecated
public void setCloseIconEnabledResource(@BoolRes int id) {
setCloseIconVisible(id);
}
public void setCheckableResource(@BoolRes int id) {
setCheckable(context.getResources().getBoolean(id));
}
public void setCheckedIconVisible(@BoolRes int id) {
setCheckedIconVisible(context.getResources().getBoolean(id));
}
/** @deprecated Use {@link ChipDrawable#setCheckedIconVisible(int)} instead. */
@Deprecated
public void setCheckedIconEnabledResource(@BoolRes int id) {
setCheckedIconVisible(context.getResources().getBoolean(id));
}
/** Sets whether this chip group is single line, or reflowed multiline. */
public void setSingleLine(@BoolRes int id) {
setSingleLine(getResources().getBoolean(id));
}
/** @deprecated Use {@link Chip#setChipIconVisible(int)} instead. */
@Deprecated
public void setChipIconEnabledResource(@BoolRes int id) {
setChipIconVisible(id);
}
/** @deprecated Use {@link Chip#setCloseIconVisible(int)} instead. */
@Deprecated
public void setCloseIconEnabledResource(@BoolRes int id) {
setCloseIconVisible(id);
}
/** @deprecated Use {@link Chip#setCheckedIconVisible(int)} instead. */
@Deprecated
public void setCheckedIconEnabledResource(@BoolRes int id) {
setCheckedIconVisible(id);
}
private static boolean getBooleanPreference(Context context, String name, @BoolRes int res) {
return getPreferences(context).getBoolean(name, context.getResources().getBoolean(res));
}
protected boolean getBooleanPreference(String name, @BoolRes int res) {
return getPreferences().getBoolean(name, getResources().getBoolean(res));
}
protected boolean getBooleanPreference(String name, @BoolRes int res) {
return getPreferences().getBoolean(name, getResources().getBoolean(res));
}
/**
* Sets the initial state of the checkbox
*
* @param preset initial state as boolean resource
* @return this instance
*/
public Check check(@BoolRes int preset){
this.presetId = preset;
return this;
}
/**
* Returns the boolean value assigned to the resource key
*
* @param defaultResID
* The resource key ID
*
* @return
* The resource value
*/
public static boolean getBoolean(@BoolRes int defaultResID) {
return getRes().getBoolean(defaultResID);
}
/**
* Returns a {@link Boolean} given a {@link BoolRes}
* @param res an {@link BoolRes}
* @return an {@link Boolean} associated with the given {@link BoolRes}
*/
public static boolean getDefaultBoolValue(@BoolRes int res) {
return TwistyTimer.getAppContext().getResources().getBoolean(res);
}
/**
* Sets the initial state of the checkbox
*
* @param preset initial state as boolean resource
* @return this instance
*/
public Check check(@BoolRes int preset){
this.presetId = preset;
return this;
}
/**
* Sets whether this group only allows a single button to be checked.
*
* <p>Calling this method results in all the buttons in this group to become unchecked.
*
* @param id boolean resource ID of whether this group only allows a single button to be checked
* @attr ref R.styleable#MaterialButtonToggleGroup_singleSelection
*/
public void setSingleSelection(@BoolRes int id) {
setSingleSelection(getResources().getBoolean(id));
}
/**
* Set whether tab labels will be displayed inline with tab icons, or if they will be displayed
* underneath tab icons.
*
* @param inlineResourceId Resource ID for boolean inline flag
* @see #isInlineLabel()
* @attr ref com.google.android.material.R.styleable#TabLayout_tabInlineLabel
*/
public void setInlineLabelResource(@BoolRes int inlineResourceId) {
setInlineLabel(getResources().getBoolean(inlineResourceId));
}
/**
* Set whether this {@link TabLayout} will have an unbounded ripple effect or if ripple will be
* bound to the tab item size. Defaults to false.
*
* @param unboundedRippleResourceId Resource ID for boolean unbounded ripple value
* @see #hasUnboundedRipple()
* @attr ref com.google.android.material.R.styleable#TabLayout_tabUnboundedRipple
*/
public void setUnboundedRippleResource(@BoolRes int unboundedRippleResourceId) {
setUnboundedRipple(getResources().getBoolean(unboundedRippleResourceId));
}
/**
* Sets whether this chip group only allows a single chip to be checked.
*
* <p>Calling this method results in all the chips in this group to become unchecked.
*/
public void setSingleSelection(@BoolRes int id) {
setSingleSelection(getResources().getBoolean(id));
}
/**
* Sets the visibility of this chip's icon using a resource id.
*
* @param id The resource id for the visibility of this chip's icon.
* @attr ref com.google.android.material.R.styleable#Chip_chipIconVisible
*/
public void setChipIconVisible(@BoolRes int id) {
if (chipDrawable != null) {
chipDrawable.setChipIconVisible(id);
}
}
/**
* Sets whether this chip close icon is visible using a resource id.
*
* @param id The resource id of this chip's close icon visibility.
* @attr ref com.google.android.material.R.styleable#Chip_closeIconVisible
*/
public void setCloseIconVisible(@BoolRes int id) {
setCloseIconVisible(getResources().getBoolean(id));
}
/**
* Sets whether this chip is checkable using a resource id.
*
* @param id The resource id of this chip is checkable.
* @attr ref com.google.android.material.R.styleable#Chip_android_checkable
*/
public void setCheckableResource(@BoolRes int id) {
if (chipDrawable != null) {
chipDrawable.setCheckableResource(id);
}
}
/**
* Sets whether this chip's checked icon is visible using a resource id.
*
* @param id The resource id of this chip's check icon visibility.
* @attr ref com.google.android.material.R.styleable#Chip_checkedIconVisible
*/
public void setCheckedIconVisible(@BoolRes int id) {
if (chipDrawable != null) {
chipDrawable.setCheckedIconVisible(id);
}
}