package com.example.patrice.boot_01;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.Toast;

import static android.content.Context.NOTIFICATION_SERVICE;

public class notification_display extends BroadcastReceiver
{

    public static String _NOTIFICATION_ID = "notification-id";
    public static String _NOTIFICATION = "notification";

    public void onReceive(Context context, Intent intent)
    {
/*
        final Intent launchNotifiactionIntent = new Intent(this, TutoNotificationHomeActivity.class);
        final PendingIntent pendingIntent = PendingIntent.getActivity(this,
                100, launchNotifiactionIntent,
                PendingIntent.FLAG_ONE_SHOT);
 */
        Toast.makeText(context, "Ajout d'une notification", Toast.LENGTH_LONG).show();

        Log.v("*********", "trace");


        int num = 1; //(int) System.currentTimeMillis();

        NotificationManager notificationManagerCompat = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setTicker("Retour jeu ludothéque !")
                .setContentTitle("title")
                .setSmallIcon(R.drawable.notification)
                .setContentText("message")
                .setColor(ContextCompat.getColor(context, android.R.color.black))
                //.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
                .setSound(alarmSound)

              //  .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT))

                .setAutoCancel(true);
                //.setContentIntent(pendingIntent);

        // hide the notification after its selected
        //builder.build().flags |= Notification.FLAG_AUTO_CANCEL;

        builder.build().flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

        //  notificationManagerCompat.notify(notifId, builder.build());

        notificationManagerCompat.notify(num, builder.build());

    //    http://www.androidbegin.com/tutorial/android-broadcast-receiver-notification-tutorial//

/*
        final NotificationManager mNotification = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);

        final Intent launchNotifiactionIntent = new Intent(this, notification_display.class);
        final PendingIntent pendingIntent = PendingIntent.getActivity(context,  100, launchNotifiactionIntent, PendingIntent.FLAG_ONE_SHOT);

        Notification.Builder aaabuilder = new Notification.Builder(context)
                .setWhen(System.currentTimeMillis())
                .setTicker("notificationTitle")
                .setSmallIcon(R.drawable.notification)
                //.setColor(Color.BLUE)
                .setContentTitle("title")
                .setContentText("desc")
                .setAutoCancel(true)
                .setContentIntent(pendingIntent);

        mNotification.notify(1 , aaabuilder.build());
*/

    }
}