《Android-Java 巧用16进制进行属性设置》 ----方便Boolean属性复制

方便Boolean属性复制

代码摘自 android.view.accessibility.AccessibilityNodeInfo

//*****************************************************
// Boolean attributes.

private static final int BOOLEAN_PROPERTY_CHECKABLE = 0x00000001;

private static final int BOOLEAN_PROPERTY_CHECKED = 0x00000002;

private static final int BOOLEAN_PROPERTY_FOCUSABLE = 0x00000004;

private static final int BOOLEAN_PROPERTY_FOCUSED = 0x00000008;

private static final int BOOLEAN_PROPERTY_SELECTED = 0x00000010;

private static final int BOOLEAN_PROPERTY_CLICKABLE = 0x00000020;

private static final int BOOLEAN_PROPERTY_LONG_CLICKABLE = 0x00000040;

private static final int BOOLEAN_PROPERTY_ENABLED = 0x00000080;

private static final int BOOLEAN_PROPERTY_PASSWORD = 0x00000100;

private static final int BOOLEAN_PROPERTY_SCROLLABLE = 0x00000200;

private static final int BOOLEAN_PROPERTY_ACCESSIBILITY_FOCUSED = 0x00000400;

private static final int BOOLEAN_PROPERTY_VISIBLE_TO_USER = 0x00000800;

private static final int BOOLEAN_PROPERTY_EDITABLE = 0x00001000;

private static final int BOOLEAN_PROPERTY_OPENS_POPUP = 0x00002000;


//*****************************************************
/**
 * Gets the value of a boolean property.
 *
 * @param property The property.
 * @return The value.
 */
private boolean getBooleanProperty(int property) {
    return (mBooleanProperties & property) != 0;
}

/**
 * Sets a boolean property.
 *
 * @param property The property.
 * @param value The value.
 *
 * @throws IllegalStateException If called from an AccessibilityService.
 */
private void setBooleanProperty(int property, boolean value) {
    enforceNotSealed();
    if (value) {
        mBooleanProperties |= property;
    } else {
        mBooleanProperties &= ~property;
    }
}


//*****************************************************
/**
 * Gets whether this node is checkable.
 *
 * @return True if the node is checkable.
 */
public boolean isCheckable() {
    return getBooleanProperty(BOOLEAN_PROPERTY_CHECKABLE);
}

/**
 * Sets whether this node is checkable.
 * <p>
 *   <strong>Note:</strong> Cannot be called from an
 *   {@link android.accessibilityservice.AccessibilityService}.
 *   This class is made immutable before being delivered to an AccessibilityService.
 * </p>
 *
 * @param checkable True if the node is checkable.
 *
 * @throws IllegalStateException If called from an AccessibilityService.
 */
public void setCheckable(boolean checkable) {
    setBooleanProperty(BOOLEAN_PROPERTY_CHECKABLE, checkable);
}
发布了170 篇原创文章 · 获赞 55 · 访问量 37万+

猜你喜欢

转载自blog.csdn.net/w695050167/article/details/91393452