<commit_before>package net.squanchy.schedule.tracksfilter.widget

import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.support.annotation.ColorInt
import android.support.annotation.Px
import android.support.v4.content.ContextCompat
import android.support.v4.content.res.ResourcesCompat
import android.support.v7.widget.AppCompatTextView
import android.util.AttributeSet
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.Checkable
import net.squanchy.R
import net.squanchy.support.graphics.darkenToEnsureTextContrasts
import net.squanchy.support.graphics.pickBestTextColorByContrast

class FilterChipView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet,
    defStyle: Int = 0
) : AppCompatTextView(context, attrs, defStyle), Checkable {

    private var isInitialized = false

    private var isChecked: Boolean = false
    private var isBroadcastingCheckedChange: Boolean = false

    private var baseColor: Int
    private var checkedTextColorDark: Int
    private var checkedTextColorLight: Int
    private var uncheckedFallbackTextColor: Int

    @Px
    private var strokeWidth: Int

    // It sounds weird, but a <shape> with a stroke color inflates as a GradientDrawable
    private var backgroundDrawable: GradientDrawable
    private var backgroundAlpha: CheckableValue<Float>

    private lateinit var backgroundColor: CheckableValue<Int>
    private lateinit var strokeColor: CheckableValue<Int>
    private lateinit var textColor: CheckableValue<Int>

    init {
        val a = this.context.obtainStyledAttributes(attrs, R.styleable.FilterChipView, defStyle, R.style.Widget_Squanchy_FilterChipView)

        checkedTextColorDark = a.getColor(R.styleable.FilterChipView_checkedTextColorDark, Color.YELLOW)
        checkedTextColorLight = a.getColor(R.styleable.FilterChipView_checkedTextColorLight, Color.MAGENTA)
        uncheckedFallbackTextColor = a.getColor(R.styleable.FilterChipView_uncheckedFallbackTextColor, Color.GREEN)

        baseColor = a.getColor(R.styleable.FilterChipView_color, ContextCompat.getColor(context, R.color.chip_default_background_tint))

        strokeWidth = a.getDimensionPixelSize(R.styleable.FilterChipView_strokeWidth, 0)

        backgroundDrawable = ResourcesCompat.getDrawable(resources, R.drawable.chip_background, context.theme) as GradientDrawable
        super.setBackground(backgroundDrawable)

        backgroundAlpha = CheckableValue(
            checkedValue = a.getFloat(R.styleable.FilterChipView_checkedAlpha, DEFAULT_CHECKED_ALPHA),
            uncheckedValue = a.getFloat(R.styleable.FilterChipView_uncheckedAlpha, DEFAULT_UNCHECKED_ALPHA)<commit_msg>Add TODO for better defaults in FilterChipView<commit_after>package net.squanchy.schedule.tracksfilter.widget

import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.support.annotation.ColorInt
import android.support.annotation.Px
import android.support.v4.content.ContextCompat
import android.support.v4.content.res.ResourcesCompat
import android.support.v7.widget.AppCompatTextView
import android.util.AttributeSet
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.Checkable
import net.squanchy.R
import net.squanchy.support.graphics.darkenToEnsureTextContrasts
import net.squanchy.support.graphics.pickBestTextColorByContrast

class FilterChipView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet,
    defStyle: Int = 0
) : AppCompatTextView(context, attrs, defStyle), Checkable {

    private var isInitialized = false

    private var isChecked: Boolean = false
    private var isBroadcastingCheckedChange: Boolean = false

    private var baseColor: Int
    private var checkedTextColorDark: Int
    private var checkedTextColorLight: Int
    private var uncheckedFallbackTextColor: Int

    @Px
    private var strokeWidth: Int

    // It sounds weird, but a <shape> with a stroke color inflates as a GradientDrawable
    private var backgroundDrawable: GradientDrawable
    private var backgroundAlpha: CheckableValue<Float>

    private lateinit var backgroundColor: CheckableValue<Int>
    private lateinit var strokeColor: CheckableValue<Int>
    private lateinit var textColor: CheckableValue<Int>

    init {
        val a = this.context.obtainStyledAttributes(attrs, R.styleable.FilterChipView, defStyle, R.style.Widget_Squanchy_FilterChipView)

        // TODO use more appropriate defaults once finished dev'ing
        checkedTextColorDark = a.getColor(R.styleable.FilterChipView_checkedTextColorDark, Color.YELLOW)
        checkedTextColorLight = a.getColor(R.styleable.FilterChipView_checkedTextColorLight, Color.MAGENTA)
        uncheckedFallbackTextColor = a.getColor(R.styleable.FilterChipView_uncheckedFallbackTextColor, Color.GREEN)

        baseColor = a.getColor(R.styleable.FilterChipView_color, ContextCompat.getColor(context, R.color.chip_default_background_tint))

        strokeWidth = a.getDimensionPixelSize(R.styleable.FilterChipView_strokeWidth, 0)

        backgroundDrawable = ResourcesCompat.getDrawable(resources, R.drawable.chip_background, context.theme) as GradientDrawable
        super.setBackground(backgroundDrawable)

        backgroundAlpha = CheckableValue(
            checkedValue = a.getFloat(R.styleable.FilterChipView_checkedAlpha, DEFAULT_CHECKED_ALPHA),
            uncheckedValue = a.getFloat(R.styleable.FilterChipView_uncheckedAlpha, DEFAULT_UNCHECKED_ALPHA)
{'fraction_non_alphanumeric': 0.06533851088975182, 'fraction_numerical': 0.0016883336147222692, 'mean_word_length': 5.196652719665272, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1118832', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1604, 'n_words': 339}