<commit_before>package com.fuse.StreamingPlayer;

import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v7.app.NotificationCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.view.KeyEvent;

import java.io.IOException;
import java.net.URL;

public final class ArtworkMediaNotification
{
    static String _cachedArtworkURL = null;
    static Bitmap _cachedArtwork = null;

    static void FreeCached()
    {
        _cachedArtwork.recycle();
        _cachedArtwork = null;
    }

    private class DownloadArtworkBitmapTask extends AsyncTask<String, Void, Bitmap>
    {
        protected Bitmap doInBackground(String... urls)
        {
            if (urls.length > 0)
            {
                try
                {
                    String urlStr = urls[0];
                    if (_cachedArtworkURL !=null && _cachedArtworkURL.equals(urlStr))
                    {
                        return _cachedArtwork;
                    }
                    URL url = new URL(urlStr);
                    Bitmap myBitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                    _cachedArtwork = myBitmap;
                    _cachedArtworkURL = urlStr;
                    return myBitmap;
                }
                catch (IOException e)
                {
                    Logger.Log("We were not able to get a bitmap of the artwork");
                }
            }
            return null;
        }

        protected void onPostExecute(Bitmap result)
        {
            if (result != null)
            {
                setArtworkBitmap(result);
            }
        }
    }

    private MediaSessionCompat _session;
    private StreamingAudioService _service;
    private int _primaryActionIcon;
    private String _primaryActionTitle;
    private int _primaryActionKeyEvent;
    private MediaMetadataCompat.Builder _metadataBuilder;

    private ArtworkMediaNotification(MediaMetadataCompat metadata, MediaSessionCompat session, StreamingAudioService service, String urlStr,
                                     int primaryActionIcon, String primaryActionTitle, int primaryActionKeyEvent)
    {
        _session = session;
        _service = service;
        _primaryActionIcon = primaryActionIcon;
        _primaryActionTitle = primaryActionTitle;
        _primaryActionKeyEvent = primaryActionKeyEvent;
        _metadataBuilder = new MediaMetadataCompat.Builder(metadata);
        if (urlStr!=null)<commit_msg>If not http or https then load artwork as local file<commit_after>package com.fuse.StreamingPlayer;

import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v7.app.NotificationCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.view.KeyEvent;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public final class ArtworkMediaNotification
{
    static String _cachedArtworkURL = null;
    static Bitmap _cachedArtwork = null;

    static void FreeCached()
    {
        _cachedArtwork.recycle();
        _cachedArtwork = null;
    }

    static boolean IsRemoteFile(String url)
    {
        try
        {
            URI u = new URI(url);
            return "http".equalsIgnoreCase(u.getScheme())
                    || "https".equalsIgnoreCase(u.getScheme());
        }
        catch (URISyntaxException e)
        {
            return false;
        }
    }

    private class DownloadArtworkBitmapTask extends AsyncTask<String, Void, Bitmap>
    {
        protected Bitmap doInBackground(String... urls)
        {
            if (urls.length > 0)
            {
                String urlStr = urls[0];
                if (_cachedArtworkURL !=null && _cachedArtworkURL.equals(urlStr))
                {
                    return _cachedArtwork;
                }
                else if (IsRemoteFile(urlStr))
                {
                    return LoadRemote(urlStr);
                }
                else
                {
                    return LoadLocal(urlStr);
                }
            }
            return null;
        }

        Bitmap LoadRemote(String urlStr)
        {
            try
            {
                URL url = new URL(urlStr);
                Bitmap myBitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                _cachedArtwork = myBitmap;
                _cachedArtworkURL = urlStr;
                return myBitmap;
            }
            catch (IOException e)
            {
                Logger.Log("We were not able to get a bitmap of the artwork");
                return null;
            }
        }

        Bitmap LoadLocal(String urlStr)
        {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            return BitmapFactory.decodeFile(urlStr, options);
        }

        protected void onPostExecute(Bitmap result)
        {
            if (result != null)
            {
                setArtworkBitmap(result);
            }
        }
    }

    private MediaSessionCompat _session;
    private StreamingAudioService _service;
    private int _primaryActionIcon;
    private String _primaryActionTitle;
    private int _primaryActionKeyEvent;
    private MediaMetadataCompat.Builder _metadataBuilder;

    private ArtworkMediaNotification(MediaMetadataCompat metadata, MediaSessionCompat session, StreamingAudioService service, String urlStr,
                                     int primaryActionIcon, String primaryActionTitle, int primaryActionKeyEvent)
    {
        _session = session;
        _service = service;
        _primaryActionIcon = primaryActionIcon;
        _primaryActionTitle = primaryActionTitle;
        _primaryActionKeyEvent = primaryActionKeyEvent;
        _metadataBuilder = new MediaMetadataCompat.Builder(metadata);
        if (urlStr!=null)
{'fraction_non_alphanumeric': 0.06837201957997789, 'fraction_numerical': 0.0022106426654034425, 'mean_word_length': 1.9681349578256795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7546001', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1514, 'n_words': 357}