Exemplo n.º 1
0
  protected Map<Long, Long> getLongIDsMap(
      Context context,
      Uri uri,
      String selection,
      String[] selectionArgs,
      String longColumn,
      String idColumn) {
    Map<Long, Long> longIDsMap = new HashMap<Long, Long>();

    Cursor c = null;
    try {
      c =
          context
              .getContentResolver()
              .query(uri, new String[] {idColumn, longColumn}, selection, selectionArgs, null);
      if (c != null && c.moveToFirst()) {
        do {
          longIDsMap.put(c.getLong(1), c.getLong(0));
        } while (c.moveToNext());
      }
    } finally {
      if (c != null && !c.isClosed()) c.close();
    }

    return longIDsMap;
  }
Exemplo n.º 2
0
 public ParcelableUser(final Cursor cursor, final long account_id) {
   this.account_id = account_id;
   position = -1;
   is_follow_request_sent = false;
   id = cursor.getLong(cursor.getColumnIndex(CachedUsers.USER_ID));
   name = cursor.getString(cursor.getColumnIndex(CachedUsers.NAME));
   screen_name = cursor.getString(cursor.getColumnIndex(CachedUsers.SCREEN_NAME));
   profile_image_url = cursor.getString(cursor.getColumnIndex(CachedUsers.PROFILE_IMAGE_URL));
   created_at = cursor.getLong(cursor.getColumnIndex(CachedUsers.CREATED_AT));
   is_protected = cursor.getInt(cursor.getColumnIndex(CachedUsers.IS_PROTECTED)) == 1;
   is_verified = cursor.getInt(cursor.getColumnIndex(CachedUsers.IS_VERIFIED)) == 1;
   favorites_count = cursor.getInt(cursor.getColumnIndex(CachedUsers.FAVORITES_COUNT));
   followers_count = cursor.getInt(cursor.getColumnIndex(CachedUsers.FOLLOWERS_COUNT));
   friends_count = cursor.getInt(cursor.getColumnIndex(CachedUsers.FRIENDS_COUNT));
   statuses_count = cursor.getInt(cursor.getColumnIndex(CachedUsers.STATUSES_COUNT));
   location = cursor.getString(cursor.getColumnIndex(CachedUsers.LOCATION));
   description_plain = cursor.getString(cursor.getColumnIndex(CachedUsers.DESCRIPTION_PLAIN));
   description_html = cursor.getString(cursor.getColumnIndex(CachedUsers.DESCRIPTION_HTML));
   description_expanded =
       cursor.getString(cursor.getColumnIndex(CachedUsers.DESCRIPTION_EXPANDED));
   url = cursor.getString(cursor.getColumnIndex(CachedUsers.URL));
   url_expanded = cursor.getString(cursor.getColumnIndex(CachedUsers.URL_EXPANDED));
   profile_banner_url = cursor.getString(cursor.getColumnIndex(CachedUsers.PROFILE_BANNER_URL));
   is_cache = true;
   description_unescaped = toPlainText(description_html);
   is_following = cursor.getInt(cursor.getColumnIndex(CachedUsers.IS_FOLLOWING)) == 1;
 }
Exemplo n.º 3
0
  private void loadNote() {
    Cursor cursor =
        mContext
            .getContentResolver()
            .query(
                ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId),
                NOTE_PROJECTION,
                null,
                null,
                null);

    if (cursor != null) {
      if (cursor.moveToFirst()) {
        mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
        mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
        mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
        mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
        mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
        mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
      }
      cursor.close();
    } else {
      Log.e(TAG, "No note with id:" + mNoteId);
      throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
    }
    loadNoteData();
  }
Exemplo n.º 4
0
  /**
   * 获取count条未读短消息(有bug,获取的都是已读的)
   *
   * @param count
   * @return
   */
  public JSArray getUnreadSms(int count) {
    boolean limit = count > 0; // count大于0,则加上limit
    JSArray smsArray = new JSArray();
    ContentResolver resolver = context.getContentResolver();
    // 查询短消息详细信息,按日期降序排列
    Cursor cursor =
        resolver.query(
            Telephony.Sms.Inbox.CONTENT_URI,
            null,
            Telephony.Sms.Inbox.READ + "=?",
            new String[] {"0"},
            Telephony.Sms.DEFAULT_SORT_ORDER + (limit ? " limit 0," + count : ""));
    int idIndex = cursor.getColumnIndexOrThrow(Telephony.Sms._ID);
    int addressIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.ADDRESS);
    int dateIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.DATE);
    int pidIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.PERSON_ID);
    int bodyIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.BODY);

    while (cursor.moveToNext()) {
      long id = cursor.getLong(idIndex);
      String address = cursor.getString(addressIndex);
      long pid = cursor.getLong(pidIndex);
      long date = cursor.getLong(dateIndex);
      String body = cursor.getString(bodyIndex);

      SmsInfo sms = new SmsInfo(body, date, address, id, pid);
      smsArray.add(sms);
    }
    return smsArray;
  }
