Commit 211878bc by Krishna Vemulawada

offline handle with voice

parents 9cb09194 964f4635
...@@ -72,7 +72,7 @@ android { ...@@ -72,7 +72,7 @@ android {
vportal { vportal {
applicationId "com.vsoft.vera.vportal" applicationId "com.vsoft.vera.vportal"
versionCode 1 versionCode 1
versionName "0.1.6" versionName "0.1.7"
} }
} }
} }
......
...@@ -156,6 +156,7 @@ public class CatalogueApplication extends MultiDexApplication { ...@@ -156,6 +156,7 @@ public class CatalogueApplication extends MultiDexApplication {
options.upgrade = true; options.upgrade = true;
mSocket = IO.socket(Constants.CHAT_SERVER_URL,options); mSocket = IO.socket(Constants.CHAT_SERVER_URL,options);
mSocket.io().timeout(-1); mSocket.io().timeout(-1);
mSocket.io().reconnection(true); mSocket.io().reconnection(true);
mSocket.io().reconnectionDelay(0); mSocket.io().reconnectionDelay(0);
......
...@@ -3,12 +3,14 @@ package com.vsoft.vera.ui; ...@@ -3,12 +3,14 @@ package com.vsoft.vera.ui;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
...@@ -18,6 +20,7 @@ import android.support.v7.app.AppCompatActivity; ...@@ -18,6 +20,7 @@ import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
...@@ -69,6 +72,8 @@ import java.util.List; ...@@ -69,6 +72,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static com.vsoft.vera.utils.Util.convertDpToPx;
public class ADALActivity extends AppCompatActivity { public class ADALActivity extends AppCompatActivity {
...@@ -121,6 +126,7 @@ public class ADALActivity extends AppCompatActivity { ...@@ -121,6 +126,7 @@ public class ADALActivity extends AppCompatActivity {
private static final boolean sTelemetryAggregationIsRequired = true; private static final boolean sTelemetryAggregationIsRequired = true;
private LinearLayout mainLayt; private LinearLayout mainLayt;
private Handler mWaitHandler = new Handler();
/* Telemetry dispatcher registration */ /* Telemetry dispatcher registration */
static { static {
...@@ -169,10 +175,15 @@ public class ADALActivity extends AppCompatActivity { ...@@ -169,10 +175,15 @@ public class ADALActivity extends AppCompatActivity {
callGraphButton.setOnClickListener(new View.OnClickListener() { callGraphButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
if (NetworkConnectivity.haveNetworkConnection(ADALActivity.this)) { if (NetworkConnectivity.haveNetworkConnection(ADALActivity.this)) {
onCallGraphClicked(); onCallGraphClicked();
mWaitHandler.postDelayed(new Runnable() {
@Override
public void run() {
updateSuccessUI();
}
}, 5000);
} else { } else {
DialogUtils.showNoConnectionDialog(ADALActivity .this); DialogUtils.showNoConnectionDialog(ADALActivity .this);
...@@ -185,10 +196,8 @@ public class ADALActivity extends AppCompatActivity { ...@@ -185,10 +196,8 @@ public class ADALActivity extends AppCompatActivity {
login_with_otp.setOnClickListener(new View.OnClickListener() { login_with_otp.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
// onSignOutClicked(); // onSignOutClicked();
Intent intent = new Intent(ADALActivity.this,OtpValidationActivity.class); Intent intent = new Intent(ADALActivity.this,OtpValidationActivity.class);
startActivity(intent); startActivity(intent);
} }
}); });
...@@ -284,13 +293,13 @@ public class ADALActivity extends AppCompatActivity { ...@@ -284,13 +293,13 @@ public class ADALActivity extends AppCompatActivity {
private void callGraphAPI() { private void callGraphAPI() {
Log.d(TAG, "Starting volley request to graph");
mProgressDlg = new ProgressDialog(ADALActivity.this); mProgressDlg = new ProgressDialog(ADALActivity.this);
mProgressDlg.setMessage(getString(R.string.loading_string)); mProgressDlg.setMessage(getString(R.string.loading_string));
mProgressDlg.show(); mProgressDlg.show();
mProgressDlg.setCancelable(false); mProgressDlg.setCancelable(false);
Log.d(TAG, "Starting volley request to graph");
/* Make sure we have a token to send to graph */ /* Make sure we have a token to send to graph */
if (mAuthResult.getAccessToken() == null) {return;} if (mAuthResult.getAccessToken() == null) {return;}
...@@ -317,7 +326,6 @@ public class ADALActivity extends AppCompatActivity { ...@@ -317,7 +326,6 @@ public class ADALActivity extends AppCompatActivity {
/*Send broadcast to start SyncService*/ /*Send broadcast to start SyncService*/
if(!isLogin){ if(!isLogin){
new LoginDetailsSendToServer().execute(); new LoginDetailsSendToServer().execute();
} }
...@@ -325,7 +333,6 @@ public class ADALActivity extends AppCompatActivity { ...@@ -325,7 +333,6 @@ public class ADALActivity extends AppCompatActivity {
e.printStackTrace(); e.printStackTrace();
} }
} }
}, new Response.ErrorListener() { }, new Response.ErrorListener() {
@Override @Override
...@@ -378,19 +385,24 @@ public class ADALActivity extends AppCompatActivity { ...@@ -378,19 +385,24 @@ public class ADALActivity extends AppCompatActivity {
// Called on success from /me endpoint // Called on success from /me endpoint
// Removed call Graph API button and paint Sign out // Removed call Graph API button and paint Sign out
callGraphButton.setVisibility(View.GONE);
login_with_otp.setVisibility(View.GONE);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(convertDpToPx(this, 300),
convertDpToPx(this, 450));
layoutParams.setMargins(convertDpToPx(this, 30), convertDpToPx(this, 30), convertDpToPx(this, 30), convertDpToPx(this, 30));
logo_banner.setLayoutParams(layoutParams);
signOutButton.setVisibility(View.GONE); signOutButton.setVisibility(View.GONE);
findViewById(R.id.welcome).setVisibility(View.GONE); findViewById(R.id.welcome).setVisibility(View.GONE);
((TextView) findViewById(R.id.welcome)).setText("Welcome, " + /*((TextView) findViewById(R.id.welcome)).setText("Welcome, " +
mAuthResult.getUserInfo().getGivenName()); mAuthResult.getUserInfo().getGivenName());*/
findViewById(R.id.graphData).setVisibility(View.GONE); findViewById(R.id.graphData).setVisibility(View.GONE);
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private void updateSignedOutUI() { private void updateSignedOutUI() {
signOutButton.setVisibility(View.GONE); signOutButton.setVisibility(View.GONE);
findViewById(R.id.welcome).setVisibility(View.INVISIBLE); findViewById(R.id.welcome).setVisibility(View.INVISIBLE);
findViewById(R.id.graphData).setVisibility(View.INVISIBLE); findViewById(R.id.graphData).setVisibility(View.INVISIBLE);
...@@ -427,8 +439,6 @@ public class ADALActivity extends AppCompatActivity { ...@@ -427,8 +439,6 @@ public class ADALActivity extends AppCompatActivity {
/* Successfully got a token, call graph now */ /* Successfully got a token, call graph now */
Log.d(TAG, "Successfully authenticated"); Log.d(TAG, "Successfully authenticated");
/* Store the mAuthResult */ /* Store the mAuthResult */
mAuthResult = authenticationResult; mAuthResult = authenticationResult;
...@@ -440,7 +450,6 @@ public class ADALActivity extends AppCompatActivity { ...@@ -440,7 +450,6 @@ public class ADALActivity extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
updateSuccessUI(); updateSuccessUI();
} }
}); });
} }
...@@ -522,6 +531,7 @@ public class ADALActivity extends AppCompatActivity { ...@@ -522,6 +531,7 @@ public class ADALActivity extends AppCompatActivity {
updateSuccessUI(); updateSuccessUI();
} }
}); });
/* set the sIntSignInInvoked boolean back to false */ /* set the sIntSignInInvoked boolean back to false */
sIntSignInInvoked.set(false); sIntSignInInvoked.set(false);
} }
...@@ -714,5 +724,4 @@ public class ADALActivity extends AppCompatActivity { ...@@ -714,5 +724,4 @@ public class ADALActivity extends AppCompatActivity {
} }
} }
} }
} }
...@@ -23,6 +23,7 @@ import android.os.PowerManager; ...@@ -23,6 +23,7 @@ import android.os.PowerManager;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener; import android.speech.tts.UtteranceProgressListener;
import android.support.design.widget.Snackbar;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
...@@ -148,6 +149,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -148,6 +149,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
String takePictureFilePath = ""; String takePictureFilePath = "";
private Speaker speaker; private Speaker speaker;
private Boolean isConnected = false; private Boolean isConnected = false;
private Boolean isConnectError = false;
private static final int NONE = -1; private static final int NONE = -1;
private static final int VOICE_STATE = 1; private static final int VOICE_STATE = 1;
private static final int TYPING_STATE = 2; private static final int TYPING_STATE = 2;
...@@ -249,7 +251,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -249,7 +251,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
mSocket.connect(); mSocket.connect();
checkTTS(); checkTTS();
speaker = new Speaker(this); //speaker = new Speaker(this);
textDotLoader = findViewById(R.id.avi); textDotLoader = findViewById(R.id.avi);
mMessagesView = (RecyclerView) findViewById(R.id.messages); mMessagesView = (RecyclerView) findViewById(R.id.messages);
sendImageToserv = (ImageButton) findViewById(R.id.image_button); sendImageToserv = (ImageButton) findViewById(R.id.image_button);
...@@ -261,7 +263,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -261,7 +263,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override @Override
public void imageViewOnClick(String imagePath) { public void imageViewOnClick(String imagePath) {
shoawUserImagePopupImageAlert(imagePath); shoawUserImagePopupImageAlert(imagePath);
} }
@Override @Override
...@@ -376,17 +377,24 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -376,17 +377,24 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Util.hideSoftKeyboard(ChatActivity.this, v); if (NetworkConnectivity.haveNetworkConnection(ChatActivity.this)) {
mInputMessageView.setText(""); Util.hideSoftKeyboard(ChatActivity.this, v);
mInputMessageView.setText("");
if (null == mLoggedInUsername) return; if (null == mLoggedInUsername) return;
if (!mSocket.connected()) return; if (!mSocket.connected()) return;
if(speaker != null && speaker.isSpeaking()) { if(speaker != null && speaker.isSpeaking()) {
speaker.stop(); speaker.stop();
}
droidSpeech.startDroidSpeechRecognition();
CURRENT_STATE = VOICE_STATE;
} else {
DialogUtils.showNoConnectionDialog(ChatActivity.this);
} }
droidSpeech.startDroidSpeechRecognition();
CURRENT_STATE = VOICE_STATE;
// readAndWriteCallsData(); // readAndWriteCallsData();
...@@ -664,52 +672,59 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -664,52 +672,59 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
* This method calls when we will send message to server. * This method calls when we will send message to server.
*/ */
private void attemptSend() { private void attemptSend() {
String message = mInputMessageView.getText().toString().trim();
if (!TextUtils.isEmpty(message)){
if (null == mLoggedInUsername) return;
if (!mSocket.connected())
return;
//Whenever we'll click on send button, running TTS speak should stop
if(speaker != null && speaker.isSpeaking()) {
speaker.stop();
}
textDotLoader.show();
if (TextUtils.isEmpty(message)) {
mInputMessageView.requestFocus();
return;
}
mInputMessageView.setText(""); if (NetworkConnectivity.haveNetworkConnection(ChatActivity.this)) {
addMessage(mLoggedInUsername, message,""); String message = mInputMessageView.getText().toString().trim();
if (!TextUtils.isEmpty(message)){
if (null == mLoggedInUsername) return;
if (!mSocket.connected())
return;
// perform the sending message attempt. //Whenever we'll click on send button, running TTS speak should stop
JSONObject jsonObject = new JSONObject(); if(speaker != null && speaker.isSpeaking()) {
try { speaker.stop();
jsonObject.put(CLIENT_MESSAGE_KEY, message); }
jsonObject.put(CLIENT_MAIL_KEY, PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_EMAIL_ID)); textDotLoader.show();
jsonObject.put(SESSION_ID_UNIQ, PrefManager.getSharedPref(ChatActivity.this, PrefManager.SESSION_ID));
jsonObject.put(LOCATION, "location"); if (TextUtils.isEmpty(message)) {
jsonObject.put(USER_SYSID, userSysId); mInputMessageView.requestFocus();
jsonObject.put(SCANNED_IMAGE, ""); return;
} catch (JSONException e) { }
e.printStackTrace();
} mInputMessageView.setText("");
mSocket.emit(NEW_MESSAGE, jsonObject); addMessage(mLoggedInUsername, message,"");
// perform the sending message attempt.
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(CLIENT_MESSAGE_KEY, message);
jsonObject.put(CLIENT_MAIL_KEY, PrefManager.getSharedPref(this, PrefManager.PREFERENCE_USER_EMAIL_ID));
jsonObject.put(SESSION_ID_UNIQ, PrefManager.getSharedPref(ChatActivity.this, PrefManager.SESSION_ID));
jsonObject.put(LOCATION, "location");
jsonObject.put(USER_SYSID, userSysId);
jsonObject.put(SCANNED_IMAGE, "");
} catch (JSONException e) {
e.printStackTrace();
}
mSocket.emit(NEW_MESSAGE, jsonObject);
} else {
Toast toast = Toast.makeText(getApplicationContext(), "Please enter the message", Toast.LENGTH_LONG);
View toastView = toast.getView(); // This'll return the default View of the Toast.
/* And now you can get the TextView of the default View of the Toast. */
TextView toastMessage = (TextView) toastView.findViewById(android.R.id.message);
toastMessage.setTextSize(15);
toastMessage.setTextColor(Color.WHITE);
toastMessage.setGravity(Gravity.CENTER);
toastMessage.setPadding(30,0,30,0);
toastView.setBackgroundColor(Color.BLACK);
toast.show();
}
} else { } else {
Toast toast = Toast.makeText(getApplicationContext(), "Please enter the message", Toast.LENGTH_LONG); DialogUtils.showNoConnectionDialog(ChatActivity.this);
View toastView = toast.getView(); // This'll return the default View of the Toast.
/* And now you can get the TextView of the default View of the Toast. */
TextView toastMessage = (TextView) toastView.findViewById(android.R.id.message);
toastMessage.setTextSize(15);
toastMessage.setTextColor(Color.WHITE);
toastMessage.setGravity(Gravity.CENTER);
toastMessage.setPadding(30,0,30,0);
toastView.setBackgroundColor(Color.BLACK);
toast.show();
} }
} }
...@@ -777,8 +792,21 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -777,8 +792,21 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override @Override
public void run() { public void run() {
isConnected = false; isConnected = false;
Toast.makeText(getApplicationContext(), isConnectError = false;
R.string.disconnect, Toast.LENGTH_LONG).show();
Snackbar snackbar = Snackbar
.make(mMessagesView, R.string.disconnect, Snackbar.LENGTH_LONG);
snackbar.show();
// Changing action button text color
View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.YELLOW);
snackbar.show();
/*Toast.makeText(getApplicationContext(),
R.string.disconnect, Toast.LENGTH_LONG).show();*/
} }
}); });
} }
...@@ -802,8 +830,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -802,8 +830,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private Emitter.Listener onReconnect = new Emitter.Listener() { private Emitter.Listener onReconnect = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
Toast.makeText(getApplicationContext(), /*Toast.makeText(getApplicationContext(),
"Reconnection Called", Toast.LENGTH_LONG).show(); "Reconnection Called", Toast.LENGTH_LONG).show();*/
//reconnect(); //reconnect();
} }
...@@ -818,18 +846,42 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -818,18 +846,42 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
if(!isConnectError) {
Snackbar snackbar = Snackbar
.make(mMessagesView, R.string.error_connect, Snackbar.LENGTH_LONG)
.setAction("Dismiss", new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
snackbar.show();
// Changing message text color
snackbar.setActionTextColor(Color.RED);
// Changing action button text color
View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.YELLOW);
snackbar.show();
isConnectError = true;
}
Toast toast = Toast.makeText(getApplicationContext(), R.string.error_connect, Toast.LENGTH_LONG); /*Toast toast = Toast.makeText(getApplicationContext(), R.string.error_connect, Toast.LENGTH_LONG);
View toastView = toast.getView(); // This'll return the default View of the Toast. View toastView = toast.getView(); // This'll return the default View of the Toast.
/* And now you can get the TextView of the default View of the Toast. */ *//* And now you can get the TextView of the default View of the Toast. *//*
TextView toastMessage = (TextView) toastView.findViewById(android.R.id.message); TextView toastMessage = (TextView) toastView.findViewById(android.R.id.message);
toastMessage.setTextSize(15); toastMessage.setTextSize(15);
toastMessage.setTextColor(Color.WHITE); toastMessage.setTextColor(Color.WHITE);
toastMessage.setGravity(Gravity.CENTER); toastMessage.setGravity(Gravity.CENTER);
toastMessage.setPadding(30,0,30,0); toastMessage.setPadding(30,0,30,0);
toastView.setBackgroundColor(Color.BLACK); toastView.setBackgroundColor(Color.BLACK);
toast.show(); toast.show();*/
} }
}); });
} }
...@@ -1337,8 +1389,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -1337,8 +1389,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
mSocket.off(Socket.EVENT_CONNECT, onConnect); mSocket.off(Socket.EVENT_CONNECT, onConnect);
mSocket.off(Socket.EVENT_DISCONNECT, onDisconnect); mSocket.off(Socket.EVENT_DISCONNECT, onDisconnect);
mSocket.off(Socket.EVENT_CONNECT_ERROR, onConnectError); mSocket.off(Socket.EVENT_CONNECT_ERROR, onConnectError);
mSocket.on(Socket.EVENT_CONNECT_TIMEOUT, onConnectTimeOut); mSocket.off(Socket.EVENT_CONNECT_TIMEOUT, onConnectTimeOut);
mSocket.on(Socket.EVENT_RECONNECT, onReconnect); mSocket.off(Socket.EVENT_RECONNECT, onReconnect);
mSocket.off(NEW_MESSAGE, onNewMessage); mSocket.off(NEW_MESSAGE, onNewMessage);
mSocket.off(AUTHENTICATED, authenticated); mSocket.off(AUTHENTICATED, authenticated);
mSocket.off(UNAUTHORIZED, unAuthorized); mSocket.off(UNAUTHORIZED, unAuthorized);
......
...@@ -208,6 +208,9 @@ public class HomeScreen extends HandleNotificationActivity { ...@@ -208,6 +208,9 @@ public class HomeScreen extends HandleNotificationActivity {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Username: "); stringBuilder.append("Username: ");
stringBuilder.append(userFullName); stringBuilder.append(userFullName);
stringBuilder.append("\n");
stringBuilder.append("\n");
stringBuilder.append("Version: "+BuildConfig.VERSION_NAME);
builder.setMessage(stringBuilder.toString()) builder.setMessage(stringBuilder.toString())
.setTitle("User Details") .setTitle("User Details")
......
...@@ -1160,9 +1160,16 @@ public class Util { ...@@ -1160,9 +1160,16 @@ public class Util {
}) })
// .setNegativeButton(android.R.string.no, null) // .setNegativeButton(android.R.string.no, null)
.show(); .show();
}
/**
* This method converts dp unit to equivalent pixels, depending on device density.
*
* @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
* @param context Context to get resources and device specific display metrics
* @return A int value to represent px equivalent to dp depending on device density
*/
public static int convertDpToPx(Context context, float dp) {
return (int) (dp * context.getResources().getDisplayMetrics().density);
} }
} }
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