package com.cn.android.daming;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
public class SoundSettingMainActivity extends PreferenceActivity {
private static final int SMS_RINGTONE_PICKED = 1;
private static final int PHONE_RINGTONE_PICKED = 2;
private static final int ALARM_RINGTONE_PICKED = 3;
private static final int SDCARD_RINGTONE_PICKED = 4;
public static final String NOTIFICATION_RINGTONE = "pref_notification_ringtone";
public static final String NOTIFICATION_RINGTONE_TITLE_NAME = "pref_notification_ringtone_name";
public static final String PHONE_RINGTONE = "pref_phone_ringtone";
public static final String PHONE_RINGTONE_TITLE_NAME = "pref_phone_ringtone_title_name";
public static final String ALARM_RINGTONE = "pref_alarm_ringtone";
public static final String ALARM_RINGTONE_TITLE_NAME = "pref_alarm_ringtone_title_name";
public static final String SDCARD_RINGTONE = "pref_sdcard_ringtone";
public static final String SDCARD_RINGTONE_TITLE_NAME = "pref_sdcard_ringtone_title_name";
private String notificationStr;
private String phoneStr;
private String alarmStr;
private String sdcardStr;
private Preference mMmsSoundsPref;
private Preference mPhoneSoundsPref;
private Preference mAlarmSoundsPref;
private Preference mSdcardSoundsPref;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
setMessagePreferences();
setDefaultPreferences();
}
private void setMessagePreferences() {
mMmsSoundsPref = findPreference("pref_sms_ringtone");
mPhoneSoundsPref = findPreference("pref_phone_ringtone");
mAlarmSoundsPref = findPreference("pref_alarm_ringtone");
mSdcardSoundsPref = findPreference("pref_sdcard_ringtone");
}
private void setDefaultPreferences(){
SharedPreferences innersharedPreferences = PreferenceManager.getDefaultSharedPreferences(SoundSettingMainActivity.this);
String notificationRingtoneTitleName = innersharedPreferences.getString(NOTIFICATION_RINGTONE_TITLE_NAME, null);
if(notificationRingtoneTitleName!=null){
mMmsSoundsPref.setSummary(notificationRingtoneTitleName);
}else{
mMmsSoundsPref.setSummary(getString(R.string.pref_summary_notification_ringtone));
}
String phoneRingtoneTitleName = innersharedPreferences.getString(PHONE_RINGTONE_TITLE_NAME, null);
if(phoneRingtoneTitleName!=null){
mPhoneSoundsPref.setSummary(phoneRingtoneTitleName);
}else{
mPhoneSoundsPref.setSummary(getString(R.string.pref_summary_phone_ringtone));
}
String alarmRingtoneTitleName = innersharedPreferences.getString(ALARM_RINGTONE_TITLE_NAME, null);
if(alarmRingtoneTitleName!=null){
mAlarmSoundsPref.setSummary(alarmRingtoneTitleName);
}else{
mAlarmSoundsPref.setSummary(getString(R.string.pref_summary_alarm_ringtone));
}
String sdcardRingtoneTitleName = innersharedPreferences.getString(SDCARD_RINGTONE_TITLE_NAME, null);
if(sdcardRingtoneTitleName!=null){
mSdcardSoundsPref.setSummary(sdcardRingtoneTitleName);
}else{
mSdcardSoundsPref.setSummary(getString(R.string.pref_summary_sdcard_ringtone));
}
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
if (preference == mMmsSoundsPref){
doPickSmsRingtone();
}
else if(preference == mPhoneSoundsPref){
doPickPhoneRingtone();
}
else if(preference == mAlarmSoundsPref){
doPickAlarmRingtone();
}
else if(preference == mSdcardSoundsPref){
doPickSdcardRingtone();
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
private void doPickSmsRingtone(){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
notificationStr = sharedPreferences.getString(NOTIFICATION_RINGTONE, null);
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
// Allow user to pick 'Default'
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
// Show only ringtones
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
//set the default Notification value
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
// Don't show 'Silent'
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
Uri notificationUri;
if (notificationStr != null) {
notificationUri = Uri.parse(notificationStr);
// Put checkmark next to the current ringtone for this contact
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, notificationUri);
} else {
// Otherwise pick default ringtone Uri so that something is selected.
notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// Put checkmark next to the current ringtone for this contact
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, notificationUri);
}
// Launch!
startActivityForResult(intent, SMS_RINGTONE_PICKED);
}
private void doPickPhoneRingtone(){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
phoneStr = sharedPreferences.getString(PHONE_RINGTONE, null);
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
// Allow user to pick 'Default'
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
// Show only ringtones
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
//set the default Notification value
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
// Don't show 'Silent'
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
Uri phoneUri;
if (phoneStr != null) {
phoneUri = Uri.parse(phoneStr);
// Put checkmark next to the current ringtone for this contact
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, phoneUri);
} else {
// Otherwise pick default ringtone Uri so that something is selected.
phoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
// Put checkmark next to the current ringtone for this contact
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, phoneUri);
}
startActivityForResult(intent, PHONE_RINGTONE_PICKED);
}
private void doPickAlarmRingtone(){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
没有合适的资源?快使用搜索试试~ 我知道了~
android 闹钟选择SD卡音乐铃声
共24个文件
class:7个
xml:4个
png:3个
5星 · 超过95%的资源 需积分: 14 172 下载量 47 浏览量
2011-11-24
23:28:29
上传
评论 7
收藏 6.67MB RAR 举报
温馨提示
简单的android 闹钟选择SD卡音乐铃声 android 闹钟选择SD卡音乐铃声 android 闹钟选择SD卡音乐铃声
资源推荐
资源详情
资源评论
收起资源包目录
Sound.rar (24个子文件)
Sound
.project 841B
郑源 - 怎么会狠心伤害我.mp3 6.63MB
proguard.cfg 1KB
src
com
cn
android
daming
SoundSettingMainActivity.java 14KB
AndroidManifest.xml 699B
res
drawable-ldpi
icon.png 2KB
xml
preferences.xml 2KB
drawable-hdpi
icon.png 4KB
drawable-mdpi
icon.png 3KB
layout
main.xml 382B
values
strings.xml 968B
assets
gen
com
cn
android
daming
R.java 1KB
default.properties 362B
.classpath 280B
bin
resources.ap_ 12KB
com
cn
android
daming
R$layout.class 403B
R$drawable.class 409B
R$attr.class 349B
R$xml.class 401B
SoundSettingMainActivity.class 7KB
R.class 554B
R$string.class 947B
classes.dex 8KB
Sound.apk 17KB
共 24 条
- 1
liujianminghero
- 粉丝: 50
- 资源: 35
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页