Exemplo n.º 5
0
  public ArrayList<Episode> listBySerieAndSeason(Serie serie) {
    Cursor c = getCursor();
    ArrayList<Episode> episodes = new ArrayList<Episode>();
    if (c.moveToFirst()) {

      int idxName = c.getColumnIndex(Episodes.NAME);
      int idxId = c.getColumnIndex(Episodes.PK_ID);
      int idxSeason = c.getColumnIndex(Episodes.SEASON);
      int idxEpisode = c.getColumnIndex(Episodes.NUMBER);
      int idxIdSerie = c.getColumnIndex(Episodes.ID_SERIE);

      do {
        if (serie.getId() == c.getLong(idxIdSerie)
            && serie.getSeason().intValue() == c.getInt(idxSeason)) {
          Episode episode = new Episode();
          episode.setName(c.getString(idxName));
          episode.setId(c.getLong(idxId));
          episode.setSeason(c.getInt(idxSeason));
          episode.setNumber(c.getInt(idxEpisode));
          episodes.add(episode);
        }
      } while (c.moveToNext());
    }
    c.close();
    super.close();
    return episodes;
  }
Exemplo n.º 6
0
  /**
   * Query the DB and return the number of undelivered messages (total for both SMS and MMS)
   *
   * @param context The context
   * @param threadIdResult A container to put the result in, according to the following rules:
   *     threadIdResult[0] contains the thread id of the first message. threadIdResult[1] is nonzero
   *     if the thread ids of all the messages are the same. You can pass in null for
   *     threadIdResult. You can pass in a threadIdResult of size 1 to avoid the comparison of each
   *     thread id.
   */
  private static int getUndeliveredMessageCount(Context context, long[] threadIdResult) {
    Cursor undeliveredCursor =
        SqliteWrapper.query(
            context,
            context.getContentResolver(),
            UNDELIVERED_URI,
            new String[] {Mms.THREAD_ID},
            "read=0",
            null,
            null);
    if (undeliveredCursor == null) {
      return 0;
    }
    int count = undeliveredCursor.getCount();
    try {
      if (threadIdResult != null && undeliveredCursor.moveToFirst()) {
        threadIdResult[0] = undeliveredCursor.getLong(0);

        if (threadIdResult.length >= 2) {
          // Test to see if all the undelivered messages belong to the same thread.
          long firstId = threadIdResult[0];
          while (undeliveredCursor.moveToNext()) {
            if (undeliveredCursor.getLong(0) != firstId) {
              firstId = 0;
              break;
            }
          }
          threadIdResult[1] = firstId; // non-zero if all ids are the same
        }
      }
    } finally {
      undeliveredCursor.close();
    }
    return count;
  }
  private Event cursorToEvent(Cursor cursor) {
    Event event = new EventImpl();
    event.setID(cursor.getLong(0));

    long ts = cursor.getLong(1);
    Timestamp timestamp = new Timestamp(ts);
    event.setTimestamp(timestamp);

    event.setTitle(cursor.getString(2));
    event.setUser(cursor.getString(3));

    ts = cursor.getLong(4);
    timestamp = new Timestamp(ts);
    event.setStartTime(timestamp);

    ts = cursor.getLong(5);
    timestamp = new Timestamp(ts);
    event.setEndTime(timestamp);

    event.setDescription(cursor.getString(6));

    event.setProfilePicURI(cursor.getString(7));

    return event;
  }
Exemplo n.º 8
0
 @Override
 public void bindView(View view, Context context, Cursor cursor) {
   super.bindView(view, context, cursor);
   TextView setup = (TextView) view.findViewById(R.id.text3);
   TextView reply = (TextView) view.findViewById(R.id.text4);
   locationCursor.moveToPosition(cursor.getPosition());
   long rt = locationCursor.getLong(1);
   if (rt > 0) {
     Calendar cal = Calendar.getInstance();
     cal.setTimeInMillis(rt);
     DateFormat sdf = SimpleDateFormat.getDateTimeInstance();
     setup.setText("requested on: " + sdf.format(cal.getTime()));
   } else {
     setup.setText("requested on: <not available>");
   }
   rt = locationCursor.getLong(2);
   if (rt > 0) {
     Calendar cal = Calendar.getInstance();
     cal.setTimeInMillis(rt);
     DateFormat sdf = SimpleDateFormat.getDateTimeInstance();
     reply.setText("updated on:" + sdf.format(cal.getTime()));
     ((ImageView) view.findViewById(R.id.status))
         .setImageResource(android.R.drawable.presence_online);
   } else {
     reply.setText("updated on: <not available>");
   }
 }
  public CoffeeLog[] getCoffeeLogs() {
    ArrayList<CoffeeLog> array_list = new ArrayList<>();

    // hp = new HashMap();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res = db.rawQuery("select * from " + COFFEELOG_TABLE_NAME, null);
    res.moveToFirst();

    while (!res.isAfterLast()) {
      CoffeeLog coffeeLog = new CoffeeLog();
      coffeeLog.Id = res.getInt(res.getColumnIndex(COFFEELOG_COLUMN_ID));
      coffeeLog.Name = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_NAME));
      coffeeLog.Roaster = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_ROASTER));
      coffeeLog.City = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_CITY));
      coffeeLog.Country = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_COUNTRY));
      coffeeLog.RoastDate = new Date(res.getLong(res.getColumnIndex(COFFEELOG_COLUMN_ROASTDATE)));
      coffeeLog.BrewDate = new Date(res.getLong(res.getColumnIndex(COFFEELOG_COLUMN_BREWDATE)));
      coffeeLog.BrewMethod = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_BREWMETHOD));
      coffeeLog.CoffeeGrams = res.getDouble(res.getColumnIndex(COFFEELOG_COLUMN_COFFEEGRAMS));
      coffeeLog.WaterGrams = res.getDouble(res.getColumnIndex(COFFEELOG_COLUMN_WATERGRAMS));
      coffeeLog.Overall = res.getInt(res.getColumnIndex(COFFEELOG_COLUMN_OVERALL));
      coffeeLog.TasteProfile = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_TASTEPROFILE));
      coffeeLog.Notes = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_NOTES));
      coffeeLog.ImageLocation = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_IMAGELOCATION));

      array_list.add(coffeeLog);
      res.moveToNext();
    }
    res.close();
    CoffeeLog[] dbCoffeeLogs = new CoffeeLog[array_list.size()];
    array_list.toArray(dbCoffeeLogs);

    return dbCoffeeLogs;
  }
Exemplo n.º 10
0
 @Override
 public boolean copyValue(
     String mColum, int position, Cursor theCursor, CursorWindow data, int dataRow) {
   switch (position) {
     case 1:
       long saldo = theCursor.getLong(position);
       mSaldoGesamt += saldo;
       data.putLong(mSaldoGesamt, rowKT, position);
       break;
     case 2:
       mEinstand = theCursor.getLong(position);
       mEinstandGesamt += mEinstand;
       data.putLong(mEinstandGesamt, rowKT, position);
       break;
     case 3:
       mGewinn = theCursor.getLong(position);
       mGewinnGesamt += mGewinn;
       data.putLong(mGewinnGesamt, rowKT, position);
       break;
     case 4:
       long gewStfr = theCursor.getLong(position);
       mStrfrGesamt += gewStfr;
       data.putLong(mStrfrGesamt, rowKT, position);
       break;
   }
   return false;
 }
 /**
  * Cursor to timer.
  *
  * @param c the c
  * @return the timer´
  * @author RayBa
  * @date 07.04.2013
  */
 private Timer cursorToTimer(Cursor c) {
   String name = c.getString(c.getColumnIndex(ChannelTbl.NAME));
   long channelID = c.getLong(c.getColumnIndex(ChannelTbl.CHANNEL_ID));
   String epgTitle =
       !c.isNull(c.getColumnIndex(EpgTbl.TITLE))
           ? c.getString(c.getColumnIndex(EpgTbl.TITLE))
           : name;
   long epgStart = c.getLong(c.getColumnIndex(EpgTbl.START));
   long epgEnd = c.getLong(c.getColumnIndex(EpgTbl.END));
   DVBViewerPreferences prefs = new DVBViewerPreferences(getSherlockActivity());
   int epgBefore = prefs.getPrefs().getInt(DVBViewerPreferences.KEY_TIMER_TIME_BEFORE, 5);
   int epgAfter = prefs.getPrefs().getInt(DVBViewerPreferences.KEY_TIMER_TIME_AFTER, 5);
   Date start = epgStart > 0 ? new Date(epgStart) : new Date();
   Date end = epgEnd > 0 ? new Date(epgEnd) : new Date(start.getTime() + (1000 * 60 * 120));
   Log.i(ChannelList.class.getSimpleName(), "start: " + start.toString());
   Log.i(ChannelList.class.getSimpleName(), "end: " + end.toString());
   start = DateUtils.addMinutes(start, 0 - epgBefore);
   end = DateUtils.addMinutes(end, epgAfter);
   Timer timer = new Timer();
   timer.setTitle(epgTitle);
   timer.setChannelId(channelID);
   timer.setChannelName(name);
   timer.setStart(start);
   timer.setEnd(end);
   timer.setTimerAction(
       prefs.getPrefs().getInt(DVBViewerPreferences.KEY_TIMER_DEF_AFTER_RECORD, 0));
   return timer;
 }
