<commit_before>package com.charlesmadere.hummingbird.misc;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.graphics.Palette;

import com.charlesmadere.hummingbird.R;
import com.facebook.imagepipeline.request.BasePostprocessor;

import java.lang.ref.WeakReference;

public final class PalettePostprocessor extends BasePostprocessor implements
        Palette.PaletteAsyncListener {

    private final WeakReference<Activity> mActivity;
    private final WeakReference<CollapsingToolbarLayout> mCollapsingToolbarLayout;
    private final WeakReference<DrawerLayout> mDrawerLayout;
    private final WeakReference<TabLayout> mTabLayout;


    public PalettePostprocessor(final Activity activity,
            final CollapsingToolbarLayout collapsingToolbarLayout, final DrawerLayout drawerLayout,
            final TabLayout tabLayout) {
        mActivity = new WeakReference<>(activity);
        mCollapsingToolbarLayout = new WeakReference<>(collapsingToolbarLayout);
        mDrawerLayout = new WeakReference<>(drawerLayout);
        mTabLayout = new WeakReference<>(tabLayout);
    }

    private boolean isAlive() {
        final Activity activity = mActivity.get();
        return activity != null && !activity.isDestroyed() && mCollapsingToolbarLayout.get() != null
                && mDrawerLayout.get() != null && mTabLayout.get() != null;
    }

    @Override
    public void onGenerated(final Palette palette) {
        if (!isAlive()) {
            return;
        }

        final CollapsingToolbarLayout collapsingToolbarLayout = mCollapsingToolbarLayout.get();
        final DrawerLayout drawerLayout = mDrawerLayout.get();
        final TabLayout tabLayout = mTabLayout.get();

        if (collapsingToolbarLayout == null || drawerLayout == null || tabLayout == null) {
            return;
        }

        final Context context = tabLayout.getContext();
        final int darkMutedColor = palette.getDarkMutedColor(ContextCompat.getColor(context,
                R.color.colorPrimaryDark));
        final int darkVibrantColor = palette.getDarkVibrantColor(ContextCompat.getColor(context,
                R.color.colorPrimary));
        final int vibrantColor = palette.getVibrantColor(ContextCompat.getColor(context,
                R.color.colorAccent));

        collapsingToolbarLayout.setContentScrimColor(darkVibrantColor);
        tabLayout.setBackgroundColor(darkVibrantColor);
        tabLayout.setSelectedTabIndicatorColor(vibrantColor);
    }

    @Override
    public void process(final Bitmap bitmap) {
        super.process(bitmap);

        if (!isAlive()) {
            return;<commit_msg>the status bar now has its color set too<commit_after>package com.charlesmadere.hummingbird.misc;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.graphics.Palette;

import com.charlesmadere.hummingbird.R;
import com.facebook.imagepipeline.request.BasePostprocessor;

import java.lang.ref.WeakReference;

public final class PalettePostprocessor extends BasePostprocessor implements
        Palette.PaletteAsyncListener {

    private final WeakReference<Activity> mActivity;
    private final WeakReference<CollapsingToolbarLayout> mCollapsingToolbarLayout;
    private final WeakReference<DrawerLayout> mDrawerLayout;
    private final WeakReference<TabLayout> mTabLayout;


    public PalettePostprocessor(final Activity activity,
            final CollapsingToolbarLayout collapsingToolbarLayout, final DrawerLayout drawerLayout,
            final TabLayout tabLayout) {
        mActivity = new WeakReference<>(activity);
        mCollapsingToolbarLayout = new WeakReference<>(collapsingToolbarLayout);
        mDrawerLayout = new WeakReference<>(drawerLayout);
        mTabLayout = new WeakReference<>(tabLayout);
    }

    private boolean isAlive() {
        final Activity activity = mActivity.get();
        return activity != null && !activity.isDestroyed() && mCollapsingToolbarLayout.get() != null
                && mDrawerLayout.get() != null && mTabLayout.get() != null;
    }

    @Override
    public void onGenerated(final Palette palette) {
        if (!isAlive()) {
            return;
        }

        final CollapsingToolbarLayout collapsingToolbarLayout = mCollapsingToolbarLayout.get();
        final DrawerLayout drawerLayout = mDrawerLayout.get();
        final TabLayout tabLayout = mTabLayout.get();

        if (collapsingToolbarLayout == null || drawerLayout == null || tabLayout == null) {
            return;
        }

        final Context context = tabLayout.getContext();
        final int darkMutedColor = palette.getDarkMutedColor(ContextCompat.getColor(context,
                R.color.colorPrimaryDark));
        final int darkVibrantColor = palette.getDarkVibrantColor(ContextCompat.getColor(context,
                R.color.colorPrimary));
        final int vibrantColor = palette.getVibrantColor(ContextCompat.getColor(context,
                R.color.colorAccent));

        collapsingToolbarLayout.setStatusBarScrimColor(darkMutedColor);
        collapsingToolbarLayout.setContentScrimColor(darkVibrantColor);
        tabLayout.setBackgroundColor(darkVibrantColor);
        tabLayout.setSelectedTabIndicatorColor(vibrantColor);
    }

    @Override
    public void process(final Bitmap bitmap) {
        super.process(bitmap);

        if (!isAlive()) {
            return;
{'fraction_non_alphanumeric': 0.0841676565416596, 'fraction_numerical': 0.001018157135584592, 'mean_word_length': 3.6227450980392155, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '2019981', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1525, 'n_words': 310}