Example #1
0
  public static void showPlayingNotification(
      final Context context,
      final DownloadServiceImpl downloadService,
      Handler handler,
      MusicDirectory.Entry song) {
    // Set the icon, scrolling text and timestamp
    final Notification notification =
        new Notification(
            R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      RemoteViews expandedContentView =
          new RemoteViews(context.getPackageName(), R.layout.notification_expanded);
      setupViews(expandedContentView, context, song, playing);
      notification.bigContentView = expandedContentView;
    }

    RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    setupViews(smallContentView, context, song, playing);
    notification.contentView = smallContentView;

    Intent notificationIntent = new Intent(context, DownloadActivity.class);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    NotificationManager manager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(notificationID, notification);

    // Update widget
    DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true);
  }
Example #2
0
  public static void hidePlayingNotification(
      final Context context, final DownloadServiceImpl downloadService, Handler handler) {
    NotificationManager manager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancelAll();

    // Update widget
    DSubWidgetProvider.getInstance().notifyChange(context, downloadService, false);
  }