Search in sources :

Example 51 with Uri

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);
    }
}
Also used : Playlist(com.simplecity.amp_library.model.Playlist) Uri(android.net.Uri)

Example 52 with Uri

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());
    }
}
Also used : ContentValues(android.content.ContentValues) Uri(android.net.Uri)

Example 53 with Uri

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;
}
Also used : Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) MediaPlayer(android.media.MediaPlayer)

Example 54 with Uri

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);
}
Also used : Intent(android.content.Intent) Uri(android.net.Uri)

Example 55 with Uri

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;
}
Also used : Bitmap(android.graphics.Bitmap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Uri(android.net.Uri) File(java.io.File)

Aggregations

Uri (android.net.Uri)3406 Intent (android.content.Intent)732 Cursor (android.database.Cursor)466 ContentValues (android.content.ContentValues)349 File (java.io.File)339 IOException (java.io.IOException)254 ContentResolver (android.content.ContentResolver)242 ArrayList (java.util.ArrayList)209 Test (org.junit.Test)194 RemoteException (android.os.RemoteException)190 Bundle (android.os.Bundle)154 Bitmap (android.graphics.Bitmap)129 Context (android.content.Context)118 InputStream (java.io.InputStream)110 PendingIntent (android.app.PendingIntent)104 LargeTest (android.test.suitebuilder.annotation.LargeTest)97 View (android.view.View)95 FileNotFoundException (java.io.FileNotFoundException)94 Request (android.app.DownloadManager.Request)83 TextView (android.widget.TextView)73