Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to set a Song as Ringtone #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/values/translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ THE SOFTWARE.
<string name="all_songs">All Songs</string>
<string name="more_from_artist">More from artist</string>
<string name="more_from_album">More from album</string>
<string name="set_as_ringtone">Set As Ringtone</string>

<string name="name">Name</string>
<string name="number_of_tracks">Number of tracks</string>
Expand Down
55 changes: 53 additions & 2 deletions src/org/kreed/vanilla/LibraryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,49 @@ private void pickSongs(Intent intent, int action)
}
}

/**
* Make the selected song , ringtone of the mobile
*/

private void makeRingtone(Intent intent){
long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
Uri trackUri = ContentUris.withAppendedId(
android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
id);
String path = getRealPathFromURI(this,trackUri);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(path);
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, path);
values.put(MediaStore.MediaColumns.TITLE,intent.getStringExtra(LibraryAdapter.DATA_TITLE));
values.put(MediaStore.MediaColumns.MIME_TYPE,"");
values.put(MediaStore.Audio.Media.ARTIST,"");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);

this.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + path + "\"", null);
Uri newUri = this.getContentResolver().insert(uri, values);

RingtoneManager.setActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_RINGTONE, newUri);
}

public String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}

/**
* "Expand" the view represented by the given intent by setting the limiter
* from the view and switching to the appropriate tab.
Expand Down Expand Up @@ -702,6 +745,7 @@ private QueryTask buildQueryFromIntent(Intent intent, boolean empty, boolean all
private static final int MENU_ENQUEUE_ALL = 10;
private static final int MENU_MORE_FROM_ALBUM = 11;
private static final int MENU_MORE_FROM_ARTIST = 12;
private static final int MENU_RINGTONE = 13;

/**
* Creates a context menu for an adapter row.
Expand Down Expand Up @@ -735,8 +779,10 @@ public void onCreateContextMenu(ContextMenu menu, Intent rowData)
}
if (type == MediaUtils.TYPE_ALBUM || type == MediaUtils.TYPE_SONG)
menu.add(0, MENU_MORE_FROM_ARTIST, 0, R.string.more_from_artist).setIntent(rowData);
if (type == MediaUtils.TYPE_SONG)
if (type == MediaUtils.TYPE_SONG){
menu.add(0, MENU_MORE_FROM_ALBUM, 0, R.string.more_from_album).setIntent(rowData);
menu.add(0,MENU_RINGTONE,0,R.string.set_as_ringtone).setIntent(rowData);
}
menu.addSubMenu(0, MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
menu.add(0, MENU_DELETE, 0, R.string.delete).setIntent(rowData);
}
Expand Down Expand Up @@ -880,11 +926,16 @@ public boolean onContextItemSelected(MenuItem item)
updateLimiterViews();
break;
}
case MENU_MORE_FROM_ALBUM:
case MENU_MORE_FROM_ALBUM: {
setLimiter(MediaUtils.TYPE_ALBUM, "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
updateLimiterViews();
break;
}
case MENU_RINGTONE:{
makeRingtone(intent);
break;
}
}

return true;
}
Expand Down