AndroidFM模块学习之四源码分析(九) - 新闻资讯 - 云南小程序开发|云南软件开发|云南网站建设-昆明葵宇信息科技有限公司

159-8711-8523

云南网建设/小程序开发/软件开发

知识

不管是网站,软件还是小程序,都要直接或间接能为您产生价值,我们在追求其视觉表现的同时,更侧重于功能的便捷,营销的便利,运营的高效,让网站成为营销工具,让软件能切实提升企业内部管理水平和效率。优秀的程序为后期升级提供便捷的支持!

您当前位置>首页 » 新闻资讯 » 技术分享 >

AndroidFM模块学习之四源码分析(九)

发表时间:2020-10-19

发布人:葵宇科技

浏览次数:51


接上一篇,接下来我们看看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\PresetList.java
定义一个List列表List<PresetStation>mPresetList = new ArrayList<PresetStation>();
同步电台数量
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;
    }

 
选择电台
<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;
    }

 选择上一个电台
 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;
    }

相关案例查看更多