Android FM模块学习之四源码解析(四)
2014-12-22 15:58
666 查看
我今天想分享的是FM模块的保存方法,即FmSharedPreferences.java
FmSharedPreferences(Context context)在构造方法中加载Load()方法,
public void Load(){
Log.d(LOGTAG, "Load preferences ");
if(mContext == null)
{
return;
}
SharedPreferences sp = mContext.getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
mTunedFrequency = sp.getInt(PREF_LAST_TUNED_FREQUENCY, DEFAULT_NO_FREQUENCY);
mRecordDuration = sp.getInt(LAST_RECORD_DURATION, RECORD_DUR_INDEX_0_VAL);
mAFAutoSwitch = sp.getBoolean(LAST_AF_JUMP_VALUE, true);
mAudioOutputMode = sp.getBoolean(AUDIO_OUTPUT_MODE, true);
if(sp.getInt(FMCONFIG_COUNTRY, 0) == REGIONAL_BAND_USER_DEFINED) {
mBandMinFreq = sp.getInt(FMCONFIG_MIN, mBandMinFreq);
mBandMaxFreq = sp.getInt(FMCONFIG_MAX, mBandMaxFreq);
mChanSpacing = sp.getInt(FMCONFIG_STEP, mChanSpacing);
}
int num_lists = sp.getInt(LIST_NUM, 1);
if (mListOfPlists.size() == 0) {
for (int listIter = 0; listIter < num_lists; listIter++) {
String listName = sp.getString(LIST_NAME + listIter, "FM - " + (listIter+1));
int numStations = sp.getInt(STATION_NUM + listIter, 1);
if (listIter == 0) {
createFirstPresetList(listName);
} else {
createPresetList(listName);
}
PresetList curList = mListOfPlists.get(listIter);
for (int stationIter = 0; stationIter < numStations; stationIter++) {
String stationName = sp.getString(STATION_NAME + listIter + "x" + stationIter,
DEFAULT_NO_NAME);
int stationFreq = sp.getInt(STATION_FREQUENCY + listIter + "x" + stationIter,
DEFAULT_NO_FREQUENCY);
PresetStation station = curList.addStation(stationName, stationFreq);
int stationId = sp.getInt(STATION_ID + listIter + "x" + stationIter,
DEFAULT_NO_STATIONID);
station.setPI(stationId);
int pty = sp.getInt(STATION_PTY + listIter + "x" + stationIter, DEFAULT_NO_PTY);
station.setPty(pty);
int rdsSupported = sp.getInt(STATION_RDS + listIter + "x" + stationIter,
DEFAULT_NO_RDSSUP);
if (rdsSupported != 0) {
station.setRDSSupported(true);
} else {
station.setRDSSupported(false);
}
/* Load Configuration */
setCountry(sp.getInt(FMCONFIG_COUNTRY, REGIONAL_BAND_NORTH_AMERICA));
/* Last list the user was navigating */
mListIndex = sp.getInt(LAST_LIST_INDEX, 0);
if(mListIndex >= num_lists)
{mListIndex=0;
}
}
初始化取出sp一些数据
根据系统初始化地区设置当地频率
/*Load Configuration */
if (Locale.getDefault().equals(Locale.CHINA)) {
setCountry(sp.getInt(FMCONFIG_COUNTRY, REGIONAL_BAND_CHINA));
} else {
setCountry(sp.getInt(FMCONFIG_COUNTRY, REGIONAL_BAND_NORTH_AMERICA));
}
/* Last list the user was navigating */
保存频率
public void Save()
设置默认的地区
public static void SetDefaults()
设置调整频率
public static void setTunedFrequency(intfrequency)
获取调整频率
public static int getTunedFrequency()
获取下一个频率
public static int getNextTuneFrequency(intfrequency)
获取上一个频率
public static int getPrevTuneFrequency(intfrequency)
设置fm播放的频率范围
public static void setRadioBand(int band)
获取fm频率范围限制
public static int getRadioBand()
获取间隔
public static int getChSpacing()
设置远程数据服务
public static void setRdsStd(int std)
mFMConfiguration.setRdsStd(std);
获取远程数据服务
public static int getRdsStd()
mFMConfiguration.getRdsStd();
设置国家地区
public static void setCountry(intnCountryCode)
获取国家地区
public static int getCountry()
设置声音输出模板
setAudioOutputMode
设置录音是否持续
public static void setRecordDuration(intdurationIndex)
FmSharedPreferences(Context context)在构造方法中加载Load()方法,
public void Load(){
Log.d(LOGTAG, "Load preferences ");
if(mContext == null)
{
return;
}
SharedPreferences sp = mContext.getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
mTunedFrequency = sp.getInt(PREF_LAST_TUNED_FREQUENCY, DEFAULT_NO_FREQUENCY);
mRecordDuration = sp.getInt(LAST_RECORD_DURATION, RECORD_DUR_INDEX_0_VAL);
mAFAutoSwitch = sp.getBoolean(LAST_AF_JUMP_VALUE, true);
mAudioOutputMode = sp.getBoolean(AUDIO_OUTPUT_MODE, true);
if(sp.getInt(FMCONFIG_COUNTRY, 0) == REGIONAL_BAND_USER_DEFINED) {
mBandMinFreq = sp.getInt(FMCONFIG_MIN, mBandMinFreq);
mBandMaxFreq = sp.getInt(FMCONFIG_MAX, mBandMaxFreq);
mChanSpacing = sp.getInt(FMCONFIG_STEP, mChanSpacing);
}
int num_lists = sp.getInt(LIST_NUM, 1);
if (mListOfPlists.size() == 0) {
for (int listIter = 0; listIter < num_lists; listIter++) {
String listName = sp.getString(LIST_NAME + listIter, "FM - " + (listIter+1));
int numStations = sp.getInt(STATION_NUM + listIter, 1);
if (listIter == 0) {
createFirstPresetList(listName);
} else {
createPresetList(listName);
}
PresetList curList = mListOfPlists.get(listIter);
for (int stationIter = 0; stationIter < numStations; stationIter++) {
String stationName = sp.getString(STATION_NAME + listIter + "x" + stationIter,
DEFAULT_NO_NAME);
int stationFreq = sp.getInt(STATION_FREQUENCY + listIter + "x" + stationIter,
DEFAULT_NO_FREQUENCY);
PresetStation station = curList.addStation(stationName, stationFreq);
int stationId = sp.getInt(STATION_ID + listIter + "x" + stationIter,
DEFAULT_NO_STATIONID);
station.setPI(stationId);
int pty = sp.getInt(STATION_PTY + listIter + "x" + stationIter, DEFAULT_NO_PTY);
station.setPty(pty);
int rdsSupported = sp.getInt(STATION_RDS + listIter + "x" + stationIter,
DEFAULT_NO_RDSSUP);
if (rdsSupported != 0) {
station.setRDSSupported(true);
} else {
station.setRDSSupported(false);
}
/* Load Configuration */
setCountry(sp.getInt(FMCONFIG_COUNTRY, REGIONAL_BAND_NORTH_AMERICA));
/* Last list the user was navigating */
mListIndex = sp.getInt(LAST_LIST_INDEX, 0);
if(mListIndex >= num_lists)
{mListIndex=0;
}
}
初始化取出sp一些数据
根据系统初始化地区设置当地频率
/*Load Configuration */
if (Locale.getDefault().equals(Locale.CHINA)) {
setCountry(sp.getInt(FMCONFIG_COUNTRY, REGIONAL_BAND_CHINA));
} else {
setCountry(sp.getInt(FMCONFIG_COUNTRY, REGIONAL_BAND_NORTH_AMERICA));
}
/* Last list the user was navigating */
保存频率
public void Save()
设置默认的地区
public static void SetDefaults()
设置调整频率
public static void setTunedFrequency(intfrequency)
获取调整频率
public static int getTunedFrequency()
获取下一个频率
public static int getNextTuneFrequency(intfrequency)
获取上一个频率
public static int getPrevTuneFrequency(intfrequency)
/ * * * @param mFMConfiguration mFMConfiguration设置 * / public static void setFMConfiguration(FmConfig mFMConfig) /** *@return the mFMConfiguration */ public static FmConfig getFMConfiguration() { return mFMConfiguration; }
设置fm播放的频率范围
public static void setRadioBand(int band)
获取fm频率范围限制
public static int getRadioBand()
获取间隔
public static int getChSpacing()
设置远程数据服务
public static void setRdsStd(int std)
mFMConfiguration.setRdsStd(std);
获取远程数据服务
public static int getRdsStd()
mFMConfiguration.getRdsStd();
设置国家地区
public static void setCountry(intnCountryCode)
获取国家地区
public static int getCountry()
设置声音输出模板
setAudioOutputMode
设置录音是否持续
public static void setRecordDuration(intdurationIndex)
相关文章推荐
- AndroidFm模块学习之四源码解析(十一)
- Android FM模块学习之四源码解析(一)
- Android FM模块学习之四源码解析(三)
- Android FM 模块学习之四 源码解析(1)
- AndroidFM模块学习之四源码解析(十一)
- Android FM模块学习之四源码解析(二)
- Android FM模块学习之四源码分析(3)
- AndroidFM模块学习之四源码分析(九)
- Android FM模块学习之四源码分析(五)
- AndroidFM模块学习之四源码分析(十)
- Android FM模块学习之四源码分析(八)
- Android FM模块学习之源码分析(六)
- Android FM模块学习之四源码分析(七)
- Android FM模块学习之四源码学习(2)
- Android FM模块学习之三 FM手动调频
- Android学习备忘022——FBReader源码解析备忘
- Android FM模块学习之二 FM搜索频率流程
- AndroidFM模块学习之录音功能
- AndroidFM模块学习之五关闭FM流程
- [学习总结]7、Android AsyncTask完全解析,带你从源码的角度彻底理解