// Path: android/Brasilino/app/src/main/java/com/paypal/developer/brasilino/broadcast/PaymentOrderReceiver.java
// public class PaymentOrderReceiver extends BroadcastReceiver {
// 
//     public PaymentOrderReceiver() {}
// 
//     @Override
//     public void onReceive(Context context, Intent intent) {
// 
//         NotificationManagerCompat.from(context).cancel(Util.NOTIFICATION_ID);
// 
//         if(intent != null && intent.hasExtra(IntentParameters.UUID)) {
//             CandieSQLiteDataSource dataSource = CarrinhoApplication.getDatasource();
// 
//             if(dataSource != null) {
//                 Token token = dataSource.getToken();
//                 if(token != null) {
// 
//                     Util.sendMessage(
//                             "/candies/payment",
//                             "start"
//                     );
// 
//                     Intent serviceIntent = new Intent(context, PaymentService.class);
//                     serviceIntent.putExtras(intent.getExtras());
//                     serviceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                     context.startService(serviceIntent);
//                     return;
//                 }
//             }
// 
//             Util.sendMessage(
//                     "/candies/payment",
//                     "token"
//             );
// 
//             Intent webIntent = new Intent(context, PermissionActivity.class);
//             webIntent.putExtras(intent.getExtras());
//             webIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//             context.startActivity(webIntent);
//         }
//     }
// }


import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;
import com.paypal.developer.brasilino.R;
import com.paypal.developer.brasilino.broadcast.PaymentOrderReceiver;
import java.util.Calendar;

        NotificationManagerCompat manager = NotificationManagerCompat.from(context);
        manager.notify(NOTIFICATION_ID,notification);
    }

    public static boolean isServiceRunning(Class<?> serviceClass, Context context) {
        ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (serviceClass.getName().equals(service.service.getClassName())) {
                return true;
            }
        }
        return false;
    }

    public static void sendMessage(String path, String message) {
        Log.e("THTPAYPALCARRINHO", path + " - " + message);
    }

    public static void scheduleReceiver(Context context, Class receiver) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.MILLISECOND, 500);

        AlarmManager alarmManager = (AlarmManager)context.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent receiverIntent = new Intent(context.getApplicationContext(), receiver);
        PendingIntent receiverPendent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, receiverIntent, 0);
        alarmManager.set(
                AlarmManager.RTC_WAKEUP,
                calendar.getTimeInMillis(),
// Path: android/Brasilino/app/src/main/java/com/paypal/developer/brasilino/broadcast/PaymentOrderReceiver.java
// public class PaymentOrderReceiver extends BroadcastReceiver {
// 
//     public PaymentOrderReceiver() {}
// 
//     @Override
//     public void onReceive(Context context, Intent intent) {
// 
//         NotificationManagerCompat.from(context).cancel(Util.NOTIFICATION_ID);
// 
//         if(intent != null && intent.hasExtra(IntentParameters.UUID)) {
//             CandieSQLiteDataSource dataSource = CarrinhoApplication.getDatasource();
// 
//             if(dataSource != null) {
//                 Token token = dataSource.getToken();
//                 if(token != null) {
// 
//                     Util.sendMessage(
//                             "/candies/payment",
//                             "start"
//                     );
// 
//                     Intent serviceIntent = new Intent(context, PaymentService.class);
//                     serviceIntent.putExtras(intent.getExtras());
//                     serviceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                     context.startService(serviceIntent);
//                     return;
//                 }
//             }
// 
//             Util.sendMessage(
//                     "/candies/payment",
//                     "token"
//             );
// 
//             Intent webIntent = new Intent(context, PermissionActivity.class);
//             webIntent.putExtras(intent.getExtras());
//             webIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//             context.startActivity(webIntent);
//         }
//     }
// }


// Path: android/Brasilino/app/src/main/java/com/paypal/developer/brasilino/util/Util.java
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;
import com.paypal.developer.brasilino.R;
import com.paypal.developer.brasilino.broadcast.PaymentOrderReceiver;
import java.util.Calendar;


        NotificationManagerCompat manager = NotificationManagerCompat.from(context);
        manager.notify(NOTIFICATION_ID,notification);
    }

    public static boolean isServiceRunning(Class<?> serviceClass, Context context) {
        ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (serviceClass.getName().equals(service.service.getClassName())) {
                return true;
            }
        }
        return false;
    }

    public static void sendMessage(String path, String message) {
        Log.e("THTPAYPALCARRINHO", path + " - " + message);
    }

    public static void scheduleReceiver(Context context, Class receiver) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.MILLISECOND, 500);

        AlarmManager alarmManager = (AlarmManager)context.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent receiverIntent = new Intent(context.getApplicationContext(), receiver);
        PendingIntent receiverPendent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, receiverIntent, 0);
        alarmManager.set(
                AlarmManager.RTC_WAKEUP,
                calendar.getTimeInMillis(),
                receiverPendent