Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Krishna Vemulavada
/
vera_2.1_app
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
906939d6
authored
Oct 15, 2019
by
Krishna Vemulawada
Browse files
Options
_('Browse Files')
Download
Plain Diff
get incidents validation
parents
35ad6637
aa91bb6f
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
560 additions
and
255 deletions
app/build.gradle
app/libs/opencsv-4.6.jar
app/src/main/AndroidManifest.xml
app/src/main/java/com/vsoft/vera/CatalogueApplication.java
app/src/main/java/com/vsoft/vera/adapters/ChatMessageAdapter.java
app/src/main/java/com/vsoft/vera/api/managers/IncidentApiManager.java
app/src/main/java/com/vsoft/vera/db/DBConstants.java
app/src/main/java/com/vsoft/vera/db/DBManager.java
app/src/main/java/com/vsoft/vera/db/managers/ChatLogManager.java
app/src/main/java/com/vsoft/vera/service/SyncService.java
app/src/main/java/com/vsoft/vera/ui/ADALActivity.java
app/src/main/java/com/vsoft/vera/ui/ChatActivity.java
app/src/main/java/com/vsoft/vera/ui/OtpValidationActivity.java
app/src/main/java/com/vsoft/vera/utils/ChatLog.java
app/src/main/java/com/vsoft/vera/utils/Constants.java
app/src/main/java/com/vsoft/vera/utils/PrefManager.java
app/src/vportal/res/menu/more_menu.xml
app/vportal/staging/app-vportal-staging.apk
app/vportal/staging/output.json
app/build.gradle
View file @
906939d6
...
...
@@ -36,7 +36,7 @@ android {
defaultConfig
{
applicationId
"com.vsoft.vera"
minSdkVersion
2
1
minSdkVersion
2
3
targetSdkVersion
28
versionCode
1
versionName
"0.0.1"
...
...
@@ -72,24 +72,20 @@ android {
vportal
{
applicationId
"com.vsoft.vera.vportal"
versionCode
1
versionName
"
1.1.0
"
versionName
"
0.2.4
"
}
}
}
dependencies
{
def
appCenterSdkVersion
=
'2.3.0'
implementation
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
implementation
'com.android.volley:volley:1.1.+'
implementation
(
'com.microsoft.aad:adal:1.14.+'
)
{
exclude
group:
'com.android.support'
}
implementation
"com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation
"com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
implementation
'com.android.support:design:28.0.0'
implementation
'com.android.support:support-annotations:28.0.0'
implementation
'android.arch.lifecycle:extensions:1.1.1'
...
...
@@ -101,7 +97,6 @@ dependencies {
implementation
(
'com.google.android.gms:play-services-analytics:16.0.8'
)
{
exclude
group:
'com.google.firebase'
,
module:
'firebase-iid'
}
implementation
'com.googlecode.android-query:android-query:0.25.9'
annotationProcessor
'com.jakewharton:butterknife-compiler:8.8.1'
implementation
(
'com.crashlytics.sdk.android:crashlytics:2.9.0@aar'
)
{
...
...
@@ -124,14 +119,14 @@ dependencies {
implementation
'de.hdodenhof:circleimageview:3.0.0'
implementation
'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor
'com.github.bumptech.glide:compiler:4.8.0'
implementation
'com.quickbirdstudios:opencv:4.1.0'
//
implementation 'com.quickbirdstudios:opencv:4.1.0'
implementation
'org.jsoup:jsoup:1.11.3'
//static Reports Screen
implementation
'com.numetriclabz.numandroidcharts:numandroidcharts:1.0.9'
implementation
'info.hoang8f:android-segmented:1.0.6'
implementation
'com.github.PhilJay:MPAndroidChart:v2.1.6'
implementation
'com.android.support:multidex:1.0.3'
implementation
files
(
'libs/opencsv-4.6.jar'
)
}
apply
plugin:
'com.google.gms.google-services'
app/libs/opencsv-4.6.jar
0 → 100644
View file @
906939d6
No preview for this file type
app/src/main/AndroidManifest.xml
View file @
906939d6
...
...
@@ -88,7 +88,8 @@
android:screenOrientation=
"portrait"
/>
<activity
android:name=
".ui.InAppWebViewActivity"
/>
<service
android:name=
".service.SyncService"
/>
<service
android:name=
".service.SyncService"
android:permission=
"android.permission.BIND_JOB_SERVICE"
/>
<provider
android:name=
"android.support.v4.content.FileProvider"
...
...
app/src/main/java/com/vsoft/vera/CatalogueApplication.java
View file @
906939d6
package
com
.
vsoft
.
vera
;
import
android.app.job.JobInfo
;
import
android.app.job.JobScheduler
;
import
android.content.BroadcastReceiver
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
...
...
@@ -45,10 +48,11 @@ public class CatalogueApplication extends MultiDexApplication {
String
action
=
intent
.
getStringExtra
(
Constants
.
APPLICATION_BROADCAST_DATA_ACTION
);
Log
.
d
(
Constants
.
TAG
,
"CatalogueApplication: onReceive: action: "
+
action
);
if
(
Constants
.
ACTION_SYNC
.
equals
(
action
))
{
Intent
syncMatchSummaryIntentIntent
=
new
Intent
(
context
,
SyncService
.
class
);
//
Intent syncMatchSummaryIntentIntent = new Intent(context, SyncService.class);
if
(
Constants
.
DEBUG
)
Log
.
d
(
Constants
.
TAG
,
"CatalogueApplication: Start SyncService"
);
context
.
startService
(
syncMatchSummaryIntentIntent
);
//context.startService(syncMatchSummaryIntentIntent);
scheduleJob
(
context
);
}
}
};
...
...
@@ -75,6 +79,20 @@ public class CatalogueApplication extends MultiDexApplication {
}
};
// schedule the start of the service every 10 - 30 seconds
public
static
void
scheduleJob
(
Context
context
)
{
ComponentName
serviceComponent
=
new
ComponentName
(
context
,
SyncService
.
class
);
JobInfo
.
Builder
builder
=
new
JobInfo
.
Builder
(
0
,
serviceComponent
);
builder
.
setMinimumLatency
(
1
*
1000
);
// wait at least
builder
.
setOverrideDeadline
(
3
*
1000
);
// maximum delay
//builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); // require unmetered network
//builder.setRequiresDeviceIdle(true); // device should be idle
//builder.setRequiresCharging(false); // we don't care if the device is charging or not
JobScheduler
jobScheduler
=
context
.
getSystemService
(
JobScheduler
.
class
);
jobScheduler
.
schedule
(
builder
.
build
());
}
@Override
public
void
onCreate
()
{
super
.
onCreate
();
...
...
@@ -156,11 +174,8 @@ public class CatalogueApplication extends MultiDexApplication {
options
.
upgrade
=
true
;
mSocket
=
IO
.
socket
(
Constants
.
CHAT_SERVER_URL
,
options
);
// mSocket = IO.socket("http://10.1.8.229:12811",options);
mSocket
.
io
().
timeout
(-
1
);
mSocket
.
io
().
reconnection
(
true
);
mSocket
.
io
().
reconnectionDelay
(
0
);
mSocket
.
io
().
reconnectionAttempts
(
2000
);
}
catch
(
URISyntaxException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
app/src/main/java/com/vsoft/vera/adapters/ChatMessageAdapter.java
View file @
906939d6
package
com
.
vsoft
.
vera
.
adapters
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
...
...
@@ -10,6 +11,7 @@ import android.text.method.LinkMovementMethod;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.inputmethod.InputMethodManager
;
import
android.webkit.JavascriptInterface
;
import
android.webkit.WebView
;
import
android.widget.Button
;
...
...
@@ -37,6 +39,7 @@ import org.jsoup.select.Elements;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.regex.Pattern
;
public
class
ChatMessageAdapter
extends
RecyclerView
.
Adapter
<
ChatMessageAdapter
.
ViewHolder
>
{
...
...
@@ -135,6 +138,8 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<ChatMessageAdapter.
viewAllBT
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
InputMethodManager
imm
=
(
InputMethodManager
)
mContext
.
getSystemService
(
Activity
.
INPUT_METHOD_SERVICE
);
imm
.
hideSoftInputFromWindow
(
view
.
getWindowToken
(),
0
);
Intent
intent
=
new
Intent
(
mContext
,
MyIncidentScreen
.
class
);
mContext
.
startActivity
(
intent
);
...
...
@@ -466,19 +471,28 @@ public class ChatMessageAdapter extends RecyclerView.Adapter<ChatMessageAdapter.
webView
.
getSettings
().
setJavaScriptEnabled
(
true
);
webView
.
addJavascriptInterface
(
new
WebAppInterface
(
mContext
),
"android"
);
webView
.
loadData
(
message
,
"text/html"
,
"utf-8"
);
}
else
if
(
message
.
contains
(
"I could find following 1"
)
&&
message
.
contains
(
"I could find following 2"
)
&&
message
.
contains
(
"I could find following 3"
)&&
message
.
contains
(
"I could find following 4"
)&&
message
.
contains
(
"I could find following 5"
)
){
hr_text_layt
.
setVisibility
(
View
.
VISIBLE
);
mHRMessageView
.
setVisibility
(
View
.
VISIBLE
);
viewAllBT
.
setVisibility
(
View
.
GONE
);
mHRMessageView
.
setMovementMethod
(
LinkMovementMethod
.
getInstance
());
mHRMessageView
.
setText
(
Util
.
fromHtml
(
message
));
}
else
if
(
message
.
contains
(
"I could find following "
))
{
}
else
if
(
message
.
contains
(
"I could find following "
)){
String
[]
stringArray
=
message
.
split
(
"I could find following "
);
String
textMessage
=
stringArray
[
1
];
String
splitMessage
=
textMessage
;
String
[]
stringArray1
=
splitMessage
.
split
(
" "
);
int
incidentNumber
=
Integer
.
parseInt
(
stringArray1
[
0
]);
if
(
incidentNumber
<=
6
){
hr_text_layt
.
setVisibility
(
View
.
VISIBLE
);
mHRMessageView
.
setVisibility
(
View
.
VISIBLE
);
viewAllBT
.
setVisibility
(
View
.
GONE
);
mHRMessageView
.
setMovementMethod
(
LinkMovementMethod
.
getInstance
());
mHRMessageView
.
setText
(
Util
.
fromHtml
(
message
));
}
else
{
hr_text_layt
.
setVisibility
(
View
.
VISIBLE
);
mHRMessageView
.
setVisibility
(
View
.
VISIBLE
);
viewAllBT
.
setVisibility
(
View
.
VISIBLE
);
mHRMessageView
.
setMovementMethod
(
LinkMovementMethod
.
getInstance
());
mHRMessageView
.
setText
(
Util
.
fromHtml
(
message
));
}
hr_text_layt
.
setVisibility
(
View
.
VISIBLE
);
mHRMessageView
.
setVisibility
(
View
.
VISIBLE
);
viewAllBT
.
setVisibility
(
View
.
VISIBLE
);
mHRMessageView
.
setMovementMethod
(
LinkMovementMethod
.
getInstance
());
mHRMessageView
.
setText
(
Util
.
fromHtml
(
message
));
}
else
if
(
message
.
contains
(
"Ok, here's the link to the live agent:"
))
{
...
...
app/src/main/java/com/vsoft/vera/api/managers/IncidentApiManager.java
View file @
906939d6
...
...
@@ -40,12 +40,14 @@ import retrofit2.Retrofit;
public
class
IncidentApiManager
{
public
static
void
getIncident
(
Context
context
,
GetIncidentApiListener
listener
)
{
String
sysId
=
PrefManager
.
getSharedPref
(
context
,
PrefManager
.
PREFERENCE_DYNAMIC_USER_SYS_ID
);
CatalogueLog
.
d
(
"IncidentApiManager: getIncident: "
);
StringBuilder
stringBuilder
=
new
StringBuilder
();
stringBuilder
.
append
(
"caller_id=
javascript:gs.getUserID()"
);
stringBuilder
.
append
(
"caller_id=
"
+
sysId
);
CatalogueLog
.
d
(
"IncidentApiManager: getIncident: request parameter: "
+
stringBuilder
.
toString
());
String
accessToken
=
PrefManager
.
getSharedPref
(
context
,
PrefManager
.
PREFERENCE_ACCESS_TOKEN
);
if
(
accessToken
.
isEmpty
())
{
listener
.
onFailApiCall
();
return
;
...
...
app/src/main/java/com/vsoft/vera/db/DBConstants.java
View file @
906939d6
...
...
@@ -2,6 +2,7 @@ package com.vsoft.vera.db;
public
interface
DBConstants
{
//Tables
String
TABLE_CHAT_LOG
=
"chat_log"
;
String
TABLE_CATALOGUE
=
"catalogue_category"
;
String
TABLE_CATALOGUE_ITEM
=
"catalogue_category_item"
;
String
TABLE_CATALOGUE_VARIABLES
=
"catalogue_variable"
;
...
...
@@ -41,6 +42,16 @@ public interface DBConstants {
int
SYNC_FLAG_DELETE
=
3
;
/**
* Chat log table
*/
String
CHAT_ID
=
"chat_id"
;
String
CHAT_CLIENT_MESSAGE
=
"client_message"
;
String
CHAT_SERVER__RESPONSE
=
"server_response"
;
String
CHAT_TIMESTAMP
=
"timestamp"
;
String
CHAT_CONN_STATUS
=
"conn_status"
;
String
CHAT_SOCKET_ID
=
"socket_id"
;
/**
* Catalogue table
*/
String
CATALOGUE_ID
=
ID
;
...
...
@@ -405,6 +416,8 @@ public interface DBConstants {
*/
int
CHAT_BOT_HISTORY_COLUMN_COUNT
=
5
;
int
CHAT_LOG__COLUMN_COUNT
=
5
;
/**
* ChatBot User table
*/
...
...
app/src/main/java/com/vsoft/vera/db/DBManager.java
View file @
906939d6
...
...
@@ -40,6 +40,7 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
createCatalogueItemInputTable
(
db
);
createAttachmentTable
(
db
);
createIncidentInputTable
(
db
);
createChatLogTable
(
db
);
// if(Util.isNotificationsItemEnabled()) {
// createNotificationsTable(db);
...
...
@@ -76,6 +77,17 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
onCreate
(
db
);
}
private
void
createChatLogTable
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
"create table "
+
TABLE_CHAT_LOG
+
"("
+
CHAT_ID
+
" integer primary key autoincrement, "
+
CHAT_CLIENT_MESSAGE
+
" text, "
+
CHAT_SERVER__RESPONSE
+
" text, "
+
CHAT_TIMESTAMP
+
" text, "
+
CHAT_CONN_STATUS
+
" text, "
+
CHAT_SOCKET_ID
+
" text"
+
");"
);
}
private
void
createCatalogueTable
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
"create table "
+
TABLE_CATALOGUE
+
"("
+
CATALOGUE_ID
+
" integer primary key autoincrement, "
...
...
app/src/main/java/com/vsoft/vera/db/managers/ChatLogManager.java
0 → 100644
View file @
906939d6
package
com
.
vsoft
.
vera
.
db
.
managers
;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
com.vsoft.vera.CatalogueApplication
;
import
com.vsoft.vera.db.DBConstants
;
import
com.vsoft.vera.db.models.ChatBotHistory
;
import
com.vsoft.vera.utils.ChatLog
;
import
com.vsoft.vera.utils.Util
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
/**
*
* @author Kunj on 05-04-2018.
*/
public
class
ChatLogManager
implements
DBConstants
{
public
static
long
save
(
ChatLog
chatLog
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
long
id
=
db
.
insert
(
TABLE_CHAT_LOG
,
null
,
getChatLogContentValues
(
chatLog
));
chatLog
.
setChatId
(
id
);
return
id
;
}
else
{
return
-
1
;
}
}
public
static
List
<
ChatLog
>
getAllChatLogHistory
()
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
String
queryString
=
"select * from "
+
TABLE_CHAT_LOG
+
";"
;
Cursor
c
=
db
.
rawQuery
(
queryString
,
null
);
ArrayList
<
ChatLog
>
chatLogList
;
if
(
c
.
getCount
()
>
0
)
{
chatLogList
=
new
ArrayList
<>(
c
.
getCount
());
while
(
c
.
moveToNext
())
{
ChatLog
chatLog
=
new
ChatLog
();
chatLog
.
setChatId
(
c
.
getLong
(
0
));
chatLog
.
setClientMessage
(
c
.
getString
(
1
));
chatLog
.
setServerResponse
(
c
.
getString
(
2
));
chatLog
.
setTimestamp
(
c
.
getString
(
3
));
chatLog
.
setConnStatus
(
c
.
getString
(
4
));
chatLog
.
setSocketConnId
(
c
.
getString
(
5
));
chatLogList
.
add
(
chatLog
);
}
}
else
{
chatLogList
=
new
ArrayList
<>(
0
);
}
c
.
close
();
return
chatLogList
;
}
else
{
return
new
ArrayList
<>(
0
);
}
}
public
static
int
deleteAllRows
()
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
return
db
.
delete
(
TABLE_CHAT_LOG
,
null
,
null
);
}
return
-
1
;
}
public
static
void
saveLogEvent
(
String
clientMsg
,
String
serverMsg
,
String
connStatus
,
String
connId
,
Date
timestamp
){
ChatLog
chatLog
=
new
ChatLog
();
chatLog
.
setTimestamp
(
Util
.
getDateTime
(
timestamp
.
getTime
()));
chatLog
.
setServerResponse
(
serverMsg
);
chatLog
.
setClientMessage
(
clientMsg
);
chatLog
.
setConnStatus
(
connStatus
);
chatLog
.
setSocketConnId
(
connId
);
ChatLogManager
.
save
(
chatLog
);
}
private
static
ContentValues
getChatLogContentValues
(
ChatLog
chatLog
)
{
ContentValues
cv
=
new
ContentValues
(
CHAT_LOG__COLUMN_COUNT
-
1
);
cv
.
put
(
CHAT_CLIENT_MESSAGE
,
chatLog
.
getClientMessage
());
cv
.
put
(
CHAT_SERVER__RESPONSE
,
chatLog
.
getServerResponse
());
cv
.
put
(
CHAT_TIMESTAMP
,
chatLog
.
getTimestamp
());
cv
.
put
(
CHAT_CONN_STATUS
,
chatLog
.
getConnStatus
());
cv
.
put
(
CHAT_SOCKET_ID
,
chatLog
.
getSocketConnId
());
return
cv
;
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/vera/service/SyncService.java
View file @
906939d6
package
com
.
vsoft
.
vera
.
service
;
import
android.app.IntentService
;
import
android.app.job.JobParameters
;
import
android.app.job.JobService
;
import
android.content.Intent
;
import
android.os.AsyncTask
;
import
com.vsoft.vera.CatalogueApplication
;
import
com.vsoft.vera.api.listeners.get.GetChatServerApiListener
;
...
...
@@ -62,29 +65,45 @@ import static com.vsoft.vera.db.managers.CatalogueItemInputManager.getDirtyItemI
*/
public
class
SyncService
extends
Intent
Service
{
public
class
SyncService
extends
Job
Service
{
private
SyncStatus
syncStatus
=
SyncStatus
.
FAIL
;
public
SyncService
()
{
super
(
SyncService
.
class
.
getSimpleName
());
@Override
public
boolean
onStartJob
(
JobParameters
params
)
{
BackgroundQueueAsync
backgroundQueueAsync
=
new
BackgroundQueueAsync
();
backgroundQueueAsync
.
execute
();
return
false
;
}
@Override
p
rotected
void
onHandleIntent
(
Intent
intent
)
{
CatalogueApplication
application
=
(
CatalogueApplication
)
getApplication
()
;
if
(!
application
.
isNetConnected
())
{
CatalogueLog
.
e
(
"SyncService: onHandleIntent(): Not connected to net. Exit."
);
return
;
p
ublic
boolean
onStopJob
(
JobParameters
params
)
{
return
false
;
}
public
class
BackgroundQueueAsync
extends
AsyncTask
<
Void
,
Void
,
Void
>
{
public
BackgroundQueueAsync
()
{
}
if
(
Util
.
isChatItemEnabled
())
{
if
(
application
.
getSocket
()
==
null
)
{
getChatServerUrl
();
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
CatalogueApplication
application
=
(
CatalogueApplication
)
getApplication
();
if
(!
application
.
isNetConnected
())
{
CatalogueLog
.
e
(
"SyncService: onHandleIntent(): Not connected to net. Exit."
);
}
else
{
if
(
Util
.
isChatItemEnabled
())
{
if
(
application
.
getSocket
()
==
null
)
{
getChatServerUrl
();
}
}
startSync
();
}
}
startSync
();
return
null
;
}
}
/**
...
...
app/src/main/java/com/vsoft/vera/ui/ADALActivity.java
View file @
906939d6
...
...
@@ -15,10 +15,8 @@ import android.os.Handler;
import
android.os.Looper
;
import
android.os.Message
;
import
android.preference.PreferenceManager
;
import
android.support.annotation.Nullable
;
import
android.support.v4.content.LocalBroadcastManager
;
import
android.support.v7.app.AppCompatActivity
;
import
android.telephony.TelephonyManager
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.View
;
...
...
@@ -74,7 +72,6 @@ import org.json.JSONObject;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicBoolean
;
...
...
@@ -172,9 +169,7 @@ public class ADALActivity extends AppCompatActivity {
}
});
getCountryCode
();
// CheckLoginValues();
// CheckLoginValues();
callGraphButton
=
(
Button
)
findViewById
(
R
.
id
.
callGraph
);
signOutButton
=
(
Button
)
findViewById
(
R
.
id
.
clearCache
);
login_with_otp
=
(
Button
)
findViewById
(
R
.
id
.
login_with_otp
);
...
...
@@ -194,6 +189,7 @@ public class ADALActivity extends AppCompatActivity {
});
login_with_otp
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
public
void
onClick
(
View
v
)
{
// onSignOutClicked();
...
...
@@ -334,10 +330,10 @@ public class ADALActivity extends AppCompatActivity {
try
{
root
=
new
JSONObject
(
response
.
toString
());
String
userLoginName
=
root
.
getString
(
"givenName"
);
/*Send broadcast to start SyncService*/
String
mail
=
root
.
getString
(
"mail"
);
PrefManager
.
setSharedPref
(
ADALActivity
.
this
,
PrefManager
.
PREFERENCE_USER_FULL_NAME
,
userLoginName
);
PrefManager
.
setSharedPref
(
ADALActivity
.
this
,
PrefManager
.
PREFERENCE_USER_EMAIL_ID
,
mail
);
/*Send broadcast to start SyncService*/
if
(!
isLogin
){
new
LoginDetailsSendToServer
().
execute
();
...
...
@@ -664,32 +660,49 @@ public class ADALActivity extends AppCompatActivity {
DialogUtils
.
showNoConnectionDialog
(
ADALActivity
.
this
);
}
String
generateRandoStrPharma
=
GenerateRandomString
.
randomString
(
30
);
PrefManager
.
setSharedPref
(
ADALActivity
.
this
,
PrefManager
.
SESSION_ID
,
generateRandoStrPharma
);
String
firstName
=
mUserDetails
.
get
(
0
).
getFirstName
();
String
lastName
=
mUserDetails
.
get
(
0
).
getLastName
();
//
String sysid = mUserDetails.get(0).getSysId();
String
sysid
=
mUserDetails
.
get
(
0
).
getSysId
();
String
userFullName
=
mUserDetails
.
get
(
0
).
getFullName
();
String
userId
=
mUserDetails
.
get
(
0
).
getUserId
();
String
userEmailId
=
mUserDetails
.
get
(
0
).
getUserEmailId
();
if
(
Util
.
isChatItemEnabled
())
{
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser
localChatBotUser
=
ChatBotUserManager
.
getChatBotUsersByUserSysId
(
sysid
);
if
(
localChatBotUser
==
null
)
{
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager
.
deleteAllRows
();
ChatBotUserManager
.
deleteAllRows
();
/*Save Logged in user in local db for chat screen*/
ChatBotUser
chatBotUser
=
ChatBotUser
.
ChatBotUserBuilder
.
aChatBotUser
()
.
setUserSysId
(
sysid
)
.
setName
(
firstName
)
.
build
();
ChatBotUserManager
.
save
(
chatBotUser
);
}
else
{
//Update the name of user
localChatBotUser
.
setName
(
firstName
);
ChatBotUserManager
.
update
(
localChatBotUser
);
}
}
/*End Chat Local DB Part*/
PrefManager
.
setSharedPref
(
ADALActivity
.
this
,
PrefManager
.
PREFERENCE_USER_FIRST_NAME
,
firstName
);
PrefManager
.
setSharedPref
(
ADALActivity
.
this
,
PrefManager
.
PREFERENCE_USER_LAST_NAME
,
lastName
);
PrefManager
.
setSharedPref
(
ADALActivity
.
this
,
PrefManager
.
PREFERENCE_USER_SYS_ID
,
sysid
);
/*For pre fill value in variable form*/
PrefManager
.
setSharedPref
(
ADALActivity
.
this
,
PrefManager
.
PREFERENCE_USER_ID
,
userId
);
new
GetyUserSysIDAsync
().
execute
();
//
//
}
else
{
Util
.
simpleAlert
(
ADALActivity
.
this
,
getResources
().
getString
(
R
.
string
.
user_detail_not_available
));
}
...
...
@@ -701,7 +714,6 @@ public class ADALActivity extends AppCompatActivity {
}
}
private
class
GetyUserSysIDAsync
extends
AsyncTask
<
Void
,
Void
,
SyncStatus
>
{
private
ProgressDialog
progressDialog
;
private
SyncStatus
syncStatus
=
SyncStatus
.
FAIL
;
...
...
@@ -732,6 +744,7 @@ public class ADALActivity extends AppCompatActivity {
public
void
onDoneApiCall
(
String
url
)
{
userSysId
=
url
;
PrefManager
.
setSharedPref
(
ADALActivity
.
this
,
PrefManager
.
PREFERENCE_DYNAMIC_USER_SYS_ID
,
userSysId
);
syncStatus
=
SyncStatus
.
SUCCESS
;
}
...
...
@@ -754,28 +767,8 @@ public class ADALActivity extends AppCompatActivity {
if
(
syncStatus
==
SyncStatus
.
SUCCESS
)
{
if
(
userSysId
!=
null
){
PrefManager
.
setSharedPref
(
ADALActivity
.
this
,
PrefManager
.
PREFERENCE_USER_SYS_ID
,
userSysId
);
if
(
Util
.
isChatItemEnabled
())
{
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser
localChatBotUser
=
ChatBotUserManager
.
getChatBotUsersByUserSysId
(
userSysId
);
if
(
localChatBotUser
==
null
)
{
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager
.
deleteAllRows
();
ChatBotUserManager
.
deleteAllRows
();
/*Save Logged in user in local db for chat screen*/
ChatBotUser
chatBotUser
=
ChatBotUser
.
ChatBotUserBuilder
.
aChatBotUser
()
.
setUserSysId
(
userSysId
)
.
setName
(
userFullName
)
.
build
();
ChatBotUserManager
.
save
(
chatBotUser
);
}
else
{
//Update the name of user
localChatBotUser
.
setName
(
userFullName
);
ChatBotUserManager
.
update
(
localChatBotUser
);
}
}
/*Send broadcast to start SyncService*/
Intent
intent
=
new
Intent
(
Constants
.
APPLICATION_BROADCAST_INTENT
);
intent
.
putExtra
(
Constants
.
APPLICATION_BROADCAST_DATA_ACTION
,
Constants
.
ACTION_SYNC
);
...
...
@@ -809,27 +802,4 @@ public class ADALActivity extends AppCompatActivity {
}
}
/*
* getCountryCode - To get the Country mobile code dynamically.
*
* @return void
* */
public
void
getCountryCode
()
{
try
{
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
this
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
if
(
telephonyManager
!=
null
)
{
String
countryName
=
telephonyManager
.
getNetworkCountryIso
();
if
(
countryName
.
equalsIgnoreCase
(
"us"
))
{
Constants
.
TWILIO_COUNTRY_CODE
=
"+1"
;
}
if
(
countryName
.
equalsIgnoreCase
(
"in"
))
{
Constants
.
TWILIO_COUNTRY_CODE
=
"+91"
;
}
}
}
catch
(
Exception
e
)
{
Constants
.
TWILIO_COUNTRY_CODE
=
"+1"
;
}
}
}
app/src/main/java/com/vsoft/vera/ui/ChatActivity.java
View file @
906939d6
...
...
@@ -55,6 +55,7 @@ import com.bumptech.glide.request.target.SimpleTarget;
import
com.bumptech.glide.request.transition.Transition
;
import
com.github.nkzawa.emitter.Emitter
;
import
com.github.nkzawa.socketio.client.Socket
;
import
com.opencsv.CSVWriter
;
import
com.vsoft.vera.CatalogueApplication
;
import
com.vsoft.vera.R
;
import
com.vsoft.vera.api.listeners.get.GetLiveAgentApiListener
;
...
...
@@ -70,6 +71,7 @@ import com.vsoft.vera.chat.Speaker;
import
com.vsoft.vera.db.DBConstants
;
import
com.vsoft.vera.db.managers.ChatBotHistoryManager
;
import
com.vsoft.vera.db.managers.ChatBotUserManager
;
import
com.vsoft.vera.db.managers.ChatLogManager
;
import
com.vsoft.vera.db.models.ChatBotHistory
;
import
com.vsoft.vera.db.models.ChatBotUser
;
import
com.vsoft.vera.db.models.UserApiValues
;
...
...
@@ -78,6 +80,7 @@ import com.vsoft.vera.speechRecognizer.DroidSpeech;
import
com.vsoft.vera.speechRecognizer.OnDSListener
;
import
com.vsoft.vera.speechRecognizer.OnDSPermissionsListener
;
import
com.vsoft.vera.utils.CatalogueLog
;
import
com.vsoft.vera.utils.ChatLog
;
import
com.vsoft.vera.utils.Constants
;
import
com.vsoft.vera.utils.DialogUtils
;
import
com.vsoft.vera.utils.GenerateRandomString
;
...
...
@@ -91,16 +94,10 @@ import com.wang.avi.AVLoadingIndicatorView;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.opencv.android.BaseLoaderCallback
;
import
org.opencv.android.LoaderCallbackInterface
;
import
org.opencv.android.OpenCVLoader
;
import
org.opencv.android.Utils
;
import
org.opencv.core.CvType
;
import
org.opencv.core.Mat
;
import
org.opencv.imgproc.Imgproc
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
...
...
@@ -167,7 +164,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private
static
final
long
LISTENING_DIALOG_DISMISS_DELAY_TIME
=
10000
;
private
Boolean
opencvEnd
=
false
;
private
boolean
isBlur
=
false
;
private
Mat
imageMat
;
//
private Mat imageMat;
private
ImageButton
sendButton
;
private
final
static
String
INIT_MSG
=
"hi"
;
private
String
chatHistroy
=
""
;
...
...
@@ -210,7 +207,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
mLoggedInUserSysId
=
PrefManager
.
getSharedPref
(
this
,
PrefManager
.
PREFERENCE_USER_SYS_ID
);
mLoggedInUsername
=
PrefManager
.
getSharedPref
(
this
,
PrefManager
.
PREFERENCE_USER_FIRST_NAME
);
userSysId
=
PrefManager
.
getSharedPref
(
this
,
PrefManager
.
PREFERENCE_USER_SYS_ID
);
userSysId
=
PrefManager
.
getSharedPref
(
this
,
PrefManager
.
PREFERENCE_
DYNAMIC_
USER_SYS_ID
);
if
(
TextUtils
.
isEmpty
(
mLoggedInUserSysId
)
||
TextUtils
.
isEmpty
(
mLoggedInUsername
))
{
CatalogueLog
.
e
(
"User Sys id or Name is Null"
);
...
...
@@ -402,6 +399,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
});
mMessagesView
.
addOnItemTouchListener
(
mOnItemTouchListener
);
}
private
void
readAndWriteCallsData
()
{
...
...
@@ -595,16 +594,65 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
finish
();
return
true
;
/*case R.id.voice_menu_icon:
case
R
.
id
.
export_log
:
//get all logs
List
<
ChatLog
>
chatLogList
=
ChatLogManager
.
getAllChatLogHistory
();
Log
.
i
(
TAG
,
"chat log list count = "
+
chatLogList
.
size
());
exportAndSaveLogs
(
chatLogList
);
//delete all logs
ChatLogManager
.
deleteAllRows
();
Toast
.
makeText
(
getApplicationContext
(),
"Export Completed. Check in your external storage."
,
Toast
.
LENGTH_LONG
).
show
();
return
true
;
case R.id.text_menu_icon:
/*
case R.id.text_menu_icon:
return true;*/
default
:
return
super
.
onOptionsItemSelected
(
menuItem
);
}
}
private
void
exportAndSaveLogs
(
List
<
ChatLog
>
chatLogList
)
{
String
baseDir
=
android
.
os
.
Environment
.
getExternalStorageDirectory
().
getAbsolutePath
();
String
dateString
=
Util
.
getDateTime
(
new
Date
().
getTime
());
String
fileName
=
"ChatLogs_"
+
dateString
+
".csv"
;
String
filePath
=
baseDir
+
File
.
separator
+
fileName
;
File
f
=
new
File
(
filePath
);
CSVWriter
writer
;
// File exist
if
(
f
.
exists
()
&&
!
f
.
isDirectory
())
{
FileWriter
mFileWriter
=
null
;
try
{
mFileWriter
=
new
FileWriter
(
filePath
,
true
);
writer
=
new
CSVWriter
(
mFileWriter
);
for
(
ChatLog
chat:
chatLogList
)
{
String
[]
line
=
{
""
+
chat
.
getChatId
(),
chat
.
getClientMessage
(),
chat
.
getServerResponse
(),
chat
.
getConnStatus
(),
chat
.
getTimestamp
()
}
;
writer
.
writeNext
(
line
);
}
writer
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
else
{
try
{
writer
=
new
CSVWriter
(
new
FileWriter
(
filePath
));
String
[]
headerLine
=
{
"Chat Id"
,
"Time Stamp"
,
"Conn Status"
,
"Socket Id"
,
"Client Msg"
,
"Server Msg"
}
;
writer
.
writeNext
(
headerLine
);
for
(
ChatLog
chat:
chatLogList
)
{
String
[]
line
=
{
""
+
chat
.
getChatId
(),
chat
.
getTimestamp
()
,
chat
.
getConnStatus
(),
chat
.
getSocketConnId
(),
chat
.
getClientMessage
(),
chat
.
getServerResponse
()
}
;
writer
.
writeNext
(
line
);
}
writer
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* this message calls when we will add send and receive message in chat screen.
*/
...
...
@@ -673,26 +721,27 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
*/
private
void
attemptSend
()
{
if
(
NetworkConnectivity
.
haveNetworkConnection
(
ChatActivity
.
this
))
{
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
();
/**
* checking socket connection, if it is false,
* then we are reconnecting and send the message again
*/
if
(!
mSocket
.
connected
()){
showSocketConnectError
();
mSocket
.
connect
();
return
;
}
textDotLoader
.
show
();
mInputMessageView
.
setText
(
""
);
addMessage
(
mLoggedInUsername
,
message
,
""
);
...
...
@@ -708,9 +757,15 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
Log
.
i
(
"Print"
,
jsonObject
.
toString
());
mSocket
.
emit
(
NEW_MESSAGE
,
jsonObject
);
ChatLogManager
.
saveLogEvent
(
message
,
""
,
String
.
valueOf
(
mSocket
.
connected
()),
mSocket
.
id
(),
new
Date
());
}
else
{
mInputMessageView
.
requestFocus
();
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.
...
...
@@ -748,7 +803,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override
public
void
run
()
{
// userAuthenticateTask();
Log
.
e
(
TAG
,
"socket got connected"
+
mSocket
.
id
());
// Toast.makeText(getApplicationContext(),
// R.string.connect, Toast.LENGTH_LONG).show();
initChatMessage
(
INIT_MSG
);
ChatLogManager
.
saveLogEvent
(
"New Connection Created"
,
""
,
"true"
,
mSocket
.
id
(),
new
Date
());
}
});
}
...
...
@@ -780,7 +839,35 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}
}
private
void
showSocketConnectError
(){
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Log
.
e
(
TAG
,
"failed to connect"
);
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
();
}
});
}
/**
* Chat server calls this if we will disconnect from server.
...
...
@@ -788,6 +875,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private
Emitter
.
Listener
onDisconnect
=
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
args
)
{
ChatLogManager
.
saveLogEvent
(
"Connection Disconnected"
,
""
,
String
.
valueOf
(
mSocket
.
connected
()),
mSocket
.
id
(),
new
Date
());
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
@@ -818,8 +907,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private
Emitter
.
Listener
onConnectTimeOut
=
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
args
)
{
Toast
.
makeText
(
getApplicationContext
(),
"onConnectTimeOut Called"
,
Toast
.
LENGTH_LONG
).
show
();
Log
.
e
(
TAG
,
"onConnectTimeOut Called"
);
ChatLogManager
.
saveLogEvent
(
"Connection Timed Out"
,
""
,
String
.
valueOf
(
mSocket
.
connected
()),
mSocket
.
id
(),
new
Date
());
// Toast.makeText(getApplicationContext(),
// "onConnectTimeOut Called", Toast.LENGTH_LONG).show();
//reconnect();
}
};
...
...
@@ -830,8 +922,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private
Emitter
.
Listener
onReconnect
=
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
args
)
{
/*Toast.makeText(getApplicationContext(),
"Reconnection Called", Toast.LENGTH_LONG).show();*/
Log
.
e
(
TAG
,
"Reconnection Called"
);
ChatLogManager
.
saveLogEvent
(
"Reconnection Called"
,
""
,
String
.
valueOf
(
mSocket
.
connected
()),
mSocket
.
id
(),
new
Date
());
// Toast.makeText(getApplicationContext(),
// "Reconnection Called", Toast.LENGTH_LONG).show();
//reconnect();
}
...
...
@@ -843,10 +938,13 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private
Emitter
.
Listener
onConnectError
=
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
args
)
{
ChatLogManager
.
saveLogEvent
(
"Failed create a socket connection"
,
""
,
String
.
valueOf
(
mSocket
.
connected
()),
mSocket
.
id
(),
new
Date
());
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(!
isConnectError
)
{
Log
.
e
(
TAG
,
"failed to connect"
);
Snackbar
snackbar
=
Snackbar
.
make
(
mMessagesView
,
R
.
string
.
error_connect
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
"Dismiss"
,
new
View
.
OnClickListener
()
{
...
...
@@ -937,6 +1035,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}
if
(!
message
.
isEmpty
())
{
ChatLogManager
.
saveLogEvent
(
""
,
message
,
String
.
valueOf
(
mSocket
.
connected
()),
mSocket
.
id
(),
new
Date
());
if
(
message
.
contains
(
Constants
.
RESET_PASSWORD_NAVIGATION_SCREEN
)){
runOnUiThread
(
new
Runnable
()
{
...
...
@@ -1133,7 +1232,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
if
(
data
!=
null
){
if
(
takePictureFilePath
!=
null
&&
!
takePictureFilePath
.
isEmpty
())
{
processImageAsBitmap
(
takePictureFilePath
);
//
processImageAsBitmap(takePictureFilePath);
}
}
else
{
initChatMessage
(
"stop"
);
...
...
@@ -1159,109 +1258,109 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private
void
processImageAsBitmap
(
String
imageFilePath
)
{
try
{
BitmapFactory
.
Options
bitmapOptions
=
new
BitmapFactory
.
Options
();
takePhotobitmap
=
BitmapFactory
.
decodeFile
(
imageFilePath
,
bitmapOptions
);
// setImageOrientation(imageFilePath, bitmap);
if
(
takePhotobitmap
!=
null
)
{
opencvProcess
(
takePhotobitmap
);
if
(
isBlur
)
{
reTakePhoto
();
}
else
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
takePhotobitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
75
,
byteArrayOutputStream
);
byte
[]
byteArray
=
byteArrayOutputStream
.
toByteArray
();
String
base64Image
=
Base64
.
encodeToString
(
byteArray
,
Base64
.
DEFAULT
);
addMessage
(
mLoggedInUsername
,
""
,
takePictureFilePath
);
if
(
null
==
mLoggedInUsername
)
return
;
if
(!
mSocket
.
connected
())
return
;
textDotLoader
.
show
();
// perform the sending message attempt.
JSONObject
jsonObject
=
new
JSONObject
();
try
{
jsonObject
.
put
(
CLIENT_MESSAGE_KEY
,
""
);
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
,
base64Image
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
mSocket
.
emit
(
NEW_MESSAGE
,
jsonObject
);
}
}
else
{
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
BaseLoaderCallback
mLoaderCallback
=
new
BaseLoaderCallback
(
this
)
{
@Override
public
void
onManagerConnected
(
int
status
)
{
switch
(
status
)
{
case
LoaderCallbackInterface
.
SUCCESS
:
{
Log
.
i
(
"OpenCV"
,
"OpenCV loaded successfully"
);
imageMat
=
new
Mat
();
}
break
;
default
:
{
super
.
onManagerConnected
(
status
);
}
break
;
}
}
};
private
void
opencvProcess
(
Bitmap
image
)
{
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inDither
=
true
;
options
.
inPreferredConfig
=
Bitmap
.
Config
.
ARGB_8888
;
int
l
=
CvType
.
CV_8UC1
;
//8-bit grey scale image
Utils
.
bitmapToMat
(
image
,
imageMat
);
Mat
matImageGrey
=
new
Mat
();
Imgproc
.
cvtColor
(
imageMat
,
matImageGrey
,
Imgproc
.
COLOR_BGR2GRAY
);
Bitmap
destImage
;
destImage
=
Bitmap
.
createBitmap
(
image
);
Mat
dst2
=
new
Mat
();
Utils
.
bitmapToMat
(
destImage
,
dst2
);
Mat
laplacianImage
=
new
Mat
();
dst2
.
convertTo
(
laplacianImage
,
l
);
Imgproc
.
Laplacian
(
matImageGrey
,
laplacianImage
,
CvType
.
CV_8U
);
Mat
laplacianImage8bit
=
new
Mat
();
laplacianImage
.
convertTo
(
laplacianImage8bit
,
l
);
Bitmap
bmp
=
Bitmap
.
createBitmap
(
laplacianImage8bit
.
cols
(),
laplacianImage8bit
.
rows
(),
Bitmap
.
Config
.
ARGB_8888
);
Utils
.
matToBitmap
(
laplacianImage8bit
,
bmp
);
int
[]
pixels
=
new
int
[
bmp
.
getHeight
()
*
bmp
.
getWidth
()];
bmp
.
getPixels
(
pixels
,
0
,
bmp
.
getWidth
(),
0
,
0
,
bmp
.
getWidth
(),
bmp
.
getHeight
());
int
maxLap
=
-
16777216
;
// 16m
for
(
int
pixel
:
pixels
)
{
if
(
pixel
>
maxLap
)
maxLap
=
pixel
;
}
int
soglia
=
-
6118750
;
if
(
maxLap
<=
soglia
)
{
System
.
out
.
println
(
"is blur image"
);
}
soglia
+=
6118750
;
maxLap
+=
6118750
;
opencvEnd
=
true
;
isBlur
=
maxLap
<=
soglia
;
}
//
private void processImageAsBitmap(String imageFilePath) {
//
try {
//
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
//
takePhotobitmap = BitmapFactory.decodeFile(imageFilePath, bitmapOptions);
//
//
setImageOrientation(imageFilePath, bitmap);
//
//
if (takePhotobitmap != null) {
//
//
opencvProcess(takePhotobitmap);
//
if (isBlur) {
//
reTakePhoto();
//
} else {
//
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//
takePhotobitmap.compress(Bitmap.CompressFormat.JPEG, 75, byteArrayOutputStream);
//
byte[] byteArray = byteArrayOutputStream.toByteArray();
//
String base64Image = Base64.encodeToString(byteArray, Base64.DEFAULT);
//
addMessage(mLoggedInUsername, "", takePictureFilePath);
//
//
if (null == mLoggedInUsername) return;
//
if (!mSocket.connected()) return;
//
textDotLoader.show();
//
//
// perform the sending message attempt.
//
JSONObject jsonObject = new JSONObject();
//
try {
//
jsonObject.put(CLIENT_MESSAGE_KEY, "");
//
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, base64Image);
//
} catch (JSONException e) {
//
e.printStackTrace();
//
}
//
mSocket.emit(NEW_MESSAGE, jsonObject);
//
}
//
//
} else {
//
}
//
//
//
} catch (Exception e) {
//
e.printStackTrace();
//
}
//
}
//
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
//
@Override
//
public void onManagerConnected(int status) {
//
switch (status) {
//
case LoaderCallbackInterface.SUCCESS:
//
{
//
Log.i("OpenCV", "OpenCV loaded successfully");
//
imageMat=new Mat();
//
} break;
//
default:
//
{
//
super.onManagerConnected(status);
//
} break;
//
}
//
}
//
};
//
private void opencvProcess(Bitmap image) {
//
BitmapFactory.Options options = new BitmapFactory.Options();
//
options.inDither = true;
//
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
//
int l = CvType.CV_8UC1; //8-bit grey scale image
//
//
Utils.bitmapToMat(image, imageMat);
//
Mat matImageGrey = new Mat();
//
Imgproc.cvtColor(imageMat, matImageGrey, Imgproc.COLOR_BGR2GRAY);
//
//
Bitmap destImage;
//
destImage = Bitmap.createBitmap(image);
//
Mat dst2 = new Mat();
//
Utils.bitmapToMat(destImage, dst2);
//
Mat laplacianImage = new Mat();
//
dst2.convertTo(laplacianImage, l);
//
Imgproc.Laplacian(matImageGrey, laplacianImage, CvType.CV_8U);
//
Mat laplacianImage8bit = new Mat();
//
laplacianImage.convertTo(laplacianImage8bit, l);
//
//
Bitmap bmp = Bitmap.createBitmap(laplacianImage8bit.cols(), laplacianImage8bit.rows(), Bitmap.Config.ARGB_8888);
//
Utils.matToBitmap(laplacianImage8bit, bmp);
//
int[] pixels = new int[bmp.getHeight() * bmp.getWidth()];
//
bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
//
//
int maxLap = -16777216; // 16m
//
for (int pixel : pixels) {
//
if (pixel > maxLap)
//
maxLap = pixel;
//
}
//
//
int soglia = -6118750;
//
if (maxLap <= soglia) {
//
System.out.println("is blur image");
//
}
//
soglia += 6118750;
//
maxLap += 6118750;
//
opencvEnd = true;
//
isBlur = maxLap <= soglia;
//
}
private
void
checkTTS
()
{
Intent
check
=
new
Intent
();
...
...
@@ -1273,15 +1372,17 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
public
void
onResume
()
{
super
.
onResume
();
if
(
mSocket
!=
null
&&
!
mSocket
.
connected
())
if
(
mSocket
!=
null
&&
!
mSocket
.
connected
())
{
mSocket
.
connect
();
if
(!
OpenCVLoader
.
initDebug
())
{
Log
.
d
(
"OpenCV"
,
"Internal OpenCV library not found. Using OpenCV Manager for initialization"
);
OpenCVLoader
.
initAsync
(
OpenCVLoader
.
OPENCV_VERSION_3_0_0
,
this
,
mLoaderCallback
);
}
else
{
Log
.
d
(
"OpenCV"
,
"OpenCV library found inside package. Using it!"
);
mLoaderCallback
.
onManagerConnected
(
LoaderCallbackInterface
.
SUCCESS
);
}
// if (!OpenCVLoader.initDebug()) {
// Log.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
// OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
// } else {
// Log.d("OpenCV", "OpenCV library found inside package. Using it!");
// mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
// }
}
RecyclerView
.
OnItemTouchListener
mOnItemTouchListener
=
new
RecyclerView
.
OnItemTouchListener
()
{
...
...
@@ -1467,7 +1568,6 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
chatHistoryPostData
.
setAttachmentName
(
"liveAgent.txt"
);
chatHistoryPostData
.
setAttachmentType
(
"application/txt"
);
chatHistoryPostData
.
setAttachmentData
(
ChatHistorybase64
);
userSysId
=
PrefManager
.
getSharedPref
(
ChatActivity
.
this
,
PrefManager
.
PREFERENCE_USER_SYS_ID
);
accessToken
=
PrefManager
.
getSharedPref
(
ChatActivity
.
this
,
PrefManager
.
PREFERENCE_ACCESS_TOKEN
);
}
...
...
app/src/main/java/com/vsoft/vera/ui/OtpValidationActivity.java
View file @
906939d6
...
...
@@ -366,6 +366,27 @@ public class OtpValidationActivity extends Activity {
String
userId
=
mUserDetails
.
get
(
0
).
getUserId
();
String
userEmailId
=
mUserDetails
.
get
(
0
).
getUserEmailId
();
if
(
Util
.
isChatItemEnabled
())
{
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser
localChatBotUser
=
ChatBotUserManager
.
getChatBotUsersByUserSysId
(
sysid
);
if
(
localChatBotUser
==
null
)
{
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager
.
deleteAllRows
();
ChatBotUserManager
.
deleteAllRows
();
/*Save Logged in user in local db for chat screen*/
ChatBotUser
chatBotUser
=
ChatBotUser
.
ChatBotUserBuilder
.
aChatBotUser
()
.
setUserSysId
(
sysid
)
.
setName
(
firstName
)
.
build
();
ChatBotUserManager
.
save
(
chatBotUser
);
}
else
{
//Update the name of user
localChatBotUser
.
setName
(
firstName
);
ChatBotUserManager
.
update
(
localChatBotUser
);
}
}
/*End Chat Local DB Part*/
...
...
@@ -443,28 +464,8 @@ public class OtpValidationActivity extends Activity {
if
(
syncStatus
==
SyncStatus
.
SUCCESS
)
{
if
(
userSysId
!=
null
){
PrefManager
.
setSharedPref
(
OtpValidationActivity
.
this
,
PrefManager
.
PREFERENCE_USER_SYS_ID
,
userSysId
);
PrefManager
.
setSharedPref
(
OtpValidationActivity
.
this
,
PrefManager
.
PREFERENCE_
DYNAMIC_
USER_SYS_ID
,
userSysId
);
if
(
Util
.
isChatItemEnabled
())
{
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser
localChatBotUser
=
ChatBotUserManager
.
getChatBotUsersByUserSysId
(
userSysId
);
if
(
localChatBotUser
==
null
)
{
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager
.
deleteAllRows
();
ChatBotUserManager
.
deleteAllRows
();
/*Save Logged in user in local db for chat screen*/
ChatBotUser
chatBotUser
=
ChatBotUser
.
ChatBotUserBuilder
.
aChatBotUser
()
.
setUserSysId
(
userSysId
)
.
setName
(
userFullName
)
.
build
();
ChatBotUserManager
.
save
(
chatBotUser
);
}
else
{
//Update the name of user
localChatBotUser
.
setName
(
userFullName
);
ChatBotUserManager
.
update
(
localChatBotUser
);
}
}
/*Send broadcast to start SyncService*/
Intent
intent
=
new
Intent
(
Constants
.
APPLICATION_BROADCAST_INTENT
);
intent
.
putExtra
(
Constants
.
APPLICATION_BROADCAST_DATA_ACTION
,
Constants
.
ACTION_SYNC
);
...
...
app/src/main/java/com/vsoft/vera/utils/ChatLog.java
0 → 100644
View file @
906939d6
package
com
.
vsoft
.
vera
.
utils
;
public
class
ChatLog
{
private
Long
chatId
;
/**
* socket connection id
*/
private
String
socketConnId
;
private
String
serverResponse
;
private
String
timestamp
;
/**
* socket connection status
* true or false
*/
private
String
connStatus
;
private
String
clientMessage
;
public
String
getSocketConnId
()
{
return
socketConnId
;
}
public
void
setSocketConnId
(
String
socketConnId
)
{
this
.
socketConnId
=
socketConnId
;
}
public
Long
getChatId
()
{
return
chatId
;
}
public
void
setChatId
(
Long
chatId
)
{
this
.
chatId
=
chatId
;
}
public
String
getClientMessage
()
{
return
clientMessage
;
}
public
void
setClientMessage
(
String
clientMessage
)
{
this
.
clientMessage
=
clientMessage
;
}
public
String
getServerResponse
()
{
return
serverResponse
;
}
public
void
setServerResponse
(
String
serverResponse
)
{
this
.
serverResponse
=
serverResponse
;
}
public
String
getTimestamp
()
{
return
timestamp
;
}
public
void
setTimestamp
(
String
timestamp
)
{
this
.
timestamp
=
timestamp
;
}
public
String
getConnStatus
()
{
return
connStatus
;
}
public
void
setConnStatus
(
String
connStatus
)
{
this
.
connStatus
=
connStatus
;
}
}
app/src/main/java/com/vsoft/vera/utils/Constants.java
View file @
906939d6
...
...
@@ -11,7 +11,8 @@ import com.vsoft.vera.api.interfaces.PendingApprovalsApi;
public
class
Constants
{
public
static
final
String
TAG
=
AppConfig
.
APP_INTERNAL_NAME
;
public
static
String
TWILIO_COUNTRY_CODE
;
// = "+91";
//default set to us
public
static
String
TWILIO_COUNTRY_CODE
=
"+1"
;
public
static
final
String
[]
month
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
/**
...
...
app/src/main/java/com/vsoft/vera/utils/PrefManager.java
View file @
906939d6
...
...
@@ -11,6 +11,7 @@ public class PrefManager {
public
static
final
String
PREFERENCE_USER_FIRST_NAME
=
"firstName"
;
public
static
final
String
PREFERENCE_USER_LAST_NAME
=
"lastName"
;
public
static
final
String
PREFERENCE_USER_SYS_ID
=
"sysId"
;
public
static
final
String
PREFERENCE_DYNAMIC_USER_SYS_ID
=
"dynamic_sysId"
;
public
static
final
String
PREFERENCE_USER_FULL_NAME
=
"full_name"
;
public
static
final
String
PREFERENCE_USER_ID
=
"user_id"
;
public
static
final
String
PREFERENCE_USER_EMAIL_ID
=
"user_email_id"
;
...
...
app/src/vportal/res/menu/more_menu.xml
View file @
906939d6
...
...
@@ -7,5 +7,9 @@
android:id=
"@+id/more_menu_clear"
android:icon=
"@drawable/ic_clear_black"
android:title=
"Clear Chat"
/>
<item
android:id=
"@+id/export_log"
android:title=
"Export Log"
/>
</menu>
app/vportal/staging/app-vportal-staging.apk
View file @
906939d6
No preview for this file type
app/vportal/staging/output.json
View file @
906939d6
[{
"outputType"
:{
"type"
:
"APK"
},
"apkData"
:{
"type"
:
"MAIN"
,
"splits"
:[],
"versionCode"
:
1
,
"versionName"
:
"0.1.8"
,
"enabled"
:
true
,
"outputFile"
:
"app-vportal-staging.apk"
,
"fullName"
:
"vportalStaging"
,
"baseName"
:
"vportal-staging"
},
"path"
:
"app-vportal-staging.apk"
,
"properties"
:{}}]
\ No newline at end of file
[{
"outputType"
:{
"type"
:
"APK"
},
"apkData"
:{
"type"
:
"MAIN"
,
"splits"
:[],
"versionCode"
:
1
,
"versionName"
:
"0.2.4"
,
"enabled"
:
true
,
"outputFile"
:
"app-vportal-staging.apk"
,
"fullName"
:
"vportalStaging"
,
"baseName"
:
"vportal-staging"
},
"path"
:
"app-vportal-staging.apk"
,
"properties"
:{}}]
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment