All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.deque.axe.android.wrappers.AxeProps.kt Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package com.deque.axe.android.wrappers

import androidx.annotation.StringDef

class AxeProps : HashMap() {

    @Retention(AnnotationRetention.SOURCE)
    @StringDef(Name.CLASS_NAME, Name.CONTENT_DESCRIPTION, Name.DPI, Name.FRAME, Name.HEIGHT_DP,
        Name.IMPORTANT, Name.IS_CLICKABLE, Name.IS_ENABLED, Name.LABELED_BY, Name.SPEAKABLE_TEXT,
        Name.WIDTH_DP, Name.EXCEPTION, Name.STACK_TRACE, Name.EVENT_STREAM, Name.IS_FOCUS_CHANGE_OK,
        Name.IS_TOUCH_EXPLORATION_GESTURE, Name.IS_TOUCH_STARTED, Name.ACCESSIBILITY_EVENT,
        Name.VISIBLE_TEXT, Name.COLOR_BACKGROUND, Name.COLOR_FOREGROUND, Name.COLOR_CONTRAST,
        Name.CONFIDENCE, Name.SCREEN_HEIGHT, Name.SCREEN_WIDTH, Name.IS_OFF_SCREEN, Name.IS_RENDERED,
        Name.IS_PARTIALLY_VISIBLE, Name.HINT_TEXT, Name.OVERRIDES_ACCESSIBILITY_DELEGATE,
        Name.LABELED_BY_VIEW_OVERRIDES_ACCESSIBILITY_DELEGATE, Name.IS_VISIBLE_TO_USER, Name.VISIBILITY,
        Name.MEASURED_HEIGHT, Name.MEASURED_WIDTH, Name.IGNORED_RULES_LIST, Name.AXE_VIEW_ID, Name.IS_COMPOSE_VIEW,
        Name.VIEW_ID, Name.CLICKABLE_SIBLING_COUNT, Name.TOTAL_SIBLING_COUNT, Name.IS_PARENT_CLICKABLE,
        Name.ARE_ALL_CLICKABLE_SIBLINGS_NOT_IMPORTANT_FOR_ACCESSIBILITY, Name.IS_PARENT_NULL, Name.IS_FOCUSABLE,
        Name.PARENT_CONTENT_DESCRIPTION, Name.IS_TEXT_ELEMENT, Name.IS_PARENT_ACCESSIBLE
    )
    annotation class Name {
        companion object {
            const val CLASS_NAME = "className"
            const val CONTENT_DESCRIPTION = "contentDescription"
            const val PARENT_CONTENT_DESCRIPTION = "parentContentDescription"
            const val DPI = "Screen Dots Per Inch"
            const val FRAME = "boundsInScreen"
            const val HEIGHT_DP = "height - density pixels"
            const val IMPORTANT = "isImportantForAccessibility"
            const val IS_CLICKABLE = "isActive"
            const val IS_ENABLED = "isEnabled"
            const val LABELED_BY = "labeledBy"
            const val SPEAKABLE_TEXT = "Speakable Text"
            const val WIDTH_DP = "width - density pixels"
            const val EXCEPTION = "Exception"
            const val STACK_TRACE = "Stack Trace"
            const val EVENT_STREAM = "Applicable Event Stream"
            const val ACCESSIBILITY_EVENT = "AccessibilityEvent"
            const val IS_TOUCH_STARTED = "Touch Interaction Started"
            const val IS_FOCUS_CHANGE_OK = "Is Focus Change Acceptable"
            const val IS_TOUCH_EXPLORATION_GESTURE = "Touch Exploration Started"
            const val VISIBLE_TEXT = "Visible Text"
            const val COLOR_FOREGROUND = "Foreground Color"
            const val COLOR_BACKGROUND = "Background Color"
            const val COLOR_CONTRAST = "Color Contrast Ratio"
            const val CONFIDENCE = "Confidence in Color Detection"
            const val SCREEN_HEIGHT = "Screen Height"
            const val SCREEN_WIDTH = "Screen Width"
            const val IS_RENDERED = "isRendered"
            const val IS_OFF_SCREEN = "isOffScreen"
            const val IS_PARTIALLY_VISIBLE = "isPartiallyVisible"
            const val HINT_TEXT = "Hint Text"
            const val OVERRIDES_ACCESSIBILITY_DELEGATE = "overridesAccessibilityDelegate"
            const val LABELED_BY_VIEW_OVERRIDES_ACCESSIBILITY_DELEGATE =
                "labeledByViewOverridesAccessibilityDelegate"
            const val IS_VISIBLE_TO_USER = "isVisibleToUser"
            const val VISIBILITY = "visibility"
            const val MEASURED_HEIGHT = "measuredHeight"
            const val MEASURED_WIDTH = "measuredWidth"
            const val IS_COMPOSE_VIEW = "isComposeView"
            const val IGNORED_RULES_LIST = "ignoredRulesList"
            const val AXE_VIEW_ID = "axeViewId"
            const val VIEW_ID = "viewId"
            const val ARE_ALL_CLICKABLE_SIBLINGS_NOT_IMPORTANT_FOR_ACCESSIBILITY = "areAllClickableSiblingsNotImportantForAccessibility"
            const val IS_PARENT_CLICKABLE = "isParentClickable"
            const val CLICKABLE_SIBLING_COUNT = "numberOfClickableSiblings"
            const val TOTAL_SIBLING_COUNT = "totalNumberOfSiblings"
            const val IS_PARENT_NULL = "isParentNull"
            const val IS_FOCUSABLE = "isFocusable"
            const val IS_TEXT_ELEMENT = "isTextElement"
            const val IS_PARENT_ACCESSIBLE = "isParentAccessible"
        }
    }

    operator fun  get(name: String?, clazz: Class): T {
        return clazz.cast(get(name))
    }

    override fun put(key: String, value: Any?): Any? {
        if (value is Throwable) RuntimeException("Could not put value in props with key: $key, reason: ${value.localizedMessage}")
        return super.put(key, value)
    }

    override fun putAll(from: Map) {
        from.forEach {
            if (it.value is Throwable) throw RuntimeException("Could not put value in props with key: ${it.key}, reason: ${(it.value as Throwable).localizedMessage}")
        }
        super.putAll(from)
    }

    override fun putIfAbsent(key: String, value: Any?): Any? {
        if (value is Throwable) throw RuntimeException("Could not put value in props with key: $key, reason: ${value.localizedMessage}")
        return super.putIfAbsent(key, value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy