use of android.net.Uri in project Shuttle by timusus.
the class PlaylistUtils method clearFavorites.
/**
* Removes all entries from the 'favorites' playlist
*/
public static void clearFavorites(Context context) {
Playlist favoritesPlaylist = Playlist.favoritesPlaylist();
if (favoritesPlaylist.id >= 0) {
final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", favoritesPlaylist.id);
context.getContentResolver().delete(uri, null, null);
}
}
use of android.net.Uri in project Shuttle by timusus.
the class PlaylistUtils method insertPlaylistItems.
private static void insertPlaylistItems(@NonNull Context context, @NonNull Playlist playlist, @NonNull List<Song> songs, int songCount) {
if (songs.isEmpty()) {
return;
}
ContentValues[] contentValues = new ContentValues[songs.size()];
for (int i = 0, length = songs.size(); i < length; i++) {
contentValues[i] = new ContentValues();
contentValues[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, songCount + i);
contentValues[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID, songs.get(i).id);
}
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlist.id);
if (uri != null) {
ShuttleApplication.getInstance().getContentResolver().bulkInsert(uri, contentValues);
PlaylistUtils.showPlaylistToast(context, songs.size());
}
}
use of android.net.Uri in project Shuttle by timusus.
the class FileHelper method getDuration.
public static long getDuration(Context context, BaseFileObject baseFileObject) {
int duration = 0;
if (baseFileObject != null && !TextUtils.isEmpty(baseFileObject.path)) {
Uri uri = Uri.parse(baseFileObject.path);
if (uri != null) {
MediaPlayer mediaPlayer = MediaPlayer.create(context, uri);
if (mediaPlayer != null) {
duration = mediaPlayer.getDuration();
mediaPlayer.reset();
mediaPlayer.release();
}
}
}
return duration;
}
use of android.net.Uri in project glitch-hq-android by tinyspeck.
the class Glitch method authorize.
//// Authorization ////
// Start browser with authorize URL so the user can authorize the app with OAuth
public void authorize(String scope, Activity activity) {
Uri authorizeUri = getAuthorizeUri(scope);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, authorizeUri);
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(browserIntent);
}
use of android.net.Uri in project jpHolo by teusink.
the class CameraLauncher method processResultFromCamera.
/**
* Applies all needed transformation to the image received from the camera.
*
* @param destType In which form should we return the image
* @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*/
private void processResultFromCamera(int destType, Intent intent) throws IOException {
int rotate = 0;
// Create an ExifHelper to save the exif data that is lost during compression
ExifHelper exif = new ExifHelper();
try {
if (this.encodingType == JPEG) {
exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg");
exif.readExifData();
rotate = exif.getOrientation();
}
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmap = null;
Uri uri = null;
// If sending base64 image back
if (destType == DATA_URL) {
bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
if (bitmap == null) {
// Try to get the bitmap from intent.
bitmap = (Bitmap) intent.getExtras().get("data");
}
// Double-check the bitmap.
if (bitmap == null) {
Log.d(LOG_TAG, "I either have a null image path or bitmap");
this.failPicture("Unable to create bitmap!");
return;
}
if (rotate != 0 && this.correctOrientation) {
bitmap = getRotatedBitmap(rotate, bitmap, exif);
}
this.processPicture(bitmap);
checkForDuplicateImage(DATA_URL);
} else // If sending filename back
if (destType == FILE_URI || destType == NATIVE_URI) {
if (this.saveToPhotoAlbum) {
Uri inputUri = getUriFromMediaStore();
try {
//Just because we have a media URI doesn't mean we have a real file, we need to make it
uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
} catch (NullPointerException e) {
uri = null;
}
} else {
uri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));
}
if (uri == null) {
this.failPicture("Error capturing image - no media storage found.");
return;
}
// If all this is true we shouldn't compress the image.
if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && !this.correctOrientation) {
writeUncompressedImage(uri);
this.callbackContext.success(uri.toString());
} else {
bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
if (rotate != 0 && this.correctOrientation) {
bitmap = getRotatedBitmap(rotate, bitmap, exif);
}
// Add compressed version of captured image to returned media store Uri
OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
os.close();
// Restore exif data to file
if (this.encodingType == JPEG) {
String exifPath;
if (this.saveToPhotoAlbum) {
exifPath = FileHelper.getRealPath(uri, this.cordova);
} else {
exifPath = uri.getPath();
}
exif.createOutFile(exifPath);
exif.writeExifData();
}
if (this.allowEdit) {
performCrop(uri);
} else {
// Send Uri back to JavaScript for viewing image
this.callbackContext.success(uri.toString());
}
}
} else {
throw new IllegalStateException();
}
this.cleanup(FILE_URI, this.imageUri, uri, bitmap);
bitmap = null;
}
Aggregations