Exemplo n.º 12
0
 /** @inheritdoc */
 @Override
 public void readEntity(Cursor cursor, MunkaEszkoz entity, int offset) {
   entity.setMunkaEszkozID(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
   entity.setMunkaEszkozNev(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
   entity.setMunkaEszkozAr(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2));
   entity.setMunkaID(cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3));
 }
Exemplo n.º 13
0
  /*package*/ void deleteMessagesInThreadBeforeDate(long threadId, long date) {
    Cursor cursor = null;

    try {
      SQLiteDatabase db = databaseHelper.getReadableDatabase();
      String where =
          THREAD_ID + " = ? AND (CASE (" + MESSAGE_BOX + " & " + Types.BASE_TYPE_MASK + ") ";

      for (long outgoingType : Types.OUTGOING_MESSAGE_TYPES) {
        where += " WHEN " + outgoingType + " THEN " + DATE_SENT + " < " + date;
      }

      where += (" ELSE " + DATE_RECEIVED + " < " + date + " END)");

      Log.w("MmsDatabase", "Executing trim query: " + where);
      cursor =
          db.query(
              TABLE_NAME, new String[] {ID}, where, new String[] {threadId + ""}, null, null, null);

      while (cursor != null && cursor.moveToNext()) {
        Log.w("MmsDatabase", "Trimming: " + cursor.getLong(0));
        delete(cursor.getLong(0));
      }

    } finally {
      if (cursor != null) cursor.close();
    }
  }
 /**
  * Form a single contact from cursor
  *
  * @param cursor
  * @return
  */
 public Contact getContact(Cursor cursor) {
   Contact contact = new Contact();
   contact.setFullName(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.FULL_NAME)));
   contact.setUserId(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.USERID)));
   contact.setLocalImageUrl(
       cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CONTACT_IMAGE_LOCAL_URI)));
   contact.setImageURL(
       cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CONTACT_IMAGE_URL)));
   String contactNumber =
       cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CONTACT_NO));
   if (TextUtils.isEmpty(contactNumber)) {
     contact.setContactNumber(
         cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.USERID)));
   } else {
     contact.setContactNumber(
         cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CONTACT_NO)));
   }
   contact.setApplicationId(
       cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.APPLICATION_ID)));
   Long connected = cursor.getLong(cursor.getColumnIndex(MobiComDatabaseHelper.CONNECTED));
   contact.setConnected(connected != 0 && connected.intValue() == 1);
   contact.setLastSeenAt(
       cursor.getLong(cursor.getColumnIndex(MobiComDatabaseHelper.LAST_SEEN_AT_TIME)));
   contact.processContactNumbers(context);
   return contact;
 }
Exemplo n.º 15
0
  @Override
  protected RotinaPECS cursorToObject(Cursor cursor) {
    RotinaPECS rotinaPecs = new RotinaPECS();

    int column = cursor.getColumnIndex(RotinaPECS.ID_COLUMN);
    if (column >= 0) {
      rotinaPecs.setIdEntity(cursor.getLong(column));
    }

    column = cursor.getColumnIndex(RotinaPECS.ID_PECS);
    if (column >= 0) {
      rotinaPecs.setPecsId(cursor.getLong(column));
    }

    column = cursor.getColumnIndex(RotinaPECS.ID_ROTINA);
    if (column >= 0) {
      rotinaPecs.setRotinaId(cursor.getLong(column));
    }

    column = cursor.getColumnIndex(RotinaPECS.POSICAO);
    if (column >= 0) {
      rotinaPecs.setPosicao(cursor.getInt(column));
    }

    return rotinaPecs;
  }
