知識
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們在追求其視覺表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏壧峁┍憬莸闹С郑?
AndroidFM模塊學(xué)習(xí)之四源碼分析(九)
發(fā)表時(shí)間:2020-10-19
發(fā)布人:葵宇科技
瀏覽次數(shù):72
接上一篇,接下來我們看看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\PresetList.java
定義一個(gè)List列表List<PresetStation>mPresetList = new ArrayList<PresetStation>();
同步電臺數(shù)量
public synchronized int getStationCount(){ return mPresetList.size(); }
獲得電臺名字
public synchronized String getStationName(int stationNum){ String name = ""; if (mPresetList.size() > stationNum){ name = mPresetList.get(stationNum).getName(); } return name; }
獲取電臺頻率
public synchronized int getStationFrequency(int stationNum){ int frequency = 102100; if (mPresetList.size() > stationNum){ frequency = mPresetList.get(stationNum).getFrequency(); } return frequency; }
設(shè)置電臺頻率
public synchronized void setStationFrequency(int stationNum, int frequency){ PresetStation mStation = mPresetList.get(stationNum); mStation.setFrequency(frequency); }
設(shè)置電臺名字
public synchronized void setStationName(int stationNum, String name){ PresetStation mStation = mPresetList.get(stationNum); mStation.setName(name); }
經(jīng)由過程ID獲得電臺
public synchronized PresetStation getStationFromIndex(int index){ int totalPresets = mPresetList.size(); PresetStation station = null; if (index < totalPresets) { station = mPresetList.get(index); } return station; }
經(jīng)由過程頻率獲得電臺
public synchronized PresetStation getStationFromFrequency(int frequency){ int totalPresets = mPresetList.size(); for (int presetNum = 0; presetNum < totalPresets; presetNum++ ) { PresetStation station = mPresetList.get(presetNum); if (station != null) { if(frequency == station.getFrequency()) { return station; } } } return null; }
添加電臺名字和頻率
public synchronized PresetStation addStation(String name, int freq){ PresetStation addStation = new PresetStation(name, freq); if(addStation != null) { mPresetList.add(addStation); } return addStation; }
添加電臺
public synchronized PresetStation addStation(PresetStation station){ PresetStation addStation = null; if(station != null) { addStation = new PresetStation (station); mPresetList.add(addStation); } return addStation; }
刪除電臺
public synchronized void removeStation(int index){ int totalPresets = mPresetList.size(); if((index >= 0) && (index < totalPresets)) { mPresetList.remove(index); } }
清除調(diào)頻列表
public synchronized void clear(){ mPresetList.clear(); }
/ *如不雅用戶選擇一個(gè)新電臺在這個(gè)列表中,將調(diào)用這個(gè)函數(shù)來更新列表。
* /
public synchronized boolean setSelectedStation(PresetStation selectStation){ int totalPresets = mPresetList.size(); if (selectStation != null) { for (int presetNum = 0; presetNum < totalPresets; presetNum++ ) { PresetStation station = mPresetList.get(presetNum); if (station != null) { if(selectStation.getFrequency() == station.getFrequency()) { if(selectStation.getName().equalsIgnoreCase(station.getName())) { mCurrentStation = presetNum; return true; } } } } } return false; }
/ *檢查是否有雷同電臺存在在列表中
* /
public synchronized boolean sameStationExists(PresetStation compareStation){ int totalPresets = mPresetList.size(); if (compareStation != null) { for (int presetNum = 0; presetNum < totalPresets; presetNum++ ) { PresetStation station = mPresetList.get(presetNum); if (station != null) { if(compareStation.getFrequency() == station.getFrequency()) { return true; } } } } return false; }
/ *如不雅用戶在這個(gè)列表中選擇一個(gè)新電臺,將調(diào)用這個(gè)例程
*更新列表。
* /
public synchronized boolean setSelectedStation(int stationIndex){ boolean foundStation = false; int totalPresets = mPresetList.size(); if (stationIndex < totalPresets) { mCurrentStation = stationIndex; foundStation = true; } return foundStation; }
選擇電臺
<pre name="code" class="java">public synchronized void selectStation(PresetStation selectStation){ int totalPresets = mPresetList.size(); if (selectStation != null) { for (int presetNum = 0; presetNum < totalPresets; presetNum++ ) { PresetStation station = mPresetList.get(presetNum); if (station != null) { if(selectStation.getFrequency() == station.getFrequency()) { mCurrentStation = presetNum; return; } } } } }
獲取選擇的┞肪
public synchronized PresetStation getSelectedStation(){ int totalPresets = mPresetList.size(); PresetStation station = null; if (mCurrentStation < totalPresets) { station = mPresetList.get(mCurrentStation); } return station; }
選擇下一電臺
public synchronized PresetStation selectNextStation(){ int totalPresets = mPresetList.size(); PresetStation station = null; if(totalPresets > 0) { mCurrentStation ++; if ( (mCurrentStation) >= totalPresets) { mCurrentStation =0; } station = mPresetList.get(mCurrentStation); } return station; }
選擇上一個(gè)電臺
public synchronized PresetStation selectPrevStation(){ int totalPresets = mPresetList.size(); PresetStation station = null; if(totalPresets > 0) { mCurrentStation --; if ( mCurrentStation < 0) { mCurrentStation = totalPresets-1; } station = mPresetList.get(mCurrentStation); } return station; }
相關(guān)案例查看更多
相關(guān)閱讀
- 小程序開發(fā)排名前十名
- 服務(wù)器
- 電商網(wǎng)站建設(shè)
- 分銷系統(tǒng)
- 云南網(wǎng)站建設(shè)選
- 云南小程序開發(fā)推薦
- 云南網(wǎng)站建設(shè)快速優(yōu)化
- 云南網(wǎng)站建設(shè)公司排名
- 云南微信小程序開發(fā)
- 麗江小程序開發(fā)
- 楚雄小程序開發(fā)
- 大理網(wǎng)站建設(shè)公司
- 政府網(wǎng)站建設(shè)服務(wù)
- typescript
- 汽車回收管理
- 汽車回收系統(tǒng)
- 網(wǎng)站制作
- 云南網(wǎng)絡(luò)營銷顧問
- 小程序表單
- 云南小程序開發(fā)費(fèi)用
- 網(wǎng)站建設(shè)列表網(wǎng)
- 汽車回收管理系統(tǒng)
- 云南小程序開發(fā)公司
- 小程序制作
- 云南建設(shè)廳官方網(wǎng)站
- 小程序開發(fā)平臺前十名
- 關(guān)鍵詞快速排名
- 網(wǎng)站開發(fā)公司哪家好
- 表單
- 網(wǎng)絡(luò)公司排名