Fix code styling issues

This commit is contained in:
Abishek 2018-03-03 06:21:29 +05:30 committed by Isaac Hutt
parent 0359bb5ad5
commit fcadd2fd41
2 changed files with 14 additions and 17 deletions

View File

@ -629,14 +629,14 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
}, new AudioManager.OnAudioFocusChangeListener() { }, new AudioManager.OnAudioFocusChangeListener() {
@Override @Override
public void onAudioFocusChange(int focusChange) { public void onAudioFocusChange(int focusChange) {
Log.d("Focus has changed", String.valueOf(focusChange)); Log.d(TAG_KIWIX, "Focus change: " + String.valueOf(focusChange));
if (tts.currentTTSTask == null) { if (tts.currentTTSTask == null) {
tts.stop(); tts.stop();
return; return;
} }
switch (focusChange) { switch (focusChange) {
case (AudioManager.AUDIOFOCUS_LOSS): case (AudioManager.AUDIOFOCUS_LOSS):
if(!tts.currentTTSTask.paused) tts.pauseOrResume(); if (!tts.currentTTSTask.paused) tts.pauseOrResume();
pauseTTSButton.setText(R.string.tts_resume); pauseTTSButton.setText(R.string.tts_resume);
break; break;
case (AudioManager.AUDIOFOCUS_GAIN): case (AudioManager.AUDIOFOCUS_GAIN):

View File

@ -37,9 +37,9 @@ public class KiwixTextToSpeech {
public TTSTask currentTTSTask = null; public TTSTask currentTTSTask = null;
private AudioManager audioManager; private AudioManager am;
final Object mFocusLock; final Object focuslock;
private OnAudioFocusChangeListener onAudioFocusChangeListener; private OnAudioFocusChangeListener onAudioFocusChangeListener;
@ -59,8 +59,8 @@ public class KiwixTextToSpeech {
this.context = context; this.context = context;
this.onSpeakingListener = onSpeakingListener; this.onSpeakingListener = onSpeakingListener;
this.onAudioFocusChangeListener = onAudioFocusChangeListener; this.onAudioFocusChangeListener = onAudioFocusChangeListener;
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mFocusLock = new Object(); focuslock = new Object();
initTTS(onInitSucceedListener); initTTS(onInitSucceedListener);
} }
@ -120,10 +120,8 @@ public class KiwixTextToSpeech {
} else { } else {
tts.setLanguage(locale); tts.setLanguage(locale);
if(requestAudioFocus() == true) { if (requestAudioFocus()) {
loadURL(webView); loadURL(webView);
} else {
return;
} }
} }
} }
@ -155,18 +153,17 @@ public class KiwixTextToSpeech {
} }
public Boolean requestAudioFocus() { public Boolean requestAudioFocus() {
Log.d("Request for audio Focus", "Focus Requested"); int audioFocusRequest = am.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
int audioFocusRequest = audioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
synchronized (mFocusLock) { Log.d(TAG_KIWIX, "Audio Focus Requested");
if(audioFocusRequest == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
synchronized (focuslock) {
if (audioFocusRequest == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
return true; return true;
} else if(audioFocusRequest == AudioManager.AUDIOFOCUS_REQUEST_FAILED) { } else {
return false; return false;
} }
} }
return false;
} }
public void pauseOrResume() { public void pauseOrResume() {
@ -174,7 +171,7 @@ public class KiwixTextToSpeech {
return; return;
if (currentTTSTask.paused) { if (currentTTSTask.paused) {
if(!requestAudioFocus()) return; if (!requestAudioFocus()) return;
currentTTSTask.start(); currentTTSTask.start();
} }
else { else {