Merge "[FM] "Speaker on/headset" should not be available while BT earphone is connected" into lmp-mr1-dev
diff --git a/res/values-zh-rHK/strings.xml b/res/values-zh-rHK/strings.xml
index d8ca937..0782f84 100644
--- a/res/values-zh-rHK/strings.xml
+++ b/res/values-zh-rHK/strings.xml
@@ -48,7 +48,7 @@
<string name="station_title" msgid="4027617747760605320">"電台"</string>
<string name="station_searching_tips" msgid="6970095710072278870">"正在取得電台"</string>
<string name="station_empty_text" msgid="6847327406626186898">"未找到任何電台"</string>
- <string name="minutes_label" msgid="3225846493097986594">"分"</string>
+ <string name="minutes_label" msgid="3225846493097986594">"分鐘"</string>
<string name="seconds_label" msgid="3998011734682420096">"秒"</string>
<string name="timer_default" msgid="8062388403825907344">"00"</string>
<string name="record_title" msgid="8695283158200902780">"正在錄音"</string>
diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml
index 9ce3854..ccdd49e 100644
--- a/res/values-zh-rTW/strings.xml
+++ b/res/values-zh-rTW/strings.xml
@@ -48,7 +48,7 @@
<string name="station_title" msgid="4027617747760605320">"電台"</string>
<string name="station_searching_tips" msgid="6970095710072278870">"正在取得電台清單"</string>
<string name="station_empty_text" msgid="6847327406626186898">"找不到電台"</string>
- <string name="minutes_label" msgid="3225846493097986594">"分"</string>
+ <string name="minutes_label" msgid="3225846493097986594">"分鐘"</string>
<string name="seconds_label" msgid="3998011734682420096">"秒"</string>
<string name="timer_default" msgid="8062388403825907344">"00"</string>
<string name="record_title" msgid="8695283158200902780">"錄音"</string>
diff --git a/src/com/android/fmradio/FmMainActivity.java b/src/com/android/fmradio/FmMainActivity.java
index 09fca23..13539b7 100644
--- a/src/com/android/fmradio/FmMainActivity.java
+++ b/src/com/android/fmradio/FmMainActivity.java
@@ -322,6 +322,12 @@
boolean isSpeakerMode = bundle.getBoolean(FmListener.KEY_IS_SPEAKER_MODE);
break;
+ case FmListener.LISTEN_RECORDSTATE_CHANGED:
+ if (mService != null) {
+ mService.updatePlayingNotification();
+ }
+ break;
+
default:
break;
}
@@ -505,6 +511,9 @@
// TODO it's on UI thread, change to sub thread
if (FmStation.isFavoriteStation(mContext, frequency)) {
FmStation.removeFromFavorite(mContext, frequency);
+ if (mCurrentStation == frequency) {
+ mTextStationName.setText(FmStation.getStationName(mContext, frequency));
+ }
mButtonAddToFavorite.setImageResource(R.drawable.btn_fm_favorite_off_selector);
// Notify scroller
mScroller.onRemoveFavorite();
@@ -908,11 +917,10 @@
// TODO it's on UI thread, change to sub thread
if (FmStation.isFavoriteStation(mContext, mCurrentStation)) {
mButtonAddToFavorite.setImageResource(R.drawable.btn_fm_favorite_on_selector);
- mTextStationName.setText(FmStation.getStationName(mContext, mCurrentStation));
} else {
mButtonAddToFavorite.setImageResource(R.drawable.btn_fm_favorite_off_selector);
- mTextStationName.setText("");
}
+ mTextStationName.setText(FmStation.getStationName(mContext, mCurrentStation));
}
/**
diff --git a/src/com/android/fmradio/FmRecordActivity.java b/src/com/android/fmradio/FmRecordActivity.java
index cfee6e2..95ba8e8 100644
--- a/src/com/android/fmradio/FmRecordActivity.java
+++ b/src/com/android/fmradio/FmRecordActivity.java
@@ -55,8 +55,10 @@
*/
public class FmRecordActivity extends Activity implements
FmSaveDialog.OnRecordingDialogClickListener {
- private static final String TAG = "FmRecordActivity/Record";
+ private static final String TAG = "FmRecordActivity";
+ private static final String FM_STOP_RECORDING = "fmradio.stop.recording";
+ private static final String FM_ENTER_RECORD_SCREEN = "fmradio.enter.record.screen";
private static final String TAG_SAVE_RECORDINGD = "SaveRecording";
private static final int MSG_UPDATE_NOTIFICATION = 1000;
private Context mContext;
@@ -161,9 +163,8 @@
private void updateRecordingNotification(long recordTime) {
if (mNotificationBuilder == null) {
- Intent intent = new Intent();
+ Intent intent = new Intent(FM_STOP_RECORDING);
intent.setClass(mContext, FmRecordActivity.class);
- intent.putExtra("is_from_notification", true);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
@@ -179,7 +180,7 @@
.addAction(R.drawable.btn_fm_rec_stop_enabled, getText(R.string.stop_record),
pendingIntent);
- Intent cIntent = new Intent();
+ Intent cIntent = new Intent(FM_ENTER_RECORD_SCREEN);
cIntent.setClass(mContext, FmRecordActivity.class);
cIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentPendingIntent = PendingIntent.getActivity(mContext, 0, cIntent,
@@ -199,10 +200,16 @@
@Override
public void onNewIntent(Intent intent) {
- // If start by notification, need stop recording
- if (intent != null && intent.getBooleanExtra("is_from_notification", false)
- && mService != null & !isStopRecording()) {
- mService.stopRecordingAsync();
+ if (intent != null && intent.getAction() != null) {
+ String action = intent.getAction();
+ if (FM_STOP_RECORDING.equals(action)) {
+ // If click stop button in notification, need to stop recording
+ if (mService != null && !isStopRecording()) {
+ mService.stopRecordingAsync();
+ }
+ } else if (FM_ENTER_RECORD_SCREEN.equals(action)) {
+ // Just enter record screen, do nothing
+ }
}
}
@@ -435,7 +442,7 @@
if (recordName != null) {
intent.setData(Uri.parse("file://" + FmService.getRecordingSdcard()
+ File.separator + FmRecorder.FM_RECORD_FOLDER + File.separator
- + recordName + FmRecorder.RECORDING_FILE_EXTENSION));
+ + Uri.encode(recordName) + FmRecorder.RECORDING_FILE_EXTENSION));
}
setResult(RESULT_OK, intent);
}
diff --git a/src/com/android/fmradio/FmService.java b/src/com/android/fmradio/FmService.java
index ca940fd..6c39d66 100644
--- a/src/com/android/fmradio/FmService.java
+++ b/src/com/android/fmradio/FmService.java
@@ -99,6 +99,9 @@
// Notification id
private static final int NOTIFICATION_ID = 1;
+ // ignore audio data
+ private static final int AUDIO_IGNORED_NUM = 3;
+
// Set audio policy for FM
// should check AUDIO_POLICY_FORCE_FOR_MEDIA in audio_policy.h
private static final int FOR_PROPRIETARY = 1;
@@ -438,37 +441,50 @@
}
class RenderThread extends Thread {
+ private int mCurrentFrame = 0;
+ private boolean isAudioFrameNeedIgnore() {
+ return mCurrentFrame < AUDIO_IGNORED_NUM;
+ }
+
@Override
public void run() {
try {
byte[] buffer = new byte[RECORD_BUF_SIZE];
while (!Thread.interrupted()) {
- boolean render = isRender();
- if (render) {
+ if (isRender()) {
+ if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_STOPPED) {
+ mAudioRecord.startRecording();
+ }
// need rendering
if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED) {
mAudioTrack.play();
}
- if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_STOPPED) {
- mAudioRecord.startRecording();
- }
int size = mAudioRecord.read(buffer, 0, RECORD_BUF_SIZE);
+ // check whether need to ignore first 3 frames audio data from AudioRecord
+ // to avoid pop noise.
+ if (isAudioFrameNeedIgnore()) {
+ mCurrentFrame += 1;
+ Log.d(TAG, "EYES ignore " + mCurrentFrame);
+ continue ;
+ }
byte[] tmpBuf = new byte[size];
System.arraycopy(buffer, 0, tmpBuf, 0, size);
// write to audio track
- mAudioTrack.write(tmpBuf, 0, tmpBuf.length);
- } else {
- // only status wait for render
- // stop all
- if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
- mAudioRecord.stop();
+ if (isRender()) {
+ mAudioTrack.write(tmpBuf, 0, tmpBuf.length);
}
-
+ } else {
+ mCurrentFrame = 0;
// Do not stop audio track to keep the native audio patch
if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING) {
mAudioTrack.stop();
}
+ // only status wait for render stop all
+ if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
+ mAudioRecord.stop();
+ }
+
//enableFmAudio(true);
synchronized (mRenderLock) {
mRenderLock.wait();
diff --git a/src/com/android/fmradio/FmStation.java b/src/com/android/fmradio/FmStation.java
index 00609e4..5924281 100644
--- a/src/com/android/fmradio/FmStation.java
+++ b/src/com/android/fmradio/FmStation.java
@@ -316,6 +316,7 @@
public static void removeFromFavorite(Context context, int frequency) {
ContentValues values = new ContentValues(1);
values.put(Station.IS_FAVORITE, false);
+ values.put(Station.STATION_NAME, "");
context.getContentResolver().update(
Station.CONTENT_URI,
values,