Android FM模組學習之源碼解析-FM模組的儲存方法

來源:互聯網
上載者:User

Android FM模組學習之源碼解析-FM模組的儲存方法

我今天想分享的是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)

 

/ * ** @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)

上一篇http://www.bkjia.com/kf/201412/363653.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.