Exemplo n.º 16
0
 public CoffeeLog getCoffeeLog(long id) {
   CoffeeLog coffeeLog = new CoffeeLog();
   SQLiteDatabase db = this.getReadableDatabase();
   Cursor res =
       db.rawQuery(
           "select * from "
               + COFFEELOG_TABLE_NAME
               + " where "
               + COFFEELOG_COLUMN_ID
               + "="
               + id
               + "",
           null);
   if (res != null) {
     res.moveToFirst();
     coffeeLog.Id = res.getLong(res.getColumnIndex(COFFEELOG_COLUMN_ID));
     coffeeLog.Name = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_NAME));
     coffeeLog.Roaster = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_ROASTER));
     coffeeLog.City = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_CITY));
     coffeeLog.Country = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_COUNTRY));
     coffeeLog.RoastDate = new Date(res.getLong(res.getColumnIndex(COFFEELOG_COLUMN_ROASTDATE)));
     coffeeLog.BrewDate = new Date(res.getLong(res.getColumnIndex(COFFEELOG_COLUMN_BREWDATE)));
     coffeeLog.BrewMethod = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_BREWMETHOD));
     coffeeLog.CoffeeGrams = res.getDouble(res.getColumnIndex(COFFEELOG_COLUMN_COFFEEGRAMS));
     coffeeLog.WaterGrams = res.getDouble(res.getColumnIndex(COFFEELOG_COLUMN_WATERGRAMS));
     coffeeLog.Overall = res.getInt(res.getColumnIndex(COFFEELOG_COLUMN_OVERALL));
     coffeeLog.TasteProfile = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_TASTEPROFILE));
     coffeeLog.Notes = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_NOTES));
     coffeeLog.ImageLocation = res.getString(res.getColumnIndex(COFFEELOG_COLUMN_IMAGELOCATION));
     if (!res.isClosed()) {
       res.close();
     }
   }
   return coffeeLog;
 }
Exemplo n.º 17
0
  private static List<Tweet> readTweets(final Cursor c) {
    if (c != null && c.moveToFirst()) {
      final int colId = c.getColumnIndex(TBL_TW_ID);
      final int colSid = c.getColumnIndex(TBL_TW_SID);
      final int colUesrname = c.getColumnIndex(TBL_TW_USERNAME);
      final int colFullname = c.getColumnIndex(TBL_TW_FULLNAME);
      final int colBody = c.getColumnIndex(TBL_TW_BODY);
      final int colTime = c.getColumnIndex(TBL_TW_TIME);
      final int colAvatar = c.getColumnIndex(TBL_TW_AVATAR);

      final List<Tweet> ret = new ArrayList<Tweet>();
      do {
        final long uid = c.getLong(colId);
        final String sid = c.getString(colSid);
        final String username = c.getString(colUesrname);
        final String fullname = c.getString(colFullname);
        final String body = c.getString(colBody);
        final long time = c.getLong(colTime);
        final String avatar = c.getString(colAvatar);
        ret.add(new Tweet(uid, sid, username, fullname, body, time, avatar, null));
      } while (c.moveToNext());
      return ret;
    }
    return Collections.EMPTY_LIST;
  }
Exemplo n.º 18
0
  public ArrayList<ActionEvent> getAllItems(Context context, boolean isHistory) {
    DatabaseHelper dh = new DatabaseHelper(context, TABLE_NAME);
    SQLiteDatabase db = dh.getReadableDatabase();

    ArrayList<ActionEvent> aeList = new ArrayList<ActionEvent>();
    Cursor c =
        db.query(
            TABLE_NAME,
            null,
            KEY_IS_HISTORY + "='" + getBooleanToLong(isHistory) + "'",
            null,
            null,
            null,
            "_id" + " DESC");
    while (c.moveToNext()) {
      ActionEvent ae =
          new ActionEvent(
              c.getString(c.getColumnIndex(KEY_ACTION_NAME)),
              c.getLong(c.getColumnIndex(KEY_START_TIMESTAMP)),
              c.getString(c.getColumnIndex(KEY_ACTION_NOTE)),
              getLongToBoolean(c.getLong(c.getColumnIndex(KEY_IS_HISTORY))),
              c.getLong(c.getColumnIndex(KEY_START_DEALY)),
              c.getLong(c.getColumnIndex(KEY_START_DEALY)));
      ae.setBreakTimestamp(c.getLong(c.getColumnIndex(KEY_BREAK_TIMESTAMP)));
      ae.setState(c.getString(c.getColumnIndex(KEY_STATE)));
      aeList.add(ae);
    }
    c.close();
    db.close();
    return aeList;
  }
