Пример #1
0
  private PartId insertPart(MasterSecret masterSecret, PduPart part, long mmsId, Bitmap thumbnail)
      throws MmsException {
    Log.w(TAG, "inserting part to mms " + mmsId);
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    Pair<File, Long> partData = null;

    if (!part.isPendingPush()) {
      partData = writePartData(masterSecret, part);
      Log.w(TAG, "Wrote part to file: " + partData.first.getAbsolutePath());
    }

    ContentValues contentValues = getContentValuesForPart(part);
    contentValues.put(MMS_ID, mmsId);

    if (partData != null) {
      contentValues.put(DATA, partData.first.getAbsolutePath());
      contentValues.put(SIZE, partData.second);
    }

    long partRowId = database.insert(TABLE_NAME, null, contentValues);
    PartId partId = new PartId(partRowId, part.getUniqueId());

    if (thumbnail != null) {
      Log.w(TAG, "inserting pre-generated thumbnail");
      ThumbnailData data = new ThumbnailData(thumbnail);
      updatePartThumbnail(masterSecret, partId, part, data.toDataStream(), data.getAspectRatio());
    } else if (!part.isPendingPush()) {
      thumbnailExecutor.submit(new ThumbnailFetchCallable(masterSecret, partId));
    }

    return partId;
  }
Пример #2
0
    @Override
    public InputStream call() throws Exception {
      final InputStream stream = getDataStream(masterSecret, partId, THUMBNAIL);
      if (stream != null) {
        return stream;
      }

      try {
        PduPart part = getPart(partId);
        ThumbnailData data =
            MediaUtil.generateThumbnail(
                context, masterSecret, part.getDataUri(), Util.toIsoString(part.getContentType()));
        if (data == null) {
          return null;
        }
        updatePartThumbnail(masterSecret, partId, part, data.toDataStream(), data.getAspectRatio());
      } catch (BitmapDecodingException bde) {
        throw new IOException(bde);
      }

      return getDataStream(masterSecret, partId, THUMBNAIL);
    }