diff --git a/res/values-ru/translatable.xml b/res/values-ru/translatable.xml index d6379f0a..435669a5 100644 --- a/res/values-ru/translatable.xml +++ b/res/values-ru/translatable.xml @@ -253,6 +253,9 @@ %d лучших Vanilla Music необходимо разрешение на чтение, чтобы отобразить Вашу музыку в фонотеке в обратном порядке + Поделиться… + Отправить… + Нет подходящих приложений для отправки! Запуск сканирования в Vanilla Music приведёт к перестройке всей базы медиаданных. Начать сканирование diff --git a/res/values/translatable.xml b/res/values/translatable.xml index ad4bf1e2..66c2d426 100644 --- a/res/values/translatable.xml +++ b/res/values/translatable.xml @@ -171,7 +171,7 @@ THE SOFTWARE. Songs without ReplayGain tag Decrease volume by Note - Android does not allow Vanilla Music to raise the volume to >100%. Setting the Pre-amp to a high value may cause issues if you are listening to \'quiet\' music. \n\nRecommended values are:\n-> -3dB for silent/classical music\n-> +3dB for post-2000 recordings + Android does not allow Vanilla Music to raise the volume to >100%. Setting the Pre-amp to a high value may cause issues if you are listening to \'quiet\' music. \n\nRecommended values are:\n-> -3dB for silent/classical music\n-> +3dB for post-2000 recordings Enable readahead Readahead the currently playing song. This option may solve \'audio dropout\' issues. (caused by a slow SD card) @@ -295,6 +295,10 @@ THE SOFTWARE. Vanilla Music needs read permission to display your music library Reverse sort + Share… + Send to… + No receiving apps found for this media type! + Starting a rescan causes Vanilla Music to trigger a full rebuild of the media database. Start Rescan diff --git a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java index 8f5400ab..5be92490 100644 --- a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java @@ -307,6 +307,7 @@ public class FullPlaybackActivity extends SlidingPlaybackActivity menu.add(0, MENU_ENQUEUE_ARTIST, 30, R.string.enqueue_current_artist); menu.add(0, MENU_ENQUEUE_GENRE, 30, R.string.enqueue_current_genre); menu.add(0, MENU_ADD_TO_PLAYLIST, 30, R.string.add_to_playlist); + menu.add(0, MENU_SHARE, 30, R.string.share); mFavorites = menu.add(0, MENU_SONG_FAVORITE, 0, R.string.add_to_favorites).setIcon(R.drawable.btn_rating_star_off_mtrl_alpha).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM); // ensure that mFavorites is updated @@ -352,6 +353,9 @@ public class FullPlaybackActivity extends SlidingPlaybackActivity dialog.show(getFragmentManager(), "PlaylistDialog"); } break; + case MENU_SHARE: + MediaUtils.shareMedia(FullPlaybackActivity.this, MediaUtils.TYPE_SONG, song.id); + break; case MENU_DELETE: final PlaybackService playbackService = PlaybackService.get(this); final PlaybackActivity activity = this; diff --git a/src/ch/blinkenlights/android/vanilla/MediaUtils.java b/src/ch/blinkenlights/android/vanilla/MediaUtils.java index 098581bc..d3c0b6e7 100644 --- a/src/ch/blinkenlights/android/vanilla/MediaUtils.java +++ b/src/ch/blinkenlights/android/vanilla/MediaUtils.java @@ -33,7 +33,11 @@ import java.util.Vector; import java.util.zip.CRC32; import junit.framework.Assert; + +import android.content.ActivityNotFoundException; import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Environment; @@ -42,6 +46,7 @@ import android.text.TextUtils; import android.database.MatrixCursor; import android.media.MediaMetadataRetriever; import android.util.Log; +import android.widget.Toast; /** @@ -341,7 +346,7 @@ public class MediaUtils { String[] projection = { "_id" }; Uri uri = MediaStore.Audio.Genres.getContentUriForAudioId("external", (int)id); Cursor cursor = queryResolver(resolver, uri, projection, null, null, null); - + if (cursor != null) { if (cursor.moveToNext()) return cursor.getLong(0); @@ -381,7 +386,7 @@ public class MediaUtils { if (albumShuffle) { List tempList = new ArrayList(list); Collections.sort(tempList); - + // Build map of albumId to start index in sorted list Map albumStartIndices = new HashMap(); int index = 0; @@ -391,11 +396,11 @@ public class MediaUtils { } index++; } - + //Extract album list and shuffle List shuffledAlbums = new ArrayList(albumStartIndices.keySet()); Collections.shuffle(shuffledAlbums, random); - + //Build Song list from album list list.clear(); for (Long albumId : shuffledAlbums) { @@ -504,6 +509,40 @@ public class MediaUtils { sAllSongs = null; } + /** + * Creates and sends share intent across the system. Includes all eligible songs found + * within this type and id (e.g. all songs in album, all songs for this artist etc.) + * @param ctx context to execute resolving on + * @param type media type to look for e.g. {@link MediaUtils#TYPE_SONG} + * @param id id of item to send + */ + public static void shareMedia(Context ctx, int type, long id) { + if (type == TYPE_INVALID || id <= 0) { // invalid + return; + } + + ContentResolver resolver = ctx.getContentResolver(); + String[] projection = new String [] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA }; + Cursor cursor = buildQuery(type, id, projection, null).runQuery(resolver); + if(cursor == null) { + return; + } + + try { + while (cursor.moveToNext()) { // for all songs resolved... + File songFile = new File(cursor.getString(1)); + Intent share = new Intent(Intent.ACTION_SEND); + share.setType("audio/*"); + share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(songFile)); + ctx.startActivity(Intent.createChooser(share, ctx.getResources().getString(R.string.sendto))); + } + } catch (ActivityNotFoundException ex) { + Toast.makeText(ctx, R.string.no_receiving_apps, Toast.LENGTH_SHORT).show(); + } finally { + cursor.close(); + } + } + /** * Returns the first matching song (or NULL) of given type + id combination * @@ -588,16 +627,16 @@ public class MediaUtils { break; } } - + pfx = (new File(pfx)).getParent(); if(pfx == null) break; /* hit root */ } } - + return path; } - + /** * Adds a final slash if the path points to an existing directory */ diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java index 0f543481..a669664d 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackActivity.java @@ -375,6 +375,7 @@ public abstract class PlaybackActivity extends Activity static final int MENU_DELETE = 16; static final int MENU_EMPTY_QUEUE = 17; static final int MENU_ADD_TO_PLAYLIST = 18; + static final int MENU_SHARE = 19; @Override public boolean onCreateOptionsMenu(Menu menu)