Android Open Source - notify-me-android Push Notification History






From Project

Back to project page notify-me-android.

License

The source code is released under:

MIT License

If you think the Android project notify-me-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.contexthub.notifyme.model;
//from   w  w  w  .ja  v  a 2 s.  co m
import android.os.Bundle;

import com.contexthub.notifyme.Constants;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.pixplicity.easyprefs.library.Prefs;

import java.util.ArrayList;

/**
 * A list of {@link com.contexthub.notifyme.model.ReceivedPushNotification} instances stored in shared preferences
 */
public class PushNotificationHistory extends ArrayList<ReceivedPushNotification> {

    private static Gson gson = new GsonBuilder()
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();

    public static void save(Bundle bundle) {
        ReceivedPushNotification notification = new ReceivedPushNotification(bundle);
        PushNotificationHistory history = load();
        history.add(0, notification);
        Prefs.putString(Constants.KEY_PUSH_HISTORY, gson.toJson(history, PushNotificationHistory.class));
    }

    public static PushNotificationHistory load() {
        try {
            String data = Prefs.getString(Constants.KEY_PUSH_HISTORY, "");
            PushNotificationHistory history = gson.fromJson(data, PushNotificationHistory.class);
            return history == null ? new PushNotificationHistory() : history;
        }
        catch (Exception e) {
            return new PushNotificationHistory();
        }
    }

    public static void delete() {
        Prefs.remove(Constants.KEY_PUSH_HISTORY);
    }
}




Java Source Code List

com.contexthub.notifyme.ApplicationTest.java
com.contexthub.notifyme.Constants.java
com.contexthub.notifyme.MainActivity.java
com.contexthub.notifyme.NotifyMeApp.java
com.contexthub.notifyme.fragments.AboutFragment.java
com.contexthub.notifyme.fragments.DeviceFragment.java
com.contexthub.notifyme.fragments.PushReceiveFragment.java
com.contexthub.notifyme.fragments.PushSendFragment.java
com.contexthub.notifyme.model.CustomData.java
com.contexthub.notifyme.model.PushNotificationHistory.java
com.contexthub.notifyme.model.ReceivedPushNotification.java
com.contexthub.notifyme.push.NotificationHandler.java
com.contexthub.notifyme.widget.ClipboardTextView.java