<commit_before>package com.anysoftkeyboard.overlay;

import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.LightingColorFilter;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;

public class ThemeOverlayCombiner {

    private static final int[][] NO_STATES = new int[][]{{0}};

    private OverlayData mOverlayData = new OverlayData();

    private final ThemeResourcesHolderImpl mThemeOriginalResources = new ThemeResourcesHolderImpl();
    private final ThemeResourcesHolderImpl mCalculatedResources = new ThemeResourcesHolderImpl();

    public void setOverlayData(@NonNull OverlayData data) {
        mOverlayData = data;
        recalculateResources();
    }

    private void recalculateResources() {
        if (mOverlayData.isValid()) {
            mCalculatedResources.mKeyBackground = overlayDrawable(mThemeOriginalResources.mKeyBackground, mOverlayData.getPrimaryColor());
            mCalculatedResources.mKeyboardBackground = overlayDrawable(mThemeOriginalResources.mKeyboardBackground, mOverlayData.getPrimaryDarkColor());
            mCalculatedResources.mKeyTextColor = new ColorStateList(NO_STATES, new int[]{mOverlayData.getPrimaryTextColor()});
            mCalculatedResources.mNameTextColor = mCalculatedResources.mHintTextColor = mOverlayData.getSecondaryTextColor();
        } else {
            if (mThemeOriginalResources.mKeyboardBackground != null) {
                mThemeOriginalResources.mKeyboardBackground.clearColorFilter();
            }

            if (mThemeOriginalResources.mKeyBackground != null) {
                mThemeOriginalResources.mKeyBackground.clearColorFilter();
            }
        }
    }

    private static Drawable overlayDrawable(Drawable original, int color) {
        if (original == null) {
            return new ColorDrawable(color);
        } else {
            original.setColorFilter(new LightingColorFilter(Color.GRAY, color));
            return original;
        }
    }

    public void setThemeKeyBackground(Drawable drawable) {
        mThemeOriginalResources.mKeyBackground = drawable;
    }

    public void setThemeKeyboardBackground(Drawable drawable) {
        mThemeOriginalResources.mKeyboardBackground = drawable;
    }

    public void setThemeTextColor(ColorStateList color) {
        mThemeOriginalResources.mKeyTextColor = color;
    }

    public void setThemeNameTextColor(@ColorInt int color) {
        mThemeOriginalResources.mNameTextColor = color;
    }
<commit_msg>Tweaking overlay colors<commit_after>package com.anysoftkeyboard.overlay;

import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.LightingColorFilter;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;

public class ThemeOverlayCombiner {

    private static final int[][] NO_STATES = new int[][]{{0}};

    private OverlayData mOverlayData = new OverlayData();

    private final ThemeResourcesHolderImpl mThemeOriginalResources = new ThemeResourcesHolderImpl();
    private final ThemeResourcesHolderImpl mCalculatedResources = new ThemeResourcesHolderImpl();

    public void setOverlayData(@NonNull OverlayData data) {
        mOverlayData = data;
        recalculateResources();
    }

    private void recalculateResources() {
        if (mThemeOriginalResources.mKeyboardBackground != null) {
            mThemeOriginalResources.mKeyboardBackground.clearColorFilter();
        }

        if (mThemeOriginalResources.mKeyBackground != null) {
            mThemeOriginalResources.mKeyBackground.clearColorFilter();
        }

        if (mOverlayData.isValid()) {
            mCalculatedResources.mKeyBackground = overlayDrawable(Color.GRAY, mThemeOriginalResources.mKeyBackground, mOverlayData.getPrimaryColor());
            mCalculatedResources.mKeyboardBackground = overlayDrawable(Color.DKGRAY, mThemeOriginalResources.mKeyboardBackground, mOverlayData.getPrimaryDarkColor());
            mCalculatedResources.mKeyTextColor = new ColorStateList(NO_STATES, new int[]{mOverlayData.getPrimaryTextColor()});
            mCalculatedResources.mNameTextColor = mCalculatedResources.mHintTextColor = mOverlayData.getSecondaryTextColor();
        }
    }

    private static Drawable overlayDrawable(@ColorInt int baseColor, Drawable original, int color) {
        if (original == null) {
            return new ColorDrawable(color);
        } else {
            original.setColorFilter(new LightingColorFilter(baseColor, color));
            return original;
        }
    }

    public void setThemeKeyBackground(Drawable drawable) {
        mThemeOriginalResources.mKeyBackground = drawable;
    }

    public void setThemeKeyboardBackground(Drawable drawable) {
        mThemeOriginalResources.mKeyboardBackground = drawable;
    }

    public void setThemeTextColor(ColorStateList color) {
        mThemeOriginalResources.mKeyTextColor = color;
    }

    public void setThemeNameTextColor(@ColorInt int color) {
        mThemeOriginalResources.mNameTextColor = color;
    }

{'fraction_non_alphanumeric': 0.07676503548748599, 'fraction_numerical': 0.00037355248412401944, 'mean_word_length': 3.8814949863263446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '141729', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1362, 'n_words': 256}