public void confirmDownload(ResourceBuilder builder) { Context context = getActivity(); if (context == null) { Log.w("Can not confirm download without context"); return; } // Block the save dialog from popping up over an existing popup. This // is a hack put in place for the DailyMotion builder that triggers // multiple downloads for some reason. if (mConfirmationInProgress) { Log.w("Ignoring download request from builder!!!"); return; } mConfirmationInProgress = true; if (builder.isContainerURL()) { // if this is mysterious, it's no surprise -- it sucks. The link // the user clicked on was not a direct link to the content, so we // need to parse the page to get the URL. Unfortunately, we don't // have access to the downloaded content, so we have to // re-download the page and parse it. This is embarrasing and // should be fixed as it would make the user experience better, // but not sure how to do it and there are other, more interesting // goals. Log.d("Found container URL."); new ResourceParserTask().run(builder); } else { sendMessage( ActivityDelegate.MSG_BROWSER, ActivityDelegate.MSG_BROWSER_SAVEDIALOG_SHOW, builder); } }
private void createThumbnail(ContentValues map) throws IOException { File videoFile = fileFromResourceMap(map); Log.d("Creating thumbnail from video file " + videoFile.toString()); Bitmap bitmap = ThumbnailUtils.createVideoThumbnail( videoFile.toString(), MediaStore.Video.Thumbnails.MINI_KIND); if (bitmap == null) { Log.w("Error creating thumbnail"); return; } String filename = (String) map.get(Resources.FILENAME); if (TextUtils.isEmpty(filename)) { throw new IOException("Must specify FILENAME when inserting Resource"); } Uri thumbnailUri = Resources.buildThumbnailUri(filename + THUMBNAIL_EXT); OutputStream ostream; try { ostream = getContext().getContentResolver().openOutputStream(thumbnailUri); } catch (FileNotFoundException e) { Log.d("Could not open output stream for thumbnail storage: " + e.getLocalizedMessage()); return; } bitmap.compress(Bitmap.CompressFormat.JPEG, 100, ostream); ostream.flush(); IOUtilities.closeStream(ostream); map.put(Resources.THUMBNAIL, thumbnailUri.toString()); }
private void removeFromMediaStore(String filename) { Log.d("removeFromMediaStore(filename=" + filename + ")"); final String[] fields = { MediaStore.MediaColumns._ID, MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.TITLE }; String select = MediaStore.MediaColumns.DATA + "=?"; Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; Cursor cursor = getContext().getContentResolver().query(uri, fields, select, new String[] {filename}, null); if (cursor.moveToFirst()) { int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); Uri mediaUri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id); getContext().getContentResolver().delete(mediaUri, null, null); getContext().getContentResolver().notifyChange(mediaUri, null); Log.d("Removing media uri: " + mediaUri); } else { Log.w("Could not find media uri"); } cursor.close(); }
/** {@inheritDoc} */ @Override public Uri insert(Uri uri, ContentValues values) { Log.v("insert(uri=" + uri + ", values=[" + values.toString() + "])"); final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); final int match = getUriMatcher().match(uri); long id = 0; switch (match) { case FAVORITES: { synchronized (mutex) { id = db.insertOrThrow(Tables.FAVORITES, null, values); } getContext().getContentResolver().notifyChange(uri, null); return Favorites.buildFavoriteUri(String.valueOf(id)); } case RESOURCES: case RESOURCES_ID: { try { addDefaultThumbnail(values); calculateDuration(values); } catch (Exception e) { Log.w("Exception thrown creating thumbnail"); e.printStackTrace(); } try { informMediaScanner(values); } catch (IOException e) { } values.put(Resources.TIMESTAMP, String.valueOf(System.currentTimeMillis())); synchronized (mutex) { id = db.insertOrThrow(Tables.RESOURCES, null, values); } Uri resourceUri = Resources.buildResourceUri(String.valueOf(id)); try { createThumbnail(values); getContext().getContentResolver().update(resourceUri, values, null, null); } catch (IOException e) { Log.w("Error creating thumbnail"); } getContext().getContentResolver().notifyChange(uri, null); return resourceUri; } case DOWNLOADS: { values.put(Downloads.STATUS, Downloads.Status.INPROGRESS.valueOf()); values.put(Downloads.TIMESTAMP, String.valueOf(System.currentTimeMillis())); values.put(Downloads.MAX_PROGRESS, Downloads.PROGRESS_MAX_NUM); synchronized (mutex) { id = db.insertOrThrow(Tables.DOWNLOADS, null, values); } getContext().getContentResolver().notifyChange(uri, null); return Downloads.buildDownloadUri(String.valueOf(id)); } default: { throw new UnsupportedOperationException("Unknown uri(" + match + "): " + uri); } } }