<commit_before>/*
 * Copyright (C) 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.veniosg.dir.view;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Xfermode;
import android.graphics.drawable.Drawable;
import android.os.Build;

import com.veniosg.dir.R;
import com.veniosg.dir.fragment.PreferenceFragment;

import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.L;

public class Themer {
    public static enum Theme {
        DIR,
        GRAYSCALE,
        DARK,
        HOLO_DARK
    }
    public static enum Flavor {
        TRANSLUCENT_NAV,
        OPAQUE
    }

    public static final void applyTheme(Activity act) {
        boolean trans = false;
        if (act instanceof Themable) {
            trans = ((Themable) act).getThemeFlavor() == Flavor.TRANSLUCENT_NAV
                        && SDK_INT < L;
        }

        switch (Theme.values()[PreferenceFragment.getThemeIndex(act)]) {
            case DIR:
                act.setTheme(trans ? R.style.Theme_Dir_TranslucentNav : R.style.Theme_Dir);
                break;
            case GRAYSCALE:
                act.setTheme(trans ? R.style.Theme_Dir_Grayscale_TranslucentNav : R.style.Theme_Dir_Grayscale);
                break;
            case DARK:
                act.setTheme(trans ? R.style.Theme_Dir_Dark_TranslucentNav : R.style.Theme_Dir_Dark);
                break;
            case HOLO_DARK:
                act.setTheme(trans ? R.style.Theme_Dir_HoloDark_TranslucentNav : R.style.Theme_Dir_HoloDark);
                break;
        }
    }

    public interface Themable {
        /**
         * Get the theme flavor this component should have.
         * @return One of the Flavor constants.
         */
        public Flavor getThemeFlavor();
    }

    public static final int getThemedResourceId(Context ctx, int attributeId) {
        TypedArray a = ctx.getTheme().obtainStyledAttributes(new int[] {attributeId});
        int attributeResourceId = a.getResourceId(0, 0);
        a.recycle();

        return attributeResourceId;
    }

    public static final Drawable colorDrawable(Context context, Drawable drawable, int color) {
        drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
        return drawable;
    }
}
<commit_msg>Minor cleanup.<commit_after>/*
 * Copyright (C) 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.veniosg.dir.view;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Xfermode;
import android.graphics.drawable.Drawable;
import android.os.Build;

import com.veniosg.dir.R;
import com.veniosg.dir.fragment.PreferenceFragment;

import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.L;
import static com.veniosg.dir.view.Themer.Flavor.TRANSLUCENT_NAV;

public class Themer {
    public static enum Theme {
        DIR,
        GRAYSCALE,
        DARK,
        HOLO_DARK
    }
    public static enum Flavor {
        TRANSLUCENT_NAV,
        OPAQUE
    }

    public static final void applyTheme(Activity act) {
        boolean trans = false;
        if (act instanceof Themable) {
            trans = ((Themable) act).getThemeFlavor() == TRANSLUCENT_NAV
                        && SDK_INT < L;
        }

        switch (Theme.values()[PreferenceFragment.getThemeIndex(act)]) {
            case DIR:
                act.setTheme(trans ? R.style.Theme_Dir_TranslucentNav : R.style.Theme_Dir);
                break;
            case GRAYSCALE:
                act.setTheme(trans ? R.style.Theme_Dir_Grayscale_TranslucentNav : R.style.Theme_Dir_Grayscale);
                break;
            case DARK:
                act.setTheme(trans ? R.style.Theme_Dir_Dark_TranslucentNav : R.style.Theme_Dir_Dark);
                break;
            case HOLO_DARK:
                act.setTheme(trans ? R.style.Theme_Dir_HoloDark_TranslucentNav : R.style.Theme_Dir_HoloDark);
                break;
        }
    }

    public interface Themable {
        /**
         * Get the theme flavor this component should have.
         * @return One of the Flavor constants.
         */
        public Flavor getThemeFlavor();
    }

    public static final int getThemedResourceId(Context ctx, int attributeId) {
        TypedArray a = ctx.getTheme().obtainStyledAttributes(new int[] {attributeId});
        int attributeResourceId = a.getResourceId(0, 0);
        a.recycle();

        return attributeResourceId;
    }

    public static final Drawable colorDrawable(Context context, Drawable drawable, int color) {
        drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
        return drawable;
    }
}

{'fraction_non_alphanumeric': 0.0841044282881692, 'fraction_numerical': 0.003304692663582287, 'mean_word_length': 2.609421586165772, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1364341', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1722, 'n_words': 460}