Commit 2d2ce205 authored by PKnittel's avatar PKnittel
Browse files

Transferred the showNotification-Function to NotificationWrapper-Class

parent e364b93b
Loading
Loading
Loading
Loading
+5 −3
Changes for src/android/Receiver.java: 5 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import android.support.v4.app.NotificationCompat.Builder;

import de.appplant.cordova.plugin.notification.*;

/**
@@ -80,12 +82,12 @@ public class Receiver extends BroadcastReceiver {
        	if (options.getInterval() == 0) {
        		LocalNotification.unpersist(options.getId());
        	}
        	builder.showNotificationToast();
        	nWrapper.showNotificationToast(options);
        	fireTriggerEvent();
        } else {
        	builder.buildNotification();
        	Builder notification = builder.buildNotification();

        	builder.showNotification();
        	nWrapper.showNotification(notification, options);
        }
    }

+3 −42
Changes for src/android/notification/NotificationBuilder.java: 3 added lines, 42 removed lines.
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ package de.appplant.cordova.plugin.notification;
import java.util.Random;

import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -31,7 +30,6 @@ import android.net.Uri;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.widget.Toast;

public class NotificationBuilder {
	private Options options;
@@ -62,7 +60,7 @@ public class NotificationBuilder {
     * Creates the notification.
     */
    @SuppressLint("NewApi")
    public void buildNotification () {
    public Builder buildNotification () {
        Uri sound = options.getSound();
        
        //DeleteIntent is called when the user clears a notification manually
@@ -94,6 +92,8 @@ public class NotificationBuilder {
        }

        setClickEvent(notification);
        
        return notification;
    }

    /**
@@ -111,43 +111,4 @@ public class NotificationBuilder {
        return notification.setContentIntent(contentIntent);
    }
	
    /**
     * Shows the notification
     */
    @SuppressWarnings("deprecation")
    public void showNotification () {
        NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        int id                  = 0;

        try {
            id = Integer.parseInt(options.getId());
        } catch (Exception e) {}

        if (Build.VERSION.SDK_INT<16) {
            // build notification for HoneyComb to ICS
            mgr.notify(id, notification.getNotification());
        } else if (Build.VERSION.SDK_INT>15) {
            // Notification for Jellybean and above
            mgr.notify(id, notification.build());
        }
    }
    
    /**
     * Show a notification as a Toast when App is runing in foreground
     * @param title Title of the notification
     * @param notification Notification to show
     */
    public void showNotificationToast(){
    	String title = options.getTitle();
    	String message = options.getMessage();
       	int duration = Toast.LENGTH_LONG;
       	if(title.equals("")){
       		title = "Notification";
       	}
       	String text = title + " \n " + message;
       	
    	Toast notificationToast = Toast.makeText(context, text, duration);
    	notificationToast.show();
   }
	
}
+41 −0
Changes for src/android/notification/NotificationWrapper.java: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.support.v4.app.NotificationCompat.Builder;
import android.widget.Toast;

/**
 * Wrapper class to schedule, cancel, clear, and update notifications.
@@ -207,6 +209,45 @@ public class NotificationWrapper {
        nc.cancelAll();
    }
    
    /**
     * Shows the notification
     */
    @SuppressWarnings("deprecation")
    public void showNotification (Builder notification, Options options) {
        NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        int id                  = 0;

        try {
            id = Integer.parseInt(options.getId());
        } catch (Exception e) {}

        if (Build.VERSION.SDK_INT<16) {
            // build notification for HoneyComb to ICS
            mgr.notify(id, notification.getNotification());
        } else if (Build.VERSION.SDK_INT>15) {
            // Notification for Jellybean and above
            mgr.notify(id, notification.build());
        }
    }
    
    /**
     * Show a notification as a Toast when App is runing in foreground
     * @param title Title of the notification
     * @param notification Notification to show
     */
    public void showNotificationToast(Options options){
    	String title = options.getTitle();
    	String message = options.getMessage();
       	int duration = Toast.LENGTH_LONG;
       	if(title.equals("")){
       		title = "Notification";
       	}
       	String text = title + " \n " + message;
       	
    	Toast notificationToast = Toast.makeText(context, text, duration);
    	notificationToast.show();
   }
	
    //---------------Manage Shared Preferences---------------------------------------------------
    
    /**