Exemplo n.º 19
0
  private static Media getLastImageThumbnail(ContentResolver resolver) {
    Uri baseUri = Images.Media.EXTERNAL_CONTENT_URI;
    Log.d("mk", "getLastImageThumbnail() = " + baseUri.toString());
    Log.d("mk", "DCIM = " + Storage.DCIM.toString());
    Uri query = baseUri.buildUpon().appendQueryParameter("limit", "1").build();
    String[] projection =
        new String[] {ImageColumns._ID, ImageColumns.ORIENTATION, ImageColumns.DATE_TAKEN};
    String selection =
        ImageColumns.MIME_TYPE
            + "='image/jpeg'"
            + "AND "
            + ImageColumns.BUCKET_ID
            + "="
            + Storage.getBucketId(Storage.FILE_TYPE_PHOTO);
    // ImageColumns.BUCKET_DISPLAY_NAME + "='Photo'";
    String order = ImageColumns.DATE_TAKEN + " DESC," + ImageColumns._ID + " DESC";

    Cursor cursor = null;
    try {
      cursor = resolver.query(query, projection, selection, null, order);
      if (cursor != null && cursor.moveToFirst()) {
        long id = cursor.getLong(0);
        return new Media(
            id, cursor.getInt(1), cursor.getLong(2), ContentUris.withAppendedId(baseUri, id));
      }
      Log.d("dyb", "cursor null");
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
    return null;
  }
Exemplo n.º 20
0
 /** @inheritdoc */
 @Override
 public void readEntity(Cursor cursor, Firsatlarim entity, int offset) {
   entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
   entity.setFirsat_id(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
   entity.setSure(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
   entity.setYararlanildi_mi(cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3) != 0);
 }
  public AlarmInstance(Cursor c) {
    mId = c.getLong(ID_INDEX);
    mYear = c.getInt(YEAR_INDEX);
    mMonth = c.getInt(MONTH_INDEX);
    mDay = c.getInt(DAY_INDEX);
    mHour = c.getInt(HOUR_INDEX);
    mMinute = c.getInt(MINUTES_INDEX);
    mLabel = c.getString(LABEL_INDEX);
    mVibrate = c.getInt(VIBRATE_INDEX) == 1;
    if (c.isNull(RINGTONE_INDEX)) {
      // Should we be saving this with the current ringtone or leave it null
      // so it changes when user changes default ringtone?
      mRingtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    } else {
      mRingtone = Uri.parse(c.getString(RINGTONE_INDEX));
    }

    if (!c.isNull(ALARM_ID_INDEX)) {
      mAlarmId = c.getLong(ALARM_ID_INDEX);
    }
    mAlarmState = c.getInt(ALARM_STATE_INDEX);

    if (!c.isNull(LIGHTUPPI_ID_INDEX)) {
      mLightuppiId = c.getLong(LIGHTUPPI_ID_INDEX);
    }
    if (!c.isNull(TIMESTAMP_INDEX)) {
      mTimestamp = c.getLong(TIMESTAMP_INDEX);
    }
  }
Exemplo n.º 22
0
  @Override
  public int delete(Uri uri, String where, String[] whereArgs) {
    switch (uriMatcher.match(uri)) {
      case PODCASTS:
        break;
      case PODCAST_ID:
        String extraWhere = COLUMN_ID + " = " + uri.getLastPathSegment();
        if (where != null) where = extraWhere + " AND " + where;
        else where = extraWhere;
        break;
      default:
        throw new IllegalArgumentException("Illegal URI for delete");
    }

    // find out what we're deleting and delete downloaded files
    SQLiteDatabase db = _dbAdapter.getWritableDatabase();
    String[] columns = new String[] {COLUMN_ID};
    String podcastsWhere = "queuePosition IS NOT NULL";
    if (where != null) podcastsWhere = where + " AND " + podcastsWhere;
    Cursor c = db.query("podcasts", columns, podcastsWhere, whereArgs, null, null, null);
    while (c.moveToNext()) {
      updateQueuePosition(c.getLong(0), null);
      deleteDownload(getContext(), c.getLong(0));
    }
    c.close();

    int count = db.delete("podcasts", where, whereArgs);
    if (!uri.equals(URI)) getContext().getContentResolver().notifyChange(URI, null);
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
Exemplo n.º 23
0
  /**
   * 从uri中获取SmsInfo对象数组
   *
   * @param uri
   * @param count
   * @return
   */
  private JSArray getSmsInfoFromUri(Uri uri, int count) {
    boolean limit = count > 0; // count大于0,则加上limit
    JSArray smsArray = new JSArray();
    ContentResolver resolver = context.getContentResolver();
    Cursor cursor =
        resolver.query(
            uri,
            null,
            null,
            null,
            Telephony.Sms.DEFAULT_SORT_ORDER + (limit ? " limit 0," + count : ""));

    int idIndex = cursor.getColumnIndexOrThrow(Telephony.Sms._ID);
    int addressIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.ADDRESS);
    int dateIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.DATE);
    int pidIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.PERSON_ID);
    int bodyIndex = cursor.getColumnIndexOrThrow(Telephony.Sms.BODY);

    while (cursor.moveToNext()) {
      long id = cursor.getLong(idIndex);
      String address = cursor.getString(addressIndex);
      long pid = cursor.getLong(pidIndex);
      long date = cursor.getLong(dateIndex);
      String body = cursor.getString(bodyIndex);

      SmsInfo sms = new SmsInfo(body, date, address, id, pid);
      smsArray.add(sms);
    }
    return smsArray;
  }
Exemplo n.º 24
0
 /** @inheritdoc */
 @Override
 protected PicItem readEntity(Cursor cursor, int offset) {
   PicItem entity =
       new PicItem( //
           cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
           cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // picId
           cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // author
           cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // authorEmail
           cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // authorUrl
           cursor.isNull(offset + 5)
               ? null
               : dateConverter.convertToEntityProperty(
                   Timestamp.class, cursor.getLong(offset + 5)), // date
           cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6), // votePositive
           cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7), // voteNegative
           cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8), // commentCount
           cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // threadId
           cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // content
           cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // textContent
           cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // pics
           cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // picFirst
           cursor.isNull(offset + 14) ? null : cursor.getLong(offset + 14), // picCount
           cursor.isNull(offset + 15) ? null : cursor.getShort(offset + 15) != 0 // hasGif
           );
   return entity;
 }
Exemplo n.º 25
0
  public Episode searchEpisode(Serie serie) {
    Cursor c = getCursor();

    Episode episode = new Episode();
    if (c.moveToFirst()) {

      int idxName = c.getColumnIndex(Episodes.NAME);
      int idxId = c.getColumnIndex(Episodes.PK_ID);
      int idxSeason = c.getColumnIndex(Episodes.SEASON);
      int idxEpisode = c.getColumnIndex(Episodes.NUMBER);
      int idxIdSerie = c.getColumnIndex(Episodes.ID_SERIE);

      do {
        if (serie.getId() == c.getLong(idxIdSerie)
            && serie.getSeason().intValue() == c.getInt(idxSeason)
            && serie.getEpisode().intValue() == c.getInt(idxEpisode)) {
          episode.setName(c.getString(idxName));
          episode.setId(c.getLong(idxId));
          episode.setSeason(c.getInt(idxSeason));
          episode.setNumber(c.getInt(idxEpisode));
          break;
        }
      } while (c.moveToNext());
    }
    c.close();
    super.close();
    return episode;
  }
Exemplo n.º 26
0
  /**
   * @param canvas
   * @param mapView
   * @param shadow
   * @see SegmentOverlay#draw(Canvas, MapView, boolean)
   */
  private void calculateDots() {
    mPathCalculation.reset();
    mDotPathCalculation.clear();

    mCalculatedPoints = 0;

    if (mWaypointsCursor == null) {
      mWaypointsCursor =
          this.mResolver.query(
              this.mWaypointsUri,
              new String[] {
                Waypoints.LATITUDE,
                Waypoints.LONGITUDE,
                Waypoints.SPEED,
                Waypoints.TIME,
                Waypoints.ACCURACY
              },
              null,
              null,
              null);
    }
    if (mRequeryFlag) {
      mWaypointsCursor.requery();
      mRequeryFlag = false;
    }
    if (mProjection != null && mWaypointsCursor.moveToFirst()) {
      GeoPoint geoPoint;

      mStartPoint = extractGeoPoint();
      mPrevGeoPoint = mStartPoint;

      do {
        geoPoint = extractGeoPoint();
        setScreenPoint(geoPoint);

        float distance = (float) distanceInPoints(this.mPrevDrawnScreenPoint, this.mScreenPoint);
        if (distance > MINIMUM_PX_DISTANCE) {
          DotVO dotVO = new DotVO();
          dotVO.x = this.mScreenPoint.x;
          dotVO.y = this.mScreenPoint.y;
          dotVO.speed = mWaypointsCursor.getLong(2);
          dotVO.time = mWaypointsCursor.getLong(3);
          dotVO.radius = mProjection.metersToEquatorPixels(mWaypointsCursor.getFloat(4));
          mDotPathCalculation.add(dotVO);

          this.mPrevDrawnScreenPoint.x = this.mScreenPoint.x;
          this.mPrevDrawnScreenPoint.y = this.mScreenPoint.y;
        }
      } while (moveToNextWayPoint());

      this.mEndPoint = extractGeoPoint();
      DotVO pointVO = new DotVO();
      pointVO.x = this.mScreenPoint.x;
      pointVO.y = this.mScreenPoint.y;
      pointVO.speed = mWaypointsCursor.getLong(2);
      pointVO.time = mWaypointsCursor.getLong(3);
      pointVO.radius = mProjection.metersToEquatorPixels(mWaypointsCursor.getFloat(4));
      mDotPathCalculation.add(pointVO);
    }
  }
Exemplo n.º 27
0
  public static CallContact buildUserContact(Context c) {
    CallContact result = null;
    try {
      Cursor mProfileCursor =
          c.getContentResolver().query(Profile.CONTENT_URI, PROFILE_PROJECTION, null, null, null);
      if (mProfileCursor != null) {
        if (mProfileCursor.moveToFirst()) {
          String key = mProfileCursor.getString(mProfileCursor.getColumnIndex(Profile.LOOKUP_KEY));
          String displayName =
              mProfileCursor.getString(mProfileCursor.getColumnIndex(Profile.DISPLAY_NAME_PRIMARY));

          if (displayName == null || displayName.isEmpty())
            displayName = c.getResources().getString(R.string.me);
          result =
              new CallContact(
                  mProfileCursor.getLong(mProfileCursor.getColumnIndex(Profile._ID)),
                  key,
                  displayName,
                  mProfileCursor.getLong(mProfileCursor.getColumnIndex(Profile.PHOTO_ID)),
                  new ArrayList<Phone>(),
                  "",
                  true);
        }
        mProfileCursor.close();
      }
    } catch (Exception e) {
      Log.w(TAG, e);
    }
    return result == null
        ? new CallContact(
            -1, null, c.getResources().getString(R.string.me), 0, new ArrayList<Phone>(), "", true)
        : result;
  }
Exemplo n.º 28
0
 /** @inheritdoc */
 @Override
 public void readEntity(Cursor cursor, Chapter entity, int offset) {
   entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
   entity.setChapterNumber(cursor.getString(offset + 1));
   entity.setIsLocal(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
   entity.setGenreId(cursor.getLong(offset + 3));
 }
Exemplo n.º 29
0
  private void loadNoteData() {
    Cursor cursor =
        mContext
            .getContentResolver()
            .query(
                Notes.CONTENT_DATA_URI,
                DATA_PROJECTION,
                DataColumns.NOTE_ID + "=?",
                new String[] {String.valueOf(mNoteId)},
                null);

    if (cursor != null) {
      if (cursor.moveToFirst()) {
        do {
          String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
          if (DataConstants.NOTE.equals(type)) {
            mContent = cursor.getString(DATA_CONTENT_COLUMN);
            mMode = cursor.getInt(DATA_MODE_COLUMN);
            mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
          } else if (DataConstants.CALL_NOTE.equals(type)) {
            mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
          } else {
            Log.d(TAG, "Wrong note type with type:" + type);
          }
        } while (cursor.moveToNext());
      }
      cursor.close();
    } else {
      Log.e(TAG, "No data with id:" + mNoteId);
      throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
    }
  }
  public void testParseTalksJson() throws Exception {
    ArrayList<ContentProviderOperation> batch =
        mTalksHandler.parse(getDummyJson(), getContext().getContentResolver());

    assertEquals(4, batch.size());

    getProvider().applyBatch(batch);

    Cursor cursor = getProvider().query(Talks.uri(24001), null, null, null, null);
    cursor.moveToFirst();

    assertEquals("Android", cursor.getString(cursor.getColumnIndex(Talks.TITLE)));
    long datetimestamp = cursor.getLong(cursor.getColumnIndex(Talks.START_DATE));
    CharSequence date = DateFormat.format("yyyy-MM-dd h:mm", new Date(datetimestamp));
    assertEquals("2012-06-23 9:30", date);

    int duration =
        (int)
            ((cursor.getLong(cursor.getColumnIndex(Talks.END_DATE)) - datetimestamp)
                / (60 * 60 * 1000));

    assertEquals(1, duration);
    assertEquals("sala3", cursor.getString(cursor.getColumnIndex(Talks.ROOM)));

    assertEquals(
        "*****@*****.**", cursor.getString(cursor.getColumnIndex(Talks.SPEAKER_EMAIL)));
    assertEquals("fbgblog", cursor.getString(cursor.getColumnIndex(Talks.SPEAKER_TWITTER)));
    assertEquals("Bill Gates", cursor.getString(cursor.getColumnIndex(Talks.SPEAKER)));
    assertEquals("¿Cuanto nos paga?", cursor.getString(cursor.getColumnIndex(Talks.DESCRIPTION)));
  }