Android FM module learning-source code parsing-Methods for saving the FM Module
What I want to share today is the storage method of the FM module, namely, FmSharedPreferences. java.
FmSharedPreferences (Context context) loads the Load () method in the constructor,
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; } }
Initialize and retrieve sp data
Set the local frequency based on the system initialization Region
/*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 */
Storage frequency
Public void Save ()
Set the default Region
Public static void SetDefaults ()
Set adjustment frequency
Public static void setTunedFrequency (intfrequency)
Get adjustment frequency
Public static int getTunedFrequency ()
Get next frequency
Public static int getNextTuneFrequency (intfrequency)
Obtain the previous frequency
Public static int getPrevTuneFrequency (intfrequency)
/*** @ Param mFMConfiguration setting */public static void setFMConfiguration (FmConfig mFMConfig)/*** @ return the mFMConfiguration */public static FmConfig getFMConfiguration () {return mFMConfiguration ;}
Set the frequency range of fm playback.
Public static void setRadioBand (int band)
Obtain the fm frequency range limit
Public static int getRadioBand ()
Get Interval
Public static int getChSpacing ()
Set Remote Data Service
Public static void setRdsStd (int std)
MFMConfiguration. setRdsStd (std );
Obtain Remote Data Service
Public static int getRdsStd ()
MFMConfiguration. getRdsStd ();
Set country and region
Public static void setCountry (intnCountryCode)
Obtain country/region
Public static int getCountry ()
Set sound output Template
SetAudioOutputMode
Set whether the recording lasts
Public static void setRecordDuration (intdurationIndex)
Http://www.bkjia.com/kf/201412/363653.html previous