All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.easypush.pushlibrary.notifications.NotificationFactory Maven / Gradle / Ivy

There is a newer version: 0.8
Show newest version
package eu.easypush.pushlibrary.notifications;

import org.json.JSONObject;

import java.util.HashMap;

public class NotificationFactory {
	public static final HashMap notificationsByType = new HashMap() {
		{
			put("simple", SimpleNotification.class.getName());
			put("expandablepicture", ExpandablePictureNotification.class.getName());
		}
	};

	public static EasypushNotification getNotification(String type, JSONObject message) {
		String className = notificationsByType.get(type);
        if (className == null){
            return new SimpleNotification(message);
        }
        try {
            Object myClass = Class.forName(className).getDeclaredConstructor(JSONObject.class)
                    .newInstance(message);
            if (myClass instanceof EasypushNotification) {
                return (EasypushNotification) myClass;
            }
        } catch (Throwable t) {
        }
        return new SimpleNotification(message);


    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy