編輯:關於Android編程
前一章我們學習了FM的自動調頻,接下來我們就看看FM手動調頻是如何進行的。如果不清楚FM自動調頻的過程,請打開超鏈接查看FM搜索頻率流程。
首先來看一下流程圖:
2.滑動刻度盤HorizontalNumberPicker控件在監聽事件裡使用方法valueToFrequency(newVal)
1.長按左右箭頭居中的頻率字符串,彈出FrequencyPickerDialog調頻對話框確定調用tuneRadio(frequency)調頻。<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGltZyBzcmM9"/uploadfile/Collfiles/20141126/201411260842539.jpg" alt="\">
獲取到頻率
protected int valueToFrequency(int value) { mFrequency = mPrefs.getLowerLimit() + value * mPrefs.getFrequencyStepSize(); return mFrequency; }發送一個handler 回調一個tuneRadio(frequency)調頻。
Runnable mRadioChangeFrequency = new Runnable(){ public void run() { mUpdatePickerValue = false; tuneRadio(mFrequency); } };
3.手動點擊按鈕左右箭頭, 通過監聽調用:
int frequency =FmSharedPreferences.getNextTuneFrequency();
int frequency =FmSharedPreferences.getPrevTuneFrequency();
tuneRadio(frequency);進行調頻
getNextTuneFrequency()方法通過判斷頻率最大限制范圍,後加200(刻度)
getPrevTuneFrequency()方法通過判斷頻率最小限制范圍,後減200(刻度)
調頻方法分析
private void tuneRadio(int frequency)
private void tuneRadio(int frequency){ /* Issue the tune command only if tuneCommand is already not active */ if((mService != null) && (mCommandActive != CMD_TUNE) && isFmOn()) { boolean bStatus = false; try { bStatus = mService.tune(frequency); if (bStatus) { postTimeoutHandler(CMD_TUNE); }else { if (isFmOn()) { mCommandFailed = CMD_TUNE; Log.e(LOGTAG, "mService.tune failed"); showDialog(DIALOG_CMD_FAILED); } }mTunedStation.setName(""); mTunedStation.setPI(0); mTunedStation.setPty(0); updateStationInfoToUI(); }catch (RemoteException e) { e.printStackTrace(); } }else { Log.e(LOGTAG, "Delayed Tune handler stopped"); } }
通過回調引用類調用FMRadioService類的tune()方法進行調頻
bStatus = mService.tune(frequency);
發送一個廣播連接是否超時
postTimeoutHandler(CMD_TUNE);
設置調頻名字,更新FMRadioUI界面信息
mTunedStation.setName("");
mTunedStation.setPI(0);
mTunedStation.setPty(0);
updateStationInfoToUI()
(通過IFMRadioSrevice.aidl通信機制onbind返回的類的引用調用FMRadioService中的調頻方法)
FMRadioService中的tune方法
public boolean tune(int frequency)
public boolean tune(int frequency) { boolean bCommandSent=false; double doubleFrequency = frequency/1000.00; Log.d(LOGTAG, "tuneRadio: " + doubleFrequency); if (mReceiver != null) { mReceiver.setStation(frequency); bCommandSent = true; } return bCommandSent; }
調用FMReceiver類的setStation方法調頻
public boolean setStation (intfrequencyKHz)
public boolean setStation (int frequencyKHz) { int ret; mControl.setFreq(frequencyKHz); ret = mControl.setStation(sFd); if(ret < 0 ) { return false; } else { return true; } }
mControl.setFreq(frequencyKHz);
設置優化調頻核心指定的頻率
ret = mControl.setStation(sFd);
public int setStation(int fd) { Log.d(TAG, "** Tune Using: "+fd); int ret = FmReceiverJNI.setFreqNative(fd, mFreq); Log.d(TAG, "** Returned: "+ret); return ret; }
最後調用FmReceiverJNI類
setFreqNative(fd, mFreq); 本地方法 JNI到 cpp文件
/*native interface */ static jint android_hardware_fmradio_FmReceiverJNI_setFreqNative (JNIEnv * env, jobject thiz, jint fd, jint freq) { int err; double tune; struct v4l2_frequency freq_struct; freq_struct.type = V4L2_TUNER_RADIO; freq_struct.frequency = (freq*TUNE_MULT/1000); err = ioctl(fd, VIDIOC_S_FREQUENCY, &freq_struct); if(err < 0){ return FM_JNI_FAILURE; } return FM_JNI_SUCCESS; }
介紹A StateListDrawable is a drawable object defined in XML that uses a several differe
Android客戶端請求服務器端的詳細解釋1. Android客戶端與服務器端通信方式:Android與服務器通信通常采用HTTP通信方式和Socket通信方式,而HTT
版本 日期 作者 說明 V1 2016.07.29 韋東山 第1版本,Android部分未寫 表格完畢我是1999年上的大學,物理專業。在大一時,
Android 中下拉菜單,即如html中的<select>,關鍵在於調用setDropDownViewResource方法,以XML的方式定義下拉菜單要顯示