<commit_before>/*
 * Copyright (C) 2010-2015 The MPDroid Project
 *
 * 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.namelessdev.mpdroid.service;

import com.anpmech.mpd.item.Music;
import com.anpmech.mpd.subsystem.status.MPDStatusMap;
import com.namelessdev.mpdroid.MPDApplication;
import com.namelessdev.mpdroid.MainMenuActivity;
import com.namelessdev.mpdroid.R;
import com.namelessdev.mpdroid.RemoteControlReceiver;
import com.namelessdev.mpdroid.helpers.AlbumCoverDownloadListener;
import com.namelessdev.mpdroid.helpers.MPDControl;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.widget.RemoteViews;

/**
 * A class to handle everything necessary for the MPDroid notification.
 */
public class NotificationHandler implements AlbumCoverHandler.NotificationCallback {

    static final int LOCAL_UID = 300;

    public static final int START = LOCAL_UID + 1;

    public static final int STOP = LOCAL_UID + 2;

    public static final int IS_ACTIVE = LOCAL_UID + 3;

    public static final int PERSISTENT_OVERRIDDEN = LOCAL_UID + 4;

    private static final int NOTIFICATION_ID = 1;

    private static final String TAG = "NotificationHandler";

    private static final String FULLY_QUALIFIED_NAME = MPDroidService.PACKAGE_NAME + TAG;

    public static final String ACTION_START = FULLY_QUALIFIED_NAME + ".ACTION_START";

    public static final String ACTION_STOP = FULLY_QUALIFIED_NAME + ".ACTION_STOP";

    private final Notification mNotification;

    private final NotificationManager mNotificationManager;

    private final MPDroidService mServiceContext;

    private Music mCurrentTrack;

    private boolean mIsActive;

    private boolean mIsForeground;

    private boolean mIsMediaPlayerBuffering;

    NotificationHandler(final MPDroidService serviceContext) {
        super();

        mServiceContext = serviceContext;

        mNotificationManager = (NotificationManager) mServiceContext
                .getSystemService(Context.NOTIFICATION_SERVICE);

        final RemoteViews resultView = new RemoteViews(mServiceContext.getPackageName(),
                R.layout.notification);

        buildBaseNotification(resultView);
        mNotification = buildCollapsedNotification(serviceContext).setContent(resultView).build();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            buildExpandedNotification();
        }

        mIsActive = true;
    }

    /**
     * This builds a new collapsed notification.
     *
     * @param context The context required to build the Notification.
     * @return Returns a notification builder object.
     */
    private static NotificationCompat.Builder
    buildCollapsedNotification(final MPDroidService context) {
        final Intent musicPlayerActivity = new Intent(context, MainMenuActivity.class);
        final PendingIntent notificationClick = PendingIntent
                .getActivity(context, 0, musicPlayerActivity,
                        PendingIntent.FLAG_UPDATE_CURRENT);

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.icon_notification);
        builder.setContentIntent(notificationClick);
        builder.setStyle(new NotificationCompat.BigTextStyle());

        return builder;
    }

    /**
     * A function to translate 'what' fields to literal debug name, used primarily for debugging.
     *
     * @param what A 'what' field.
     * @return The literal field name.
     */
    public static String getHandlerValue(final int what) {
        final String result;

        switch (what) {
            case LOCAL_UID:
                result = "LOCAL_UID";
                break;
            case START:
                result = "START";
                break;
            case STOP:<commit_msg>NotificationHandler: Make notification visibility public.<commit_after>/*
 * Copyright (C) 2010-2015 The MPDroid Project
 *
 * 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.namelessdev.mpdroid.service;

import com.anpmech.mpd.item.Music;
import com.anpmech.mpd.subsystem.status.MPDStatusMap;
import com.namelessdev.mpdroid.MPDApplication;
import com.namelessdev.mpdroid.MainMenuActivity;
import com.namelessdev.mpdroid.R;
import com.namelessdev.mpdroid.RemoteControlReceiver;
import com.namelessdev.mpdroid.helpers.AlbumCoverDownloadListener;
import com.namelessdev.mpdroid.helpers.MPDControl;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.widget.RemoteViews;

/**
 * A class to handle everything necessary for the MPDroid notification.
 */
public class NotificationHandler implements AlbumCoverHandler.NotificationCallback {

    static final int LOCAL_UID = 300;

    public static final int START = LOCAL_UID + 1;

    public static final int STOP = LOCAL_UID + 2;

    public static final int IS_ACTIVE = LOCAL_UID + 3;

    public static final int PERSISTENT_OVERRIDDEN = LOCAL_UID + 4;

    private static final int NOTIFICATION_ID = 1;

    private static final String TAG = "NotificationHandler";

    private static final String FULLY_QUALIFIED_NAME = MPDroidService.PACKAGE_NAME + TAG;

    public static final String ACTION_START = FULLY_QUALIFIED_NAME + ".ACTION_START";

    public static final String ACTION_STOP = FULLY_QUALIFIED_NAME + ".ACTION_STOP";

    private final Notification mNotification;

    private final NotificationManager mNotificationManager;

    private final MPDroidService mServiceContext;

    private Music mCurrentTrack;

    private boolean mIsActive;

    private boolean mIsForeground;

    private boolean mIsMediaPlayerBuffering;

    NotificationHandler(final MPDroidService serviceContext) {
        super();

        mServiceContext = serviceContext;

        mNotificationManager = (NotificationManager) mServiceContext
                .getSystemService(Context.NOTIFICATION_SERVICE);

        final RemoteViews resultView = new RemoteViews(mServiceContext.getPackageName(),
                R.layout.notification);

        buildBaseNotification(resultView);
        mNotification = buildCollapsedNotification(serviceContext).setContent(resultView).build();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            buildExpandedNotification();
        }

        mIsActive = true;
    }

    /**
     * This builds a new collapsed notification.
     *
     * @param context The context required to build the Notification.
     * @return Returns a notification builder object.
     */
    private static NotificationCompat.Builder
    buildCollapsedNotification(final MPDroidService context) {
        final Intent musicPlayerActivity = new Intent(context, MainMenuActivity.class);
        final PendingIntent notificationClick = PendingIntent
                .getActivity(context, 0, musicPlayerActivity,
                        PendingIntent.FLAG_UPDATE_CURRENT);

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.icon_notification);
        builder.setContentIntent(notificationClick);
        builder.setStyle(new NotificationCompat.BigTextStyle());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        }

        return builder;
    }

    /**
     * A function to translate 'what' fields to literal debug name, used primarily for debugging.
     *
     * @param what A 'what' field.
     * @return The literal field name.
     */
    public static String getHandlerValue(final int what) {
        final String result;

        switch (what) {
            case LOCAL_UID:
                result = "LOCAL_UID";
                break;
            case START:
                result = "START";
                break;
            case STOP:
{'fraction_non_alphanumeric': 0.07093773126123269, 'fraction_numerical': 0.004651654508933291, 'mean_word_length': 3.3554327808471456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1222177', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2396, 'n_words': 715}