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

上一篇,接下来我们看看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;
    }

时间: 2024-10-03 04:02:32

AndroidFM模块学习之四源码分析(九)的相关文章

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

接上一篇,今天我们来看看android\vendor\qcom\opensource\fm\qcom\fmradio\FmRxControls.java / * *打开FM Rx / Tx. * Rx = 1和Tx = 2 * / public void fmOn(int fd, int device) { int re; FmReceiverJNI.setControlNative(fd, V4L2_CID_PRIVATE_TAVARUA_STATE, device ); setAudioPa

Android FM模块学习之四源码分析(3)

接着看FM模块的其他几个次要的类的源码.这样来看FM上层的东西不是太多. 请看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\Settings.java protected void onCreate(BundlesavedInstanceState) 从FMRadio.java用使用Intent跳转携带参数过来,在onCreate获取携带数据. protected void onCreate(Bundle savedIn

Android FM模块学习之四源码分析(五)

前几章我们分析了FM模块的几个主要的类文件,今天要分析的是:FMTransceiver.java public class FmTransceiver { /* Primary FM States : * FM will be in one of the 4 states at any point of time * '0' - FMState_Turned_Off * '1' - FMState_Rx_Turned_On * '2' - FMState_Tx_Turned_On * '3' -

AndroidFm模块学习之四源码解析(十一)

接上一篇,接下来看看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\FmTags.java 当点击FMRadio.java菜单的全部频道选项,跳转到FmTags.java类 定义了一个ListView控件和一个简单适配器 private ListView la; private ArrayAdapter<String> adapter; 使用Handler刷新UI界面 private final Handler mHan

Android FM模块学习之四源码分析(七)

接上一篇,现在分析android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\StationListActivity.java protectedvoid onCreate(Bundle savedInstanceState)方法里 绑定FMRadioService服务 bindService((newIntent()).setClass(this, FMRadioService.class), osc, 0); 实例化ListVie

Android FM模块学习之四源码解析(二)

上一章我们了解了FM主activity:FMRadio.java,若没查看的,请打开链接Android FM模块学习之四源码解析(一) 查看fmradio.java源码注释.接下来我们来看看FM重要的一个类:FMRadioService.java 由上一章我们已经知道,打开FM时,在OnStart函数中会bindToService来开启服务, public boolean bindToService(Context context, ServiceConnection callback) { L

Android FM模块学习之源码分析(六)

现在是2015年1月啦,得改口说去年了,去年抽时间整理了一些FM模块的主要源码类的东西,今年再整理一下几个次要的类的源码.这样来看FM上层的东西不是太多. 请看android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\Settings.java protected void onCreate(BundlesavedInstanceState) 从FMRadio.java用使用Intent跳转携带参数过来,在onCreate获取携带数

Android FM模块学习之四源码解析(三)

由于最近一直忙项目,没有时间来更新文档,今天抽空来写一点,希望大家可以学习使用! 这一章当然还是来分析FM模块的源码.FmReceiver.java publicFmReceiver(String devicePath,FmRxEvCallbacksAdaptor callback) throwsInstantiationException { mControl = new FmRxControls(); mRxEvents = new FmRxEventListner(); //registe

Android FM模块学习之四源码解析(一)

前一章我们了解了FM手动调频,接下来我们要分析FM模块用到的源码.此源码是基于高通平台的,别的平台都大同小异,只不过是平台自己作了些小改动而已. 首先要看的当然是主activity, FMRadio.java fmradio类启动FMRadioService.java类调用FmSharedPreferences类进行存储数据,PresetStation调整频率 setVolumeControlStream(AudioManager.STREAM_MUSIC);音乐回放即媒体音量 LoadedDa