Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android FM模塊學習之源碼解析-FM模塊的保存方法

Android FM模塊學習之源碼解析-FM模塊的保存方法

編輯:關於Android編程

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

上一篇/kf/201412/363653.html
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved