diff options
author | sundarajan srinivasan <ssrinivasan@cyngn.com> | 2016-01-24 11:59:42 -0800 |
---|---|---|
committer | Sundarajan Srinivasan <ssrinivasan@cyngn.com> | 2016-03-07 10:39:16 -0800 |
commit | 62d40c3563b9f4b63a44ef18de91901f108922c4 (patch) | |
tree | 62177588fa917ca9941b65b397daae3be982dd5a | |
parent | b79b119854a16bdff2f54236016290495ac1a468 (diff) | |
download | android_hardware_qcom_fm-62d40c3563b9f4b63a44ef18de91901f108922c4.tar.gz android_hardware_qcom_fm-62d40c3563b9f4b63a44ef18de91901f108922c4.tar.bz2 android_hardware_qcom_fm-62d40c3563b9f4b63a44ef18de91901f108922c4.zip |
fmapp2: Add support for long press and short press from headset
*Long press - toggle's FM on/off
*short press - scans the next channel.
SAMOSA-7
Change-Id: Id670b0275d949ba449d4fa47167e4bee8e15f09f
(cherry picked from commit 13c72eb945006651f39510903684f016a81a9be9)
-rw-r--r-- | fmapp2/src/com/caf/fmradio/FMRadio.java | 101 | ||||
-rw-r--r-- | fmapp2/src/com/caf/fmradio/FMRadioService.java | 61 | ||||
-rw-r--r-- | fmapp2/src/com/caf/fmradio/IFMRadioService.aidl | 4 |
3 files changed, 116 insertions, 50 deletions
diff --git a/fmapp2/src/com/caf/fmradio/FMRadio.java b/fmapp2/src/com/caf/fmradio/FMRadio.java index b05d64c..d685ffb 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadio.java +++ b/fmapp2/src/com/caf/fmradio/FMRadio.java @@ -239,7 +239,6 @@ public class FMRadio extends Activity /* Current Status Indicators */ private static boolean mRecording = false; private static boolean mIsScaning = false; - private static boolean mIsSeeking = false; private static boolean mIsSearching = false; private static int mScanPty = 0; private static int mScanPtyIndex = 0; @@ -626,7 +625,12 @@ public class FMRadio extends Activity boolean radioOn = isFmOn(); boolean recording = isRecording(); boolean sleepActive = isSleepTimerActive(); - boolean searchActive = isScanActive() || isSeekActive(); + boolean searchActive = false; + try{ + searchActive = isScanActive() || mService.isSeekActive(); + } catch(RemoteException e) { + e.printStackTrace(); + } item = menu.add(0, MENU_SCAN_START, 0, R.string.menu_scan_start). setIcon(R.drawable.ic_btn_search); @@ -681,7 +685,13 @@ public class FMRadio extends Activity MenuItem item; boolean radioOn = isFmOn(); boolean recording = isRecording(); - boolean searchActive = isScanActive() || isSeekActive(); + boolean searchActive = false; + + try { + searchActive = isScanActive() || mService.isSeekActive(); + } catch(RemoteException e) { + e.printStackTrace(); + } item = menu.findItem(MENU_SCAN_START); if (item != null) { @@ -1201,8 +1211,15 @@ public class FMRadio extends Activity String []items; double frequency = mTunedStation.getFrequency() / 1000.0; boolean bSearchActive = false; + boolean isSeekActive = false; + + try { + isSeekActive = mService.isSeekActive(); + } catch(RemoteException e) { + e.printStackTrace(); + } - if (isSeekActive()) { + if (isSeekActive) { msgStr = getString(R.string.msg_seeking); bSearchActive = true; }else if (isScanActive()) { @@ -1626,7 +1643,6 @@ public class FMRadio extends Activity private void enableRadio() { mIsScaning = false; - mIsSeeking = false; mIsSearching = false; boolean bStatus = false; if (mService != null) { @@ -2044,7 +2060,13 @@ public class FMRadio extends Activity } private void updateSearchProgress() { - boolean searchActive = isScanActive() || isSeekActive() || isSearchActive(); + boolean searchActive = false; + try { + searchActive = isScanActive() || mService.isSeekActive() || isSearchActive(); + } catch(RemoteException e) { + e.printStackTrace(); + } + if (searchActive) { synchronized (this) { if(mProgressDialog == null) { @@ -2187,9 +2209,6 @@ public class FMRadio extends Activity return(mIsScaning); } - private boolean isSeekActive() { - return(mIsSeeking); - } private boolean isSearchActive() { return(mIsSearching); } @@ -2201,18 +2220,15 @@ public class FMRadio extends Activity private void SeekPreviousStation() { Log.d(LOGTAG, "SeekPreviousStation"); if (mService != null) { - try { - if(!isSeekActive()) { - mIsSeeking = mService.seek(false); - if (mIsSeeking == false) { - mCommandFailed = CMD_SEEK; - Log.e(LOGTAG, "mService.seek failed"); - showDialog(DIALOG_CMD_FAILED); + try { + if(!mService.seekNextStation(false)) { + mCommandFailed = CMD_SEEK; + Log.e(LOGTAG, "mService.seekNextStation failed"); + showDialog(DIALOG_CMD_FAILED); + } + } catch(RemoteException e) { + Log.d(LOGTAG, "Error when trying to scan the previous station"); } - } - }catch (RemoteException e) { - e.printStackTrace(); - } } updateSearchProgress(); } @@ -2220,18 +2236,15 @@ public class FMRadio extends Activity private void SeekNextStation() { Log.d(LOGTAG, "SeekNextStation"); if(mService != null) { - try { - if(!isSeekActive()) { - mIsSeeking = mService.seek(true); - if (mIsSeeking == false) { - mCommandFailed = CMD_SEEK; - Log.e(LOGTAG, "mService.seek failed"); - showDialog(DIALOG_CMD_FAILED); + try { + if(!mService.seekNextStation(true)) { + mCommandFailed = CMD_SEEK; + Log.e(LOGTAG, "mService.seekNextStation failed"); + showDialog(DIALOG_CMD_FAILED); + } + } catch(RemoteException e) { + Log.d(LOGTAG, "Error when trying to scan the next station"); } - } - }catch (RemoteException e) { - e.printStackTrace(); - } } updateSearchProgress(); } @@ -2262,25 +2275,21 @@ public class FMRadio extends Activity private void initiatePISearch(int pi) { Log.d(LOGTAG, "initiatePISearch"); if(mService != null) { - try { - if(!isSeekActive()) { - mIsSeeking = mService.seekPI(pi); - if (mIsSeeking == false) { - mCommandFailed = CMD_SEEKPI; - Log.e(LOGTAG, "mService.seekPI failed"); - showDialog(DIALOG_CMD_FAILED); + try { + if(!mService.initiatePISearch(pi)) { + mCommandFailed = CMD_SEEKPI; + Log.e(LOGTAG, "mService.initiatePISearch failed"); + showDialog(DIALOG_CMD_FAILED); + } + } catch(RemoteException e) { + e.printStackTrace(); } - } - }catch (RemoteException e) { - e.printStackTrace(); - } } updateSearchProgress(); } private void resetSearch() { mIsScaning = false; - mIsSeeking = false; mIsSearching = false; resetSearchProgress(); } @@ -2290,11 +2299,10 @@ public class FMRadio extends Activity if (mService != null) { try { if ((mIsScaning == true) - || (mIsSeeking == true) + || (mService.isSeekActive() == true) || (mIsSearching == true)) { mService.cancelSearch(); mIsScaning = false; - mIsSeeking = false; mIsSearching=false; } }catch (RemoteException e) { @@ -2625,6 +2633,7 @@ public class FMRadio extends Activity } return super.onKeyDown(keyCode, event); } + private void resetFMStationInfoUI() { mTunedStation.setFrequency(FmSharedPreferences.getTunedFrequency()); mTunedStation.setName(""); @@ -2689,7 +2698,6 @@ public class FMRadio extends Activity mScanPty=0; mScanPtyIndex = 0; mIsScaning = false; - mIsSeeking = false; mIsSearching = false; updateSearchProgress(); resetFMStationInfoUI(); @@ -3131,7 +3139,6 @@ public class FMRadio extends Activity mScanPty = 0; mScanPtyIndex = 0; mIsScaning = false; - mIsSeeking = false; mIsSearching = false; mHandler.post(mSearchComplete); } diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java index 4669b06..a351cf5 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadioService.java +++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java @@ -122,6 +122,7 @@ public class FMRadioService extends Service private static int mFreq = 0; private static boolean mResumeAfterCall = false; private static String mAudioDevice="headset"; + private static boolean mIsSeeking = false; MediaRecorder mRecorder = null; MediaRecorder mA2dp = null; private boolean mFMOn = false; @@ -793,16 +794,49 @@ public class FMRadioService extends Service } } + private boolean isSeekActive() { + Log.d(LOGTAG, "Seeking is "+mIsSeeking); + return(mIsSeeking); + } + + private void setIsSeeking(boolean val) { + mIsSeeking = val; + } + + private boolean seekNextStation(boolean dir) { + Log.d(LOGTAG, "seekNextStation direction "+(dir?"next":"previous")); + boolean result = !isSeekActive() && seek(dir); + setIsSeeking(result); + return result; + } + + /** SEEK Station with the matching PI */ + public boolean initiatePISearch(int pi) { + Log.d(LOGTAG, "initiatePISearch"); + boolean result = !isSeekActive() && seekPI(pi); + setIsSeeking(result); + return result; + } + private final MediaSession.Callback mSessionCallback = new MediaSession.Callback() { @Override public boolean onMediaButtonEvent(Intent intent) { KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); Log.d(LOGTAG, "SessionCallback.onMediaButton()... event = " +event); int key_action = event.getAction(); - if ((event != null) && ((event.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK) - || (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)) + if(event != null + && (event.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK) + && (key_action == KeyEvent.ACTION_DOWN)) { + if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { + Log.d(LOGTAG, "SessionCallback.onMediaButton() its a long press"); + toggleFM(); + } else if (isFmOn()) { + seekNextStation(true); + } + return true; + } else if ((event != null) && (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) && (key_action == KeyEvent.ACTION_DOWN)) { - Log.d(LOGTAG, "SessionCallback: HEADSETHOOK/MEDIA_PLAY_PAUSE"); + Log.d(LOGTAG, "SessionCallback: MEDIA_PLAY_PAUSE"); toggleFM(); return true; } else if((event != null) && (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PAUSE) @@ -1749,6 +1783,22 @@ public class FMRadioService extends Service public List<Integer> getScannedFrequencies() { return(mService.get().getScannedFrequencies()); } + + public boolean isSeekActive() { + return(mService.get().isSeekActive()); + } + + public void setIsSeeking(boolean val) { + mService.get().setIsSeeking(val); + } + + public boolean seekNextStation(boolean dir) { + return(mService.get().seekNextStation(dir)); + } + + public boolean initiatePISearch(int pi) { + return(mService.get().initiatePISearch(pi)); + } } private final IBinder mBinder = new ServiceStub(this); @@ -1957,6 +2007,7 @@ public class FMRadioService extends Service bStatus = mReceiver.disable(); mReceiver = null; } + setIsSeeking(false); stop(); return(bStatus); } @@ -1979,6 +2030,7 @@ public class FMRadioService extends Service bStatus = mReceiver.reset(); mReceiver = null; } + setIsSeeking(false); stop(); return(bStatus); } @@ -2403,6 +2455,8 @@ public class FMRadioService extends Service Log.d(LOGTAG, "cancelSearch"); bCommandSent = mReceiver.cancelSearch(); } + + setIsSeeking(false); return bCommandSent; } @@ -2876,6 +2930,7 @@ public class FMRadioService extends Service public void FmRxEvSearchComplete(int frequency) { Log.d(LOGTAG, "FmRxEvSearchComplete: Tuned Frequency: " +frequency); + setIsSeeking(false); try { FmSharedPreferences.setTunedFrequency(frequency); diff --git a/fmapp2/src/com/caf/fmradio/IFMRadioService.aidl b/fmapp2/src/com/caf/fmradio/IFMRadioService.aidl index bd32102..989a372 100644 --- a/fmapp2/src/com/caf/fmradio/IFMRadioService.aidl +++ b/fmapp2/src/com/caf/fmradio/IFMRadioService.aidl @@ -75,5 +75,9 @@ interface IFMRadioService boolean isSSRInProgress(); boolean isSearchInProgress(); List getScannedFrequencies(); + boolean isSeekActive(); + boolean seekNextStation(boolean dir); + boolean initiatePISearch(int pi); + void setIsSeeking(boolean val); } |