package com.example.patrice.rerservation01.alarm02;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;
import android.support.v4.app.NotificationCompat;
import android.widget.Toast;

import com.example.patrice.rerservation01.R;

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

public class MyBroadcastReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        Toast.makeText(context, "Time Up... Now Vibrating !!!",  Toast.LENGTH_LONG).show();

        //Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        //vibrator.vibrate(2000);

        Notification(context, "Wifi Connection Off");

    }

    public void Notification(Context context, String message)
    {
        // Set Notification Title
        String strtitle = context.getString(R.string.notification_title);

        // Open NotificationView Class on Notification Click
        Intent intent = new Intent(context, NotificationView.class);

        // Send data to NotificationView Class
        intent.putExtra("title", strtitle);
        intent.putExtra("text", message);

        // Open NotificationView.java Activity
        PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent,  PendingIntent.FLAG_UPDATE_CURRENT);

        // Create Notification using NotificationCompat.Builder
        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context)
                // Set Icon
                .setSmallIcon(R.drawable.notifications)
                // Set Ticker Message
                .setTicker(message)
                // Set Title
                .setContentTitle(context.getString(R.string.notification_title))
                // Set Text
                .setContentText(message)
                // Add an Action Button below Notification
                .addAction(R.drawable.ic_launcher, "Action Button", pIntent)
                // Set PendingIntent into Notification
                .setContentIntent(pIntent)
                // Dismiss Notification
                .setAutoCancel(true);

        // Create Notification Manager
        NotificationManager notificationmanager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        // Build Notification with Notification Manager
        notificationmanager.notify(0, builder.build());

    }

}
