Example #1
0
  @Override
  public int update(Uri uri, ContentValues values, String where, String[] selectionArgs) {

    int count;
    Util.showDLog(TAG + ":" + "update()" + values.toString());
    Util.showDLog(TAG + ":" + "update()" + uri.toString());
    Util.showDLog(TAG + ":" + "update(),match:" + "" + uriMatcher.match(uri));
    switch (uriMatcher.match(uri)) {
      case ITEM:
        Log.e(TAG + "update", ITEM + "");
        //			count = contactsDB.update(CONTACTS_TABLE, values, where,
        //					selectionArgs);

        count =
            pvrDB.update(
                CONTACTS_TABLE,
                values,
                AlarmColumn.TASKID
                    + "="
                    + values.getAsString(AlarmColumn.TASKID)
                    + (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""),
                selectionArgs);

        break;
      case ITEM_ID:
        String contactID1 = uri.getPathSegments().get(1);
        Log.e(TAG + "update", contactID1 + "");
        count =
            pvrDB.update(
                CONTACTS_TABLE,
                values,
                AlarmColumn.TASKID
                    + "="
                    + contactID1
                    + (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : ""),
                selectionArgs);
        break;
      default:
        throw new IllegalArgumentException("Unsupported URI: " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
Example #2
0
  @Override
  public Uri insert(Uri uri, ContentValues initialValues) {

    if ((uriMatcher.match(uri) != ITEM)) {
      throw new IllegalArgumentException("Unknown URI " + uri);
    }

    ContentValues values;

    switch (uriMatcher.match(uri)) {
      case ITEM:
        if (initialValues != null) {
          values = new ContentValues(initialValues);
        } else {
          values = new ContentValues();
        }
        Long now1 = Long.valueOf(System.currentTimeMillis());

        if (!values.containsKey(AlarmColumn.INPUTSOURCE)) {
          values.put(AlarmColumn.INPUTSOURCE, "DTV");
        }
        if (!values.containsKey(AlarmColumn.CHANNELNUM)) {
          values.put(AlarmColumn.CHANNELNUM, now1);
        }
        if (!values.containsKey(AlarmColumn.STARTTIME)) {
          values.put(AlarmColumn.STARTTIME, "");
        }
        if (!values.containsKey(AlarmColumn.ENDTIME)) {
          values.put(AlarmColumn.ENDTIME, "");
        }
        if (!values.containsKey(AlarmColumn.SCHEDULETYPE)) {
          values.put(AlarmColumn.SCHEDULETYPE, -1);
        }
        if (!values.containsKey(AlarmColumn.REPEATTYPE)) {
          values.put(AlarmColumn.REPEATTYPE, "");
        }
        if (!values.containsKey(AlarmColumn.DAYOFWEEK)) {
          values.put(AlarmColumn.DAYOFWEEK, 0);
        }
        if (!values.containsKey(AlarmColumn.ISENABLE)) {
          values.put(AlarmColumn.ISENABLE, 1);
        }

        Util.showDLog(values.toString());
        long rowId1 = pvrDB.insert(CONTACTS_TABLE, null, values);
        if (rowId1 > 0) {
          Uri noteUri = ContentUris.withAppendedId(CONTENT_URI, rowId1);
          getContext().getContentResolver().notifyChange(noteUri, null);
          Util.showDLog(TAG + ":" + "insert() Success.row: " + noteUri.toString());
          return noteUri;
        }
        Util.showDLog(TAG + ":" + "insert() fail... ...");
        break;
      case ITEM_ID:
        Util.showDLog(TAG + ":" + "case CONTACT_ID");
        return null;
      default:
        throw new IllegalArgumentException("Unsupported URI: " + uri);
    }
    throw new SQLException("Failed to insert row into " + uri);
  }