Android Open Source - RadioRake Notification Helper






From Project

Back to project page RadioRake.

License

The source code is released under:

GNU General Public License

If you think the Android project RadioRake 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.asp.radiorake;
/* ww w. j av  a2s.c o m*/
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.aspillai.R;

public abstract class NotificationHelper {

    public static final int NOTIFICATION_PLAYING_ID = 1;
    public static final int NOTIFICATION_RECORDING_ID = 2;

    public static Notification getNotification(Context context, int notificationId, RadioDetails radioDetails, CharSequence tickerText, CharSequence contentText, int flag) {
        long when = System.currentTimeMillis();
        Notification notification;

        switch (notificationId) {
            case NOTIFICATION_PLAYING_ID:
                notification = new Notification(R.drawable.ic_notification_playing, tickerText, when);
                break;
            case NOTIFICATION_RECORDING_ID:
                notification = new Notification(R.drawable.ic_notification_recording, tickerText, when);
                break;
            default:
                notification = new Notification();
        }

        CharSequence contentTitle = context.getString(R.string.app_name);
        Intent notificationIntent = new Intent(context, RadioActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        notification.flags = flag;

        return notification;
    }

    public static void showNotification(Context context, int notificationId, CharSequence tickerText, CharSequence contentText) {

        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        long when = System.currentTimeMillis();
        Notification notification = null;

        switch (notificationId) {
            case NOTIFICATION_PLAYING_ID:
                notification = new Notification(R.drawable.ic_notification_playing, tickerText, when);
                break;
            case NOTIFICATION_RECORDING_ID:
                notification = new Notification(R.drawable.ic_notification_recording, tickerText, when);
                break;
        }

        CharSequence contentTitle = context.getString(R.string.app_name);
        Intent notificationIntent = new Intent(context, RadioActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        if (notification != null) {
            notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
            notification.flags = Notification.FLAG_ONGOING_EVENT;
        }

        notificationManager.notify(notificationId, notification);
    }

    public static void cancelNotification(Context context, int notificationId) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(notificationId);
    }
}




Java Source Code List

com.asp.radiorake.AddNewScheduledRecordingActivity.java
com.asp.radiorake.AlarmHelper.java
com.asp.radiorake.CallReceiver.java
com.asp.radiorake.ConfirmDetailsActivity.java
com.asp.radiorake.DatabaseHelper.java
com.asp.radiorake.DatePickerFragment.java
com.asp.radiorake.LastPlayedFile.java
com.asp.radiorake.ListScheduledRecordingsActivity.java
com.asp.radiorake.NotificationHelper.java
com.asp.radiorake.PlayerService.java
com.asp.radiorake.PlayingFile.java
com.asp.radiorake.RadioActivity.java
com.asp.radiorake.RadioApplication.java
com.asp.radiorake.RadioDetails.java
com.asp.radiorake.RebootBroadcastReceiver.java
com.asp.radiorake.RecordingsActivity.java
com.asp.radiorake.RecordioBaseActivity.java
com.asp.radiorake.RemoteControlReceiver.java
com.asp.radiorake.ScheduledRecordingsCursorAdaptor.java
com.asp.radiorake.TimePickerFragment.java
com.asp.radiorake.filehandling.FileHandler.java
com.asp.radiorake.filehandling.M3uHandler.java
com.asp.radiorake.filehandling.PlsHandler.java
com.asp.radiorake.recording.RecorderService.java
com.asp.radiorake.recording.RecordingBroadcastReceiver.java
com.asp.radiorake.utils.DateUtils.java
com.asp.radiorake.utils.StringUtils.java