AndroidFM模組學習之四源碼分析(九)

來源:互聯網
上載者:User

AndroidFM模組學習之四源碼分析(九)

接下來我們看看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\PresetList.java

 

定義一個List列表List

mPresetList = new ArrayList
();

同步電台數量

 

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;    }

 

 

設定電台頻率

 

public synchronized void setStationFrequency(int stationNum, int frequency){        PresetStation mStation = mPresetList.get(stationNum);        mStation.setFrequency(frequency);    }

設定電台名字

 

public synchronized void setStationName(int stationNum, String name){        PresetStation mStation = mPresetList.get(stationNum);        mStation.setName(name);    }

 

 

通過ID得到電台

 

public synchronized PresetStation getStationFromIndex(int index){        int totalPresets = mPresetList.size();        PresetStation station = null;        if (index < totalPresets) {            station = mPresetList.get(index);        }        return station;    }

 

 

通過頻率得到電台

 

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);       }    }

 

 

清除調頻列表

 

public synchronized void clear(){        mPresetList.clear();    }

 

 

/ *如果使用者選擇一個新電台在這個列表中,將調用這個函數來更新列表。

* /

 

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;    }

 

 

/ *如果使用者在這個列表中選擇一個新電台,將調用這個常式

*更新列表。

* /

 

public synchronized boolean setSelectedStation(int stationIndex){        boolean foundStation = false;        int totalPresets = mPresetList.size();        if (stationIndex < totalPresets) {            mCurrentStation = stationIndex;            foundStation = true;        }        return foundStation;    }

 

 

選擇電台

 

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;    }


 

選擇上一個電台

 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;    }


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.