Commit 26d2ec39 by Kunj Gupta

Fixed - Screen should not get turned off while voice chatting actively.

parent c6fc059a
......@@ -519,6 +519,7 @@ public class DroidSpeech {
muteAudio(false);
dsProperties.onReadyForSpeech = true;
droidSpeechListener.onDroidSpeechStarted();
}
@Override
......
......@@ -49,4 +49,9 @@ public interface OnDSListener {
* @param errorMsg The error message
*/
void onDroidSpeechError(String errorMsg);
/**
* The droid speech recognition is started
*/
void onDroidSpeechStarted();
}
package com.vsoft.servicenow.ui;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.support.v7.app.ActionBar;
......@@ -15,6 +18,7 @@ import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageButton;
......@@ -93,6 +97,9 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private String mNewMessageUtteranceId;
private static final int SCREEN_OFF = 0;
private static final int SCREEN_ON = 1;
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
......@@ -145,8 +152,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
checkTTS();
mVoiceButton = (ImageButton) findViewById(R.id.voice_button);
mMessagesView = (RecyclerView) findViewById(R.id.messages);
mMessagesView.setLayoutManager(new LinearLayoutManager(this));
......@@ -186,6 +191,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}
});
mVoiceButton = (ImageButton) findViewById(R.id.voice_button);
mVoiceButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -463,6 +469,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
speaker.getTTS().setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onDone(String utteranceId) {
callScreenOnAndOff(SCREEN_OFF);
/*Start Code
Sometime speaker is not getting stop that's why it is breaking.
......@@ -492,6 +499,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override
public void onStart(String utteranceId) {
callScreenOnAndOff(SCREEN_ON);
if (droidSpeech != null) {
droidSpeech.closeDroidSpeechOperations();
}
......@@ -546,7 +555,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override
public void onDroidSpeechSupportedLanguages(String currentSpeechLanguage, List<String> supportedSpeechLanguages) {
}
@Override
......@@ -568,6 +576,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override
public void onDroidSpeechClosedByUser() {
callScreenOnAndOff(SCREEN_OFF);
}
@Override
......@@ -593,9 +602,16 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}
@Override
public void onDroidSpeechStarted() {
callScreenOnAndOff(SCREEN_ON);
}
@Override
public void onDestroy() {
super.onDestroy();
callScreenOnAndOff(SCREEN_OFF);
if(mSocket != null) {
mSocket.disconnect();
......@@ -613,10 +629,39 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}
}
private String firstLetterCaps ( String data ) {
private String firstLetterCaps (String data) {
String firstLetter = data.substring(0,1).toUpperCase();
String restLetters = data.substring(1).toLowerCase();
return firstLetter + restLetters;
}
/**
* This handler will set and clear the SCREEN_ON and SCREEN_OFF flag.
* How will it work - It will work in two scenario
* First - Listening - Whenever listening dialog will open, screen will keep ON and wait to Close the dialog that mean when listening dialog will dismiss then SCREEN_ON flag will clear.
* Second - Speaking - Whenever speaking will start, screen will keep ON and wait to Stop the speaking that mean when Speaking will stop then SCREEN_ON flag will clear.
* */
@SuppressLint("HandlerLeak")
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SCREEN_ON:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
break;
case SCREEN_OFF:
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
break;
default:
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
};
private void callScreenOnAndOff(final int screenState) {
Message message = handler.obtainMessage();
message.what = screenState;
handler.sendMessage(message);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment