Android Open Source - watchme Notification Client






From Project

Back to project page watchme.

License

The source code is released under:

Copyright (c) 2012 Johan Brook, Robin Andersson, Lisa Stenberg, Mattias Henriksson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documen...

If you think the Android project watchme 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

/**
*  NotificationClient.java/*from  ww  w  .j  av  a  2  s  . co m*/
*
*  The client responsible for handling notifications. This client
*  should be bound to a service. See the methods connectToService()
*  and disconnectFromService().
*
*  @author Johan
*  @copyright (c) 2012 Johan Brook, Robin Andersson, Lisa Stenberg, Mattias Henriksson
*  @license MIT
*/

package se.chalmers.watchme.notifications;

import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

public class NotificationClient {
  
  private Context ctx;
  private NotificationService service;
  private boolean isBound;
  private ServiceConnection connection;

  /**
   * Create a new client from a context.
   * 
   * @param context The context
   */
  public NotificationClient(Context context) {
    this.ctx = context;
    this.isBound = false;
    
    /**
     * The connection to the notification service.
     */
    this.connection = new ServiceConnection() {

      public void onServiceConnected(ComponentName name, IBinder s) {
        service = ((NotificationService.ServiceBinder) s).getService();
        
      }

      public void onServiceDisconnected(ComponentName name) {
        service = null;
      }
      
    };
  }
  
  /**
   * Initiate the connection to the service. 
   */
  public void connectToService() {
    Log.i("Custom", "Connecting to service");
    
    // Bind to NotificationService with the connection.
    this.isBound = this.ctx.bindService(
                new Intent(this.ctx, NotificationService.class), 
                this.connection, 
                Context.BIND_AUTO_CREATE);
  }
  
  /**
   * Disconnect from the service
   */
  public void disconnectService() {
    if(this.isBound) {
      this.ctx.unbindService(this.connection);
      this.isBound = false;
    }
  }
  
  /**
   * Set a notification for a movie.
   * 
   * @param movie The movie
   */
  public void setMovieNotification(Notifiable movie) {
    
    if(this.service != null){
      Log.i("Custom", "Set date for notification");
      this.service.setAlarmTaskForMovie(movie);
    }
  }
  
  /**
   * Cancel a notification for a notifiable object
   * 
   * @param obj The object to cancel notification for
   */
  public void cancelNotification(Notifiable obj) {
    cancelNotification(this.ctx, obj);
  }
  
  /**
   * Cancel a notification for a notifiable object from
   * a certain context.
   * 
   * @param context The context
   * @param obj The object to cancel notification for
   */
  public static void cancelNotification(Context context, Notifiable obj) {
    NotificationManager manager = (NotificationManager) context.
        getSystemService(Context.NOTIFICATION_SERVICE);
    
    int id = obj.getNotificationId();
    manager.cancel(id);
    Log.i("Custom", "** Notification "+id+" was cancelled");
  }
}




Java Source Code List

se.chalmers.watchme.activity.AddMovieActivity.java
se.chalmers.watchme.activity.AutoCompleteAdapter.java
se.chalmers.watchme.activity.MainActivity.java
se.chalmers.watchme.activity.MovieDetailsActivity.java
se.chalmers.watchme.activity.SearchableActivity.java
se.chalmers.watchme.activity.TabsAdapter.java
se.chalmers.watchme.activity.TagMovieListActivity.java
se.chalmers.watchme.database.DatabaseAdapter.java
se.chalmers.watchme.database.DatabaseHelper.java
se.chalmers.watchme.database.GenericCursorLoader.java
se.chalmers.watchme.database.HasTagTable.java
se.chalmers.watchme.database.ICursorHelper.java
se.chalmers.watchme.database.MovieAlreadyExistsException.java
se.chalmers.watchme.database.MoviesTable.java
se.chalmers.watchme.database.TagsTable.java
se.chalmers.watchme.database.WatchMeContentProvider.java
se.chalmers.watchme.model.Movie.java
se.chalmers.watchme.model.Tag.java
se.chalmers.watchme.net.HttpRetriever.java
se.chalmers.watchme.net.IMDBHandler.java
se.chalmers.watchme.net.ImageDownloadTask.java
se.chalmers.watchme.net.MovieSource.java
se.chalmers.watchme.net.NoEntityException.java
se.chalmers.watchme.notifications.Notifiable.java
se.chalmers.watchme.notifications.NotificationClient.java
se.chalmers.watchme.notifications.NotificationService.java
se.chalmers.watchme.notifications.NotifyService.java
se.chalmers.watchme.ui.ContentListFragment.java
se.chalmers.watchme.ui.DatePickerFragment.java
se.chalmers.watchme.ui.ImageDialog.java
se.chalmers.watchme.ui.MovieListFragment.java
se.chalmers.watchme.ui.TagListFragment.java
se.chalmers.watchme.utils.DateTimeUtils.java
se.chalmers.watchme.utils.ImageCache.java
se.chalmers.watchme.utils.MenuUtils.java
se.chalmers.watchme.utils.MovieHelper.java
se.chalmers.watchmetest.Constants.java
se.chalmers.watchmetest.activity.MainActivityTest.java
se.chalmers.watchmetest.activity.MovieDetailsActivityTest.java
se.chalmers.watchmetest.activity.SearchableActivityTest.java
se.chalmers.watchmetest.activity.TabsAdapterTest.java
se.chalmers.watchmetest.activity.TagMovieListActivityTest.java
se.chalmers.watchmetest.database.WatchMeContentProviderTest.java
se.chalmers.watchmetest.model.MovieTest.java
se.chalmers.watchmetest.model.TagTest.java
se.chalmers.watchmetest.net.HttpRetrieverTest.java
se.chalmers.watchmetest.net.IMDBHandlerTest.java
se.chalmers.watchmetest.ui.MovieListFragmentTest.java
se.chalmers.watchmetest.ui.TagListFragmentTest.java
se.chalmers.watchmetest.util.DateTimeUtilsTest.java
se.chalmers.watchmetest.util.MovieHelperTest.java