Android Open Source - DashNotifier Notification Provider






From Project

Back to project page DashNotifier.

License

The source code is released under:

MIT License

If you think the Android project DashNotifier 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.umang.dashnotifier.provider;
//  www  .  j a  va 2 s .  c o  m
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

public class NotificationProvider extends ContentProvider {
  private static final String TAG = "NotificationProvider";
  private NotificationStore db;
  // Used for the UriMacher
  private static final int NOTIFICATIONS = 10;
  private static final int NOTIFICATION_ID = 20;

  // public constants for client development
  public static final String AUTHORITY = "com.umang.provider.dashnotifier";
  private static final String BASE_PATH = "notifications";
  public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/" + BASE_PATH);
  public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
          + "/notifications";
      public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
          + "/notification";
      
  private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
  static {
    sURIMatcher.addURI(AUTHORITY, BASE_PATH, NOTIFICATIONS);
    sURIMatcher.addURI(AUTHORITY, BASE_PATH + "/#", NOTIFICATION_ID);
  }
  // helper constants for use with the UriMatcher
  
  //private static final UriMatcher URI_MATCHER;
  public boolean check(){
    return true;
  }

    @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
      int uriType = sURIMatcher.match(uri);
        int rowsDeleted = 0;
        switch (uriType) {
        case NOTIFICATIONS:
          rowsDeleted = db.removeNotification(selection, selectionArgs);
          break;
        case NOTIFICATION_ID:
          String id = uri.getLastPathSegment();
          if (TextUtils.isEmpty(selection)) {
            rowsDeleted = db.removeNotification(id);
          } else {
            rowsDeleted = db.removeNotification(selection, selectionArgs);
          }
          break;
        default:
          throw new IllegalArgumentException("Unknown URI: " + uri);
        }
        if (rowsDeleted > 0)
          getContext().getContentResolver().notifyChange(uri, null);
        return rowsDeleted;
  }

  @Override
  public String getType(Uri arg0) {
    return null;
  }

  @Override
  public Uri insert(Uri uri, ContentValues notif) {
    
    int uriType = sURIMatcher.match(uri);
      long id = 0;
      switch (uriType) {
      case NOTIFICATIONS:
        id = db.storeNotification(notif);
        break;
      default:
        throw new IllegalArgumentException("Unknown URI: " + uri);
      }
      getContext().getContentResolver().notifyChange(uri, null);
      return Uri.parse(BASE_PATH + "/" + id);
  }

  @Override
  public boolean onCreate() {
    Log.d(TAG,"ContentProvider created");
    this.db = new NotificationStore(this.getContext());
    db.open();
      if (this.db == null) {
        return false;
      }
      return true;
  }

  @Override
  public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    
    return db.query(projection, selection, selectionArgs, sortOrder);
  }

  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    int uriType = sURIMatcher.match(uri);
      int rowsUpdated = 0;
      switch (uriType) {
      case NOTIFICATIONS:
        rowsUpdated = db.updateNotification( 
            values, 
            selection,
            selectionArgs);
        break;
      case NOTIFICATION_ID:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
          rowsUpdated = db.updateNotification(
              values,
              NotifSQLiteHelper.COL_ID + "=" + id, 
              null);
        } else {
          rowsUpdated = db.updateNotification( 
              values,
              NotifSQLiteHelper.COL_ID + "=" + id 
              + " and " 
              + selection,
              selectionArgs);
        }
        break;
      default:
        throw new IllegalArgumentException("Unknown URI: " + uri);
      }
      if (rowsUpdated > 0)
        getContext().getContentResolver().notifyChange(uri, null);
      return rowsUpdated;
    
  }
  
}




Java Source Code List

com.google.android.apps.dashclock.configuration.AppChooserPreference.java
com.google.android.apps.dashclock.ui.SimplePagedTabsHelper.java
com.umang.dashnotifier.AbstractSettings.java
com.umang.dashnotifier.AppListFragment.java
com.umang.dashnotifier.AppSelectActivity.java
com.umang.dashnotifier.ClickIntentActivity.java
com.umang.dashnotifier.Commons.java
com.umang.dashnotifier.DashNotificationListenerAcc.java
com.umang.dashnotifier.DashNotificationListener.java
com.umang.dashnotifier.DashNotifierExtension10.java
com.umang.dashnotifier.DashNotifierExtension11.java
com.umang.dashnotifier.DashNotifierExtension2.java
com.umang.dashnotifier.DashNotifierExtension3.java
com.umang.dashnotifier.DashNotifierExtension4.java
com.umang.dashnotifier.DashNotifierExtension5.java
com.umang.dashnotifier.DashNotifierExtension6.java
com.umang.dashnotifier.DashNotifierExtension7.java
com.umang.dashnotifier.DashNotifierExtension8.java
com.umang.dashnotifier.DashNotifierExtension9.java
com.umang.dashnotifier.DashNotifierExtension.java
com.umang.dashnotifier.DashNotifierSettingsActivity10.java
com.umang.dashnotifier.DashNotifierSettingsActivity11.java
com.umang.dashnotifier.DashNotifierSettingsActivity2.java
com.umang.dashnotifier.DashNotifierSettingsActivity3.java
com.umang.dashnotifier.DashNotifierSettingsActivity4.java
com.umang.dashnotifier.DashNotifierSettingsActivity5.java
com.umang.dashnotifier.DashNotifierSettingsActivity6.java
com.umang.dashnotifier.DashNotifierSettingsActivity7.java
com.umang.dashnotifier.DashNotifierSettingsActivity8.java
com.umang.dashnotifier.DashNotifierSettingsActivity9.java
com.umang.dashnotifier.DashNotifierSettingsActivity.java
com.umang.dashnotifier.HelpUtils.java
com.umang.dashnotifier.IconPicker.java
com.umang.dashnotifier.PackageAdapter.java
com.umang.dashnotifier.PackageItem.java
com.umang.dashnotifier.PrefsFragment.java
com.umang.dashnotifier.UnlockReceiver.java
com.umang.dashnotifier.provider.NotifSQLiteHelper.java
com.umang.dashnotifier.provider.NotificationProvider.java
com.umang.dashnotifier.provider.NotificationStore.java