Commit ee2269b4 authored by Alexandre Perraud's avatar Alexandre Perraud Committed by Jean-Baptiste Kempf
Browse files

Set ringtone from VLC


Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent ce2f0ad6
......@@ -14,6 +14,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<application
android:name="org.videolan.vlc.VLCApplication"
......
......@@ -15,6 +15,12 @@
android:title="@string/append_all" />
<item
android:id="@+id/audio_list_browser_delete"
android:title="@string/delete" />
android:title="@string/delete"/>
</group>
<group android:id="@+id/phone_only" >
<item
android:id="@+id/audio_list_browser_set_song"
android:title="@string/set_song"/>
</group>
</menu>
\ No newline at end of file
......@@ -22,6 +22,7 @@
<string name="play_all">Lire tout</string>
<string name="append_all">Lire tout à la suite</string>
<string name="delete">Supprimer</string>
<string name="set_song">Définir comme sonnerie</string>
<string name="info">Information</string>
<string name="confirm_delete">Supprimer le média \'%1$s\' ?</string>
<string name="pause">Pause</string>
......
......@@ -24,6 +24,7 @@
<string name="play_all">Play all</string>
<string name="append_all">Append all</string>
<string name="delete">Delete</string>
<string name="set_song">Set as ringtone</string>
<string name="info">Information</string>
<string name="confirm_delete">Delete the file \'%1$s\' ?</string>
<string name="pause">Pause</string>
......
......@@ -36,6 +36,7 @@ import java.util.Properties;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Display;
......@@ -330,4 +331,12 @@ public class Util {
isCompatible = true;
return true;
}
public static boolean isPhone(){
TelephonyManager manager = (TelephonyManager)VLCApplication.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
if(manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE){
return false;
}else{
return true;
}
}
}
......@@ -28,6 +28,7 @@ import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.Media;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.VlcRunnable;
import org.videolan.vlc.WeakHandler;
import org.videolan.vlc.gui.CommonDialogs;
......@@ -234,8 +235,12 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.audio_list_browser, menu);
if (v.getId() != R.id.songs_list)
if (v.getId() != R.id.songs_list) {
menu.setGroupEnabled(R.id.songs_view_only, false);
menu.setGroupEnabled(R.id.phone_only, false);
}
if (!Util.isPhone())
menu.setGroupVisible(R.id.phone_only, false);
}
@Override
......@@ -283,6 +288,11 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
return true;
}
if (id == R.id.audio_list_browser_set_song) {
AudioUtil.setRingtone(mSongsAdapter.getItem(groupPosition),getActivity());
return true;
}
if (useAllItems) {
startPosition = groupPosition;
medias = mSongsAdapter.getLocations();
......
......@@ -28,6 +28,7 @@ import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.Media;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.VlcRunnable;
import org.videolan.vlc.WeakHandler;
import org.videolan.vlc.gui.CommonDialogs;
......@@ -128,6 +129,8 @@ public class AudioListFragment extends SherlockListFragment {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.audio_list_browser, menu);
if (!Util.isPhone())
menu.setGroupVisible(R.id.phone_only, false);
}
@Override
......@@ -161,6 +164,11 @@ public class AudioListFragment extends SherlockListFragment {
return true;
}
if (id == R.id.audio_list_browser_set_song) {
AudioUtil.setRingtone(mSongsAdapter.getItem(menuInfo.position),getActivity());
return true;
}
if (useAllItems) {
startPosition = menuInfo.position;
medias = mSongsAdapter.getLocations();
......
/*****************************************************************************
* AudioUtil.java
*****************************************************************************
* Copyright © 2011-2012 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui.audio;
import java.io.File;
import org.videolan.vlc.Media;
import org.videolan.vlc.Util;
import android.app.Activity;
import android.content.ContentValues;
import android.media.RingtoneManager;
import android.net.Uri;
import android.provider.MediaStore;
public class AudioUtil {
public static void setRingtone( Media song, Activity activity){
File newringtone = Util.URItoFile(song.getLocation());
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, newringtone.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, song.getTitle());
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
values.put(MediaStore.Audio.Media.ARTIST, song.getArtist());
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);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(newringtone.getAbsolutePath());
activity.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + newringtone.getAbsolutePath() + "\"", null);
Uri newUri = activity.getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(
activity.getApplicationContext(),
RingtoneManager.TYPE_RINGTONE,
newUri
);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment