Android Open Source - led-notifier Notification Utils






From Project

Back to project page led-notifier.

License

The source code is released under:

Apache License

If you think the Android project led-notifier 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.ciubotariu_levy.lednotifier;
//from w  ww .ja  v  a  2  s.c  om
import android.annotation.TargetApi;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;

public class NotificationUtils {
  public static final String TAG = NotificationUtils.class.getName();
  public static final int RECEIVER_REQUEST_CODE = 1;
  public static final int NOTIFICATION_ID = 1;
  public static final int DELAY_TIME = 10*60*1000;

  
  public static String title;
  public static String message;
  public static PendingIntent contentIntent;
  
  @TargetApi(19)
  public static void notify (Context context, Notification notif, boolean timeoutLED){
    dismissAlarm (context);
    if (notif.ledARGB == Color.GRAY){ //ensure LED is turned off
      notif.ledARGB = 0;
      notif.ledOnMS = 0;
      notif.ledOffMS = 0;
      notif.flags = notif.flags & ~Notification.FLAG_SHOW_LIGHTS;
      timeoutLED = false;
    }
    if (timeoutLED){
      Intent i = new Intent (context,LEDCancelReceiver.class);
      PendingIntent p = PendingIntent.getBroadcast(context, RECEIVER_REQUEST_CODE, i, PendingIntent.FLAG_UPDATE_CURRENT);
      AlarmManager a = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT){
        a.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+DELAY_TIME, p);
      }
      else {
        a.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+DELAY_TIME, p);
      }
    }
    notify (context,notif);
  }
  
  public static void notify (Context context, Notification notif){
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, notif);
  }
  
  public static void dismissAlarm (Context context){
    Intent i = new Intent (context,LEDCancelReceiver.class);
    PendingIntent p = PendingIntent.getBroadcast(context, RECEIVER_REQUEST_CODE, i, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager a = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    a.cancel(p);
  }
  
  public static void cancel (Context context){
    dismissAlarm(context);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(NOTIFICATION_ID);
    title = null;
    message = null;
    contentIntent = null;
  }
}




Java Source Code List

com.ciubotariu_levy.lednotifier.AboutActivity.java
com.ciubotariu_levy.lednotifier.AlarmDismissReceiver.java
com.ciubotariu_levy.lednotifier.BoldCheckedView.java
com.ciubotariu_levy.lednotifier.BootBroadcastReceiver.java
com.ciubotariu_levy.lednotifier.CircularColorView.java
com.ciubotariu_levy.lednotifier.ColorDialog.java
com.ciubotariu_levy.lednotifier.ColorVibrateDialog.java
com.ciubotariu_levy.lednotifier.ContactsFragment.java
com.ciubotariu_levy.lednotifier.CustomContactsFragment.java
com.ciubotariu_levy.lednotifier.DataFetcher.java
com.ciubotariu_levy.lednotifier.DefaultColorChooserContainer.java
com.ciubotariu_levy.lednotifier.FastScrollThemedListView.java
com.ciubotariu_levy.lednotifier.LEDCancelReceiver.java
com.ciubotariu_levy.lednotifier.MainActivity.java
com.ciubotariu_levy.lednotifier.NotificationService.java
com.ciubotariu_levy.lednotifier.NotificationUtils.java
com.ciubotariu_levy.lednotifier.ObserverService.java
com.ciubotariu_levy.lednotifier.SMSAppAdapter.java
com.ciubotariu_levy.lednotifier.SMSAppChooserContainer.java
com.ciubotariu_levy.lednotifier.SMSReceiver.java
com.ciubotariu_levy.lednotifier.SectionedCursorAdapter.java
com.ciubotariu_levy.lednotifier.SettingsActivity.java
com.ciubotariu_levy.lednotifier.SmsAppChooserDialog.java
com.ciubotariu_levy.lednotifier.providers.LedContactInfo.java
com.ciubotariu_levy.lednotifier.providers.LedContactProvider.java
com.ciubotariu_levy.lednotifier.providers.LedContacts.java
com.larswerkman.holocolorpicker.ColorPicker.java
com.larswerkman.holocolorpicker.EndColorPicker.java
com.larswerkman.holocolorpicker.LinearColorPicker.java
com.larswerkman.holocolorpicker.OnColorChangedListener.java
com.larswerkman.holocolorpicker.OpacityBar.java
com.larswerkman.holocolorpicker.SVBar.java
com.larswerkman.holocolorpicker.SaturationBar.java
com.larswerkman.holocolorpicker.ValueBar.java
com.makeramen.RoundedDrawable.java
com.makeramen.RoundedTransformationBuilder.java