1st version that works
This commit is contained in:
parent
ee2884b2ff
commit
3806d2c80d
10
.classpath
10
.classpath
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="lib" path="libs/android-support-v4.jar"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
188
.gitignore
vendored
Normal file
188
.gitignore
vendored
Normal file
@ -0,0 +1,188 @@
|
||||
|
||||
# Created by https://www.gitignore.io/api/android,windows,androidstudio
|
||||
|
||||
### Android ###
|
||||
# Built application files
|
||||
*.apk
|
||||
*.ap_
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
out/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
# Android Studio Navigation editor temp files
|
||||
.navigation/
|
||||
|
||||
# Android Studio captures folder
|
||||
captures/
|
||||
|
||||
# Intellij
|
||||
*.iml
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/gradle.xml
|
||||
.idea/dictionaries
|
||||
.idea/libraries
|
||||
|
||||
# External native build folder generated in Android Studio 2.2 and later
|
||||
.externalNativeBuild
|
||||
|
||||
# Freeline
|
||||
freeline.py
|
||||
freeline/
|
||||
freeline_project_description.json
|
||||
|
||||
### Android Patch ###
|
||||
gen-external-apklibs
|
||||
|
||||
### AndroidStudio ###
|
||||
# Covers files to be ignored for android development using Android Studio.
|
||||
|
||||
# Built application files
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
|
||||
# Java class files
|
||||
|
||||
# Generated files
|
||||
|
||||
# Gradle files
|
||||
.gradle
|
||||
|
||||
# Signing files
|
||||
.signing/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
|
||||
# Log Files
|
||||
|
||||
# Android Studio
|
||||
/*/build/
|
||||
/*/local.properties
|
||||
/*/out
|
||||
/*/*/build
|
||||
/*/*/production
|
||||
*.ipr
|
||||
*~
|
||||
*.swp
|
||||
|
||||
# Android Patch
|
||||
|
||||
# External native build folder generated in Android Studio 2.2 and later
|
||||
|
||||
# NDK
|
||||
obj/
|
||||
|
||||
# IntelliJ IDEA
|
||||
*.iws
|
||||
/out/
|
||||
|
||||
# User-specific configurations
|
||||
.idea/libraries/
|
||||
.idea/.name
|
||||
.idea/compiler.xml
|
||||
.idea/copyright/profiles_settings.xml
|
||||
.idea/encodings.xml
|
||||
.idea/misc.xml
|
||||
.idea/modules.xml
|
||||
.idea/scopes/scope_settings.xml
|
||||
.idea/vcs.xml
|
||||
.idea/jsLibraryMappings.xml
|
||||
.idea/datasources.xml
|
||||
.idea/dataSources.ids
|
||||
.idea/sqlDataSources.xml
|
||||
.idea/dynamic.xml
|
||||
.idea/uiDesigner.xml
|
||||
|
||||
# OS-specific files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# Legacy Eclipse project files
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
|
||||
hs_err_pid*
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/mongoSettings.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
### AndroidStudio Patch ###
|
||||
|
||||
!/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# End of https://www.gitignore.io/api/android,windows,androidstudio
|
||||
/.idea/gradle.xml
|
||||
/.idea/misc.xml
|
||||
/.idea
|
||||
/.idea/modules.xml
|
||||
/.idea/gradle.xml
|
||||
/.idea/misc.xml
|
33
.project
33
.project
@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>SafeDispatch</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,3 +0,0 @@
|
||||
#Thu Nov 24 10:30:15 EET 2011
|
||||
eclipse.preferences.version=1
|
||||
filesCopiedToWebInfLib=
|
@ -1,12 +0,0 @@
|
||||
#Fri Dec 09 16:13:31 EET 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
@ -1,75 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.safemobile.dispatch_demo"
|
||||
android:versionCode="9"
|
||||
android:versionName="1.0.9" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="8"
|
||||
android:targetSdkVersion="19" />
|
||||
|
||||
<!-- require OpenGL ES version 2 for Google Maps -->
|
||||
<uses-feature
|
||||
android:glEsVersion="0x00020000"
|
||||
android:required="true"/>
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
|
||||
|
||||
|
||||
<!-- The following two permissions are not required to use
|
||||
Google Maps Android API v2, but are recommended. -->
|
||||
<!--
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
-->
|
||||
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
|
||||
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> -->
|
||||
<!-- <uses-permission android:name="android.permission.BLUETOOTH"></uses-permission> -->
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"></uses-permission>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
||||
|
||||
<uses-feature android:name="android.hardware.camera"/>
|
||||
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
|
||||
<uses-feature android:name="android.hardware.camera.flash" android:required="false"/>
|
||||
|
||||
<application
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@style/Theme.Safedispatch">
|
||||
<uses-library android:name="com.google.android.maps" android:required="false"/>
|
||||
<service android:name="com.safemobile.services.TCPService" />
|
||||
|
||||
<meta-data android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.android.maps.v2.API_KEY"
|
||||
android:value="@string/googleMapsApiv2" />
|
||||
|
||||
<activity
|
||||
android:name="SDMobileActivity"
|
||||
android:label="@string/app_name_demo"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:screenOrientation="landscape" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="SetupActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="TabLayoutActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="LiveActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="HistoryActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="MessagesActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="AlarmActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="RadioActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="RecordingsActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape"></activity>
|
||||
<activity android:name="EmptyActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="NotificationActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,57 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.safemobile.safedispatchmobile"
|
||||
android:versionCode="4"
|
||||
android:versionName="1.0.4" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="7"
|
||||
android:targetSdkVersion="15" />
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> -->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_LOCATION"></uses-permission> -->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_GPS"></uses-permission> -->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"></uses-permission> -->
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
|
||||
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> -->
|
||||
<!-- <uses-permission android:name="android.permission.BLUETOOTH"></uses-permission> -->
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"></uses-permission>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
||||
|
||||
<uses-feature android:name="android.hardware.camera"/>
|
||||
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
|
||||
<uses-feature android:name="android.hardware.camera.flash" android:required="false"/>
|
||||
|
||||
<application
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@style/Theme.NoBackground">
|
||||
<uses-library android:name="com.google.android.maps" android:required="false"/>
|
||||
<service android:name="com.safemobile.services.TCPService" />
|
||||
|
||||
<activity
|
||||
android:name="SDMobileActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:screenOrientation="landscape" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="SetupActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="TabLayoutActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="LiveActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="HistoryActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="MessagesActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="AlarmActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="RadioActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="RecordingsActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape"></activity>
|
||||
<activity android:name="EmptyActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="NotificationActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,55 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.safemobile.safedispatchmobiledemo"
|
||||
android:versionCode="4"
|
||||
android:versionName="1.0.4" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="7"
|
||||
android:targetSdkVersion="15" />
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> -->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_LOCATION"></uses-permission> -->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_GPS"></uses-permission> -->
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"></uses-permission> -->
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
|
||||
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> -->
|
||||
<!-- <uses-permission android:name="android.permission.BLUETOOTH"></uses-permission> -->
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"></uses-permission>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
||||
|
||||
<uses-feature android:name="android.hardware.camera"/>
|
||||
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
|
||||
<uses-feature android:name="android.hardware.camera.flash" android:required="false"/>
|
||||
|
||||
<application
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:icon="@drawable/icon_demo"
|
||||
android:label="@string/app_name_demo"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@style/Theme.NoBackground">
|
||||
<uses-library android:name="com.google.android.maps" android:required="false"/>
|
||||
<activity
|
||||
android:name="SDMobileActivity"
|
||||
android:label="@string/app_name_demo"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:screenOrientation="landscape" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="SetupActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="TabLayoutActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="LiveActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="HistoryActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="MessagesActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="AlarmActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="RadioActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="RecordingsActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape"></activity>
|
||||
<activity android:name="EmptyActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
<activity android:name="NotificationActivity" android:configChanges="orientation|screenSize" android:screenOrientation="landscape" ></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
22
build.gradle
Normal file
22
build.gradle
Normal file
@ -0,0 +1,22 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
url 'https://maven.google.com/'
|
||||
name 'Google'
|
||||
}
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.1.2'
|
||||
classpath 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
}
|
||||
}
|
41
gradle.properties
Normal file
41
gradle.properties
Normal file
@ -0,0 +1,41 @@
|
||||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
# Default value: -Xmx10248m -XX:MaxPermSize=256m
|
||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
VERSION_NAME=1.2
|
||||
|
||||
# Increase memory allotted to JVM
|
||||
org.gradle.jvmargs=-Xmx2048M
|
||||
#Xmx1536M
|
||||
#org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
|
||||
# Enable Gradle Daemon
|
||||
#org.gradle.daemon=true
|
||||
|
||||
# Enable Configure on demand
|
||||
#org.gradle.configureondemand=true
|
||||
|
||||
# Enable parallel builds
|
||||
org.gradle.parallel=true
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
|
||||
# Enable Build Cache
|
||||
#android.enableBuildCache=true
|
||||
|
||||
# Enable simple gradle caching
|
||||
#org.gradle.caching=true
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#Thu Mar 10 10:35:08 EET 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
185
gradlew
vendored
Normal file
185
gradlew
vendored
Normal file
@ -0,0 +1,185 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
85
import-summary.txt
Normal file
85
import-summary.txt
Normal file
@ -0,0 +1,85 @@
|
||||
ECLIPSE ANDROID PROJECT IMPORT SUMMARY
|
||||
======================================
|
||||
|
||||
Manifest Merging:
|
||||
-----------------
|
||||
Your project uses libraries that provide manifests, and your Eclipse
|
||||
project did not explicitly turn on manifest merging. In Android Gradle
|
||||
projects, manifests are always merged (meaning that contents from your
|
||||
libraries' manifests will be merged into the app manifest. If you had
|
||||
manually copied contents from library manifests into your app manifest
|
||||
you may need to remove these for the app to build correctly.
|
||||
|
||||
Ignored Files:
|
||||
--------------
|
||||
The following files were *not* copied into the new Gradle project; you
|
||||
should evaluate whether these are still needed in your project and if
|
||||
so manually move them:
|
||||
|
||||
From LibSafeMobile:
|
||||
* proguard-project.txt
|
||||
* safemobile.keystore
|
||||
From SafeDispatch:
|
||||
* AndroidManifest_Safe.xml
|
||||
* AndroidManifest_demo.xml
|
||||
* proguard.cfg
|
||||
|
||||
Replaced Jars with Dependencies:
|
||||
--------------------------------
|
||||
The importer recognized the following .jar files as third party
|
||||
libraries and replaced them with Gradle dependencies instead. This has
|
||||
the advantage that more explicit version information is known, and the
|
||||
libraries can be updated automatically. However, it is possible that
|
||||
the .jar file in your project was of an older version than the
|
||||
dependency we picked, which could render the project not compileable.
|
||||
You can disable the jar replacement in the import wizard and try again:
|
||||
|
||||
android-support-v4.jar => com.android.support:support-v4:18.0.0
|
||||
|
||||
Replaced Libraries with Dependencies:
|
||||
-------------------------------------
|
||||
The importer recognized the following library projects as third party
|
||||
libraries and replaced them with Gradle dependencies instead. This has
|
||||
the advantage that more explicit version information is known, and the
|
||||
libraries can be updated automatically. However, it is possible that
|
||||
the source files in your project were of an older version than the
|
||||
dependency we picked, which could render the project not compileable.
|
||||
You can disable the library replacement in the import wizard and try
|
||||
again:
|
||||
|
||||
LibGooglePlayServices => [com.google.android.gms:play-services:+]
|
||||
|
||||
Moved Files:
|
||||
------------
|
||||
Android Gradle projects use a different directory structure than ADT
|
||||
Eclipse projects. Here's how the projects were restructured:
|
||||
|
||||
In LibSafeMobile:
|
||||
* AndroidManifest.xml => libSafeMobile\src\main\AndroidManifest.xml
|
||||
* assets\ => libSafeMobile\src\main\assets
|
||||
* libs\Citizen_Android_1063.jar => libSafeMobile\libs\Citizen_Android_1063.jar
|
||||
* res\ => libSafeMobile\src\main\res\
|
||||
* src\ => libSafeMobile\src\main\java\
|
||||
* truck5_large.PNG => truck5_large.png
|
||||
In SafeDispatch:
|
||||
* disable.PNG => disable.png
|
||||
* AndroidManifest.xml => safeDispatch\src\main\AndroidManifest.xml
|
||||
* assets\ => safeDispatch\src\main\assets\
|
||||
* lint.xml => safeDispatch\lint.xml
|
||||
* res\ => safeDispatch\src\main\res\
|
||||
* src\ => safeDispatch\src\main\java\
|
||||
|
||||
Next Steps:
|
||||
-----------
|
||||
You can now build the project. The Gradle project needs network
|
||||
connectivity to download dependencies.
|
||||
|
||||
Bugs:
|
||||
-----
|
||||
If for some reason your project does not build, and you determine that
|
||||
it is due to a bug or limitation of the Eclipse to Gradle importer,
|
||||
please file a bug at http://b.android.com with category
|
||||
Component-Tools.
|
||||
|
||||
(This import summary is for your information only, and can be deleted
|
||||
after import once you are satisfied with the results.)
|
44
libSafeMobile/build.gradle
Normal file
44
libSafeMobile/build.gradle
Normal file
@ -0,0 +1,44 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
|
||||
|
||||
android {
|
||||
compileSdkVersion 31
|
||||
buildToolsVersion "31.0.0"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 31
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation files('libs/Citizen_Android_1063.jar')
|
||||
|
||||
// support libraries
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
implementation 'androidx.media:media:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
implementation 'com.google.android.gms:play-services-auth:20.1.0'
|
||||
|
||||
// Fused location provider with and without google services
|
||||
implementation 'com.google.android.gms:play-services-location:19.0.1'
|
||||
|
||||
// Google maps library
|
||||
implementation 'com.google.android.gms:play-services-maps:18.0.2'
|
||||
|
||||
// add Gson
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
}
|
BIN
libSafeMobile/libs/Citizen_Android_1063.jar
Normal file
BIN
libSafeMobile/libs/Citizen_Android_1063.jar
Normal file
Binary file not shown.
14
libSafeMobile/src/main/AndroidManifest.xml
Normal file
14
libSafeMobile/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.safemobile.lib"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,15 @@
|
||||
package com.safemobile.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class AbstractEmptyActivity extends Activity {
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.safemobile.activities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public abstract class AbstractLiveActivity extends AppCompatActivity {
|
||||
|
||||
private AbstractSDParentActivity parentTab;
|
||||
private Activity activity;
|
||||
private Context context;
|
||||
|
||||
private Bundle savedInstanceState;
|
||||
|
||||
public abstract void refreshMap(); // --> updateMap
|
||||
public abstract void vehiclesReceived(ArrayList<Vehicle> vehiclesList); // --> SaveVehicleInfo
|
||||
public abstract void pollReceived(int position, double lat, double lng); // --> UpdatePoll
|
||||
public abstract void vehicleStatusReceived(long imei, int opCode, int status); // --> UpdateOptions
|
||||
public abstract void emergencyAlarmReceived(int position, double lat, double lng); // --> UpdateEmergencyAlarm
|
||||
|
||||
|
||||
/** Misc */
|
||||
public AbstractSDParentActivity getParentTab() {
|
||||
return parentTab;
|
||||
}
|
||||
|
||||
public void setParentTab(AbstractSDParentActivity parentTab) {
|
||||
this.parentTab = parentTab;
|
||||
}
|
||||
|
||||
public Activity getActivity() {
|
||||
return activity;
|
||||
}
|
||||
|
||||
public void setActivity(Activity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Bundle getSavedInstanceState() {
|
||||
return savedInstanceState;
|
||||
}
|
||||
|
||||
public void setSavedInstanceState(Bundle savedInstanceState) {
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.safemobile.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
public abstract class AbstractMessagesActivity extends Activity {
|
||||
|
||||
/** Misc */
|
||||
public AbstractParentActivity parentTab;
|
||||
public Activity activity;
|
||||
public Context context;
|
||||
|
||||
// GridView Type
|
||||
public boolean LASTMESSAGES = true;
|
||||
|
||||
/*
|
||||
public abstract void UpdateSMS(ArrayList<SMS> list);
|
||||
public abstract void updateResultsInUi();
|
||||
public abstract void selectVehicle4Sc_id(long sc_id);
|
||||
public abstract void updateTCPConnection(boolean connected);
|
||||
public abstract void ConfirmSMS(String data);
|
||||
public abstract void NewSMS(String imei, String message);
|
||||
public abstract void onContactsUpdate();
|
||||
*/
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package com.safemobile.activities;
|
||||
|
||||
import com.safemobile.bluetooth.BluetoothTether;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.services.TCPhandler;
|
||||
import com.safemobile.services.TCPmsgParser;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.TabActivity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class AbstractParentActivity extends TabActivity {
|
||||
|
||||
/** UI Elements */
|
||||
public RelativeLayout layoutLoading, relativeLayoutMenu;
|
||||
public ImageView imageViewLoading;
|
||||
|
||||
/** Misc */
|
||||
public Activity activity;
|
||||
public Context context;
|
||||
public NotificationManager mNotificationManager;
|
||||
public boolean displayLogCat = false; // show logCat messages when TCP send was successful
|
||||
|
||||
/** Handler */
|
||||
public Handler myHandler = new Handler();
|
||||
|
||||
/** BlueTooth Tether */
|
||||
public BluetoothTether bluetoothTether = null;
|
||||
|
||||
/** Broadcast Receiver */
|
||||
public BroadcastReceiver mReceiver = null;
|
||||
|
||||
/** TCP */
|
||||
protected TCPhandler tcp = null;
|
||||
protected TCPmsgParser tcpParser = null;
|
||||
|
||||
/** Methods */
|
||||
//public void onCreate(Bundle savedInstanceState) { };
|
||||
public abstract void startAudioHandler();
|
||||
public abstract void getSetZoneAndChannel(int gwID, int rgwID, int zoneNR, int channelNR);
|
||||
public abstract void getRadioStatus(int gwID, int rgwID);
|
||||
public abstract void sendPTT(int callType, long id);
|
||||
public abstract void sendCallType(int callType, long id);
|
||||
public abstract void sendDekey();
|
||||
public abstract void sendReset();
|
||||
public abstract void sendEmergency(int onOFF);
|
||||
public abstract void sendEmergency(int onOFF, long group_id);
|
||||
public abstract void sendSMS(String seqId, long sc_id, String txt);
|
||||
public abstract void displayToast(final String msg);
|
||||
public abstract void whenBackPressed(AppParams.ActivityResult result);
|
||||
public abstract void whenMenuPressed();
|
||||
public abstract void changeLanguage();
|
||||
public abstract Contact getVehicleById(long imei);
|
||||
|
||||
/** enable the menu buttons placed on the right side of the screen
|
||||
* @param enable if set to true, the buttons will be enabled, else they will be disabled */
|
||||
public abstract void enableMenuButtons(boolean enable);
|
||||
|
||||
public abstract void setRadioActivity(AbstractRadioActivity radioActivity);
|
||||
public abstract void setMessagesActivity(AbstractMessagesActivity messageActivity);
|
||||
|
||||
/** Send a TCP Command using Async Tasks
|
||||
* @param params Here you will add parameters for commands, and params[0] will be the Operation Code
|
||||
* followed by others parameters accordingly to the command*/
|
||||
public abstract void executeNetworkStuff(String[] params);
|
||||
|
||||
|
||||
/** get if TCP is connected or disconnected or null */
|
||||
public Object getTCPState() {
|
||||
// return true if tcp connection is on, false if not connected and null
|
||||
|
||||
if(tcp!=null && tcp.isConnectionUP)
|
||||
return "true";
|
||||
else if(tcp!=null && !tcp.isConnectionUP)
|
||||
return "false";
|
||||
return null;
|
||||
}
|
||||
|
||||
public void showMenu(boolean show)
|
||||
{
|
||||
if(relativeLayoutMenu != null)
|
||||
{
|
||||
// do not performe animation if already shown or already hidden
|
||||
if((relativeLayoutMenu.isShown() && show) || (!relativeLayoutMenu.isShown() && !show))
|
||||
;
|
||||
else {
|
||||
Animation anim = AnimationUtils.loadAnimation(this, R.anim.slide_out_bottom);
|
||||
if(show)
|
||||
anim = AnimationUtils.loadAnimation(this, R.anim.slide_in_bottom);
|
||||
relativeLayoutMenu.clearAnimation();
|
||||
relativeLayoutMenu.startAnimation(anim);
|
||||
relativeLayoutMenu.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMenuVisibile()
|
||||
{
|
||||
if(relativeLayoutMenu!= null && relativeLayoutMenu.getVisibility() == View.VISIBLE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract void unregisterReceivers(BroadcastReceiver receiver);
|
||||
public abstract void cancelNotification(int drawable);
|
||||
public abstract void stopTethering();
|
||||
public abstract void stopAudio();
|
||||
public abstract void stopTCP();
|
||||
public abstract void recreateTCPConnection();
|
||||
public abstract void removeITCPListener();
|
||||
|
||||
/*
|
||||
public abstract void onResume();
|
||||
public abstract void onStart();
|
||||
public abstract void onPause();
|
||||
*/
|
||||
}
|
@ -0,0 +1,264 @@
|
||||
package com.safemobile.activities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Timer;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.radio.Channel;
|
||||
import com.safemobile.lib.radio.Emerg;
|
||||
import com.safemobile.lib.radio.IncCall;
|
||||
import com.safemobile.lib.radio.Zone;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
public abstract class AbstractRadioActivity extends Activity {
|
||||
|
||||
|
||||
/** Misc */
|
||||
public AbstractParentActivity parentTab;
|
||||
public Activity activity;
|
||||
public Context context;
|
||||
public boolean emergencyOn = false;
|
||||
public boolean pttONoff = false;
|
||||
public IncCall incCall;
|
||||
public String chMsg = "";
|
||||
public Emerg emerg;
|
||||
public Dialog dialogExternal;
|
||||
// only in PadRadio
|
||||
//public int radioID, GWID, zoneNR, chNR;
|
||||
|
||||
/** Handler */
|
||||
public Handler myHandler = new Handler();
|
||||
public Timer timerInCall, timerPTTOn, timerCallType;
|
||||
|
||||
/** Lists */
|
||||
//public ArrayList<String> allContactsNames = new ArrayList<String>();
|
||||
//public ArrayList<String> allGroupsNames = new ArrayList<String>();
|
||||
//public ArrayList<Integer> allContactsIDs = new ArrayList<Integer>();
|
||||
//public ArrayList<Integer> allGroupsIDs = new ArrayList<Integer>();
|
||||
//public ArrayList<Zone> crtZones = new ArrayList<Zone>();
|
||||
//public ArrayList<Channel> crtChannels = new ArrayList<Channel>();
|
||||
public ArrayAdapter<String> adapter;
|
||||
|
||||
|
||||
/** Methods */
|
||||
//public void onCreate(Bundle savedInstanceState) { };
|
||||
public abstract void startAudioHandler();
|
||||
public void PTTclick(int type) { };
|
||||
/*
|
||||
public abstract void updateRadioTCPdown();
|
||||
public abstract void UpdateRadios(ArrayList<RadioGW> radios);
|
||||
public abstract void UpdateCallTypeChanged(IncCall response);
|
||||
public abstract void UpdateZoneCH(int _radioID, int _GWID, int _zoneNR, int _chNR);
|
||||
public abstract void UpdateRadioStatus(int status);
|
||||
public abstract void UpdateIncCall (IncCall iCall);
|
||||
public abstract String updateUI(EnumCallState radioStatus);
|
||||
public abstract void UpdateEmerg (Emerg emerg);
|
||||
public abstract void onContactsUpdate();
|
||||
*/
|
||||
public abstract void sendPTTFromBlueTooth(boolean on);
|
||||
public abstract void ShowDialog(String title, String errorMsg);
|
||||
public abstract void stopAudioHandler();
|
||||
public abstract Object getAudioHandlerState();
|
||||
public abstract void initUDP();
|
||||
|
||||
|
||||
|
||||
/** Stop the timer that ends call after one minute */
|
||||
public void stopTimerInCall()
|
||||
{
|
||||
timerInCall.cancel();
|
||||
timerInCall.purge();
|
||||
timerInCall = null;
|
||||
}
|
||||
|
||||
|
||||
/** get Group Contact ID from Name */
|
||||
public long getGroupID4Name_old(String name)
|
||||
{
|
||||
try {
|
||||
ListIterator<Contact> it = AppParams.listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact ctc = it.next();
|
||||
// if searched name - return corresponding id
|
||||
if(ctc.name.equals(name) && ctc.contactType == Contact.GROUP)
|
||||
return ctc.id;
|
||||
}
|
||||
|
||||
long id = -1;
|
||||
|
||||
// try to get id from name because the id was manual dialed
|
||||
try {
|
||||
id = Long.parseLong(name);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/** get Private Contact ID from Name */
|
||||
public long getPrivateID4Name_old(String name)
|
||||
{
|
||||
try {
|
||||
ListIterator<Contact> it = AppParams.listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact ctc = it.next();
|
||||
// if searched name - return corresponding id
|
||||
if(ctc.name.equals(name) && ctc.contactType == Contact.PRIVATE)
|
||||
return ctc.id;
|
||||
}
|
||||
|
||||
long id = -1;
|
||||
|
||||
// try to get id from name because the id was manual dialed
|
||||
try {
|
||||
id = Long.parseLong(name);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** get Private Contact ID from Name */
|
||||
public String getName4PrivateID(long id)
|
||||
{
|
||||
try {
|
||||
ListIterator<Contact> it = AppParams.listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact ctc = it.next();
|
||||
// if searched name - return corresponding id
|
||||
if(ctc.id == id && ctc.contactType == Contact.PRIVATE)
|
||||
return ctc.name;
|
||||
}
|
||||
|
||||
return id+"";
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
return id+"";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** get Group Contact ID from Name */
|
||||
public String getName4GroupID(long id)
|
||||
{
|
||||
try {
|
||||
ListIterator<Contact> it = AppParams.listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact ctc = it.next();
|
||||
// if searched name - return corresponding id
|
||||
if(ctc.id == id && ctc.contactType == Contact.GROUP)
|
||||
return ctc.name;
|
||||
}
|
||||
|
||||
return id+"";
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
return id+"";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** get zone number from spinner zoneName */
|
||||
public int getNR4Zone_old(String zoneName)
|
||||
{
|
||||
for(Zone zone: AppParams.listZones)
|
||||
if(zone.ZoneName.equals(zoneName))
|
||||
return zone.id;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** get channel number from spinner chName */
|
||||
public int getNR4CH_old(String chName)
|
||||
{
|
||||
for(Channel ch: AppParams.crtZone.channelList)
|
||||
if(ch.chName.equals(chName))
|
||||
return ch.id;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/** get All Contacts Names */
|
||||
public static ArrayList<String> getAllContactsName(String type, ArrayList<Contact> listContacts)
|
||||
{
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
try {
|
||||
ListIterator<Contact> it = listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact contact = it.next();
|
||||
|
||||
if(type.equals("Call"))
|
||||
list.add(contact.name);
|
||||
else {
|
||||
if((type.equalsIgnoreCase("Private Call") && contact.contactType == Contact.PRIVATE) ||
|
||||
(type.equalsIgnoreCase("Group Call") && contact.contactType == Contact.GROUP))
|
||||
list.add(contact.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/** get All Contacts Names */
|
||||
public static ArrayList<Long> getAllContactsIDs(String type, ArrayList<Contact> listContacts)
|
||||
{
|
||||
ArrayList<Long> list = new ArrayList<Long>();
|
||||
|
||||
try
|
||||
{
|
||||
ListIterator<Contact> it = listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact contact = it.next();
|
||||
|
||||
if(type.equals("Call"))
|
||||
list.add((long)contact.id);
|
||||
|
||||
if((type.equalsIgnoreCase("Private Call") && contact.contactType == Contact.PRIVATE) ||
|
||||
(type.equalsIgnoreCase("Group Call") && contact.contactType == Contact.GROUP))
|
||||
list.add((long)contact.id);
|
||||
}
|
||||
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/** Display a toast Message */
|
||||
public void displayToast(String msg)
|
||||
{
|
||||
parentTab.displayToast(msg);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.safemobile.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
public abstract class AbstractRecordingsActivity extends Activity {
|
||||
|
||||
/** Misc */
|
||||
public AbstractParentActivity parentTab;
|
||||
public Activity activity;
|
||||
public Context context;
|
||||
|
||||
public abstract void deleteSelected(final int position);
|
||||
|
||||
}
|
@ -0,0 +1,323 @@
|
||||
package com.safemobile.activities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import com.safemobile.bluetooth.BluetoothTether;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.SuperVehicle;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
import com.safemobile.services.TCPhandler;
|
||||
import com.safemobile.services.TCPmsgParser;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.TabActivity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class AbstractSDParentActivity extends TabActivity {
|
||||
|
||||
/** UI Elements */
|
||||
public RelativeLayout layoutLoading;
|
||||
public ImageView imageViewLoading;
|
||||
|
||||
/** Misc */
|
||||
public Activity activity;
|
||||
public Context context;
|
||||
public NotificationManager mNotificationManager;
|
||||
public boolean displayLogCat = true; // show logCat messages when TCP send was successful
|
||||
public String imei, mess;
|
||||
public int demoPosition = 0;
|
||||
|
||||
/** Lists */
|
||||
public ArrayList<Vehicle> allVehicle = new ArrayList<Vehicle>();
|
||||
public Hashtable<Long, SuperVehicle> SuperVehHash = new Hashtable<Long, SuperVehicle>();
|
||||
public Hashtable<Long, Vehicle> VehHashbySc_id = new Hashtable<Long, Vehicle>();
|
||||
|
||||
/** Handler */
|
||||
public Handler myHandler = new Handler();
|
||||
|
||||
/** BlueTooth Tether */
|
||||
public BluetoothTether bluetoothTether = null;
|
||||
|
||||
/** Broadcast Receiver */
|
||||
public BroadcastReceiver mReceiver = null;
|
||||
|
||||
/** TCP */
|
||||
protected TCPhandler tcp = null;
|
||||
protected TCPmsgParser tcpParser = null;
|
||||
|
||||
/** Methods */
|
||||
public abstract void displayToast(final String msg);
|
||||
public abstract void whenBackPressed(AppParams.ActivityResult result);
|
||||
public abstract void changeLanguage();
|
||||
public abstract void enableMenuButtons(boolean enable);
|
||||
public abstract void setRadioActivity(AbstractRadioActivity radioActivity);
|
||||
public abstract void setLiveActivity(AbstractLiveActivity liveActivity);
|
||||
public abstract void setMessagesActivity(AbstractMessagesActivity messageActivity);
|
||||
|
||||
/** get if TCP is connected or disconnected or null */
|
||||
public Object getTCPState() {
|
||||
// return true if tcp connection is on, false if not connected and null
|
||||
|
||||
if(tcp!=null && tcp.isConnectionUP)
|
||||
return "true";
|
||||
else if(tcp!=null && !tcp.isConnectionUP)
|
||||
return "false";
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract void unregisterReceivers(BroadcastReceiver receiver);
|
||||
public abstract void cancelNotification(int drawable);
|
||||
public abstract void stopTCP();
|
||||
public abstract void stopTCPParser();
|
||||
public abstract void executeNetworkStuff(String[] params);
|
||||
public abstract void recreateTCPConnection();
|
||||
public abstract void removeITCPListener();
|
||||
|
||||
|
||||
public abstract void updateDemoPosition();
|
||||
public abstract void updateResultsPollInUi(String type);
|
||||
public abstract double best_zoom(double LATMAX,double LATmin,double LNGMAX,double LNGmin);
|
||||
|
||||
/* SafeDispatch Mobile functions */
|
||||
/** get Vehicles for an user id */
|
||||
public boolean getVehicles(int userID)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#21#" + AppParams.USERID + "#");
|
||||
if(res && displayLogCat)
|
||||
SM.Debug("Message (getVehs) sent to app server");
|
||||
else
|
||||
SM.Debug("Could not send message(getVehs)!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/** get vehicles Last Positions for an user id */
|
||||
public boolean getLastPositions(int userID)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#25#" + userID + "#");
|
||||
if(res && displayLogCat)
|
||||
SM.Debug("Message (getLastPOS) sent to app server");
|
||||
else
|
||||
SM.Debug("Could not send message(getLastSMS)!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/** set Enable/Disable a vehicle */
|
||||
public boolean setVehicleStatus(int radioCode, int opCode, int sc_id, int enable)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#"+radioCode+"#"+opCode+"#" + sc_id+"#" + enable + "#");
|
||||
if(res && displayLogCat)
|
||||
SM.Debug("Message (Option4Unit) sent to app server radioCode:"+radioCode+ " opCode:"+opCode+ " sc_id:"+sc_id+ " value:" + enable);
|
||||
else
|
||||
SM.Debug("Could not send message(Option4Unit)!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/** get Last SMSs for an user */
|
||||
public boolean getLastSMSs(int userID)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#23#" + userID + "#");
|
||||
if(res && displayLogCat)
|
||||
SM.Debug("#Send Request#", "Message [getLastSMSs] sent to app server");
|
||||
else
|
||||
SM.Debug("#Send Request#", "Could not send message [getLastSMSs]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/** get SMSs for an user that are recent than timeGMT
|
||||
* @param sc_id the vehicle imei for which we want the SMSs
|
||||
* @param timeGMT the unix time for the last message in the grid or messages that are newer than this time */
|
||||
public boolean getRecentSMSs(int sc_id, long timeGMT)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#22#"+sc_id+"#" +timeGMT+"#");
|
||||
if(res && displayLogCat)
|
||||
SM.Debug("#Send Request#", "Message [getRecentSMSs] sent to app server");
|
||||
else
|
||||
SM.Debug("#Send Request#", "Could not send message [getRecentSMSs]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/** send a SMS to a vehicle
|
||||
* @param seqID is a unique identifier for the SMS
|
||||
* @param sc_id vehicle imei to which you want to send the SMS
|
||||
* @param txt the message to be send */
|
||||
public boolean sendSMS(String seqID, int sc_id, String txt)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write(seqID, "#24#" + AppParams.USERID + "#" + sc_id + "#" + txt + "#");
|
||||
if(res && displayLogCat)
|
||||
SM.Debug("Message [sendSMS] sent to app server sc_id:"+sc_id+ " txt:"+txt);
|
||||
else
|
||||
SM.Debug("Could not send message [sendSMS]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public boolean sendAlarmAcknoledge(int alarm_id, int type)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#28#" + alarm_id + "#" + type + "#");
|
||||
if(res)
|
||||
SM.Debug("Message [sendAlarmAcknoledge] sent to app server alarm_id:" + alarm_id + " type:" + type);
|
||||
else
|
||||
SM.Debug("Could not send message [sendAlarmAcknoledge]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean sendPlayRecordingRequest(long record_id)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#18#" + record_id + "#");
|
||||
if(res)
|
||||
SM.Debug("Message [sendPlayRecordingRequest] sent to app server record_id:"+record_id);
|
||||
else
|
||||
SM.Debug("Could not send message [sendPlayRecordingRequest]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public boolean sendDekey(int gwID, int radioID)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#30#160#" + gwID + "." + radioID + "#");
|
||||
if(res)
|
||||
SM.Debug("Message [sendDekey] sent to app server record_id");
|
||||
else
|
||||
SM.Debug("Could not send message [sendDeKey]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean getHistoryPositions(int sc_id, long timeGMTStart, long timeGMTStop)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
String histSeqID = "1."+Integer.toString((int) (System.currentTimeMillis() / 1000L));
|
||||
boolean res = tcp.Write(histSeqID,"#26#"+sc_id+"#"+timeGMTStart+"#"+timeGMTStop+"#");
|
||||
if(res)
|
||||
SM.Debug("Message [getHistoryPositions] sent to app server");
|
||||
else
|
||||
SM.Debug("Could not send message [getHistoryPositions]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean getRadiosList()
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#30#100#");
|
||||
if(res)
|
||||
SM.Debug("Message [getRadiosList] sent to app server");
|
||||
else
|
||||
SM.Debug("Could not send message [getRadiosList]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// if zoneNr=0 and channelNR =0 then function acts as GET
|
||||
public boolean getSetZoneAndChannel(int gwID, int rgwID, int zoneNR, int channelNR)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#30#104#" + gwID + "#" + rgwID + "#" + zoneNR + "#" +channelNR +"#");
|
||||
if(res)
|
||||
SM.Debug("Message [GetSetZoneAndChannel] sent to app server zoneNR:"+zoneNR+ " channelNR:"+channelNR);
|
||||
else
|
||||
SM.Debug("Could not send message [GetSetZoneAndChannel]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean getRadioStatus(int gwID, int rgwID)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#30#99#" + gwID + "#" + rgwID + "#");
|
||||
if(res)
|
||||
SM.Debug("Message [RadioGetRadioList] sent to app server || gwID: " + gwID + " | rgwID: " + rgwID);
|
||||
else
|
||||
SM.Debug("Could not send message [getLastSMS]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean getAlarms(long userID)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#27#" + userID + "#"); // = tcp.Write("0.0", "#30#99#" + gwID + "#" + rgwID + "#");
|
||||
if(res)
|
||||
SM.Debug("Message [GetAlarms] sent to app server");
|
||||
else
|
||||
SM.Debug("Could not send message [GetAlarms]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public boolean getRecordings(int gwID, int radioID)
|
||||
{
|
||||
if(tcp == null)
|
||||
return false;
|
||||
|
||||
boolean res = tcp.Write("0.0", "#29#"+AppParams.USERID+"#"+ gwID +"#"+ radioID +"#");
|
||||
if(res)
|
||||
SM.Debug("Message [GetRecordings] sent to app server");
|
||||
else
|
||||
SM.Debug("Could not send message [GetRecordings]!!");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//public abstract void getVehiclePosition(long imei);
|
||||
/*
|
||||
public abstract void onResume();
|
||||
public abstract void onStart();
|
||||
public abstract void onPause();
|
||||
*/
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.Alarm;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public class AlertGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Alarm> listAlarms;
|
||||
private Activity activity;
|
||||
private ArrayList<Boolean> acknowledged = new ArrayList<Boolean>();
|
||||
|
||||
public AlertGridViewAdapter(Activity activity, ArrayList<Alarm> listAlarms, Context context, ArrayList<Boolean> acknowledged) {
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listAlarms = listAlarms;
|
||||
this.acknowledged = acknowledged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listAlarms.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Alarm getItem(int position) {
|
||||
return listAlarms.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public LinearLayout layoutAlert;
|
||||
public ImageView imageViewAlert, imageViewRecycle;
|
||||
public TextView textViewUnitName, textViewType, textViewDate;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_alert, null);
|
||||
|
||||
view.textViewUnitName = (TextView) convertView.findViewById(R.id.textViewUnitName);
|
||||
view.textViewType = (TextView) convertView.findViewById(R.id.textViewType);
|
||||
view.textViewDate = (TextView) convertView.findViewById(R.id.textViewDate);
|
||||
view.imageViewRecycle = (ImageView) convertView.findViewById(R.id.imageViewRecycle);
|
||||
view.imageViewAlert = (ImageView) convertView.findViewById(R.id.imageViewAlert);
|
||||
view.layoutAlert = (LinearLayout) convertView.findViewById(R.id.layoutAlert);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
view.textViewUnitName.setText(listAlarms.get(position).unitName);
|
||||
view.textViewType.setText(listAlarms.get(position).typestr);
|
||||
|
||||
//view.txtViewDescription.setText(listAlarms.get(position).description);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
Date date = new Date((long)listAlarms.get(position).timeGMT * 1000);
|
||||
if(date.getDate() == Calendar.getInstance().get(Calendar.DAY_OF_MONTH))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm");
|
||||
view.textViewDate.setText(String.valueOf(sdf.format(date)));
|
||||
|
||||
// set ack/!ack image
|
||||
switch(acknowledged.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imageViewAlert.setImageResource(R.drawable.alert_off);
|
||||
//view.layoutAlarm.setBackgroundColor(0xffffffff);
|
||||
break;
|
||||
case 0:
|
||||
view.imageViewAlert.setImageResource(R.drawable.alert);
|
||||
//view.layoutAlarm.setBackgroundColor(0xffcccccc);
|
||||
break;
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public void changeACK(int position)
|
||||
{
|
||||
SM.Debug("ACK ON START: " + position + " | " + (acknowledged.get(position) ? "true": "false"));
|
||||
// change in list
|
||||
acknowledged.remove(position);
|
||||
acknowledged.add(position, true);
|
||||
|
||||
ViewHolder view = new ViewHolder();
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
View convertView = null;
|
||||
if(convertView==null)
|
||||
{
|
||||
convertView = inflator.inflate(R.layout.row_alert, null);
|
||||
try
|
||||
{
|
||||
view.imageViewAlert = (ImageView) convertView.findViewById(R.id.imageViewAlert);
|
||||
view.imageViewAlert.setImageResource(R.drawable.alert_off);
|
||||
convertView.setTag(view);
|
||||
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,107 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ContactsComboBoxAdapter extends ArrayAdapter<Contact>{
|
||||
|
||||
private Context context;
|
||||
int layoutResourceId;
|
||||
private ArrayList<Contact> listValues;
|
||||
|
||||
public ContactsComboBoxAdapter(Context context, int textViewResourceId, ArrayList<Contact> listValues) {
|
||||
super(context, textViewResourceId, listValues);
|
||||
this.context = context;
|
||||
this.layoutResourceId = textViewResourceId;
|
||||
this.listValues = listValues;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
public View getCustomView(int position, View convertView, ViewGroup parent) {
|
||||
View row = convertView;
|
||||
ImagesSpinnerHolder holder = null;
|
||||
|
||||
if(row == null) {
|
||||
|
||||
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||||
/*LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);*/
|
||||
|
||||
row = inflater.inflate(layoutResourceId, parent, false);
|
||||
|
||||
holder = new ImagesSpinnerHolder();
|
||||
holder.textSpinner = (TextView)row.findViewById(R.id.language);
|
||||
holder.imgSpinner = (ImageView)row.findViewById(R.id.icon);
|
||||
|
||||
row.setTag(holder);
|
||||
}
|
||||
else
|
||||
holder = (ImagesSpinnerHolder)row.getTag();
|
||||
|
||||
holder.textSpinner.setText(getTextFromArrayList(position));
|
||||
holder.imgSpinner.setImageResource(getImageFromArrayList(position));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find which generic type which is used in the array list and then display the string field for that class type
|
||||
* @param position The position in the array list which needs to be displayed
|
||||
* @return The string which will be used
|
||||
*/
|
||||
private String getTextFromArrayList(int position) {
|
||||
return listValues.get(position).name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find which generic type which is used in the array list and then get the icon which needs to be displayed
|
||||
* @param position The position in the array list which needs to be displayed
|
||||
* @return The Image Resource which will be displayed
|
||||
*/
|
||||
private int getImageFromArrayList(int position) {
|
||||
int contactType = listValues.get(position).contactType;
|
||||
|
||||
switch(contactType)
|
||||
{
|
||||
case AppParams.MotoManualDial:
|
||||
return R.drawable.dial;
|
||||
case AppParams.MotoAllCall:
|
||||
return R.drawable.call_all_green_small;
|
||||
case AppParams.MotoPrivate:
|
||||
return R.drawable.call_private_green_small;
|
||||
case AppParams.MotoGroup:
|
||||
return R.drawable.call_group_green_small;
|
||||
|
||||
default: return R.drawable.call_private_blue_small;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class ImagesSpinnerHolder {
|
||||
ImageView imgSpinner;
|
||||
TextView textSpinner;
|
||||
}
|
||||
}
|
@ -0,0 +1,200 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.Msg;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class ConversationGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Msg> listMessages;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
private ArrayList<Boolean> dispatcher_positions = new ArrayList<Boolean>();
|
||||
private ArrayList<Boolean> ackPositions = new ArrayList<Boolean>();
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
|
||||
public ConversationGridViewAdapter(Activity activity, ArrayList<Msg> listMessages, Context context, long sc_id, int unit_type, ArrayList<Boolean> dispatcher_positions, ArrayList<Boolean> ackPositions) {
|
||||
this.activity = activity;
|
||||
this.listMessages = listMessages;
|
||||
this.dispatcher_positions = dispatcher_positions;
|
||||
this.ackPositions = ackPositions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listMessages.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Msg getItem(int position) {
|
||||
return listMessages.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewContact;
|
||||
public TextView txtViewMsg;
|
||||
public TextView txtViewDateTime;
|
||||
public ImageView imgViewReceivedContact;
|
||||
public TextView txtViewReceivedMsg;
|
||||
public TextView txtViewReceivedDateTime;
|
||||
public ImageView imageAck;
|
||||
public TextView textViewNotACK;
|
||||
public LinearLayout layoutSend;
|
||||
public LinearLayout layoutReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_conversation, null);
|
||||
|
||||
view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewSenderIco);
|
||||
view.txtViewMsg = (TextView) convertView.findViewById(R.id.textViewSendMsg);
|
||||
view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewSendDate);
|
||||
view.imgViewReceivedContact = (ImageView) convertView.findViewById(R.id.imageViewReceivedIco);
|
||||
view.txtViewReceivedMsg = (TextView) convertView.findViewById(R.id.textViewReceivedMsg);
|
||||
view.txtViewReceivedDateTime = (TextView) convertView.findViewById(R.id.textViewReceivedDate);
|
||||
view.layoutSend = (LinearLayout) convertView.findViewById(R.id.layoutSend);
|
||||
view.layoutReceived = (LinearLayout) convertView.findViewById(R.id.layoutReceived);
|
||||
view.textViewNotACK = (TextView) convertView.findViewById(R.id.textViewNotACKSendMsg);
|
||||
view.imageAck = (ImageView) convertView.findViewById(R.id.imageAck);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
try
|
||||
{
|
||||
hash.put(position, convertView);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm MMM-dd");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
if(listMessages.get(position).received.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
else
|
||||
sdf = new SimpleDateFormat("HH:mm MMM-dd");
|
||||
|
||||
|
||||
//view.imgViewContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||||
view.imgViewContact.setImageResource(R.drawable.peoplegreen_large);
|
||||
view.txtViewMsg.setText(listMessages.get(position).message);
|
||||
view.txtViewDateTime.setText(sdf.format(listMessages.get(position).received));
|
||||
//view.imgViewReceivedContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||||
view.imgViewReceivedContact.setImageResource(listMessages.get(position).from.getLargeIcon());
|
||||
view.txtViewReceivedMsg.setText(listMessages.get(position).message);
|
||||
view.txtViewReceivedDateTime.setText(sdf.format(listMessages.get(position).received));
|
||||
|
||||
if(ackPositions.size() > 0)
|
||||
switch(ackPositions.get(position) ? 1: 0) {
|
||||
case 0:
|
||||
// show not ack
|
||||
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||||
view.imageAck.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case 1:
|
||||
// show not ack
|
||||
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||||
view.imageAck.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
switch(dispatcher_positions.get(position) ? 1 : 0) {
|
||||
case 1:
|
||||
view.layoutReceived.setVisibility(View.GONE);
|
||||
view.layoutSend.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case 0:
|
||||
view.layoutReceived.setVisibility(View.VISIBLE);
|
||||
view.layoutSend.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public void setACK(String seqID)
|
||||
{
|
||||
int position = -1, i=0;
|
||||
|
||||
for(Msg msg: listMessages)
|
||||
{
|
||||
if(msg.seqID.equals(seqID))
|
||||
position = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if(position > -1 && position < ackPositions.size()) {
|
||||
ackPositions.remove(position);
|
||||
ackPositions.add(position, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeView(String seqID)
|
||||
{
|
||||
int position = -1, i=0;
|
||||
|
||||
for(Msg msg: listMessages)
|
||||
{
|
||||
if(msg.seqID.equals(seqID))
|
||||
position = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if(position != -1 && hash.size() > position)
|
||||
{
|
||||
SM.Debug("POSITON : " + position);
|
||||
View con = hash.get(position);
|
||||
ViewHolder view = (ViewHolder) con.getTag();
|
||||
|
||||
switch(ackPositions.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imageAck.setVisibility(View.INVISIBLE);
|
||||
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||||
break;
|
||||
case 0:
|
||||
view.imageAck.setVisibility(View.VISIBLE);
|
||||
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import com.safemobile.lib.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class LanguageSpinnerAdapter extends ArrayAdapter<String>{
|
||||
|
||||
private String[] Languages;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
public LanguageSpinnerAdapter(Context context, int textViewResourceId,String[] Languages, LayoutInflater inflater) {
|
||||
super(context, textViewResourceId, Languages);
|
||||
this.Languages = Languages;
|
||||
this.inflater = inflater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
public View getCustomView(int position, View convertView, ViewGroup parent) {
|
||||
View row = inflater.inflate(R.layout.spinner, parent, false);
|
||||
TextView label=(TextView)row.findViewById(R.id.language);
|
||||
label.setText(Languages[position]);
|
||||
ImageView icon =(ImageView)row.findViewById(R.id.icon);
|
||||
|
||||
switch (position)
|
||||
{
|
||||
case 0: icon.setImageResource(R.drawable.en); break;
|
||||
case 1: icon.setImageResource(R.drawable.de); break;
|
||||
case 2: icon.setImageResource(R.drawable.tr); break;
|
||||
case 3: icon.setImageResource(R.drawable.ro); break;
|
||||
case 4: icon.setImageResource(R.drawable.ru); break;
|
||||
case 5: icon.setImageResource(R.drawable.es); break;
|
||||
case 6: icon.setImageResource(R.drawable.ara); break;
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
}
|
@ -0,0 +1,231 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
public class LiveGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Vehicle> listVehicle;
|
||||
private ArrayList<Boolean> displayedVehicles;
|
||||
public ArrayList<Boolean> disabledVehicles;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
public LiveGridViewAdapter(Activity activity, ArrayList<Vehicle> listVehicle, Context context, ArrayList<Boolean> displayedVehicles, ArrayList<Boolean> disabledVehicles)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listVehicle = listVehicle;
|
||||
//this.time = time;
|
||||
this.displayedVehicles = displayedVehicles;
|
||||
this.disabledVehicles = disabledVehicles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listVehicle.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vehicle getItem(int position) {
|
||||
return listVehicle.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewIcon, imgViewChecked;
|
||||
public TextView txtViewName;
|
||||
public LinearLayout layoutVehicle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_vehicle, null);
|
||||
|
||||
view.imgViewIcon = (ImageView) convertView.findViewById(R.id.imageViewIcon);
|
||||
view.txtViewName = (TextView) convertView.findViewById(R.id.textViewName);
|
||||
view.imgViewChecked = (ImageView) convertView.findViewById(R.id.imageViewChecked);
|
||||
|
||||
//view.linearLayoutChecked = (LinearLayout) convertView.findViewById(R.id.linearLayoutChecked);
|
||||
view.layoutVehicle = (LinearLayout) convertView.findViewById(R.id.layoutVehicle);
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
hash.put(position, convertView);
|
||||
|
||||
view.imgViewIcon.setImageResource(listVehicle.get(position).getSmallIcon());
|
||||
view.txtViewName.setText(listVehicle.get(position).name);
|
||||
// set color
|
||||
//int colorPos = position % colors.length;
|
||||
//view.layoutVehicle.setBackgroundColor(colors[colorPos]);
|
||||
switch(displayedVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
break;
|
||||
case 0:
|
||||
view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(disabledVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.layoutVehicle.setBackgroundColor(0xffcccccc);
|
||||
//view.imgViewIcon.setImageDrawable(convertToGrayscale(activity.getResources().getDrawable(listVehicle.get(position).getSmallIcon())));
|
||||
break;
|
||||
case 0:
|
||||
view.layoutVehicle.setBackgroundColor(0xffFFFFFF);
|
||||
//view.imgViewIcon.setImageResource(listVehicle.get(position).getSmallIcon());
|
||||
break;
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public void changeDisplayed(int position, int status)
|
||||
{
|
||||
SM.Debug("DISABLE ON START: " + position + " | " + (disabledVehicles.get(position) ? "true": "false"));
|
||||
SM.Debug("DISPLAY ON START: " + position + " | " + (displayedVehicles.get(position) ? "true": "false"));
|
||||
// if vehicle is enable
|
||||
if(status == 1)
|
||||
{
|
||||
// change icon
|
||||
//view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
// change in list
|
||||
disabledVehicles.remove(position);
|
||||
disabledVehicles.add(position, false);
|
||||
}
|
||||
else if(status == 0)
|
||||
{
|
||||
// change icon
|
||||
//view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
// change in list
|
||||
disabledVehicles.remove(position);
|
||||
disabledVehicles.add(position, true);
|
||||
}
|
||||
// change displayed
|
||||
else if (status == -1)
|
||||
{
|
||||
// check selected position
|
||||
displayedVehicles.remove(position);
|
||||
displayedVehicles.add(position, true);
|
||||
}
|
||||
|
||||
ViewHolder view = new ViewHolder();
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
View convertView = null;
|
||||
if(convertView==null)
|
||||
{
|
||||
convertView = inflator.inflate(R.layout.row_vehicle, null);
|
||||
try
|
||||
{
|
||||
view.layoutVehicle = (LinearLayout) convertView.findViewById(R.id.layoutVehicle);
|
||||
view.imgViewIcon = (ImageView) convertView.findViewById(R.id.imageViewIcon);
|
||||
view.imgViewChecked = (ImageView) convertView.findViewById(R.id.imageViewChecked);
|
||||
convertView.setTag(view);
|
||||
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
SM.Debug("DISABLE AFTER: " + position + " | " + (disabledVehicles.get(position) ? "true": "false"));
|
||||
SM.Debug("DISPLAY AFTER: " + position + " | " + (displayedVehicles.get(position) ? "true": "false"));
|
||||
switch(disabledVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.layoutVehicle.setBackgroundColor(0xffcccccc);
|
||||
//view.imgViewIcon.setImageDrawable(convertToGrayscale(activity.getResources().getDrawable(listVehicle.get(position).getSmallIcon())));
|
||||
break;
|
||||
case 0:
|
||||
view.layoutVehicle.setBackgroundColor(0xffFFFFFF);
|
||||
//view.imgViewIcon.setImageResource(listVehicle.get(position).getSmallIcon());
|
||||
break;
|
||||
}
|
||||
|
||||
switch(displayedVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
break;
|
||||
case 0:
|
||||
view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void changeView(int position)
|
||||
{
|
||||
View con = hash.get(position);
|
||||
ViewHolder view = (ViewHolder) con.getTag();
|
||||
switch(disabledVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.layoutVehicle.setBackgroundColor(0xffcccccc);
|
||||
//view.imgViewIcon.setImageDrawable(convertToGrayscale(activity.getResources().getDrawable(listVehicle.get(position).getSmallIcon())));
|
||||
break;
|
||||
case 0:
|
||||
view.layoutVehicle.setBackgroundColor(0xffFFFFFF);
|
||||
//view.imgViewIcon.setImageResource(listVehicle.get(position).getSmallIcon());
|
||||
break;
|
||||
}
|
||||
|
||||
switch(displayedVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
break;
|
||||
case 0:
|
||||
view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected Drawable convertToGrayscale(Drawable drawable)
|
||||
{
|
||||
ColorMatrix matrix = new ColorMatrix();
|
||||
matrix.setSaturation(0);
|
||||
|
||||
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
|
||||
|
||||
drawable.setColorFilter(filter);
|
||||
|
||||
return drawable;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.Msg;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class MessagesGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Msg> listMessages;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
|
||||
|
||||
public MessagesGridViewAdapter(Activity activity, ArrayList<Msg> listMessages, Context context) {
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listMessages = listMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listMessages.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Msg getItem(int position) {
|
||||
return listMessages.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewContact;
|
||||
public TextView txtViewContact;
|
||||
public TextView txtViewDateTime;
|
||||
public TextView txtViewLastMsg;
|
||||
public LinearLayout layoutMessage;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_message, null);
|
||||
|
||||
view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewContact);
|
||||
view.txtViewContact = (TextView) convertView.findViewById(R.id.textViewContact);
|
||||
view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewLastDate);
|
||||
view.txtViewLastMsg = (TextView) convertView.findViewById(R.id.textViewLastMsg);
|
||||
view.layoutMessage = (LinearLayout) convertView.findViewById(R.id.layoutMessage);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
view.imgViewContact.setImageResource(listMessages.get(position).from.getLargeIcon());
|
||||
//view.imgViewContact.setImageResource(R.drawable.peopleblue);
|
||||
view.txtViewContact.setText(listMessages.get(position).from.name+ " :");
|
||||
if(listMessages.get(position).message.length() > 25)
|
||||
view.txtViewLastMsg.setText(listMessages.get(position).message.substring(0, 25) + "...");
|
||||
else
|
||||
view.txtViewLastMsg.setText(listMessages.get(position).message);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
if(listMessages.get(position).received.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm");
|
||||
|
||||
view.txtViewDateTime.setText(sdf.format(listMessages.get(position).received));
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public int getIcon(int user_type, String username)
|
||||
{
|
||||
// if request was send by MessagesActivity -> Spinner
|
||||
if(user_type == -1)
|
||||
{
|
||||
// get unit_type for selected username
|
||||
for (Msg mes: listMessages)
|
||||
{
|
||||
// if user is selected
|
||||
if(mes.from.name.equals(username))
|
||||
{
|
||||
user_type = (int) mes.from.driver_id; // save user_type
|
||||
|
||||
return mes.from.getLargeIcon();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.libpad.PadTextMessage;
|
||||
|
||||
public class PadConversationGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<PadTextMessage> listMessages;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
private ArrayList<Boolean> outgoingPositions = new ArrayList<Boolean>();
|
||||
private ArrayList<Boolean> ackPositions = new ArrayList<Boolean>();
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
|
||||
public PadConversationGridViewAdapter(Activity activity, ArrayList<PadTextMessage> listMessages, Context context, ArrayList<Boolean> outgoingPositions, ArrayList<Boolean> ackPositions) {
|
||||
this.activity = activity;
|
||||
this.listMessages = listMessages;
|
||||
this.outgoingPositions = outgoingPositions;
|
||||
this.ackPositions = ackPositions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listMessages.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PadTextMessage getItem(int position) {
|
||||
return listMessages.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** return the list of messages in the adapter
|
||||
* @return an ArrayList of PadTextMessages
|
||||
*/
|
||||
public ArrayList<PadTextMessage> getMessages() {
|
||||
return listMessages;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewContact;
|
||||
public TextView txtViewMsg;
|
||||
public TextView txtViewDateTime;
|
||||
public ImageView imgViewReceivedContact;
|
||||
public TextView txtViewReceivedMsg;
|
||||
public TextView txtViewReceivedDateTime;
|
||||
public ImageView imageAck;
|
||||
public TextView textViewNotACK;
|
||||
public LinearLayout layoutSend;
|
||||
public LinearLayout layoutReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_conversation, null);
|
||||
|
||||
view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewSenderIco);
|
||||
view.txtViewMsg = (TextView) convertView.findViewById(R.id.textViewSendMsg);
|
||||
view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewSendDate);
|
||||
view.imgViewReceivedContact = (ImageView) convertView.findViewById(R.id.imageViewReceivedIco);
|
||||
view.txtViewReceivedMsg = (TextView) convertView.findViewById(R.id.textViewReceivedMsg);
|
||||
view.txtViewReceivedDateTime = (TextView) convertView.findViewById(R.id.textViewReceivedDate);
|
||||
view.layoutSend = (LinearLayout) convertView.findViewById(R.id.layoutSend);
|
||||
view.layoutReceived = (LinearLayout) convertView.findViewById(R.id.layoutReceived);
|
||||
view.textViewNotACK = (TextView) convertView.findViewById(R.id.textViewNotACKSendMsg);
|
||||
view.imageAck = (ImageView) convertView.findViewById(R.id.imageAck);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
try
|
||||
{
|
||||
hash.put(position, convertView);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm MMM-dd", Locale.getDefault());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Date date = new Date(listMessages.get(position).timeGMT * 1000);
|
||||
|
||||
if(date.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
else
|
||||
sdf = new SimpleDateFormat("HH:mm MMM-dd", Locale.getDefault());
|
||||
|
||||
// set gmt time
|
||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
//view.imgViewContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||||
view.imgViewContact.setImageResource(R.drawable.peoplegreen_large);
|
||||
view.txtViewMsg.setText(listMessages.get(position).message);
|
||||
view.txtViewDateTime.setText(sdf.format(date));
|
||||
//view.imgViewReceivedContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||||
view.imgViewReceivedContact.setImageResource(R.drawable.peopleblue_large);
|
||||
view.txtViewReceivedMsg.setText(listMessages.get(position).message);
|
||||
|
||||
view.txtViewReceivedDateTime.setText(sdf.format(date));
|
||||
|
||||
if(ackPositions.size() > 0)
|
||||
switch(ackPositions.get(position) ? 1: 0) {
|
||||
case 0:
|
||||
// show not ack
|
||||
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||||
view.imageAck.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case 1:
|
||||
// show not ack
|
||||
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||||
view.imageAck.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
switch(outgoingPositions.get(position) ? 1 : 0) {
|
||||
case 1:
|
||||
view.layoutReceived.setVisibility(View.GONE);
|
||||
view.layoutSend.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case 0:
|
||||
view.layoutReceived.setVisibility(View.VISIBLE);
|
||||
view.layoutSend.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
/*
|
||||
public void setACK(String seqID)
|
||||
{
|
||||
int position = -1, i=0;
|
||||
|
||||
for(Msg msg: listMessages)
|
||||
{
|
||||
if(msg.seqID.equals(seqID))
|
||||
position = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
ackPositions.remove(position);
|
||||
ackPositions.add(position, true);
|
||||
}
|
||||
|
||||
public void changeView(String seqID)
|
||||
{
|
||||
int position = -1, i=0;
|
||||
|
||||
for(Msg msg: listMessages)
|
||||
{
|
||||
if(msg.seqID.equals(seqID))
|
||||
position = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if(position != -1 && hash.size() > position)
|
||||
{
|
||||
SM.Debug("POSITON : " + position);
|
||||
View con = hash.get(position);
|
||||
ViewHolder view = (ViewHolder) con.getTag();
|
||||
|
||||
switch(ackPositions.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imageAck.setVisibility(View.INVISIBLE);
|
||||
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||||
break;
|
||||
case 0:
|
||||
view.imageAck.setVisibility(View.VISIBLE);
|
||||
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.libpad.PadTextMessage;
|
||||
|
||||
public class PadMessagesGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<PadTextMessage> listMessages;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
|
||||
|
||||
public PadMessagesGridViewAdapter(Activity activity, ArrayList<PadTextMessage> listMessages, Context context) {
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listMessages = listMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listMessages.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PadTextMessage getItem(int position) {
|
||||
return listMessages.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** return the list of messages in the adapter
|
||||
* @return an ArrayList of PadTextMessages
|
||||
*/
|
||||
public ArrayList<PadTextMessage> getMessages() {
|
||||
return listMessages;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewContact;
|
||||
public TextView txtViewContact;
|
||||
public TextView txtViewDateTime;
|
||||
public TextView txtViewLastMsg;
|
||||
public LinearLayout layoutMessage;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_message, null);
|
||||
|
||||
view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewContact);
|
||||
view.txtViewContact = (TextView) convertView.findViewById(R.id.textViewContact);
|
||||
view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewLastDate);
|
||||
view.txtViewLastMsg = (TextView) convertView.findViewById(R.id.textViewLastMsg);
|
||||
view.layoutMessage = (LinearLayout) convertView.findViewById(R.id.layoutMessage);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
view.imgViewContact.setImageResource(R.drawable.peopleblue_large);
|
||||
//view.imgViewContact.setImageResource(R.drawable.peopleblue);
|
||||
view.txtViewContact.setText(Contact.getNameForRadioID(AppParams.listContacts, listMessages.get(position).radioID)+ " :");
|
||||
if(listMessages.get(position).message.length() > 25)
|
||||
view.txtViewLastMsg.setText(listMessages.get(position).message.substring(0, 25) + "...");
|
||||
else
|
||||
view.txtViewLastMsg.setText(listMessages.get(position).message);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss",Locale.getDefault());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
Date date = new Date(listMessages.get(position).timeGMT * 1000);
|
||||
|
||||
if(date.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm", Locale.getDefault());
|
||||
|
||||
// set gmt time
|
||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
view.txtViewDateTime.setText(sdf.format(date));
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
}
|
@ -0,0 +1,328 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.activities.AbstractRecordingsActivity;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.libpad.PadRecording;
|
||||
|
||||
public class PadRecordingsGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<PadRecording> listRecordings;
|
||||
private ArrayList<Boolean> recordingExists;
|
||||
private ArrayList<Boolean> playingPositions;
|
||||
private Activity activity;
|
||||
private Context context;
|
||||
private int removePosition = -1;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
public PadRecordingsGridViewAdapter(Activity activity, Context context, ArrayList<PadRecording> listRecordings)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.context = context;
|
||||
this.listRecordings = listRecordings;
|
||||
|
||||
this.recordingExists = new ArrayList<Boolean>();
|
||||
for(int i=0; i<listRecordings.size(); i++)
|
||||
recordingExists.add(true);
|
||||
|
||||
playingPositions = new ArrayList<Boolean>();
|
||||
for(int i=0; i<listRecordings.size(); i++)
|
||||
playingPositions.add(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listRecordings.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PadRecording getItem(int position) {
|
||||
return listRecordings.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ArrayList<PadRecording> getRecordings() {
|
||||
return listRecordings;
|
||||
}
|
||||
|
||||
/** Define Row Template */
|
||||
public static class ViewHolder
|
||||
{
|
||||
public LinearLayout layoutRecording;
|
||||
public ImageView imageViewPlay, imageViewRecycle;
|
||||
public TextView textViewSender, textViewDuration, textViewDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_recordings, null);
|
||||
view.layoutRecording = (LinearLayout) convertView.findViewById(R.id.layoutRecording);
|
||||
view.imageViewPlay = (ImageView) convertView.findViewById(R.id.imageViewPlay);
|
||||
view.textViewSender = (TextView) convertView.findViewById(R.id.textViewSender);
|
||||
view.textViewDuration = (TextView) convertView.findViewById(R.id.textViewDuration);
|
||||
view.textViewDate = (TextView) convertView.findViewById(R.id.textViewDate);
|
||||
view.imageViewRecycle = (ImageView) convertView.findViewById(R.id.imageViewRecycle);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
hash.put(position, convertView);
|
||||
|
||||
try {
|
||||
//SM.Debug("SIZE EXISTS : " + recordingExists.size() + " | " + playingPositions.size());
|
||||
/* if recording doesn't exists change background */
|
||||
/*
|
||||
if(recordingExists.size()> position && !recordingExists.get(position))
|
||||
view.layoutRecording.setBackgroundColor(0xFFDDDDDD);
|
||||
else
|
||||
*/
|
||||
|
||||
if(playingPositions.size() > position)
|
||||
{
|
||||
/* if recording is not playing let background to white */
|
||||
|
||||
if(!playingPositions.get(position))
|
||||
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
view.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
|
||||
}
|
||||
else
|
||||
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
|
||||
/* change icon according to call type [outgoing or incoming] */
|
||||
if(listRecordings.size() > position)
|
||||
switch(listRecordings.get(position).callType)
|
||||
{
|
||||
case AppParams.MotoAllCall:
|
||||
if(!listRecordings.get(position).isOutgoing)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received_all);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made_all);
|
||||
break;
|
||||
case AppParams.MotoPrivate:
|
||||
if(!listRecordings.get(position).isOutgoing)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
||||
break;
|
||||
case AppParams.MotoGroup:
|
||||
if(!listRecordings.get(position).isOutgoing)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received_group);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made_group);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(IndexOutOfBoundsException ex) {
|
||||
SM.Exception("IndexOutOfBounds Exception [PadRecordingsGridViewAdapter]" + ex.toString());
|
||||
}
|
||||
/*
|
||||
try
|
||||
{
|
||||
if(receivedPositions.get(position))
|
||||
{
|
||||
if(playingPositions.get(position))
|
||||
view.imageViewPlay.setImageResource(R.drawable.play_received);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(playingPositions.get(position))
|
||||
view.imageViewPlay.setImageResource(R.drawable.play_made);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("EXCeptioN", ex.toString());
|
||||
view.imageViewPlay.setImageResource(R.drawable.play);
|
||||
}*/
|
||||
|
||||
/* intercept Recycle click */
|
||||
view.imageViewRecycle.setVisibility(View.GONE);
|
||||
view.imageViewRecycle.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// save the position of the marked record
|
||||
removePosition = position;
|
||||
|
||||
// change the background for marked record
|
||||
View view = (View) hash.get(position);
|
||||
ViewHolder viewHolder = (ViewHolder) view.getTag();
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
((AbstractRecordingsActivity) activity).deleteSelected(position);
|
||||
}
|
||||
});
|
||||
|
||||
String sender = "", name="", initName="";
|
||||
|
||||
for(Contact cont: AppParams.listContacts)
|
||||
{
|
||||
if(cont.id == getItem(position).radioID)
|
||||
{
|
||||
// get name only if callType equals with the one from the ConfigFile
|
||||
if( (getItem(position).callType == AppParams.MotoPrivate && cont.contactType == Contact.PRIVATE)
|
||||
|| (getItem(position).callType == AppParams.MotoGroup && cont.contactType == Contact.GROUP)
|
||||
|| (getItem(position).callType == AppParams.MotoAllCall))
|
||||
// || getItem(position).type == AppParams.AllCall && cont.callType.equals("All Call"))
|
||||
name = cont.name;
|
||||
}
|
||||
if (cont.id == getItem(position).initRadioID) {
|
||||
// get name only if callType equals with the one from the ConfigFile
|
||||
if( (getItem(position).callType == AppParams.MotoPrivate && cont.contactType == Contact.PRIVATE)
|
||||
|| (getItem(position).callType == AppParams.MotoGroup && cont.contactType == Contact.GROUP)
|
||||
|| (getItem(position).callType == AppParams.MotoAllCall))
|
||||
// || getItem(position).type == AppParams.AllCall && cont.callType.equals("All Call"))
|
||||
initName = cont.name;
|
||||
}
|
||||
|
||||
// if call type is Group I should find a private
|
||||
if(getItem(position).callType == AppParams.MotoGroup && (cont.id == getItem(position).initRadioID && cont.contactType == Contact.PRIVATE))
|
||||
initName = cont.name;
|
||||
|
||||
}
|
||||
|
||||
// // set name to All Call if call was made from tabled
|
||||
if(getItem(position).callType == AppParams.MotoAllCall && getItem(position).isOutgoing)
|
||||
sender += context.getResources().getString(R.string.AllCall);
|
||||
else if(getItem(position).callType == AppParams.MotoAllCall) {
|
||||
name = context.getResources().getString(R.string.AllCall);
|
||||
if(initName.length() > 0)
|
||||
sender = name + " [" + initName + "]";
|
||||
else
|
||||
sender = name + " [" + getItem(position).initRadioID + "]";
|
||||
}
|
||||
// add the name/id of the contact that initiated the AllCall
|
||||
else if(name.length() < 1)
|
||||
sender += getItem(position).radioID;
|
||||
else
|
||||
sender += name;
|
||||
|
||||
// add caller name for group call
|
||||
if(listRecordings.get(position).callType == AppParams.MotoGroup)
|
||||
{
|
||||
if(!getItem(position).isOutgoing) {
|
||||
if(initName.length() > 0)
|
||||
sender = name + " [" + initName + "]";
|
||||
else
|
||||
sender = name + " [" + getItem(position).initRadioID + "]";
|
||||
}
|
||||
else
|
||||
sender = name;
|
||||
}
|
||||
// for private call that was received I have to get the id from the initRadioID
|
||||
else if(listRecordings.get(position).callType == AppParams.MotoPrivate)
|
||||
{
|
||||
if(!getItem(position).isOutgoing && initName.length()>0)
|
||||
sender = initName;
|
||||
else if (!getItem(position).isOutgoing)
|
||||
sender += getItem(position).initRadioID + "";
|
||||
}
|
||||
|
||||
view.textViewSender.setText(sender);
|
||||
view.textViewDuration.setText("[" + listRecordings.get(position).duration + " sec]");
|
||||
|
||||
/* Add call Date */
|
||||
Date date = new Date(getItem(position).timeGMT * 1000);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
if(date.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm", Locale.getDefault());
|
||||
|
||||
// set gmt time
|
||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
view.textViewDate.setText(sdf.format(date));
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
/** Reset row background when recycle was canceled */
|
||||
public void cancelDelete()
|
||||
{
|
||||
View view = (View) hash.get(removePosition);
|
||||
if(recordingExists.get(removePosition))
|
||||
view.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
view.setBackgroundColor(0xFFDDDDDD);
|
||||
|
||||
removePosition = -1;
|
||||
}
|
||||
|
||||
|
||||
/** Get the View for one row in the GridView */
|
||||
public View getView(int position)
|
||||
{
|
||||
return (View) hash.get(position);
|
||||
}
|
||||
|
||||
|
||||
/** Change playing recording background */
|
||||
public void changePlaying(int position, boolean playing)
|
||||
{
|
||||
// change value in the vector
|
||||
playingPositions.set(position, playing);
|
||||
|
||||
// make changes in the UI //
|
||||
try {
|
||||
PadRecordingsGridViewAdapter.ViewHolder viewHolder = (PadRecordingsGridViewAdapter.ViewHolder) getView(position).getTag();
|
||||
if(!playing)
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
}
|
||||
catch (NullPointerException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,254 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.activities.AbstractRecordingsActivity;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.Recording;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class RecordingsGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Recording> listRecordings;
|
||||
private ArrayList<Boolean> recordingExists;
|
||||
private ArrayList<Boolean> playingPositions;
|
||||
private Activity activity;
|
||||
private Context context;
|
||||
private int removePosition = -1;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
public RecordingsGridViewAdapter(Activity activity, Context context, ArrayList<Recording> listRecordings, ArrayList<Boolean> recordingExists)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.context = context;
|
||||
this.listRecordings = listRecordings;
|
||||
this.recordingExists = recordingExists;
|
||||
|
||||
playingPositions = new ArrayList<Boolean>();
|
||||
for(int i=0; i<recordingExists.size(); i++) {
|
||||
playingPositions.add(false);
|
||||
|
||||
listRecordings.get(i).date = listRecordings.get(i).startGMT;
|
||||
listRecordings.get(i).duration = listRecordings.get(i).endGMT - listRecordings.get(i).startGMT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listRecordings.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recording getItem(int position) {
|
||||
return listRecordings.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Define Row Template */
|
||||
public static class ViewHolder
|
||||
{
|
||||
public LinearLayout layoutRecording;
|
||||
public ImageView imageViewPlay, imageViewRecycle;
|
||||
public TextView textViewSender, textViewDuration, textViewDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_recordings, null);
|
||||
view.layoutRecording = (LinearLayout) convertView.findViewById(R.id.layoutRecording);
|
||||
view.imageViewPlay = (ImageView) convertView.findViewById(R.id.imageViewPlay);
|
||||
view.textViewSender = (TextView) convertView.findViewById(R.id.textViewSender);
|
||||
view.textViewDuration = (TextView) convertView.findViewById(R.id.textViewDuration);
|
||||
view.textViewDate = (TextView) convertView.findViewById(R.id.textViewDate);
|
||||
view.imageViewRecycle = (ImageView) convertView.findViewById(R.id.imageViewRecycle);
|
||||
view.imageViewRecycle.setVisibility(View.GONE);
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
hash.put(position, convertView);
|
||||
|
||||
|
||||
|
||||
/* if recording doesn't exists change background */
|
||||
if(!recordingExists.get(position))
|
||||
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
{
|
||||
/* if recording is not playing let background to white */
|
||||
if(!playingPositions.get(position))
|
||||
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
view.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
}
|
||||
|
||||
/* change icon according to call type [outgoing or incoming] */
|
||||
SM.Exception("REC TYPE : " + listRecordings.get(position).type);
|
||||
switch(listRecordings.get(position).type)
|
||||
{
|
||||
case AppParams.AllCall:
|
||||
if(listRecordings.get(position).destinationRadioID == 0)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received_all);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made_all);
|
||||
break;
|
||||
case AppParams.PrivateCall:
|
||||
if(listRecordings.get(position).destinationRadioID == 0)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
||||
break;
|
||||
case AppParams.GroupCall:
|
||||
if(listRecordings.get(position).destinationRadioID == 0)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received_group);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made_group);
|
||||
break;
|
||||
}
|
||||
/*
|
||||
try
|
||||
{
|
||||
if(receivedPositions.get(position))
|
||||
{
|
||||
if(playingPositions.get(position))
|
||||
view.imageViewPlay.setImageResource(R.drawable.play_received);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(playingPositions.get(position))
|
||||
view.imageViewPlay.setImageResource(R.drawable.play_made);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("EXCeptioN", ex.toString());
|
||||
view.imageViewPlay.setImageResource(R.drawable.play);
|
||||
}*/
|
||||
|
||||
/* intercept Recycle click */
|
||||
view.imageViewRecycle.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// save the position of the marked record
|
||||
removePosition = position;
|
||||
|
||||
// change the background for marked record
|
||||
View view = (View) hash.get(position);
|
||||
ViewHolder viewHolder = (ViewHolder) view.getTag();
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
((AbstractRecordingsActivity) activity).deleteSelected(position);
|
||||
}
|
||||
});
|
||||
|
||||
// set recording image
|
||||
if(getItem(position).NameForDisplay.equals(AppParams.USERNAME))
|
||||
view.imageViewPlay.setImageDrawable(context.getResources().getDrawable(R.drawable.call_made_group));
|
||||
else
|
||||
view.imageViewPlay.setImageDrawable(context.getResources().getDrawable(R.drawable.call_received_group));
|
||||
|
||||
view.textViewSender.setText(getItem(position).NameForDisplay);
|
||||
view.textViewDuration.setText("[" + getItem(position).duration + " sec]");
|
||||
|
||||
/* Add call Date */
|
||||
Date date = new Date();
|
||||
date.setTime(listRecordings.get(position).date * 1000);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
|
||||
|
||||
if(date.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm");
|
||||
|
||||
// set gmt time
|
||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
view.textViewDate.setText(sdf.format(date));
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
/** Reset row background when recycle was canceled */
|
||||
public void cancelDelete()
|
||||
{
|
||||
View view = (View) hash.get(removePosition);
|
||||
if(recordingExists.get(removePosition))
|
||||
view.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
view.setBackgroundColor(0xFFDDDDDD);
|
||||
|
||||
removePosition = -1;
|
||||
}
|
||||
|
||||
|
||||
/** Get the View for one row in the GridView */
|
||||
public View getView(int position)
|
||||
{
|
||||
return (View) hash.get(position);
|
||||
}
|
||||
|
||||
|
||||
/** Change playing recording background */
|
||||
public void changePlaying(int position, boolean playing)
|
||||
{
|
||||
// change value in the vector
|
||||
playingPositions.set(position, playing);
|
||||
|
||||
RecordingsGridViewAdapter.ViewHolder viewHolder = (RecordingsGridViewAdapter.ViewHolder) getView(position).getTag();
|
||||
if(!playing)
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
|
||||
// update hash
|
||||
hash.get(position).setTag(viewHolder);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
public class VehiclesGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Vehicle> listVehicles;
|
||||
private ArrayList<Boolean> disabledVehicles;
|
||||
private ArrayList<Boolean> displayedVehicles;
|
||||
private Activity activity;
|
||||
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
public VehiclesGridViewAdapter(Activity activity, Context context, ArrayList<Vehicle> listVehicles, ArrayList<Boolean> disabledVehicles)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listVehicles = listVehicles;
|
||||
this.disabledVehicles = disabledVehicles;
|
||||
|
||||
// set displayed positions to false
|
||||
displayedVehicles = new ArrayList<Boolean>();
|
||||
for(Vehicle veh: listVehicles)
|
||||
{
|
||||
if(AppParams.DEMO && (veh.sc_id == 101 || veh.sc_id == 102))
|
||||
displayedVehicles.add(true);
|
||||
else
|
||||
displayedVehicles.add(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listVehicles.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vehicle getItem(int position) {
|
||||
return listVehicles.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Define Row Template */
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewIcon, imgViewChecked;
|
||||
public TextView txtViewName;
|
||||
public LinearLayout layoutVehicle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_vehicle, null);
|
||||
|
||||
view.imgViewIcon = (ImageView) convertView.findViewById(R.id.imageViewIcon);
|
||||
view.txtViewName = (TextView) convertView.findViewById(R.id.textViewName);
|
||||
view.imgViewChecked = (ImageView) convertView.findViewById(R.id.imageViewChecked);
|
||||
view.layoutVehicle = (LinearLayout) convertView.findViewById(R.id.layoutVehicle);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
hash.put(position, convertView);
|
||||
|
||||
/* if recording disabled change background */
|
||||
try
|
||||
{
|
||||
if(!disabledVehicles.get(position))
|
||||
view.layoutVehicle.setBackgroundColor(0xFFDDDDDD);
|
||||
else
|
||||
view.layoutVehicle.setBackgroundColor(0xFFFFFFFF);
|
||||
|
||||
}
|
||||
catch(IndexOutOfBoundsException ex) {
|
||||
view.layoutVehicle.setBackgroundColor(0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/* set vehicle name and icon */
|
||||
view.imgViewIcon.setImageResource(listVehicles.get(position).getSmallIcon());
|
||||
view.txtViewName.setText(listVehicles.get(position).name);
|
||||
|
||||
/* set checked or not */
|
||||
if(displayedVehicles.get(position))
|
||||
view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Get the View for one row in the GridView */
|
||||
public View getView(int position)
|
||||
{
|
||||
return (View) hash.get(position);
|
||||
}
|
||||
|
||||
/** Change all vehicles checkBox */
|
||||
public void changeDisplayAll(boolean display)
|
||||
{
|
||||
for(int i=0; i<listVehicles.size(); i++)
|
||||
displayedVehicles.set(i, display);
|
||||
|
||||
for(int i=0; i<hash.size(); i++)
|
||||
{
|
||||
// change value in the vector
|
||||
displayedVehicles.set(i, display);
|
||||
|
||||
// make changes in the UI //
|
||||
ViewHolder viewHolder = (ViewHolder) getView(i).getTag();
|
||||
if(viewHolder!=null)
|
||||
{
|
||||
if(display)
|
||||
viewHolder.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
viewHolder.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Change displayed vehicle checkBox */
|
||||
public void changeDisplayed(int position, boolean display)
|
||||
{
|
||||
// change value in the vector
|
||||
displayedVehicles.set(position, display);
|
||||
|
||||
// make changes in the UI //
|
||||
ViewHolder viewHolder = (ViewHolder) getView(position).getTag();
|
||||
if(display)
|
||||
viewHolder.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
viewHolder.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
}
|
||||
|
||||
/** Change disabled vehicle background */
|
||||
public void changeDisabled(int position, boolean disabled)
|
||||
{
|
||||
// change value in the vector
|
||||
disabledVehicles.set(position, disabled);
|
||||
|
||||
// make changes in the UI //
|
||||
ViewHolder viewHolder = (ViewHolder) getView(position).getTag();
|
||||
if(disabled)
|
||||
viewHolder.layoutVehicle.setBackgroundColor(0xFFDDDDDD);
|
||||
else
|
||||
viewHolder.layoutVehicle.setBackgroundColor(0xFFFFFFFF);
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.radio.ZoneChannel;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ZoneChannelComboBoxAdapter extends ArrayAdapter<ZoneChannel>{
|
||||
|
||||
private static final int TYPE_ZONE = 0;
|
||||
private static final int TYPE_CHANNEL = 1;
|
||||
private static final int TYPE_MAX_COUNT = 2;
|
||||
|
||||
|
||||
private Context context;
|
||||
int layoutResourceId;
|
||||
private ArrayList<ZoneChannel> listValues;
|
||||
|
||||
public ZoneChannelComboBoxAdapter(Context context, int textViewResourceId, ArrayList<ZoneChannel> listValues) {
|
||||
super(context, textViewResourceId, listValues);
|
||||
this.context = context;
|
||||
this.layoutResourceId = textViewResourceId;
|
||||
this.listValues = listValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return listValues.get(position).isSection() ? TYPE_ZONE : TYPE_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return TYPE_MAX_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listValues.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneChannel getItem(int position) {
|
||||
return listValues.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
if(getItemViewType(position) == TYPE_ZONE)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public View getCustomView(int position, View convertView, ViewGroup parent) {
|
||||
ImagesSpinnerHolder holder = null;
|
||||
int type = getItemViewType(position);
|
||||
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||||
|
||||
if(convertView == null) {
|
||||
holder = new ImagesSpinnerHolder();
|
||||
|
||||
switch (type) {
|
||||
case TYPE_ZONE:
|
||||
convertView = inflater.inflate(R.layout.combobox_section_header, parent, false);
|
||||
holder.title = (TextView) convertView.findViewById(R.id.txtHeader);
|
||||
break;
|
||||
|
||||
case TYPE_CHANNEL:
|
||||
convertView = inflater.inflate(R.layout.combobox_row, parent, false);
|
||||
holder.textSpinner = (TextView)convertView.findViewById(R.id.text);
|
||||
holder.imgSpinner = (ImageView)convertView.findViewById(R.id.icon);
|
||||
holder.imgSpinner.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
convertView.setTag(holder);
|
||||
}
|
||||
else
|
||||
holder = (ImagesSpinnerHolder) convertView.getTag();
|
||||
|
||||
switch(type) {
|
||||
case TYPE_ZONE:
|
||||
holder.title.setText(listValues.get(position).getZone().ZoneName);
|
||||
|
||||
break;
|
||||
|
||||
case TYPE_CHANNEL:
|
||||
holder.textSpinner.setText(listValues.get(position).getChannel().chName);
|
||||
holder.imgSpinner.setImageResource(R.drawable.channel_small);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
View row = convertView;
|
||||
|
||||
|
||||
if(row == null) {
|
||||
// check if section header -> isSection will return true
|
||||
if(sectionList.get(position))
|
||||
{
|
||||
row = inflater.inflate(R.layout.spinner_header, parent, false);
|
||||
holder.title = (TextView) row.findViewById(R.id.txtHeader);
|
||||
holder.title.setText(listValues.get(position).getZone().ZoneName);
|
||||
}
|
||||
else
|
||||
{
|
||||
row = inflater.inflate(R.layout.spinner, parent, false);
|
||||
holder.textSpinner = (TextView)row.findViewById(R.id.language);
|
||||
holder.imgSpinner = (ImageView)row.findViewById(R.id.icon);
|
||||
holder.imgSpinner.setVisibility(View.INVISIBLE);
|
||||
|
||||
holder.textSpinner.setText(listValues.get(position).getChannel().chName);
|
||||
holder.imgSpinner.setImageResource(R.drawable.channel_small);
|
||||
}
|
||||
|
||||
row.setTag(holder);
|
||||
}
|
||||
else {
|
||||
|
||||
holder = (ImagesSpinnerHolder)row.getTag();
|
||||
if(sectionList.get(position)){
|
||||
if(holder.title!= null)
|
||||
holder.title.setText(listValues.get(position).getZone().ZoneName);
|
||||
}
|
||||
else {
|
||||
if(holder.textSpinner!=null)
|
||||
holder.textSpinner.setText(listValues.get(position).getChannel().chName);
|
||||
if(holder.imgSpinner != null)
|
||||
holder.imgSpinner.setImageResource(R.drawable.channel_small);
|
||||
}
|
||||
}
|
||||
*/
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private class ImagesSpinnerHolder {
|
||||
ImageView imgSpinner;
|
||||
TextView textSpinner;
|
||||
TextView title;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.safemobile.bluetooth;
|
||||
|
||||
import java.util.EventObject;
|
||||
public class BlueEvent extends EventObject {
|
||||
|
||||
private static final long serialVersionUID = -7646259130917916952L;
|
||||
private int PTTclicked;
|
||||
private int Connected;
|
||||
public BlueEvent (Object source, int _PTTclicked, int _connected) {
|
||||
super(source);
|
||||
PTTclicked =_PTTclicked;
|
||||
Connected = _connected;
|
||||
}
|
||||
|
||||
public int PTTclicked()
|
||||
{
|
||||
return PTTclicked;
|
||||
}
|
||||
|
||||
public int Connected()
|
||||
{
|
||||
return Connected;
|
||||
}
|
||||
}
|
@ -0,0 +1,525 @@
|
||||
package com.safemobile.bluetooth;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.safemobile.bluetooth.BlueEvent;
|
||||
import com.safemobile.bluetooth.IBlueListener;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothHeadset;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.media.AudioManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public class BluetoothTether {
|
||||
|
||||
private Context mContext;
|
||||
private Activity activity;
|
||||
private AudioManager audioManager;
|
||||
|
||||
private BluetoothAdapter bluetoothAdapter;
|
||||
private BluetoothHeadset bluetoothHeadset = null;
|
||||
private BluetoothDevice bluetoothDevice= null;
|
||||
|
||||
/* For bluComm Microphone */
|
||||
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
|
||||
private List<IBlueListener> _listeners = new ArrayList<IBlueListener>();
|
||||
private Thread bluCommThread = null;
|
||||
private int bluetoothProfile;
|
||||
private BluetoothProfile bluetoothProxy;
|
||||
private BluetoothSocket bluetoothSocket = null;
|
||||
private InputStream inputStream =null;
|
||||
private Boolean socketIsConnected = false;
|
||||
|
||||
public BluetoothTether(Context context, Activity activity) {
|
||||
this.mContext = context;
|
||||
this.activity = activity;
|
||||
|
||||
audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
|
||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
bluetoothAdapter.getProfileProxy(context, mProfileListener, BluetoothProfile.HEADSET);
|
||||
|
||||
IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
|
||||
IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
|
||||
IntentFilter filter3 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
|
||||
|
||||
activity.registerReceiver(mReceiver, filter1);
|
||||
activity.registerReceiver(mReceiver, filter2);
|
||||
activity.registerReceiver(mReceiver, filter3);
|
||||
|
||||
filter3 = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
activity.registerReceiver(mReceiver, filter3);
|
||||
}
|
||||
|
||||
private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
|
||||
@Override
|
||||
public void onServiceDisconnected(int profile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||
|
||||
SM.Debug("###BluetoothProfile###", "###Connected###");
|
||||
bluetoothProfile = profile;
|
||||
bluetoothProxy = proxy;
|
||||
|
||||
if(profile == BluetoothProfile.HEADSET)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
bluetoothHeadset = (BluetoothHeadset) proxy;
|
||||
List<BluetoothDevice> test;
|
||||
test = bluetoothHeadset.getConnectedDevices();
|
||||
SM.Debug("###BluetoothProfile###", "Headset Connected devices nr: " + test.size());
|
||||
// check if one of three headsets are connected
|
||||
|
||||
for(BluetoothDevice dev : test)
|
||||
bluetoothDevice = dev;
|
||||
/*
|
||||
if(dev.getAddress().contains(AppParams.MotorolaH730) ||
|
||||
dev.getAddress().contains(AppParams.SamsungWep460) || dev.getAddress().contains(AppParams.BluCom))
|
||||
bluetoothDevice = dev;
|
||||
*/
|
||||
|
||||
if(bluetoothDevice!=null)
|
||||
{
|
||||
if(AppParams.TETHERSOUND)
|
||||
{
|
||||
SM.Debug("###BluetoothProfile###", "Device : " + bluetoothDevice.getName() + " [" + bluetoothDevice.getAddress() + "]");
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(mContext,
|
||||
String.format(mContext.getString(R.string.bthDeviceConnected), bluetoothDevice.getName()), Toast.LENGTH_SHORT).show();
|
||||
TetherSound(bluetoothDevice, true);
|
||||
|
||||
//*
|
||||
|
||||
SM.Debug("### blueComm ###", "BLUEcOMMFunction");
|
||||
new connectTask().execute();
|
||||
//blueCommFunction(bluetoothProfile, bluetoothProxy);
|
||||
|
||||
_fireBluetoothTethered(true);
|
||||
|
||||
final Timer t = new Timer();
|
||||
t.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
// start thread that will manage bluComm button press
|
||||
bluCommThread = new Thread(bluCommRunnable);
|
||||
bluCommThread.start();
|
||||
t.cancel();
|
||||
t.purge();
|
||||
}
|
||||
}, 2500);
|
||||
//*/
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Function that will intercept bluComm button press */
|
||||
private void blueCommFunction(int profile, BluetoothProfile proxy) {
|
||||
//Boolean result = true;
|
||||
SM.Debug("################");
|
||||
if(profile == BluetoothProfile.HEADSET)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// if device connected -> redundant check
|
||||
if(bluetoothDevice != null)
|
||||
{
|
||||
SM.Debug("###HEADSET###","Connected Device Address: " + bluetoothDevice.getAddress());
|
||||
|
||||
final Timer t = new Timer();
|
||||
t.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if(bluetoothDevice!=null)
|
||||
{
|
||||
// create socket and then connect to it
|
||||
bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(MY_UUID);
|
||||
bluetoothSocket.connect();
|
||||
inputStream = bluetoothSocket.getInputStream();
|
||||
SM.Debug("##BTSocketConnected##", "Connection socket ok");
|
||||
socketIsConnected = true;
|
||||
t.cancel();
|
||||
t.purge();
|
||||
}
|
||||
else
|
||||
{
|
||||
t.cancel();
|
||||
t.purge();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
//result = false;
|
||||
//SM.Exception("###BTSocketError###", e.toString());
|
||||
socketIsConnected = false;
|
||||
if(bluetoothSocket!=null)
|
||||
try {
|
||||
bluetoothSocket.close();
|
||||
bluetoothSocket = null;
|
||||
}
|
||||
catch (IOException e1) {
|
||||
SM.Exception("###BTSocketError2###", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
SM.Debug("BTSocketCreated", "bluetooth socket creation ended with result: " + socketIsConnected);
|
||||
/*
|
||||
if(result)
|
||||
_fireDataArrived(blueSOCKET,-1);
|
||||
else
|
||||
_fireDataArrived(noBlueSOCKET,-1);
|
||||
*/
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
SM.Exception("###BTSocketInterruptedException###", e.toString());
|
||||
}
|
||||
}
|
||||
}, 500, 3000);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** Runnable to intercept bluComm button press */
|
||||
private Runnable bluCommRunnable = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SM.Debug("####HERE####", "after Profile");
|
||||
|
||||
int read = 0;
|
||||
byte[] buffer = new byte[20];
|
||||
|
||||
while(true)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (socketIsConnected)
|
||||
{
|
||||
|
||||
//SM.Debug("####Socket####", "Socket is Connected");
|
||||
try
|
||||
{
|
||||
//Log.d("DECIVE STATUS", bhead.getConnectionState(mybluedev) + "");
|
||||
read = inputStream.read(buffer);
|
||||
/*
|
||||
String buf = "";
|
||||
for(int k=0;k<read;k++)
|
||||
buf += buffer[k] + " | "; */
|
||||
//SM.Debug("###SocketRead###", buf);
|
||||
if (read==6)
|
||||
{
|
||||
if (buffer[5]==80)
|
||||
{
|
||||
SM.Debug("##BTpttPress##", "PTTON");
|
||||
AppParams.BluCommState = 2;
|
||||
_fireDataArrived(AppParams.PTTON,-1);
|
||||
}
|
||||
if (buffer[5]==82)
|
||||
{
|
||||
SM.Debug("##BTpttPress##", "PTTOFF");
|
||||
AppParams.BluCommState = 1;
|
||||
_fireDataArrived(AppParams.PTTOFF,-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
//Log.d("bigutag", "Error on read");
|
||||
/*
|
||||
cntError++;
|
||||
if (cntError>10)
|
||||
{
|
||||
_fireDataArrived(-1,0);
|
||||
Disconect();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
Log.d("bigutag", "Error on");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** BroadcastReceiver that will manage BlueTooth Connection and Disconnection */
|
||||
public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
if(device!=null)
|
||||
Log.d("BlueTooth State Changed", "DEVICE " + device.getName() + " [" + device.getAddress() + "]" + " is now : " + action );
|
||||
|
||||
// Tether sound only if selected in setup
|
||||
if(AppParams.TETHERSOUND)
|
||||
{
|
||||
if(BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
|
||||
if(intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF)
|
||||
untetherSound(bluetoothDevice);
|
||||
}
|
||||
else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
|
||||
Toast.makeText(mContext, mContext.getString(R.string.bthDeviceFound) + ":" + bluetoothDevice.getName(), Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
|
||||
//Toast.makeText(mContext, "Done searching", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else
|
||||
if(device.getAddress()!= null) /* && (device.getAddress().contains(AppParams.MotorolaH730) ||
|
||||
device.getAddress().contains(AppParams.SamsungWep460) || device.getAddress().contains(AppParams.BluCom)))*/
|
||||
{
|
||||
// save device
|
||||
bluetoothDevice = device;
|
||||
|
||||
// if bluetooth device has disconnected
|
||||
if(action.contains("_DISCONNECTED"))
|
||||
{
|
||||
untetherSound(device);
|
||||
}
|
||||
// if bluetooth device had connected
|
||||
else
|
||||
{
|
||||
new Handler().post(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(mContext,
|
||||
String.format(mContext.getString(R.string.bthDeviceConnected), bluetoothDevice.getName()), Toast.LENGTH_SHORT).show();
|
||||
// set that bluComm Microphone is connected
|
||||
if(bluetoothDevice != null)
|
||||
{
|
||||
TetherSound(bluetoothDevice, true);
|
||||
|
||||
if(bluetoothDevice.getAddress().contains(AppParams.BluCom))
|
||||
{
|
||||
AppParams.BluCommState = 1;
|
||||
//TetherSound(bluetoothDevice, true);
|
||||
|
||||
_fireBluetoothTethered(true);
|
||||
|
||||
// create bluComm socket
|
||||
new connectTask().execute();
|
||||
|
||||
/*
|
||||
* if bluComm is not connected when RadioPad starts i will need
|
||||
* to create the Thread that reads on socket
|
||||
*/
|
||||
|
||||
if(bluCommThread == null)
|
||||
{
|
||||
final Timer t = new Timer();
|
||||
t.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
SM.Exception("bluComm", "creating blu comm thread");
|
||||
// start thread that will manage bluComm button press
|
||||
bluCommThread = new Thread(bluCommRunnable);
|
||||
bluCommThread.start();
|
||||
t.cancel();
|
||||
t.purge();
|
||||
}
|
||||
}, 2500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* UnTether all the sound when a device is disconnected or then the BlueTooth is turned off
|
||||
* @param device The BlueTooth device which needs to be unTethered
|
||||
*/
|
||||
private void untetherSound(final BluetoothDevice device) {
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(device == null)
|
||||
return;
|
||||
|
||||
Toast.makeText(mContext,
|
||||
String.format(mContext.getString(R.string.bthDeviceDisconnected),
|
||||
(bluetoothDevice.getName() == null ? "?" : bluetoothDevice.getName())), Toast.LENGTH_SHORT).show();
|
||||
|
||||
_fireBluetoothTethered(false);
|
||||
// set that bluComm Microphone is disconnected
|
||||
if(bluetoothDevice!=null && bluetoothDevice.getAddress().contains(AppParams.BluCom))
|
||||
AppParams.BluCommState = 0;
|
||||
socketIsConnected = false;
|
||||
Disconect();
|
||||
|
||||
TetherSound(device, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Unregister BroadcastReceiver **/
|
||||
public void UnregisterReceiver()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(mReceiver!=null && activity!=null)
|
||||
{
|
||||
SM.Debug("#### unregister Receiver ### ", "unregister receiver");
|
||||
activity.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
if(mProfileListener!=null)
|
||||
activity.unbindService((ServiceConnection) mProfileListener);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Tether sound */
|
||||
private void TetherSound(final BluetoothDevice device, Boolean enable)
|
||||
{
|
||||
if(enable && AppParams.TETHERSOUND)
|
||||
{
|
||||
final Timer t = new Timer();
|
||||
t.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
SM.Debug("### Start Tethering ###", "tethering " + device.getName());
|
||||
audioManager.setBluetoothScoOn(true);
|
||||
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||
audioManager.startBluetoothSco();
|
||||
t.cancel();
|
||||
t.purge();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
else
|
||||
{
|
||||
audioManager.stopBluetoothSco();
|
||||
audioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
socketIsConnected = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Stop BluetoothTether and unregister BroadcastReceiver */
|
||||
public void Stop()
|
||||
{
|
||||
TetherSound(null, false);
|
||||
UnregisterReceiver();
|
||||
Disconect();
|
||||
}
|
||||
|
||||
public void Disconect()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(bluetoothSocket!=null)
|
||||
bluetoothSocket.close();
|
||||
socketIsConnected = false;
|
||||
socketIsConnected = false;
|
||||
bluetoothDevice = null;
|
||||
bluetoothSocket = null;
|
||||
//bhead.stopVoiceRecognition(mybluedev);
|
||||
//_fireDataArrived(-1,0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
socketIsConnected = false;
|
||||
bluetoothDevice = null;
|
||||
bluetoothSocket = null;
|
||||
SM.Exception("##BTDisconnectError",e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized void addBlueListener( IBlueListener l ) {
|
||||
_listeners.add( l );
|
||||
}
|
||||
|
||||
public synchronized void removeBlueListener( IBlueListener l ) {
|
||||
_listeners.remove( l );
|
||||
}
|
||||
|
||||
private synchronized void _fireDataArrived(int PTTClicked, int Connected)
|
||||
{
|
||||
BlueEvent event = new BlueEvent( this,PTTClicked,Connected);
|
||||
Iterator<IBlueListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (IBlueListener) listeners.next() ).dataRecv(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireBluetoothTethered (boolean isTethered) {
|
||||
Iterator<IBlueListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (IBlueListener) listeners.next() ).bluetoothTethered(isTethered);;
|
||||
}
|
||||
}
|
||||
|
||||
public class connectTask extends AsyncTask<String, Void, Void>
|
||||
{
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(String... params) {
|
||||
SM.Debug("### blueComm ###", "recreate bluComm socket");
|
||||
blueCommFunction(bluetoothProfile, bluetoothProxy);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.safemobile.bluetooth;
|
||||
|
||||
public interface IBlueListener {
|
||||
public void dataRecv( BlueEvent event );
|
||||
public void bluetoothTethered (boolean isTethered);
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
package com.safemobile.database;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
public class DataBaseHelper extends SQLiteOpenHelper{
|
||||
|
||||
//The Android's default system path of your application database.
|
||||
private static String DB_PATH = "/data/data/com.safemobile.motopad/databases/";
|
||||
|
||||
private static String DB_NAME = "safedispatch" + AppParams.Database;
|
||||
|
||||
private SQLiteDatabase myDataBase;
|
||||
|
||||
private final Context myContext;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Takes and keeps a reference of the passed context in order to access to the application assets and resources.
|
||||
* @param context
|
||||
*/
|
||||
public DataBaseHelper(Context context) {
|
||||
|
||||
super(context, DB_NAME, null, 1);
|
||||
this.myContext = context;
|
||||
DB_PATH = "/data/data/" + context.getPackageName().toString() + "/databases/";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a empty database on the system and rewrites it with your own database.
|
||||
* */
|
||||
public void createDataBase() throws IOException{
|
||||
|
||||
boolean dbExist = checkDataBase();
|
||||
|
||||
if(dbExist){
|
||||
//do nothing - database already exist
|
||||
}else{
|
||||
|
||||
//By calling this method and empty database will be created into the default system path
|
||||
//of your application so we are gonna be able to overwrite that database with our database.
|
||||
this.getReadableDatabase();
|
||||
|
||||
try {
|
||||
|
||||
copyDataBase();
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
throw new Error("Error copying database");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the database already exist to avoid re-copying the file each time you open the application.
|
||||
* @return true if it exists, false if it doesn't
|
||||
*/
|
||||
private boolean checkDataBase(){
|
||||
|
||||
SQLiteDatabase checkDB = null;
|
||||
|
||||
try{
|
||||
String myPath = DB_PATH + DB_NAME;
|
||||
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
|
||||
|
||||
}catch(SQLiteException e){
|
||||
|
||||
//database does't exist yet.
|
||||
|
||||
}
|
||||
|
||||
if(checkDB != null){
|
||||
|
||||
checkDB.close();
|
||||
|
||||
}
|
||||
|
||||
return checkDB != null ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies your database from your local assets-folder to the just created empty database in the
|
||||
* system folder, from where it can be accessed and handled.
|
||||
* This is done by transfering bytestream.
|
||||
* */
|
||||
private void copyDataBase() throws IOException{
|
||||
|
||||
//Open your local db as the input stream
|
||||
InputStream myInput = myContext.getAssets().open(DB_NAME);
|
||||
|
||||
// Path to the just created empty db
|
||||
String outFileName = DB_PATH + DB_NAME;
|
||||
|
||||
//Open the empty db as the output stream
|
||||
OutputStream myOutput = new FileOutputStream(outFileName);
|
||||
|
||||
//transfer bytes from the inputfile to the outputfile
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = myInput.read(buffer))>0){
|
||||
myOutput.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
//Close the streams
|
||||
myOutput.flush();
|
||||
myOutput.close();
|
||||
myInput.close();
|
||||
|
||||
}
|
||||
|
||||
public SQLiteDatabase openDataBase(Boolean readonly) throws SQLException{
|
||||
|
||||
//Open the database
|
||||
String myPath = DB_PATH + DB_NAME;
|
||||
if(readonly)
|
||||
return myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
|
||||
else
|
||||
return myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
|
||||
if(myDataBase != null)
|
||||
myDataBase.close();
|
||||
|
||||
super.close();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
}
|
||||
|
||||
// Add your public helper methods to access and get content from the database.
|
||||
// You could return cursors by doing "return myDataBase.query(....)" so it'd be easy
|
||||
// to you to create adapters for your views.
|
||||
|
||||
}
|
@ -0,0 +1,639 @@
|
||||
package com.safemobile.database;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.Recording;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.SMS;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
import com.safemobile.lib.radio.Channel;
|
||||
import com.safemobile.lib.radio.Zone;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.provider.BaseColumns;
|
||||
import android.util.Log;
|
||||
|
||||
public class DatabaseCommunication {
|
||||
/* Database */
|
||||
private SQLiteDatabase database;
|
||||
private DataBaseHelper myDbHelper;
|
||||
private boolean first = false, READONLY = false;;
|
||||
private Context context;
|
||||
|
||||
public DatabaseCommunication(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
// open database Connection
|
||||
public void openConnection()
|
||||
{
|
||||
// start database connection
|
||||
myDbHelper = new DataBaseHelper(context);
|
||||
try
|
||||
{
|
||||
myDbHelper.createDataBase();
|
||||
Log.d("CONNECT", "Succes connection");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
throw new Error("Unable to create database");
|
||||
}
|
||||
// end database connection
|
||||
|
||||
myDbHelper = new DataBaseHelper(context);
|
||||
|
||||
try {
|
||||
if(database!=null)
|
||||
database.close();
|
||||
database = myDbHelper.openDataBase(READONLY);
|
||||
Log.d("CONNECT", "Opened Connection");
|
||||
|
||||
}catch(SQLException sqle){
|
||||
first = true;
|
||||
//throw sqle;
|
||||
}
|
||||
|
||||
if(first)
|
||||
{
|
||||
try {
|
||||
if(database!=null)
|
||||
database.close();
|
||||
database = myDbHelper.openDataBase(READONLY);
|
||||
Log.d("CONNECT", "Opened Connection");
|
||||
|
||||
}catch(SQLException sqle){
|
||||
first = false;
|
||||
//throw sqle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// close database Connection
|
||||
public void closeConnection()
|
||||
{
|
||||
database.close();
|
||||
}
|
||||
|
||||
public boolean isOpen()
|
||||
{
|
||||
if(database!=null)
|
||||
return database.isOpen();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// get all vehicles
|
||||
public ArrayList<Vehicle> getAllVehicle()
|
||||
{
|
||||
ArrayList<Vehicle> allVehicles = new ArrayList<Vehicle>();
|
||||
|
||||
// build iterator
|
||||
Cursor cursor = null;
|
||||
if(database == null)
|
||||
Log.d("NULL", "Database is null");
|
||||
else
|
||||
{
|
||||
cursor = database.rawQuery("SELECT * from vehicle",new String [] {});
|
||||
Log.d("CURSOR", "cursor created");
|
||||
|
||||
cursor.moveToFirst();
|
||||
while (cursor.isAfterLast() == false)
|
||||
{
|
||||
//old = new Vehicle(int lp, String name, long driver_id, int time_route, int GPS_reporting_interval, int is_stolen)
|
||||
// new = Vehicle(int sc_id, String imei, int lp, String name, long driver_id, int time_route, int GPS_reporting_interval, int is_stolen)
|
||||
allVehicles.add(new Vehicle(0, "imei", cursor.getInt(1), cursor.getString(2), cursor.getInt(3), cursor.getInt(4), cursor.getInt(5), cursor.getInt(6)));
|
||||
// move to next record
|
||||
cursor.moveToNext();
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
allVehicles.add(new Vehicle(0, "imei", 1, "Demo103", 89, 0, 0, 0));
|
||||
allVehicles.add(new Vehicle(0, "imei", 1, "Demo104", 101, 0, 0, 0));
|
||||
allVehicles.add(new Vehicle(0, "imei", 1, "Demo105", 95, 0, 0, 0));
|
||||
allVehicles.add(new Vehicle(0, "imei", 1, "Demo106", 118, 0, 0, 0));
|
||||
allVehicles.add(new Vehicle(0, "imei", 1, "Demo107", 111, 0, 0, 0));
|
||||
|
||||
return allVehicles;
|
||||
}
|
||||
|
||||
|
||||
// get all users
|
||||
public ArrayList<SMS> getAllSMS()
|
||||
{
|
||||
ArrayList<SMS> allSMS = new ArrayList<SMS>();
|
||||
Cursor cursor = null;
|
||||
if(database == null)
|
||||
SM.Debug("DBQuery","Database is null");
|
||||
else
|
||||
{
|
||||
cursor = database.rawQuery("SELECT _id, timeGMT, imei_sour, imei_dest, mess, status from SMS",new String [] {});
|
||||
cursor.moveToFirst();
|
||||
while (cursor.isAfterLast() == false)
|
||||
{
|
||||
SMS sms = new SMS();//cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getInt(5), cursor.getInt(6));
|
||||
sms.idx =cursor.getInt(0);
|
||||
sms.timeGMT = cursor.getInt(1);
|
||||
sms.sc_id_sour = cursor.getInt(2);
|
||||
sms.sc_id_dest = cursor.getInt(3);
|
||||
sms.mess = cursor.getString(4);
|
||||
sms.status = cursor.getInt(5);
|
||||
sms.seq_idx = "";
|
||||
|
||||
allSMS.add(sms);
|
||||
// move to next record
|
||||
cursor.moveToNext();
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
return allSMS;
|
||||
}
|
||||
|
||||
public ArrayList<SMS> getSMS_4Imei(long imei)
|
||||
{
|
||||
ArrayList<SMS> allSMS = new ArrayList<SMS>();
|
||||
Cursor cursor = null;
|
||||
if(database == null)
|
||||
SM.Debug("DBQuery","Database is null");
|
||||
else
|
||||
{
|
||||
cursor = database.rawQuery("SELECT _id, timeGMT, imei_sour, imei_dest, mess, status from SMS where imei_sour ="+imei+" OR imei_dest ="+imei+" ORDER BY timeGMT ASC",new String [] {});
|
||||
cursor.moveToFirst();
|
||||
while (cursor.isAfterLast() == false)
|
||||
{
|
||||
SMS sms = new SMS();
|
||||
sms.idx =cursor.getInt(0);
|
||||
sms.timeGMT = cursor.getInt(1);
|
||||
sms.sc_id_sour = cursor.getInt(2);
|
||||
sms.sc_id_dest = cursor.getInt(3);
|
||||
sms.mess = cursor.getString(4);
|
||||
sms.status = cursor.getInt(5);
|
||||
sms.seq_idx = "";
|
||||
|
||||
allSMS.add(sms);
|
||||
// move to next record
|
||||
cursor.moveToNext();
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
return allSMS;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public ArrayList<SMS> getAllLastSMS()
|
||||
{
|
||||
ArrayList<SMS> allLastSMS = new ArrayList<SMS>();
|
||||
Cursor cursor = null;
|
||||
if(database == null)
|
||||
SM.Debug("DBQuery","Database is null");
|
||||
else
|
||||
{
|
||||
ArrayList<Integer> imeis= new ArrayList<Integer>();
|
||||
cursor = database.rawQuery("SELECT B.imei FROM (SELECT DISTINCT imei_sour AS imei FROM SMS WHERE imei_sour>0 UNION SELECT DISTINCT imei_dest AS imei FROM SMS WHERE imei_dest>0) AS B",new String [] {});
|
||||
cursor.moveToFirst();
|
||||
while (cursor.isAfterLast() == false)
|
||||
{
|
||||
/*
|
||||
Integer imei_sour =cursor.getInt(0);
|
||||
Integer imei_dest = cursor.getInt(1);
|
||||
|
||||
if(imei_sour != 0)
|
||||
if(!imeis.contains(imei_sour))
|
||||
{
|
||||
imeis.add(imei_sour);
|
||||
}
|
||||
if(imei_dest != 0)
|
||||
if(!imeis.contains(imei_dest))
|
||||
{
|
||||
imeis.add(imei_dest);
|
||||
}
|
||||
*/
|
||||
imeis.add(cursor.getInt(0));
|
||||
// move to next record
|
||||
cursor.moveToNext();
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
for(Integer imei:imeis)
|
||||
{
|
||||
ArrayList<SMS> smss = getSMS_4Imei(imei);
|
||||
if(smss.size() > 0)
|
||||
allLastSMS.add(smss.get(smss.size() - 1));
|
||||
}
|
||||
|
||||
Collections.sort(allLastSMS, new Comparator(){
|
||||
|
||||
public int compare(Object o1, Object o2) {
|
||||
SMS sms1 = (SMS) o1;
|
||||
SMS sms2 = (SMS) o2;
|
||||
if(sms1.timeGMT < sms2.timeGMT)
|
||||
return -1;
|
||||
else if (sms1.timeGMT > sms2.timeGMT)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
// return sms1.timeGMT.compareToIgnoreCase(p2.getFirstName());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
return allLastSMS;
|
||||
}
|
||||
|
||||
public boolean insertSMS(SMS sms)
|
||||
{
|
||||
long id = -1;
|
||||
if(database == null)
|
||||
SM.Debug("DBQuery","Database is null");
|
||||
else
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("timeGMT", sms.timeGMT);
|
||||
values.put("imei_sour", sms.sc_id_sour);
|
||||
values.put("imei_dest", sms.sc_id_dest);
|
||||
values.put("mess", sms.mess);
|
||||
values.put("status", sms.status);
|
||||
id = database.insert("SMS", "", values); //.rawQuery("SELECT imei_sour, imei_dest from SMS",new String [] {});
|
||||
SM.Debug("DBQuery","Database Insert result: " + id);
|
||||
}
|
||||
//INSERT into SMS (timeGMT, imei_sour, imei_dest, mess, status) VALUES( 1324016412, 0, 101, 'two', 1)
|
||||
return (id == -1)? false: true;
|
||||
}
|
||||
|
||||
|
||||
// get all users
|
||||
public ArrayList<Recording> getAllRecordings()
|
||||
{
|
||||
ArrayList<Recording> allRecordings = new ArrayList<Recording>();
|
||||
Cursor cursor = null;
|
||||
if(database == null)
|
||||
SM.Debug("DBQuery","Database is null");
|
||||
else
|
||||
{
|
||||
cursor = database.rawQuery("SELECT _id, id_sour, id_dest, date, duration, filename, type from Recordings order by _id desc",new String [] {});
|
||||
cursor.moveToFirst();
|
||||
while (cursor.isAfterLast() == false)
|
||||
{
|
||||
Recording rec = new Recording();
|
||||
rec.ID =cursor.getInt(0);
|
||||
rec.sourceRadioID = cursor.getInt(1);
|
||||
rec.destinationRadioID = cursor.getInt(2);
|
||||
rec.date = cursor.getInt(3);
|
||||
rec.duration = cursor.getInt(4);
|
||||
rec.filename = cursor.getString(5);
|
||||
rec.type = cursor.getInt(6);
|
||||
|
||||
allRecordings.add(rec);
|
||||
// move to next record
|
||||
cursor.moveToNext();
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
return allRecordings;
|
||||
}
|
||||
|
||||
// get all users
|
||||
public Recording getLastRecording()
|
||||
{
|
||||
Cursor cursor = null;
|
||||
if(database == null)
|
||||
SM.Debug("DBQuery","Database is null");
|
||||
else
|
||||
{
|
||||
cursor = database.rawQuery("SELECT _id, id_sour, id_dest, date, duration, filename, type from Recordings order by _id desc",new String [] {});
|
||||
cursor.moveToFirst();
|
||||
if(cursor.getCount() > 0)
|
||||
{
|
||||
Recording rec = new Recording();
|
||||
rec.ID =cursor.getInt(0);
|
||||
rec.sourceRadioID = cursor.getInt(1);
|
||||
rec.destinationRadioID = cursor.getInt(2);
|
||||
rec.date = cursor.getInt(3);
|
||||
rec.duration = cursor.getInt(4);
|
||||
rec.filename = cursor.getString(5);
|
||||
rec.type = cursor.getInt(6);
|
||||
return rec;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public long insertRecording(Recording rec)
|
||||
{
|
||||
long id = -1;
|
||||
if(database == null)
|
||||
SM.Debug("Database is null");
|
||||
else
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("id_sour", rec.sourceRadioID);
|
||||
values.put("id_dest", rec.destinationRadioID);
|
||||
values.put("date", rec.date);
|
||||
values.put("duration", rec.duration);
|
||||
values.put("filename", rec.filename);
|
||||
values.put("type", rec.type);
|
||||
id = database.insert("Recordings", "", values); //.rawQuery("SELECT imei_sour, imei_dest from SMS",new String [] {});
|
||||
SM.Debug("DBQuery","Database Insert result: " + id);
|
||||
}
|
||||
//INSERT into SMS (timeGMT, imei_sour, imei_dest, mess, status) VALUES( 1324016412, 0, 101, 'two', 1)
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean removeRecording(Recording rec)
|
||||
{
|
||||
long id = -1;
|
||||
if(database == null)
|
||||
SM.Debug("Database is null");
|
||||
else
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("id_sour", rec.sourceRadioID);
|
||||
values.put("id_dest", rec.destinationRadioID);
|
||||
values.put("date", rec.date);
|
||||
values.put("duration", rec.duration);
|
||||
values.put("filename", rec.filename);
|
||||
values.put("type", rec.type);
|
||||
id = database.delete("Recordings", "_id=" + rec.ID, null);
|
||||
SM.Debug("DBQuery","Database Remove result: " + id);
|
||||
}
|
||||
//INSERT into SMS (timeGMT, imei_sour, imei_dest, mess, status) VALUES( 1324016412, 0, 101, 'two', 1)
|
||||
return (id == -1)? false: true;
|
||||
}
|
||||
|
||||
|
||||
// get all Contacts
|
||||
public ArrayList<Contact> getAllContacts(boolean TRBO)
|
||||
{
|
||||
ArrayList<Contact> allContacts = new ArrayList<Contact>();
|
||||
Cursor cursor = null;
|
||||
if(database == null)
|
||||
SM.Debug("DBQuery","Database is null");
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
cursor = database.rawQuery("SELECT _id, call_id, name, call_type from contacts order by call_id asc",new String [] {});
|
||||
if(cursor!=null)
|
||||
{
|
||||
cursor.moveToFirst();
|
||||
while (cursor.isAfterLast() == false)
|
||||
{
|
||||
Contact contact = new Contact();
|
||||
contact.id = cursor.getInt(1);
|
||||
contact.name = cursor.getString(2);
|
||||
String type = cursor.getString(3);
|
||||
if(type.equals("Private Call"))
|
||||
contact.contactType = Contact.PRIVATE;
|
||||
else if (type.equals("Group Call"))
|
||||
contact.contactType = Contact.GROUP;
|
||||
|
||||
allContacts.add(contact);
|
||||
// move to next record
|
||||
cursor.moveToNext();
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
// table doesn't exist so I have to create and populate it
|
||||
createContactsTable();
|
||||
populateContactsTable(TRBO);
|
||||
}
|
||||
}
|
||||
return allContacts;
|
||||
}
|
||||
|
||||
|
||||
// get all Contacts
|
||||
public ArrayList<Zone> getAllZones(boolean TRBO)
|
||||
{
|
||||
ArrayList<Zone> allZones = new ArrayList<Zone>();
|
||||
Cursor cursor = null;
|
||||
if(database == null)
|
||||
SM.Debug("DBQuery","Database is null");
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
cursor = database.rawQuery("SELECT _id, position, name, type, zone_id from zonechannel order by zone_id asc, type desc",new String [] {});
|
||||
if(cursor!=null)
|
||||
{
|
||||
cursor.moveToFirst();
|
||||
ArrayList<Channel> listChannels = new ArrayList<Channel>();
|
||||
|
||||
while (cursor.isAfterLast() == false)
|
||||
{
|
||||
// add zone to list
|
||||
if(cursor.getString(3).equals("zone"))
|
||||
{
|
||||
Zone z = new Zone();
|
||||
z.channelList = new ArrayList<Channel>();
|
||||
z.dbID = cursor.getInt(1);
|
||||
z.ZoneName = cursor.getString(2);
|
||||
z.id = cursor.getInt(4);
|
||||
|
||||
// add channels to zone
|
||||
z.channelList = listChannels;
|
||||
|
||||
// clear channels list
|
||||
listChannels = new ArrayList<Channel>();
|
||||
|
||||
// add zone
|
||||
allZones.add(z);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// add channel to corresponding list
|
||||
Channel c = new Channel();
|
||||
c.id = cursor.getInt(1);
|
||||
c.chName = cursor.getString(2);
|
||||
c.id = cursor.getInt(1);
|
||||
|
||||
// add channel to zone if exists or add it to the list
|
||||
for(Zone zone: allZones)
|
||||
{
|
||||
// if channel is in this zone
|
||||
if(zone.id == cursor.getInt(4))
|
||||
{
|
||||
// create list if not exists
|
||||
if(zone.channelList == null)
|
||||
zone.channelList = new ArrayList<Channel>();
|
||||
|
||||
// add channel to list;
|
||||
zone.channelList.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// move to next record
|
||||
cursor.moveToNext();
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
// table doesn't exist so I have to create and populate it
|
||||
createZoneChannelTable();
|
||||
populateZoneChannelTable(TRBO);
|
||||
}
|
||||
}
|
||||
|
||||
return allZones;
|
||||
}
|
||||
|
||||
|
||||
public void writeConfigFileZonesAndChannels(ArrayList<Zone> zones) {
|
||||
|
||||
// delete all values from zonechannel table
|
||||
database.execSQL("DELETE FROM zonechannel where 1=1");
|
||||
|
||||
for(Zone zone:zones) {
|
||||
// insert zone into database
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (" + zone.id + ",'" + zone.ZoneName + "'," +
|
||||
"'zone'" + "," + zone.id + ")");
|
||||
|
||||
// add channels for current zone
|
||||
for(Channel ch: zone.channelList) {
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (" + ch.id + ",'" + ch.chName + "'," +
|
||||
"'channel'" + "," + ch.id + ")");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeConfigFileContacts(ArrayList<Contact> contacts) {
|
||||
// delete all values from contacts table
|
||||
database.execSQL("DELETE FROM contacts where 1=1");
|
||||
|
||||
for(Contact contact: contacts) {
|
||||
// insert contact into database
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (" + contact.id + ",'" + contact.name +"','" +
|
||||
contact.contactType + "')");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createZoneChannelTable()
|
||||
{
|
||||
// create table
|
||||
String sqlDataStore = "create table if not exists " +
|
||||
"zonechannel" + " ("+ BaseColumns._ID + " integer primary key autoincrement,"
|
||||
+ "position" + " INTEGER ,"
|
||||
+ "name" + " text not null,"
|
||||
+ "type" + " text not null,"
|
||||
+ "zone_id" + " INTEGER not null)";
|
||||
database.execSQL(sqlDataStore);
|
||||
|
||||
}
|
||||
|
||||
public void populateZoneChannelTable(boolean TRBO)
|
||||
{
|
||||
// populate table
|
||||
|
||||
if(TRBO)
|
||||
{
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (1,'Zone1','zone',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (1,'Channel1','channel',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (2,'Channel2','channel',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (3,'Channel3','channel',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (4,'Channel4','channel',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (5,'Channel5','channel',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (6,'Channel6','channel',1)");
|
||||
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (3,'Zone2','zone',3)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (1,'Ch5[Z2]','channel',3)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (2,'Ch6[Z2]','channel',3)");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (1,'Zone1','zone',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (456,'DMO TG1','channel',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (457,'DMO TG2','channel',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (458,'DMO TG3','channel',1)");
|
||||
database.execSQL("INSERT INTO zonechannel (position, name, type, zone_id) VALUES (459,'DMO TG4','channel',1)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createContactsTable()
|
||||
{
|
||||
// create table
|
||||
String sqlDataStore = "create table if not exists " +
|
||||
"contacts" + " ("+ BaseColumns._ID + " integer primary key autoincrement,"
|
||||
+ "call_id" + " INTEGER ,"
|
||||
+ "name" + " text not null,"
|
||||
+ "call_type" + " text not null)";
|
||||
database.execSQL(sqlDataStore);
|
||||
}
|
||||
|
||||
|
||||
public void populateContactsTable(boolean TRBO)
|
||||
{
|
||||
|
||||
if(TRBO)
|
||||
{
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (101,'UNIT101','Private Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (102,'UNIT102','Private Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (103,'UNIT103','Private Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (104,'BASE104','Private Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (114,'BASE114','Private Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (124,'BASE124','Private Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (1,'Call1','Group Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (2,'Call2','Group Call')");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (101,'UNIT101','Private Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (102,'UNIT102','Private Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (103,'UNIT103','Private Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (456,'DMO TG1','Group Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (457,'DMO TG2','Group Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (458,'DMO TG3','Group Call')");
|
||||
database.execSQL("INSERT INTO contacts (call_id, name, call_type) VALUES (459,'DMO TG4','Group Call')");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public long insertContact(Contact contact)
|
||||
{
|
||||
long id = -1;
|
||||
if(database == null)
|
||||
SM.Debug("Database is null");
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("call_id", contact.id);
|
||||
values.put("name", contact.name);
|
||||
values.put("call_type", contact.contactType);
|
||||
id = database.insert("contacts", "", values); //.rawQuery("SELECT imei_sour, imei_dest from SMS",new String [] {});
|
||||
SM.Debug("DBQuery","Database Insert result: " + id);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("DB[Insert Contact]","Could not insert into DB");
|
||||
}
|
||||
}
|
||||
//INSERT into SMS (timeGMT, imei_sour, imei_dest, mess, status) VALUES( 1324016412, 0, 101, 'two', 1)
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package com.safemobile.enums;
|
||||
|
||||
public enum MapType {
|
||||
NONE(0),
|
||||
STYLE_NORMAL(1),
|
||||
SATELLITE(2),
|
||||
TERRAIN(3),
|
||||
HYBRID(4),
|
||||
|
||||
STYLE_RETRO(10),
|
||||
STYLE_GRAYSCALE(11),
|
||||
STYLE_NIGHT(12),
|
||||
STYLE_DARK(13),
|
||||
STYLE_AUBERGINE(14);
|
||||
|
||||
|
||||
private int value;
|
||||
|
||||
|
||||
MapType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert an integer value to the corresponding Map Type enum value
|
||||
* @param x Desired value to be converted
|
||||
* @return Map Type enum value that corresponds to the int value
|
||||
*/
|
||||
public static MapType fromInteger(int x) {
|
||||
switch (x) {
|
||||
case 0:
|
||||
return NONE;
|
||||
case 1:
|
||||
return STYLE_NORMAL;
|
||||
case 2:
|
||||
return SATELLITE;
|
||||
case 3:
|
||||
return TERRAIN;
|
||||
case 4:
|
||||
return HYBRID;
|
||||
case 10:
|
||||
return STYLE_RETRO;
|
||||
case 11:
|
||||
return STYLE_GRAYSCALE;
|
||||
case 12:
|
||||
return STYLE_NIGHT;
|
||||
case 13:
|
||||
return STYLE_DARK;
|
||||
case 14:
|
||||
return STYLE_AUBERGINE;
|
||||
default:
|
||||
return STYLE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a string value to the corresponding GPS Provider enum value
|
||||
* @param mapType Desired value to be converted
|
||||
* @return Map Type enum value that corresponds to the string value
|
||||
*/
|
||||
public static MapType fromString(String mapType) {
|
||||
switch (mapType) {
|
||||
case "NONE":
|
||||
return NONE;
|
||||
case "STYLE_NORMAL":
|
||||
return STYLE_NORMAL;
|
||||
case "SATELLITE":
|
||||
return SATELLITE;
|
||||
case "TERRAIN":
|
||||
return TERRAIN;
|
||||
case "HYBRID":
|
||||
return HYBRID;
|
||||
case "STYLE_RETRO":
|
||||
return STYLE_RETRO;
|
||||
case "STYLE_GRAYSCALE":
|
||||
return STYLE_GRAYSCALE;
|
||||
case "STYLE_NIGHT":
|
||||
return STYLE_NIGHT;
|
||||
case "STYLE_DARK":
|
||||
return STYLE_DARK;
|
||||
case "STYLE_AUBERGINE":
|
||||
return STYLE_AUBERGINE;
|
||||
default:
|
||||
return STYLE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the int value of current Map Type enum instance
|
||||
* @return Corresponding int value of the enum instance
|
||||
*/
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.safemobile.interfaces;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
public class AudioEvent extends EventObject {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private byte[] data;
|
||||
private int len;
|
||||
public AudioEvent(Object source, byte[] _data, int _len) {
|
||||
super(source);
|
||||
data =_data;
|
||||
len = _len;
|
||||
}
|
||||
public byte[] data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public int len()
|
||||
{
|
||||
return len;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.safemobile.interfaces;
|
||||
|
||||
public interface IAudioListener {
|
||||
public void soundReceived( AudioEvent event );
|
||||
public void soundSent( AudioEvent event );
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.safemobile.interfaces;
|
||||
|
||||
import com.safemobile.lib.radio.IncCall;
|
||||
|
||||
public interface ICallStatusListener {
|
||||
|
||||
public void decoded ( IncCall call );
|
||||
public void initiated ( IncCall call );
|
||||
public void inProgress ( IncCall call );
|
||||
public void hangtime ( IncCall call );
|
||||
public void ended ( IncCall call );
|
||||
|
||||
/** Event used when any incoming Call message is received */
|
||||
public void incoming (IncCall call );
|
||||
}
|
210
libSafeMobile/src/main/java/com/safemobile/interfaces/IMap.java
Normal file
210
libSafeMobile/src/main/java/com/safemobile/interfaces/IMap.java
Normal file
@ -0,0 +1,210 @@
|
||||
package com.safemobile.interfaces;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.safemobile.enums.MapType;
|
||||
import com.safemobile.lib.Position;
|
||||
import com.safenet.lib.Geofence;
|
||||
import com.safenet.lib.Landmark;
|
||||
import com.safenet.lib.Unit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by Adi on 3/25/2016.
|
||||
*/
|
||||
public interface IMap {
|
||||
|
||||
interface MapInteraction
|
||||
{
|
||||
void onMapLocationChanged(double latitude, double longitude, float zoomLevel);
|
||||
void onInfoBubbleClosed(long assetId, LatLng position);
|
||||
void onInfoBubbleOpened(long assetId, LatLng position);
|
||||
}
|
||||
|
||||
void setMapInteractionListener(MapInteraction delegate);
|
||||
|
||||
long MYSELF = 0l;
|
||||
long LABEL_START = 16777215;
|
||||
|
||||
|
||||
int MAPBOX = 1;
|
||||
int GOOGLE = 2;
|
||||
int OSM = 3;
|
||||
|
||||
|
||||
/** INTENTS **/
|
||||
String MAP_TERRAIN_REQ = "MAP_TERRAIN_REQ";
|
||||
String MAP_SATELLITE_REQ = "MAP_SATELLITE_REQ";
|
||||
String MAP_NORMAL_REQ = "MAP_NORMAL_REQ";
|
||||
String MAP_HYBRID_REQ = "MAP_HYBRID_REQ";
|
||||
String MAP_SHOW_ME = "MAP_SHOW_ME";
|
||||
String MAP_LOCATION_REQUEST = "MAP_LOCATION_REQUEST";
|
||||
|
||||
/** GOOGLE MAP TYPE **/
|
||||
int MAP_TYPE_NONE = 0;
|
||||
int MAP_TYPE_NORMAL = 1;
|
||||
int MAP_TYPE_SATELLITE = 2;
|
||||
int MAP_TYPE_TERRAIN = 3;
|
||||
int MAP_TYPE_HYBRID = 4;
|
||||
|
||||
/**
|
||||
* Display the contacts that are flaged as onMap to be drawn on the
|
||||
* Google map. The list is available on the AppParams .
|
||||
* The same function will remove previous contacts that were on the map
|
||||
* @param units The list of assets that needs to be displayed
|
||||
*/
|
||||
void showContactsOnMap(ArrayList<Unit> units);
|
||||
|
||||
|
||||
/**
|
||||
* Update the marker icon/location if displayed else do nothing. This method is called
|
||||
* whenever the asset position is changed, or when the asset goes offline/online or in emergency
|
||||
* @param unit The asset that changed the state or position
|
||||
*/
|
||||
void updateMarkerPosition(Unit unit);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Change the map type to one of the following options
|
||||
* GoogleMap.MAP_TYPE_HYBRID
|
||||
* GoogleMap.MAP_TYPE_NORMAL
|
||||
* GoogleMap.MAP_TYPE_SATELLITE
|
||||
* GoogleMap.MAP_TYPE_TERRAIN
|
||||
* @param mapType The mapType value of the map
|
||||
*/
|
||||
void setMapType(MapType mapType);
|
||||
|
||||
|
||||
/**
|
||||
* Change the map type to one of the following options
|
||||
* Style.MAPBOX_STREETS
|
||||
* Style.EMERALD
|
||||
* Style.LIGHT
|
||||
* Style.DARK
|
||||
* Style.SATELLITE
|
||||
* Style.SATELLITE_STREETS
|
||||
* @param mapType The int value of the map
|
||||
*/
|
||||
void setMapType(String mapType);
|
||||
|
||||
|
||||
/**
|
||||
* Center map and then zoom to the location of a specific contact
|
||||
* @param unit The contact which needs to be focused. It contains the
|
||||
* gps location
|
||||
*/
|
||||
void centerZoomContact(Unit unit);
|
||||
|
||||
/**
|
||||
* Center the map on a particular position represented by a LatLng point
|
||||
* @param mapLocation Location to which the map needs to center
|
||||
*/
|
||||
void centerZoomMapOnLocation(LatLng mapLocation);
|
||||
|
||||
|
||||
/**
|
||||
* Center the map on a particular position represented by a LatLng point
|
||||
* @param mapLocation Location to which the map needs to center
|
||||
* @param zoomLevel The zoom at which the map needs to be set
|
||||
*
|
||||
*/
|
||||
void centerZoomMapOnLocation(LatLng mapLocation, float zoomLevel);
|
||||
|
||||
|
||||
/**
|
||||
* Show a custom marker on the map representing the current user
|
||||
* @param position The location at which the user is
|
||||
* @param shouldOpenInfoBubble Specify if the info bubble for the myself location should be opened
|
||||
* @param shouldCenterNow Specify if the map needs to be animated to that location
|
||||
*/
|
||||
void showMyselfOnMap(Position position, boolean shouldOpenInfoBubble,
|
||||
boolean shouldCenterNow);
|
||||
|
||||
|
||||
/**
|
||||
* Hide the marker for myself from the map
|
||||
*/
|
||||
void hideMyselfFromMap();
|
||||
|
||||
|
||||
/**
|
||||
* Open the info bubble for a specific marker
|
||||
* @param markerKey The marker identifier from the hashtable
|
||||
*/
|
||||
void openInfoBubbleForMarker(Long markerKey);
|
||||
|
||||
|
||||
/**
|
||||
* Open the info bubble for the last opened marker if it wasn't closed by the user explicitly
|
||||
*/
|
||||
void openInfoBubble();
|
||||
|
||||
/**
|
||||
* Show or hide the landmarks on the map
|
||||
* @param isShown Boolean that will flag if the landmarks should be
|
||||
* displayed. True is affirmative
|
||||
* @param landmarks The landmarks that needs to be shown, Empty if none
|
||||
*/
|
||||
void onShowLandmarksChangedHandler(boolean isShown, ArrayList<Landmark> landmarks);
|
||||
|
||||
|
||||
/**
|
||||
* Show or hide the geofence on the map
|
||||
* @param isShown Boolean that will flag if the geofence should be
|
||||
* displayed. True is affirmative
|
||||
* @param geofences The geofences that needs to be shown. Empty if none
|
||||
*/
|
||||
void onShowGeofencesChangedHandler(boolean isShown, ArrayList<Geofence> geofences);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Show or hide the traffic on the map
|
||||
* @param isShown Boolean that will flag if the traffic should be
|
||||
* displayed. True is affirmative
|
||||
*/
|
||||
void onShowTrafficChangedHandler(boolean isShown);
|
||||
|
||||
|
||||
/**
|
||||
* Handler for when the map is ready and bound to the UI
|
||||
* @param map The received map
|
||||
* @param layoutInflater Inflater needed to inflate the InfoBubble
|
||||
*/
|
||||
void onMapReceived(Object map, LayoutInflater layoutInflater);
|
||||
|
||||
|
||||
/**
|
||||
* Handler for when the map is ready and bound to the UI
|
||||
* @param map The received map
|
||||
* @param tileServer Map tile server used for OSM or other private environments
|
||||
*/
|
||||
void onMapReceived(Object map, String tileServer);
|
||||
|
||||
/**
|
||||
* Change the map center and zoom level to allow the display of all the displayed markers
|
||||
*/
|
||||
void panZoomMap();
|
||||
|
||||
|
||||
/**
|
||||
* On activity paused
|
||||
*/
|
||||
void onPause();
|
||||
|
||||
/**
|
||||
* On activity resumed
|
||||
*/
|
||||
void onResume();
|
||||
|
||||
/**
|
||||
* Handler for when the map needs to be refreshed/invalidated
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
|
||||
boolean isMapAvailable();
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.safemobile.interfaces;
|
||||
|
||||
public interface IPlaybackListener {
|
||||
public void finishedPlaying();
|
||||
public void startPlaying();
|
||||
public void stopedPlaying();
|
||||
public void failedPlaying();
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.safemobile.interfaces;
|
||||
|
||||
public interface ITCPListener {
|
||||
public void onLoginReceived( TCPEvent event );
|
||||
public void onGPSReceived( TCPEvent event );
|
||||
public void onVehiclesReceived( TCPEvent event );
|
||||
|
||||
public void onLastSMSsReceived( TCPEvent event );
|
||||
public void onSMSReceived( TCPEvent event );
|
||||
public void onSMSAckReceived( TCPEvent event );
|
||||
public void onNewSMSReceived( TCPEvent event );
|
||||
|
||||
public void onLastPositionsReceived( TCPEvent event );
|
||||
public void onRadioMsgReceived( TCPEvent event );
|
||||
public void onHistoryPositionsReceived( TCPEvent event );
|
||||
public void onHistoryPositionsCountReceived( TCPEvent event );
|
||||
public void onAlarmsReceived( TCPEvent event );
|
||||
public void onAlarmAckReceived(TCPEvent event);
|
||||
public void alarmLiveRecv(TCPEvent event);
|
||||
|
||||
public void onRecordingPlayReceived(TCPEvent event);
|
||||
public void onPollReceived(TCPEvent event);
|
||||
public void onConnectionReplyReceived (TCPEvent event);
|
||||
|
||||
public void onContactsListReceived (TCPEvent event);
|
||||
public void onTextMessagesListReceived (TCPEvent event);
|
||||
public void onRecordingsListReceived(TCPEvent event);
|
||||
|
||||
public void onPONGReceived();
|
||||
public void onTCPConnectionDown(boolean previuosWasConnectionUp);
|
||||
public void onTCPConnectionUp(boolean previuosWasConnectionUp);
|
||||
public void onTCPConnectionStatusReceived(boolean isConnectionUp, boolean previuosWasConnectionUp);
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.safemobile.interfaces;
|
||||
|
||||
public interface IUDPListener {
|
||||
public void dataRecv( UDPevent event );
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.safemobile.interfaces;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
import com.safemobile.lib.TCPmsg;
|
||||
|
||||
public class TCPEvent extends EventObject {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private TCPmsg _msg;
|
||||
|
||||
public TCPEvent(Object source, TCPmsg msg ) {
|
||||
super( source );
|
||||
_msg = msg;
|
||||
}
|
||||
public TCPmsg msg() {
|
||||
return _msg;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.safemobile.interfaces;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
public class UDPevent extends EventObject {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private byte[] data;
|
||||
private int len;
|
||||
public UDPevent(Object source, byte[] _data, int _len) {
|
||||
super(source);
|
||||
data =_data;
|
||||
len = _len;
|
||||
}
|
||||
public byte[] data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public int len()
|
||||
{
|
||||
return len;
|
||||
}
|
||||
}
|
47
libSafeMobile/src/main/java/com/safemobile/lib/Alarm.java
Normal file
47
libSafeMobile/src/main/java/com/safemobile/lib/Alarm.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class Alarm {
|
||||
public int idx;
|
||||
public String unitName;
|
||||
public int type;
|
||||
public String typestr;
|
||||
public String description;
|
||||
public long timeGMT;
|
||||
public int ack;
|
||||
public long sc_id;
|
||||
|
||||
public Alarm()
|
||||
{
|
||||
}
|
||||
|
||||
public Alarm(int idx, int type, String description, int timeGMT, int ack, int sc_id)
|
||||
{
|
||||
this.idx = idx;
|
||||
this.sc_id = sc_id;
|
||||
this.type = type;
|
||||
this.description = description;
|
||||
this.timeGMT = timeGMT;
|
||||
this.ack = ack;
|
||||
switch (this.type)
|
||||
{
|
||||
case 0: typestr = "emergency";
|
||||
break;
|
||||
case 1: typestr = "landmark";
|
||||
break;
|
||||
case 2: typestr = "zone";
|
||||
break;
|
||||
case 3: typestr = "speed";
|
||||
break;
|
||||
case 4: typestr = "telemetry";
|
||||
break;
|
||||
default:
|
||||
typestr = "emergency";
|
||||
}
|
||||
this.unitName = "Empty";
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "idx: " + idx + " | sc_id: " + sc_id + " | type: " + type + " | description: " + description + " | timeGMT: " + timeGMT + " | ack:" + ack + " | typestr:" + typestr+" | unitName:" + unitName;
|
||||
}
|
||||
}
|
34
libSafeMobile/src/main/java/com/safemobile/lib/AlarmMSG.java
Normal file
34
libSafeMobile/src/main/java/com/safemobile/lib/AlarmMSG.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AlarmMSG extends TCPmsg {
|
||||
|
||||
public ArrayList<Alarm> alarmList;
|
||||
public static int count=0;
|
||||
public AlarmMSG(TCPmsg tcp) {
|
||||
super(tcp);
|
||||
alarmList = new ArrayList<Alarm>();
|
||||
String date4parsing = super.data;
|
||||
//SM.Debug("SMS date4parsing:"+date4parsing);
|
||||
String[] tempArr = date4parsing.split(";");
|
||||
|
||||
//SM.Debug("SMS tempArr.length:" +tempArr.length);
|
||||
for(int i =0; i<tempArr.length;i++)
|
||||
{
|
||||
String[] tempVeh = tempArr[i].split("&");
|
||||
if(tempVeh.length<6)
|
||||
continue;
|
||||
//int idx, int type, String description, int timeGMT, int ack, int sc_id
|
||||
Alarm alarm = new Alarm(Integer.parseInt(tempVeh[1]),Integer.parseInt(tempVeh[5]),tempVeh[3],Integer.parseInt(tempVeh[4]),
|
||||
Integer.parseInt(tempVeh[0]),Integer.parseInt(tempVeh[2]));
|
||||
|
||||
alarmList.add(alarm);
|
||||
//SM.Debug(alarm.toString());
|
||||
}
|
||||
|
||||
count +=this.alarmList.size();
|
||||
SM.Debug("alarmList size:" +this.alarmList.size() + " total:" +count);
|
||||
}
|
||||
|
||||
}
|
194
libSafeMobile/src/main/java/com/safemobile/lib/AppParams.java
Normal file
194
libSafeMobile/src/main/java/com/safemobile/lib/AppParams.java
Normal file
@ -0,0 +1,194 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import com.safemobile.lib.radio.Channel;
|
||||
import com.safemobile.lib.radio.Emerg;
|
||||
import com.safemobile.lib.radio.IncCall;
|
||||
import com.safemobile.lib.radio.RadioGW;
|
||||
import com.safemobile.lib.radio.RadioStatus;
|
||||
import com.safemobile.lib.radio.Zone;
|
||||
import com.safemobile.lib.radio.Zone_and_channel;
|
||||
import com.safemobile.libpad.PadRecording;
|
||||
import com.safemobile.libpad.PadTextMessage;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
|
||||
public class AppParams {
|
||||
|
||||
public enum EnumCallState {hangTime, callEnd, online, offline, callReceived, callMade };
|
||||
public enum Dialogs {motionless, mandown, firmware, password};
|
||||
public enum Tabs {live, history, radio, message, alarms, recordings, setup};
|
||||
public enum Theme {SAFENET, SAFEDISPATCH, HYTERA, VISION}
|
||||
public enum ActivityResult { logout, restart, exit, tcpDown};
|
||||
|
||||
/* SafeMobile Dispatch */
|
||||
public static ArrayList<User> allUsers = new ArrayList<User>();
|
||||
public static Theme theme = Theme.SAFENET; // the Theme type
|
||||
|
||||
|
||||
/* ***************************************** */
|
||||
/* ********** Radio Status Params ********** */
|
||||
/* ***************************************** */
|
||||
public static RadioStatus crtRadioStatus = new RadioStatus();
|
||||
public static Zone_and_channel crtZoneAndChannel = new Zone_and_channel();
|
||||
public static Emerg crtEmergencyState = new Emerg();
|
||||
public static IncCall crtIncCall = new IncCall();
|
||||
public static PadRecording crtPlayingRecording = new PadRecording();
|
||||
public static ByteBuffer recordingBuffer = null;
|
||||
//public static ArrayList<PadTextMessage> listTextMessages = new ArrayList<PadTextMessage>();
|
||||
public static Hashtable<String, PadTextMessage> hashNotAckMsg = new Hashtable<String, PadTextMessage>();
|
||||
|
||||
// the text message hash table will have the first key the radioID, and the second key the textMessage DB ID
|
||||
public static Hashtable<Long, Hashtable<Long, PadTextMessage>> hashTextMessagesByRadioID = new Hashtable<Long, Hashtable<Long, PadTextMessage>>();
|
||||
|
||||
//public static ArrayList<PadRecording> listRecordings = new ArrayList<PadRecording>();
|
||||
public static Hashtable<Integer, PadRecording> listRecordings = new Hashtable<Integer, PadRecording>();
|
||||
public static ArrayList<Recording> recordings = new ArrayList<Recording>();
|
||||
public static ArrayList<Contact> listContacts = new ArrayList<Contact>();
|
||||
public static ArrayList<Zone> listZones = new ArrayList<Zone>();
|
||||
public static ArrayList<RadioGW> listRadios = new ArrayList<RadioGW>();
|
||||
public static Radio crtRadio = new Radio();
|
||||
public static Zone crtZone = new Zone();
|
||||
public static Channel crtChannel;
|
||||
|
||||
public static PadTextMessage crtSentTextMessage = new PadTextMessage();
|
||||
public static PadTextMessage crtAckedTextMessage = new PadTextMessage();
|
||||
public static PadTextMessage crtReceivedTextMessage = new PadTextMessage();
|
||||
|
||||
public static Contact crtContact = new Contact();
|
||||
public static Contact crtTetraContact = new Contact();
|
||||
public static Contact crtTetraGroup = new Contact();
|
||||
public static PadRecording crtRecording = new PadRecording();
|
||||
|
||||
|
||||
public static final int TRBOO = 1, TETRA = 2, SEPURAA = 3;
|
||||
public static final int NOT_ACK = 1;
|
||||
public static final int ACK = 2;
|
||||
public static int APPLICATION_TYPE = TRBOO; // WILL BE MODIFIED AT CONNECTION
|
||||
public static final String FIRMWARE_VERSION = "2.3.1";
|
||||
|
||||
public static boolean DEMO = false; // DEMO is set by package name (contains OR !contains "demo")
|
||||
|
||||
/** Safenet Login */
|
||||
public static long USERID = -1;
|
||||
public static String USERNAME = "";
|
||||
public static String PASSWORD = "";
|
||||
public static boolean REMEMBER = false;
|
||||
public static String DEFAULT = "";
|
||||
|
||||
//private String[] Types = {"AIR", "RADIOPAD", "MOTOPAD-TRBO", "MOTOPAD-TETRA"};
|
||||
public static String TYPE = "RADIOPAD"; // blue or red version (SafeMobile or AIR version)
|
||||
//public static boolean AIR = false; // blue or red version (SafeMobile or AIR version)
|
||||
public static boolean TABLET = false; // flag if device is a TABLET or PHONE (inconsistent - 06.Nov.2012)
|
||||
public static boolean PAUSED = false; // application status: PAUSED or RUNNING
|
||||
|
||||
public static boolean SEPURA = false;
|
||||
public static boolean PRINTER = false;
|
||||
|
||||
public static int UPDATE_SIZE = 20;
|
||||
|
||||
public static String Database = ""; //"de"; // database language
|
||||
public static boolean online = false;
|
||||
|
||||
/** Tabs */
|
||||
public static Tabs crtTab = Tabs.radio;
|
||||
|
||||
public static int CallState = 3; // tablet state: 7 - Hangtime, 3 - Ended, Other - inCall
|
||||
public static long CallSourId = -1;
|
||||
public static long CallDestId = -1;
|
||||
public static int CallType = 101;
|
||||
public static long selCallId = -1;
|
||||
public static int selCallType = 101;
|
||||
public static long CallStartTime = -1;
|
||||
public static int prevCallState = 4;
|
||||
public static boolean inCall = false;
|
||||
public static boolean externalSource = false;
|
||||
|
||||
/** Configuration File */
|
||||
//public static ConfigFile configFile = null; // config file
|
||||
|
||||
/** Database */
|
||||
//public static DatabaseCommunication databaseCommunication = null;
|
||||
|
||||
/** SharedPreferences */
|
||||
public static SharedPreferences prefs; // project preferences
|
||||
public static String LANGUAGE; // displaying language
|
||||
public static String LANGUAGETMP = "en"; // temporary displayed language
|
||||
public static String STREAM = "MUSIC"; // AudioHandler's AudioTrack default stream
|
||||
public static String SOURCE = "TCP"; // AudioHandler's AudioTrack default source
|
||||
public static boolean EXTERNALMIC = false; // external mic used with what-a-pair systems
|
||||
public static boolean TETHERSOUND = false; // allow BlueTooth tethering
|
||||
public static boolean TRBO = true;
|
||||
public static boolean NOTIFICATIONS = true;
|
||||
public static boolean RECORDINGS = true;
|
||||
public static String RECORDINGS_LOCATION = "Internal Storage";
|
||||
public static boolean MANDOWN = false;
|
||||
public static int MANDOWNTHRESHOLD = 25;
|
||||
public static boolean MOTIONLESS = false;
|
||||
public static int MOTIONLESSTIME = 300;
|
||||
public static int RADIOID = 100;
|
||||
public static String RADIOIP = "192.168.10.40";
|
||||
public static String IP="n/a"; // SafeBridge's IP
|
||||
public static String PORT="13570"; // SafeBridge's PORT
|
||||
public static String PATH = "n/a"; // ConfigFile PATH
|
||||
|
||||
/** BluComm
|
||||
* states : 0 - disconnected; 1 - connected but not pressed; 2 - pressed; */
|
||||
public static int BluCommState = 0; // remembers BluComm Microphone state
|
||||
public static final int PTTON = 1;
|
||||
public static final int PTTOFF = 0;
|
||||
|
||||
/** Call Types */
|
||||
public static final int AllCall = 101;
|
||||
public static final int PrivateCall = 102;
|
||||
public static final int GroupCall = 103;
|
||||
public static final int EndAllCall = AllCall+10;
|
||||
public static final int EndPrivateCall = PrivateCall+10;
|
||||
public static final int EndGroupCall = GroupCall+10;
|
||||
public static final int PTTBUTTON = 999;
|
||||
public static final int VOXON = 555;
|
||||
public static final int VOXOFF = 000;
|
||||
|
||||
/* Old Values
|
||||
public static final int Decoded = 1;
|
||||
public static final int InProgress = 2;
|
||||
public static final int Initiated = 4;
|
||||
public static final int Hangtime = 7;
|
||||
public static final int Ended = 3;
|
||||
public static final int InitButton = 5;
|
||||
public static final int MotoPrivate = 4;
|
||||
public static final int MotoGroup = 6;
|
||||
public static final int MotoAllCall = 16777215;
|
||||
//*/
|
||||
|
||||
//* New Values
|
||||
public static final int Initiated = 0;
|
||||
public static final int Decoded = 1;
|
||||
public static final int InProgress = 2;
|
||||
public static final int Hangtime = 3;
|
||||
public static final int Ended = 4;
|
||||
public static final int InitEnded = 5;
|
||||
public static final int InitHangtime = 6;
|
||||
public static final int MotoPrivate = 1;
|
||||
public static final int MotoGroup = 2;
|
||||
public static final int MotoAllCall = 3;
|
||||
public static final int MotoManualDial = 4;
|
||||
//*/
|
||||
|
||||
|
||||
/** BlueTooth Headset MAC */
|
||||
public static String BluCom = "00:15:45:";
|
||||
/*
|
||||
public static String MotorolaH730 = "00:24:1C:";
|
||||
public static String SamsungWep460 = "18:46:17:";
|
||||
*/
|
||||
|
||||
/** Notification values */
|
||||
public static final int messageNotif = 1;
|
||||
public static final int alertNotif = 2;
|
||||
public static final int pollNotif = 3;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.radio.Zone;
|
||||
|
||||
public class ConfigFile {
|
||||
public ArrayList<Contact> contacts;
|
||||
public Radio radio;
|
||||
public ArrayList<Zone> zones;
|
||||
|
||||
public ConfigFile()
|
||||
{
|
||||
contacts = new ArrayList<Contact>();
|
||||
zones = new ArrayList<Zone>();
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Contacts: " + contacts.size() + " | Radio: " + radio.toString() + " | Zones: " + zones.size();
|
||||
}
|
||||
|
||||
public String toLongString()
|
||||
{
|
||||
String cont = "", zone="";
|
||||
for(Contact contact: contacts)
|
||||
cont += "Name: " + contact.name + " | Id: " + contact.id + "\n";
|
||||
|
||||
for(Zone zonee: zones)
|
||||
zone += "Name: " + zonee.ZoneName + " | Id: " + zonee.id + "\n";
|
||||
|
||||
return "# Contacts #\n" + cont + "# Radio #\n" + radio.toString() + "\n# Zones #\n" + zone;
|
||||
}
|
||||
}
|
94
libSafeMobile/src/main/java/com/safemobile/lib/Contact.java
Normal file
94
libSafeMobile/src/main/java/com/safemobile/lib/Contact.java
Normal file
@ -0,0 +1,94 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Contact {
|
||||
public int dbID = 0;
|
||||
public long id = 0;
|
||||
public String name = "";
|
||||
public int contactType = 0;
|
||||
public int parentDB_ID = 0;
|
||||
|
||||
public static final int PRIVATE = 1;
|
||||
public static final int GROUP = 2;
|
||||
public static final int ALL = 3;
|
||||
public static final int ZONE = 4;
|
||||
public static final int CHANNEL = 5;
|
||||
|
||||
|
||||
|
||||
public Contact()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Contact(long _id, String _name, int _contactType, int dbID, int parentDB_id)
|
||||
{
|
||||
id = _id;
|
||||
name = _name;
|
||||
contactType = _contactType;
|
||||
this.dbID = dbID;
|
||||
this.parentDB_ID = parentDB_id;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return id + ". " + name + " [" + getContactType(contactType) + "]";
|
||||
}
|
||||
|
||||
|
||||
private String getContactType(int contactType) {
|
||||
switch(contactType) {
|
||||
case PRIVATE: return "PRIVATE";
|
||||
case GROUP: return "GROUP";
|
||||
case ALL: return "ALL CALL";
|
||||
case ZONE: return "ZONE";
|
||||
case CHANNEL: return "CHANNEL";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<Contact> parseTCPMsg(String msg) {
|
||||
|
||||
ArrayList<Contact> contacts = new ArrayList<Contact>();
|
||||
try
|
||||
{
|
||||
msg = msg.replace("#", "");
|
||||
// split payload to get contacts
|
||||
|
||||
// split contact by /
|
||||
String[] contArr = msg.split("/");
|
||||
Contact ct = new Contact();
|
||||
ct.dbID = Integer.parseInt(contArr[0]);
|
||||
ct.id = Long.parseLong(contArr[1]);
|
||||
ct.name = contArr[2];
|
||||
ct.contactType = Integer.parseInt(contArr[4]);
|
||||
ct.parentDB_ID = Integer.parseInt(contArr[3]);
|
||||
|
||||
contacts.add(ct);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("Exception parse Contacts", ex.toString());
|
||||
}
|
||||
|
||||
return contacts;
|
||||
/*
|
||||
int id = 1;
|
||||
|
||||
// this will select the type
|
||||
switch(AppParams.APPLICATION_TYPE * 10 + id) {
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public static String getNameForRadioID(ArrayList<Contact> listUnits, long radioID) {
|
||||
for(Contact ctc: listUnits)
|
||||
if(ctc.id == radioID && (ctc.contactType == Contact.PRIVATE))
|
||||
return ctc.name;
|
||||
|
||||
// if contact wasn't found I should return it's radioID
|
||||
return radioID+"";
|
||||
}
|
||||
}
|
19
libSafeMobile/src/main/java/com/safemobile/lib/GPS.java
Normal file
19
libSafeMobile/src/main/java/com/safemobile/lib/GPS.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class GPS {
|
||||
|
||||
public long imei=0;
|
||||
public double lat=0;
|
||||
public double lng=0;
|
||||
public int speed=0;
|
||||
public long timeGMT=0;
|
||||
|
||||
public GPS(){
|
||||
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "imei: " + imei + " | LAT: " + lat + " | LNG: " + lng + " | speed: " + speed + " | timeGMT: " + timeGMT;
|
||||
}
|
||||
}
|
24
libSafeMobile/src/main/java/com/safemobile/lib/GPSmsg.java
Normal file
24
libSafeMobile/src/main/java/com/safemobile/lib/GPSmsg.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class GPSmsg extends TCPmsg {
|
||||
|
||||
public GPS gpsValue;
|
||||
public static int count=0;
|
||||
public GPSmsg(TCPmsg tcp)
|
||||
{
|
||||
super(tcp);
|
||||
String date4parsing = super.data;
|
||||
//SM.Debug("SMS date4parsing:"+date4parsing);
|
||||
String[] tempVeh = date4parsing.split("#");
|
||||
gpsValue = new GPS();
|
||||
gpsValue.imei = Long.parseLong(tempVeh[0]);
|
||||
gpsValue.lat = Double.parseDouble(tempVeh[3]);
|
||||
gpsValue.lng = Double.parseDouble(tempVeh[4]);
|
||||
gpsValue.speed = Integer.parseInt(tempVeh[2]);
|
||||
gpsValue.timeGMT = Long.parseLong(tempVeh[1]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class HistCount {
|
||||
public String seq_id;
|
||||
public long count;
|
||||
|
||||
public HistCount()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public HistCount(String _seq_id, long _count)
|
||||
{
|
||||
seq_id = _seq_id;
|
||||
count = _count;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "seq_id: " + seq_id + " | count: " + count;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class HistCountmsg extends TCPmsg {
|
||||
|
||||
public HistCount histcountValue;
|
||||
public long count=0;
|
||||
public HistCountmsg(TCPmsg tcp)
|
||||
{
|
||||
super(tcp);
|
||||
String date4parsing = super.data;
|
||||
//SM.Debug("SMS date4parsing:"+date4parsing);
|
||||
//String[] tempVeh = date4parsing.split("#");
|
||||
date4parsing = date4parsing.replace("#", "");
|
||||
histcountValue = new HistCount();
|
||||
histcountValue.count = Long.parseLong(date4parsing);
|
||||
histcountValue.seq_id = super.seqID;
|
||||
}
|
||||
}
|
75
libSafeMobile/src/main/java/com/safemobile/lib/HistPos.java
Normal file
75
libSafeMobile/src/main/java/com/safemobile/lib/HistPos.java
Normal file
@ -0,0 +1,75 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
|
||||
public class HistPos {
|
||||
|
||||
public double lat=0;
|
||||
public double lng=0;
|
||||
public int speed=0;
|
||||
public long timeGMT=0;
|
||||
public String Address="";
|
||||
public int heading=0;
|
||||
|
||||
public HistPos(){
|
||||
|
||||
}
|
||||
|
||||
public HistPos(double _lat, double _lng, int _speed, long _timeGMT){
|
||||
lat = _lat;
|
||||
lng = _lng;
|
||||
speed = _speed;
|
||||
timeGMT = _timeGMT;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return " LAT: " + lat + " | LNG: " + lng + " | speed: " + speed + " | timeGMT: " + timeGMT + " | Address: " + Address;
|
||||
}
|
||||
|
||||
|
||||
public int GetIconHead()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (((heading >= 0) && (heading < 11.25)) || ((heading > 348.75) && (heading <= 360)))
|
||||
return R.drawable.arrow_e;
|
||||
else if ((heading >= 11.25) && (heading < 33.75))
|
||||
return R.drawable.arrow_ene;
|
||||
else if ((heading >= 33.75) && (heading < 56.25))
|
||||
return R.drawable.arrow_ne;
|
||||
else if ((heading >= 56.25) && (heading < 78.75))
|
||||
return R.drawable.arrow_nne;
|
||||
else if ((heading >= 78.75) && (heading < 101.25))
|
||||
return R.drawable.arrow_n;
|
||||
else if ((heading >= 101.25) && (heading < 123.75))
|
||||
return R.drawable.arrow_nnv;
|
||||
else if ((heading >= 123.75) && (heading < 146.25))
|
||||
return R.drawable.arrow_nv;
|
||||
else if ((heading >= 146.25) && (heading < 168.75))
|
||||
return R.drawable.arrow_vnv;
|
||||
else if ((heading >= 168.75) && (heading < 191.25))
|
||||
return R.drawable.arrow_v;
|
||||
else if ((heading >= 191.25) && (heading < 213.75))
|
||||
return R.drawable.arrow_vsv;
|
||||
else if ((heading >= 213.75) && (heading < 236.25))
|
||||
return R.drawable.arrow_sv;
|
||||
else if ((heading >= 236.25) && (heading < 258.75))
|
||||
return R.drawable.arrow_ssv;
|
||||
else if ((heading >= 258.75) && (heading < 281.25))
|
||||
return R.drawable.arrow_s;
|
||||
else if ((heading >= 281.25) && (heading < 303.75))
|
||||
return R.drawable.arrow_sse;
|
||||
else if ((heading >= 303.75) && (heading < 326.25))
|
||||
return R.drawable.arrow_se;
|
||||
else if ((heading >= 326.25) && (heading < 348.75))
|
||||
return R.drawable.arrow_ese;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
catch (Exception e) {
|
||||
SM.Debug("Erorr on select Arrows");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
126
libSafeMobile/src/main/java/com/safemobile/lib/HistPosmsg.java
Normal file
126
libSafeMobile/src/main/java/com/safemobile/lib/HistPosmsg.java
Normal file
@ -0,0 +1,126 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//Date data = Calendar.getInstance().getTime();
|
||||
//data.getTime();
|
||||
|
||||
public class HistPosmsg extends TCPmsg {
|
||||
|
||||
public ArrayList<HistPos> PosList;
|
||||
public int count=0;
|
||||
public HistPosmsg(TCPmsg tcp) {
|
||||
super(tcp);
|
||||
PosList = new ArrayList<HistPos>();
|
||||
try{
|
||||
String date4parsing = super.data;
|
||||
//SM.Debug("SMS date4parsing:"+date4parsing);
|
||||
String[] tempArr = date4parsing.split(";");
|
||||
//SM.Debug("SMS tempArr.length:" +tempArr.length);
|
||||
for(int i =0; i<tempArr.length;i++)
|
||||
{
|
||||
String[] tempVeh = tempArr[i].split("&");
|
||||
|
||||
if(tempVeh.length<6)
|
||||
continue;
|
||||
HistPos tmpLast = new HistPos();
|
||||
tmpLast.lat = Double.parseDouble(tempVeh[1]);
|
||||
tmpLast.lng = Double.parseDouble(tempVeh[2]);
|
||||
tmpLast.speed = Integer.parseInt(tempVeh[3]);
|
||||
tmpLast.timeGMT = Long.parseLong(tempVeh[5]);
|
||||
tmpLast.Address = tempVeh[6];
|
||||
//tmpLast.Address = "";
|
||||
|
||||
PosList.add(tmpLast);
|
||||
//SM.Debug("duda",tmpLast.toString());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
SM.Debug("Error on parse hisotry:"+e.toString());
|
||||
}
|
||||
CalcHeadingForArray(PosList);
|
||||
count +=this.PosList.size();
|
||||
SM.Debug("duda","HistList size:" +this.PosList.size() + " total:" +count);
|
||||
}
|
||||
|
||||
public ArrayList<HistPos> CalcHeadingForArray(ArrayList<HistPos> list)
|
||||
{
|
||||
this.PosList = list;
|
||||
if (PosList.size()>1)
|
||||
{
|
||||
HistPos oldPos = PosList.get(0);
|
||||
HistPos tmpPos = null;
|
||||
int Headingtmp =0;
|
||||
for (int i=1;i<PosList.size();i++)
|
||||
{
|
||||
tmpPos = PosList.get(i);
|
||||
Headingtmp = CalcHead(tmpPos.lng, tmpPos.lat, oldPos.lng, oldPos.lat, Headingtmp);
|
||||
tmpPos.heading = Headingtmp;
|
||||
oldPos = tmpPos;
|
||||
}
|
||||
}
|
||||
|
||||
return this.PosList;
|
||||
}
|
||||
|
||||
private int CalcHead(double lastLocX, double lastLocY, double prevLocX, double prevLocY, int heading)
|
||||
{
|
||||
double dlng = lastLocX - prevLocX;
|
||||
double dlat = lastLocY - prevLocY;
|
||||
double mdelta_min = -0.00001;
|
||||
double delta_min = 0.00001;
|
||||
int headcalc = 0;
|
||||
double blat = 0;
|
||||
double blng = 0;
|
||||
if ((dlat > mdelta_min) && (dlat < delta_min) && ((mdelta_min < dlng) && dlng < (delta_min))) headcalc = heading;
|
||||
else
|
||||
{
|
||||
if ((mdelta_min < dlat) && (dlat < delta_min))
|
||||
{
|
||||
blng = 1;
|
||||
if (dlng < 0) headcalc = 180;
|
||||
else headcalc = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
blat = 1;
|
||||
if (dlat > 0) headcalc = 90;
|
||||
else headcalc = 270;
|
||||
}
|
||||
}
|
||||
if ((mdelta_min < dlng) && (dlng < delta_min))
|
||||
{
|
||||
if (blat == 0)
|
||||
{
|
||||
if (dlat > 0)
|
||||
{
|
||||
if (headcalc == 180) headcalc = 135;
|
||||
if (headcalc == 0) headcalc = 45;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (headcalc == 180) headcalc = 225;
|
||||
if (headcalc == 0) headcalc = 315;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (blng == 0)
|
||||
{
|
||||
if (dlng < 0)
|
||||
{
|
||||
if (headcalc == 90) headcalc = 135;
|
||||
if (headcalc == 270) headcalc = 225;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (headcalc == 90) headcalc = 45;
|
||||
if (headcalc == 270) headcalc = 315;
|
||||
}
|
||||
}
|
||||
}
|
||||
return headcalc;
|
||||
}
|
||||
|
||||
}
|
22
libSafeMobile/src/main/java/com/safemobile/lib/LastPos.java
Normal file
22
libSafeMobile/src/main/java/com/safemobile/lib/LastPos.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class LastPos {
|
||||
|
||||
public long imei=0;
|
||||
public double lat=0;
|
||||
public double lng=0;
|
||||
public int speed=0;
|
||||
public long timeGMT=0;
|
||||
public String Address="";
|
||||
public boolean isON=false;
|
||||
|
||||
public LastPos(){
|
||||
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "imei: " + imei + " | LAT: " + lat + " | LNG: " + lng + " | speed: " + speed + " | timeGMT: " + timeGMT + " | Address: " + Address + " | isON: " + isON;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LastPosmsg extends TCPmsg {
|
||||
|
||||
public ArrayList<LastPos> PosList;
|
||||
public static int count=0;
|
||||
public LastPosmsg(TCPmsg tcp) {
|
||||
super(tcp);
|
||||
PosList = new ArrayList<LastPos>();
|
||||
String date4parsing = super.data;
|
||||
//SM.Debug("SMS date4parsing:"+date4parsing);
|
||||
String[] tempArr = date4parsing.split(";");
|
||||
//SM.Debug("SMS tempArr.length:" +tempArr.length);
|
||||
for(int i =0; i<tempArr.length;i++)
|
||||
{
|
||||
String[] tempVeh = tempArr[i].split("&");
|
||||
|
||||
if(tempVeh.length<6)
|
||||
continue;
|
||||
LastPos tmpLast = new LastPos();
|
||||
tmpLast.imei = Long.parseLong(tempVeh[0]);
|
||||
tmpLast.lat = Double.parseDouble(tempVeh[1]);
|
||||
tmpLast.lng = Double.parseDouble(tempVeh[2]);
|
||||
tmpLast.speed = Integer.parseInt(tempVeh[3]);
|
||||
if (Integer.parseInt(tempVeh[4])==0) tmpLast.isON =true;
|
||||
else tmpLast.isON = false;
|
||||
tmpLast.timeGMT = Long.parseLong(tempVeh[5]);
|
||||
|
||||
//tmpLast.Address = tempVeh[6];
|
||||
tmpLast.Address = "";
|
||||
PosList.add(tmpLast);
|
||||
//SM.Debug("duda",tmpLast.toString());
|
||||
|
||||
}
|
||||
count +=this.PosList.size();
|
||||
SM.Debug("duda","LastList size:" +this.PosList.size() + " total:" +count);
|
||||
}
|
||||
|
||||
}
|
||||
|
42
libSafeMobile/src/main/java/com/safemobile/lib/LoginMSG.java
Normal file
42
libSafeMobile/src/main/java/com/safemobile/lib/LoginMSG.java
Normal file
@ -0,0 +1,42 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.User;
|
||||
|
||||
public class LoginMSG extends TCPmsg{
|
||||
|
||||
public ArrayList<User> userList;
|
||||
|
||||
public LoginMSG(TCPmsg m) {
|
||||
super(m);
|
||||
|
||||
userList = new ArrayList<User>();
|
||||
String date4parsing = super.data;
|
||||
//SM.Debug("date4parsing:"+date4parsing);
|
||||
String[] tempArr = date4parsing.split(";");
|
||||
|
||||
for(int i =0; i<tempArr.length;i++)
|
||||
{
|
||||
//SM.Debug("i:" + i+"Data :"+tempArr[i]);
|
||||
String[] tempUser = tempArr[i].split("&");
|
||||
//SM.Debug("split len:"+tempUser.length);
|
||||
|
||||
if(tempUser.length<3)
|
||||
continue;
|
||||
int ID = Integer.parseInt(tempUser[1]);
|
||||
String logName = tempUser[0];
|
||||
String pass = tempUser[2];
|
||||
User usr= new User(ID, "", "", logName, pass, 0, 0);
|
||||
|
||||
userList.add(usr);
|
||||
//SM.Debug("added user to list:" +logName);
|
||||
//SM.Debug("LoginMSG new size:" +this.userList.size());
|
||||
}
|
||||
|
||||
//SM.Debug("LoginMSG userList:" +this.userList.size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
8
libSafeMobile/src/main/java/com/safemobile/lib/Mic.java
Normal file
8
libSafeMobile/src/main/java/com/safemobile/lib/Mic.java
Normal file
@ -0,0 +1,8 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class Mic {
|
||||
public int mic_type;
|
||||
public int mic_state;
|
||||
public int mic_gain;
|
||||
public int signal_type;
|
||||
}
|
29
libSafeMobile/src/main/java/com/safemobile/lib/Msg.java
Normal file
29
libSafeMobile/src/main/java/com/safemobile/lib/Msg.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Msg {
|
||||
public Vehicle from;
|
||||
public Date received;
|
||||
public String seqID;
|
||||
|
||||
/** Safenet */
|
||||
public long id;
|
||||
public String message;
|
||||
public boolean read;
|
||||
public boolean sent;
|
||||
|
||||
public String subscriber; //will be imei or gw_id+radio_id
|
||||
public Date time, timeSent;
|
||||
public int type;
|
||||
|
||||
public Msg() { }
|
||||
|
||||
public Msg(Vehicle From, String Message, Date Received, String seqID)
|
||||
{
|
||||
this.message = Message;
|
||||
from = From;
|
||||
received = Received;
|
||||
this.seqID = seqID;
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class OperationCodes {
|
||||
|
||||
/* TCP MSG EVENTS CODES */
|
||||
|
||||
/** Login Request
|
||||
* @param username
|
||||
* @param password values must be MD5 */
|
||||
public static final int CONNECTION_REQ = 19;
|
||||
public static final int CONNECTION_REP = 219;
|
||||
|
||||
|
||||
/** Get contacts from radio */
|
||||
public static final int CONTACTS_REQ = 26;
|
||||
public static final int CONTACTS_REP = 226;
|
||||
|
||||
|
||||
public static final int UNIT_STATUS_UPDATE = 250;
|
||||
|
||||
|
||||
|
||||
|
||||
/** Send a new sms to a unit
|
||||
* @param seqID a unique identifier for the message
|
||||
* @param sc_id units imei to which you send the sms
|
||||
* @param txt the text message that you want to send*/
|
||||
public static final int SEND_TM = 24;
|
||||
public static final int TM_ACK = 224;
|
||||
public static final int TM_ACK_SD = 242;
|
||||
|
||||
|
||||
/** Get radio status that tells if it's online or offline
|
||||
* @param gwID gateway id
|
||||
* @param rgwID radio gateway id */
|
||||
public static final int RADIO_STATUS_REQ = 99;
|
||||
public static final int RADIO_STATUS_REP = 199;
|
||||
public static final int RADIO_STATUS_BRDCST = 200;
|
||||
|
||||
|
||||
/** change zone and channels
|
||||
* @param gwID gateway id
|
||||
* @param rgwID radio gateway id
|
||||
* @param zoneNR desired zone number
|
||||
* @param channelNR desired channel number */
|
||||
public static final int CHANNEL_QUERY_REQ = 104;
|
||||
public static final int CHANNEL_BRDCST = 204;
|
||||
|
||||
|
||||
/** Reset the Bridge */
|
||||
public static final int BRIDGE_RESET = 98;
|
||||
|
||||
|
||||
/** PING-PONG */
|
||||
public static final int PING = 91;
|
||||
public static final int PONG = 92;
|
||||
|
||||
/** Emergency request
|
||||
* @param value this will select to activate or deactivate alarm (TRUE = activate) */
|
||||
public static final int EMERGENCY_REQ = 130;
|
||||
public static final int EMERGENCY_REP = 230;
|
||||
|
||||
/** Initiated a call
|
||||
* @param callType this will select the type of the call (All, Private or Group Call)
|
||||
* @param radioID the contact to which the call is made */
|
||||
public static final int SEND_PTT = 1313;
|
||||
public static final int CALL_STATUS_BRDCST = 126;
|
||||
|
||||
/** Change the call type for external mic initiated calls
|
||||
* @param callType this will select the type of the call (All, Private or Group Call)
|
||||
* @param radioID the contact to which the call is made */
|
||||
public static final int CALL_TYPE_REQ = 161;
|
||||
public static final int CALL_TYPE_REP = 171;
|
||||
|
||||
/** Terminate a call */
|
||||
public static final int DEKEY_REQ = 160;
|
||||
|
||||
|
||||
/** Request the list of all messages
|
||||
* @param timeGMTStart first message time (all messages will be newer than this time) */
|
||||
public static final int TM_LIST_REQ = 25;
|
||||
public static final int TM_LIST_REP = 225;
|
||||
|
||||
|
||||
/** Request the list of all recordings
|
||||
* @param timeGMTStart first message time (all messages will be newer than this time) */
|
||||
public static final int RECORDINGS_LIST_REQ = 27;
|
||||
public static final int RECORDINGS_LIST_REP = 227;
|
||||
|
||||
|
||||
/** Request a recording to be played */
|
||||
public static final int RECORDING_REQ = 28;
|
||||
public static final int RECORDING_REP = 228;
|
||||
|
||||
/** A SMS is received */
|
||||
public static final int RECEIVED_TM = 132;
|
||||
|
||||
|
||||
/** Notification was clicked to display the received TM */
|
||||
public static final int MESSAGE_NOTIFICATION_CLICKED = 690;
|
||||
|
||||
|
||||
/** get tcp connection from service */
|
||||
public static final int TCP_CONNECTION_REQ = 678;
|
||||
public static final int TCP_CONNECTION_UP = 679;
|
||||
public static final int TCP_CONNECTION_DOWN = 677;
|
||||
|
||||
/** operation code needed to change the Radio ID in radioTAB */
|
||||
public static final int RADIOID_CHANGED = 888;
|
||||
|
||||
|
||||
/** operation code needed when a bluetooth is tethered or not */
|
||||
public static final int BLUETOOTH_TETHER = 901;
|
||||
|
||||
/** get vehicles for an user id
|
||||
* @param USERID Logged in user id */
|
||||
public static final int GetVehicles = 2;
|
||||
|
||||
/** get radios list from App Server */
|
||||
public static final int GetRadiosList = 3;
|
||||
|
||||
/** get vehicles last positions
|
||||
* @param USERID Logged in user id */
|
||||
public static final int GetLastPositions = 4;
|
||||
|
||||
/** get the last sms for all the vehicles */
|
||||
public static final int GetLastSMS = 5;
|
||||
|
||||
/** get sms for a specific vehicle newer than a date
|
||||
* @param sc_id vehicle imei for which we wish the list of sms
|
||||
* @param timeGMT the unix time from the last sms in the grid */
|
||||
public static final int GetRecentSMSs = 6;
|
||||
|
||||
/** enable/ disable vehicle status or poll it
|
||||
* @param radioCode
|
||||
* @param opCode
|
||||
* @param sc_id vehicle imei
|
||||
* @param enable */
|
||||
public static final int Option4Unit = 8;
|
||||
|
||||
|
||||
/** get alarms for an user id
|
||||
* @param USERID Logged in user id */
|
||||
public static final int GetAlarms = 9;
|
||||
|
||||
/** acknoledge an alarm based on it's index and type
|
||||
* @param idx alarm's index in the DB
|
||||
* @param type alarm's type as shown in the grid*/
|
||||
public static final int SendAlarmAcknoledge = 10;
|
||||
|
||||
/** get history position for a specific vehicle
|
||||
* @param sc_id vehicle's imei
|
||||
* @param timeGMTStart history start date in unixtime
|
||||
* @param timeGMTStop history end date in unixtime*/
|
||||
public static final int GetHistoryPositions = 11;
|
||||
|
||||
}
|
203
libSafeMobile/src/main/java/com/safemobile/lib/Position.java
Normal file
203
libSafeMobile/src/main/java/com/safemobile/lib/Position.java
Normal file
@ -0,0 +1,203 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by Adi on 8/11/2017.
|
||||
*/
|
||||
|
||||
public class Position implements Parcelable, Comparable<Position>{
|
||||
// region private fields
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
public Date positionTime;
|
||||
public double speed;
|
||||
public String address;
|
||||
public float accuracy;
|
||||
//endregion
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public Position()
|
||||
{
|
||||
latitude = 0;
|
||||
longitude = 0;
|
||||
positionTime = new Date(0);
|
||||
speed = 0;
|
||||
address = "";
|
||||
accuracy = 0;
|
||||
}
|
||||
|
||||
public Position(String json)
|
||||
{
|
||||
try {
|
||||
JSONObject posObj = new JSONObject(json);
|
||||
speed = posObj.isNull("speed")
|
||||
? 0 : posObj.getDouble("speed");
|
||||
latitude = posObj.isNull("latitude")
|
||||
? 0 : posObj.getDouble("latitude");
|
||||
longitude = posObj.isNull("longitude")
|
||||
? 0 : posObj.getDouble("longitude");
|
||||
address = posObj.isNull("address")
|
||||
? "" : posObj.getString("address");
|
||||
|
||||
accuracy = posObj.isNull("accuracy")
|
||||
? 0 : (float) posObj.getDouble("accuracy");
|
||||
|
||||
String posTime = posObj.isNull("positionTime")
|
||||
? "" : posObj.getString("positionTime");
|
||||
if(posTime.length() > 0)
|
||||
{
|
||||
//May 16, 2018 12:01:47
|
||||
try
|
||||
{
|
||||
String timeFormat = "MMMMM d, yyyy HH:mm:ss";
|
||||
DateFormat format = new SimpleDateFormat(timeFormat, Locale.ENGLISH);
|
||||
positionTime = format.parse(posTime);
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
String timeFormat = "MMM d, yyyy HH:mm:ss";
|
||||
DateFormat format = new SimpleDateFormat(timeFormat, Locale.ENGLISH);
|
||||
positionTime = format.parse(posTime);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
positionTime = new Date(0);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
positionTime = new Date(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Position(double latitude, double longitude)
|
||||
{
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
positionTime = new Date(0);
|
||||
speed = 0;
|
||||
address = "";
|
||||
accuracy = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor from Parcel, reads back fields IN THE ORDER they were
|
||||
* written
|
||||
*/
|
||||
public Position(Parcel parcel){
|
||||
latitude = parcel.readDouble();
|
||||
longitude = parcel.readDouble();
|
||||
positionTime = new Date(parcel.readLong());
|
||||
speed = parcel.readDouble();
|
||||
address = parcel.readString();
|
||||
accuracy = parcel.readFloat();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method from Parcelable class, left as auto-generated
|
||||
* @return A default value
|
||||
*/
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to create the Parcel object from the main class that
|
||||
* will be passed when a Parcelable object is used
|
||||
* @param dest Parcel object in which all the object values will
|
||||
* be added
|
||||
* @param flags Additional flags about how the object should be
|
||||
* written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.
|
||||
*/
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeDouble(latitude);
|
||||
dest.writeDouble(longitude);
|
||||
dest.writeLong(positionTime.getTime());
|
||||
dest.writeDouble(speed);
|
||||
dest.writeString(address);
|
||||
dest.writeFloat(accuracy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static field used to regenerate object, individually or as arrays
|
||||
*/
|
||||
public static final Parcelable.Creator<Position> CREATOR = new Parcelable.Creator<Position>() {
|
||||
public Position createFromParcel(Parcel in) {
|
||||
return new Position(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position[] newArray(int size) {
|
||||
return new Position[size];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Override of the method that returns a string representation of the object which
|
||||
* contains all the useful information about the object
|
||||
* @return String representation of the object
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Latitude: " + latitude + " | "
|
||||
+ "Longitude: " + longitude + " | "
|
||||
+ "Speed: " + speed + " | "
|
||||
+ "PositionTime: " + (positionTime!= null ? positionTime.toString() : "null" ) + " | "
|
||||
+ "Address " + (address!= null ? address.toString() : "null" )
|
||||
+ "Accuracy " + accuracy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull Position o) {
|
||||
return (latitude == o.latitude
|
||||
&& longitude == o.longitude
|
||||
) ? 0 : 1;
|
||||
}
|
||||
|
||||
// Overriding equals() to compare two Complex objects
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
Position pos = (Position) o;
|
||||
|
||||
return compareTo(pos) == 0;
|
||||
}
|
||||
|
||||
|
||||
// just omitted null checks
|
||||
@Override
|
||||
public int hashCode() {
|
||||
double res = latitude * longitude * 100000;
|
||||
int hash = (int)(latitude );
|
||||
hash = (int)(longitude) * hash;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
|
||||
public String toJson()
|
||||
{
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
}
|
22
libSafeMobile/src/main/java/com/safemobile/lib/Radio.java
Normal file
22
libSafeMobile/src/main/java/com/safemobile/lib/Radio.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class Radio {
|
||||
public int id = 100;
|
||||
public String ip = "192.168.10.40";
|
||||
|
||||
public Radio()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Radio(int _id, String _ip)
|
||||
{
|
||||
id = _id;
|
||||
ip = _ip;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "id: " + id + " | ip: " + ip;
|
||||
}
|
||||
}
|
344
libSafeMobile/src/main/java/com/safemobile/lib/RadioMSG.java
Normal file
344
libSafeMobile/src/main/java/com/safemobile/lib/RadioMSG.java
Normal file
@ -0,0 +1,344 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.radio.Channel;
|
||||
import com.safemobile.lib.radio.Emerg;
|
||||
import com.safemobile.lib.radio.IncCall;
|
||||
import com.safemobile.lib.radio.RadioGW;
|
||||
import com.safemobile.lib.radio.RadioStatus;
|
||||
import com.safemobile.lib.radio.SUstatus;
|
||||
import com.safemobile.lib.radio.Zone;
|
||||
import com.safemobile.lib.radio.Zone_and_channel;
|
||||
|
||||
public class RadioMSG extends TCPmsg {
|
||||
|
||||
public int rOpcode;
|
||||
public String payload="";
|
||||
public ArrayList<RadioGW> RadioGWList=null;
|
||||
|
||||
//zone and channel;
|
||||
public Zone_and_channel zac= null;
|
||||
|
||||
//radio status
|
||||
public RadioStatus rStatus = null;
|
||||
|
||||
//SU stauts
|
||||
public SUstatus suStatus = null;
|
||||
|
||||
//Incomming call
|
||||
public IncCall incCall = null;
|
||||
|
||||
//Emerg
|
||||
public Emerg emerg = null;
|
||||
|
||||
// Contacts list
|
||||
public ArrayList<Contact> contacts;
|
||||
|
||||
|
||||
public RadioMSG(TCPmsg tcp) {
|
||||
super(tcp);
|
||||
String date4parsing = super.data;
|
||||
|
||||
String[] arr = date4parsing.split("#");
|
||||
|
||||
rOpcode = Integer.parseInt(arr[0]);
|
||||
payload = arr[1];
|
||||
|
||||
switch(rOpcode)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
RadioGWList = new ArrayList<RadioGW>();
|
||||
String[] tempArr = payload.split(";");
|
||||
|
||||
int count = 0;
|
||||
for(int i =0; i<tempArr.length;i++)
|
||||
{
|
||||
String[] oneRadio = tempArr[i].split("&");
|
||||
|
||||
if(oneRadio.length<5)
|
||||
continue;
|
||||
RadioGW rgw = new RadioGW();
|
||||
|
||||
rgw.ID = Integer.parseInt(oneRadio[0]);
|
||||
rgw.GW_ID = Integer.parseInt(oneRadio[1]);
|
||||
rgw.IMEI = oneRadio[2];
|
||||
rgw.IP = oneRadio[3];
|
||||
|
||||
String zonelistStr =oneRadio[4];
|
||||
String[] zoneArr = zonelistStr.split("@");
|
||||
for(int j =0; j<zoneArr.length;j++)
|
||||
{
|
||||
Zone zon = new Zone();
|
||||
String[] oneZoneArr = zoneArr[j].split(":");
|
||||
|
||||
//TODO check what this values are from SD
|
||||
zon.dbID = Integer.parseInt(oneZoneArr[0]);
|
||||
zon.id = Integer.parseInt(oneZoneArr[1]);
|
||||
zon.ZoneName = oneZoneArr[2];
|
||||
String channelListStr = oneZoneArr[3];
|
||||
|
||||
String[] channelArr = channelListStr.split(",");
|
||||
for(int k =0; k < channelArr.length; k++)
|
||||
{
|
||||
Channel chn = new Channel();
|
||||
String[] oneChnArr = channelArr[k].split("/");
|
||||
chn.dbID = Integer.parseInt(oneChnArr[0]);
|
||||
chn.id = Integer.parseInt(oneChnArr[1]);
|
||||
chn.chName = oneChnArr[2];
|
||||
|
||||
//add channel to zone
|
||||
zon.channelList.add(chn);
|
||||
}
|
||||
|
||||
//add zone to radio GW
|
||||
rgw.zoneList.add(zon);
|
||||
}
|
||||
|
||||
RadioGWList.add(rgw);
|
||||
count++;
|
||||
}
|
||||
count +=this.RadioGWList.size();
|
||||
SM.Debug("radio","RadioGWList size:" +this.RadioGWList.size() + " total:" +count);
|
||||
break;
|
||||
}
|
||||
case OperationCodes.CHANNEL_BRDCST:
|
||||
{
|
||||
try {
|
||||
zac = new Zone_and_channel();
|
||||
String[] tempArr = payload.split("&");
|
||||
|
||||
String[] gwID_and_rgwID = tempArr[0].split("/");
|
||||
zac.gwID = Integer.parseInt(gwID_and_rgwID[0]);
|
||||
zac.rgwID = Integer.parseInt(gwID_and_rgwID[1]);
|
||||
|
||||
String[] zoneNr_and_channelNr = tempArr[1].split("/");
|
||||
zac.zoneNr = Integer.parseInt(zoneNr_and_channelNr[0]);
|
||||
zac.channelNr = Integer.parseInt(zoneNr_and_channelNr[1]);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 204 error:"+e.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.RADIO_STATUS_REP:
|
||||
{
|
||||
try {
|
||||
rStatus = new RadioStatus();
|
||||
String[] tempArr = payload.split("&");
|
||||
|
||||
if(tempArr.length == 4 || tempArr.length == 5) {
|
||||
rStatus.status = 1;
|
||||
rStatus.incCall.callStatus = Integer.parseInt(tempArr[0]);
|
||||
rStatus.incCall.callType = Integer.parseInt(tempArr[1]);
|
||||
rStatus.incCall.Imei = Integer.parseInt(tempArr[2]);
|
||||
rStatus.incCall.callerID = Integer.parseInt(tempArr[2]);
|
||||
rStatus.incCall.groupId = Integer.parseInt(tempArr[3]);
|
||||
rStatus.incCall.callDestID = Integer.parseInt(tempArr[3]);
|
||||
|
||||
if(tempArr.length == 5)
|
||||
rStatus.incCall.userID = Integer.parseInt(tempArr[4]);
|
||||
}
|
||||
else {
|
||||
String[] gwID_and_rgwID = tempArr[0].split("/");
|
||||
rStatus.gwID = Integer.parseInt(gwID_and_rgwID[0]);
|
||||
rStatus.rgwID = Integer.parseInt(gwID_and_rgwID[1]);
|
||||
rStatus.status = Integer.parseInt(tempArr[1]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 199 error:"+e.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 250:
|
||||
{
|
||||
try {
|
||||
suStatus = new SUstatus();
|
||||
String[] tempArr = payload.split("&");
|
||||
|
||||
suStatus.imei = Integer.parseInt(tempArr[0]);
|
||||
|
||||
suStatus.status = Integer.parseInt(tempArr[1]);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 250 error:"+e.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 125:
|
||||
case OperationCodes.CALL_STATUS_BRDCST:
|
||||
{
|
||||
try {
|
||||
incCall = new IncCall();
|
||||
incCall.opCode = rOpcode;
|
||||
String[] tempArr = payload.split("&");
|
||||
|
||||
String[] gwID_and_rgwID_imei = tempArr[0].split("/");
|
||||
incCall.gwID = Integer.parseInt(gwID_and_rgwID_imei[0]);
|
||||
incCall.rgwID = Integer.parseInt(gwID_and_rgwID_imei[1]);
|
||||
incCall.Imei = Long.parseLong(gwID_and_rgwID_imei[2]);
|
||||
|
||||
incCall.callStatus = Integer.parseInt(tempArr[1]);
|
||||
incCall.callType = Integer.parseInt(tempArr[2]);
|
||||
incCall.groupId = Integer.parseInt(tempArr[3]);
|
||||
incCall.userID = Integer.parseInt(tempArr[4]);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 125, 126 error:"+e.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 121:
|
||||
case 122:
|
||||
case 123:
|
||||
{
|
||||
try {
|
||||
incCall = new IncCall();
|
||||
incCall.opCode = rOpcode;
|
||||
|
||||
incCall.callStatus = Integer.parseInt(payload.substring(payload.length()-1, payload.length()));
|
||||
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 121, 122, 123 error:"+e.toString());
|
||||
}
|
||||
/*
|
||||
try {
|
||||
System.out.println("############ tmpARR: " + payload );
|
||||
incCall = new IncCall();
|
||||
incCall.opCode = rOpcode;
|
||||
String[] tempArr = payload.split("&");
|
||||
|
||||
String[] gwID_and_rgwID_imei = tempArr[0].split("/");
|
||||
incCall.gwID = Integer.parseInt(gwID_and_rgwID_imei[0]);
|
||||
incCall.rgwID = Integer.parseInt(gwID_and_rgwID_imei[1]);
|
||||
|
||||
incCall.callStatus = Integer.parseInt(tempArr[1]);
|
||||
|
||||
incCall.callType = Integer.parseInt(tempArr[2]);
|
||||
|
||||
incCall.groupId = Integer.parseInt(tempArr[3]);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 121, 122, 123 error:"+e.toString());
|
||||
}
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
case 115:
|
||||
case 116:
|
||||
case 117:
|
||||
{
|
||||
|
||||
try {
|
||||
incCall = new IncCall();
|
||||
incCall.opCode = rOpcode;
|
||||
|
||||
incCall.callStatus = Integer.parseInt(payload.substring(payload.length()-1, payload.length()));
|
||||
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 115,116,117 error:"+e.toString());
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
try {
|
||||
incCall = new IncCall();
|
||||
String[] tempArr = payload.split("&");
|
||||
incCall.opCode = rOpcode;
|
||||
String[] gwID_and_rgwID_imei = tempArr[0].split("/");
|
||||
incCall.gwID = Integer.parseInt(gwID_and_rgwID_imei[0]);
|
||||
incCall.rgwID = Integer.parseInt(gwID_and_rgwID_imei[1]);
|
||||
|
||||
incCall.callStatus = 3;
|
||||
|
||||
incCall.callType = Integer.parseInt(tempArr[2]);
|
||||
|
||||
incCall.groupId = Integer.parseInt(tempArr[3]);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 115, 116, 117 error:"+e.toString());
|
||||
}
|
||||
|
||||
break;
|
||||
*/
|
||||
}
|
||||
|
||||
case OperationCodes.CALL_TYPE_REP:
|
||||
{
|
||||
|
||||
try {
|
||||
incCall = new IncCall();
|
||||
incCall.opCode = rOpcode;
|
||||
String[] tempArr = payload.split("/");
|
||||
incCall.callType = Integer.parseInt(tempArr[0]);
|
||||
incCall.callStatus = Integer.parseInt(tempArr[1]);
|
||||
|
||||
SM.Debug("GOT CHANGE CALL TYPE MSG", incCall.opCode + " # " + incCall.callType + " # " + incCall.callStatus);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 115,116,117 error:"+e.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 172:
|
||||
{
|
||||
|
||||
try {
|
||||
incCall = new IncCall();
|
||||
incCall.opCode = rOpcode;
|
||||
String[] tempArr = payload.split("/");
|
||||
incCall.mic = new Mic();
|
||||
incCall.mic.mic_type = Integer.parseInt(tempArr[0]);
|
||||
incCall.mic.signal_type = Integer.parseInt(tempArr[1]);
|
||||
incCall.mic.mic_state = Integer.parseInt(tempArr[2]);
|
||||
incCall.mic.mic_gain = Integer.parseInt(tempArr[3]);
|
||||
|
||||
SM.Debug("GOT Mic state changed", incCall.opCode + " # " + incCall.mic.mic_state);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 172 error:"+e.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.EMERGENCY_REP:
|
||||
{
|
||||
try {
|
||||
emerg = new Emerg();
|
||||
String[] tempArr = payload.split("/");
|
||||
|
||||
emerg.function = Integer.parseInt(tempArr[0]);
|
||||
emerg.status = Integer.parseInt(tempArr[1]);
|
||||
|
||||
// emerg.userID = Integer.parseInt(tempArr[2]);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("Cmd 230 error:"+e.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
case OperationCodes.CONTACTS_REP:
|
||||
{
|
||||
try
|
||||
{
|
||||
SM.Debug("Parsing Contacts");
|
||||
contacts = Contact.parseTCPMsg(payload);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("Exception parse Contacts", ex.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//SM.Debug("RadioMSG", "Done parsing");
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RecordMSG extends TCPmsg {
|
||||
|
||||
public ArrayList<Recording> recordList;
|
||||
public static int count=0;
|
||||
public RecordMSG(TCPmsg tcp)
|
||||
{
|
||||
super(tcp);
|
||||
recordList = new ArrayList<Recording>();
|
||||
String date4parsing = super.data;
|
||||
//SM.Debug("SMS date4parsing:"+date4parsing);
|
||||
String[] tempArr = date4parsing.split(";");
|
||||
|
||||
//SM.Debug("SMS tempArr.length:" +tempArr.length);
|
||||
for(int i =0; i<tempArr.length;i++)
|
||||
{
|
||||
String[] tempRec = tempArr[i].split("&");
|
||||
if(tempRec.length<7)
|
||||
continue;
|
||||
|
||||
Recording RecValue = new Recording();
|
||||
RecValue.ID = Long.parseLong(tempRec[0]);
|
||||
RecValue.startGMT = Integer.parseInt(tempRec[1]);
|
||||
RecValue.endGMT = Integer.parseInt(tempRec[2]);
|
||||
RecValue.gwID = Integer.parseInt(tempRec[3]);
|
||||
RecValue.radioGWID = Integer.parseInt(tempRec[4]);
|
||||
RecValue.subID = Integer.parseInt(tempRec[5]);
|
||||
RecValue.typeID = Integer.parseInt(tempRec[6]);
|
||||
|
||||
recordList.add(RecValue);
|
||||
}
|
||||
|
||||
count +=this.recordList.size();
|
||||
SM.Debug("alarmList size:" +this.recordList.size() + " total:" +count);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class Recording {
|
||||
public long ID;
|
||||
public int startGMT;
|
||||
public int endGMT;
|
||||
public int gwID;
|
||||
public int radioGWID;
|
||||
public int subID;
|
||||
public int typeID;
|
||||
public String NameForDisplay="";
|
||||
|
||||
/** RadioPad */
|
||||
public long date;
|
||||
public int duration;
|
||||
public String filename;
|
||||
public long destinationRadioID;
|
||||
public long sourceRadioID;
|
||||
public int type;
|
||||
|
||||
public Recording()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "ID: " + ID + " | start: " + startGMT + " | end: " + endGMT + " | gwID: " + gwID + " | radioGWID: " + radioGWID + " | subID: " + subID + " | typeID: " + typeID;
|
||||
}
|
||||
}
|
36
libSafeMobile/src/main/java/com/safemobile/lib/SM.java
Normal file
36
libSafeMobile/src/main/java/com/safemobile/lib/SM.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class SM
|
||||
{
|
||||
public static void Debug(String tag, String msg)
|
||||
{
|
||||
Log.d(tag,msg);
|
||||
/*
|
||||
try
|
||||
{
|
||||
if (!tag.toUpperCase().contains("DEFAULT"))
|
||||
Log.d("Default",msg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.d("Default","Error parse tag:"+ex.toString());
|
||||
}
|
||||
//*/
|
||||
}
|
||||
public static void Debug(String msg)
|
||||
{
|
||||
Log.d("Default",msg);
|
||||
}
|
||||
|
||||
public static void Exception(String msg)
|
||||
{
|
||||
Log.e("Exception",msg);
|
||||
}
|
||||
|
||||
public static void Exception(String tag, String msg)
|
||||
{
|
||||
Log.e(tag,msg);
|
||||
}
|
||||
}
|
34
libSafeMobile/src/main/java/com/safemobile/lib/SMS.java
Normal file
34
libSafeMobile/src/main/java/com/safemobile/lib/SMS.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class SMS {
|
||||
public int idx = 0;
|
||||
public int status = 0;
|
||||
public int timeGMT = 0;
|
||||
public String mess = "";
|
||||
public long sc_id_dest = 0;
|
||||
public long sc_id_sour = 0;
|
||||
public String seq_idx = "";
|
||||
|
||||
public SMS(){
|
||||
|
||||
}
|
||||
|
||||
public SMS(int _idx, int _status, int _timeGMT, String _mess, long _sc_id_dest, long _sc_id_sour)
|
||||
{
|
||||
idx = _idx;
|
||||
status = _status;
|
||||
timeGMT = _timeGMT;
|
||||
mess = _mess;
|
||||
sc_id_dest = _sc_id_dest;
|
||||
sc_id_sour = _sc_id_sour;
|
||||
seq_idx = "";
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "idx: " + idx + " | status: " + status + " | timeGMT: " + timeGMT
|
||||
+ " | mess: " + mess + " | sc_id_dest: " + sc_id_dest + " | sc_id_sour: " + sc_id_sour
|
||||
+ " | seq_idx: " + seq_idx;
|
||||
}
|
||||
|
||||
}
|
53
libSafeMobile/src/main/java/com/safemobile/lib/SMSmsg.java
Normal file
53
libSafeMobile/src/main/java/com/safemobile/lib/SMSmsg.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.SMS;
|
||||
|
||||
public class SMSmsg extends TCPmsg {
|
||||
|
||||
public ArrayList<SMS> smsList;
|
||||
public static int count=0;
|
||||
public SMSmsg(TCPmsg tcp) {
|
||||
super(tcp);
|
||||
smsList = new ArrayList<SMS>();
|
||||
String date4parsing = super.data;
|
||||
//SM.Debug("SMS date4parsing:"+date4parsing);
|
||||
String[] tempArr = date4parsing.split(";");
|
||||
|
||||
//SM.Debug("SMS tempArr.length:" +tempArr.length);
|
||||
for(int i =0; i<tempArr.length;i++)
|
||||
{
|
||||
//SM.Debug("i:" + i+"Data :"+tempArr[i]);
|
||||
String[] tempVeh = tempArr[i].split("&");
|
||||
|
||||
if(tempVeh.length<7)
|
||||
continue;
|
||||
SMS sms = new SMS();
|
||||
String sm = "";
|
||||
try {
|
||||
sms.idx = Integer.parseInt(tempVeh[0]);
|
||||
sm = sms.idx + "";
|
||||
sms.status = Integer.parseInt(tempVeh[1]);
|
||||
sm = sms.status + "";
|
||||
sms.timeGMT = Integer.parseInt(tempVeh[2]);
|
||||
sm = sms.timeGMT + "";
|
||||
sms.mess = tempVeh[3];
|
||||
sms.sc_id_sour = Integer.parseInt(tempVeh[4]);
|
||||
sm = sms.sc_id_sour + "";
|
||||
sms.sc_id_dest = Integer.parseInt(tempVeh[5]);
|
||||
sm = sms.sc_id_dest + "";
|
||||
sms.seq_idx = tempVeh[6];
|
||||
}
|
||||
catch(Exception ex) {
|
||||
SM.Exception("Exception in SMSmsg: " + ex.toString() + " | " + sm);
|
||||
}
|
||||
smsList.add(sms);
|
||||
//SM.Debug(sms.toString());
|
||||
}
|
||||
|
||||
count +=this.smsList.size();
|
||||
//SM.Debug("smsList size:" +this.smsList.size() + " total:" +count);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SerializedObject implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Object object;
|
||||
private String type;
|
||||
|
||||
public SerializedObject (Object object, String type){
|
||||
this.setObject(object);
|
||||
this.setType(type);
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return object;
|
||||
}
|
||||
public void setObject(Object object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class SuperVehicle extends Vehicle{
|
||||
|
||||
public double lat=0;
|
||||
public double lng=0;
|
||||
public boolean needUpdate=false;
|
||||
public int speed=0;
|
||||
public long timeGMT=0;
|
||||
public String Address="";
|
||||
public boolean isON=false;
|
||||
|
||||
public SuperVehicle(long sc_id, String imei, long lp, String name, long driver_id, int time_route, int GPS_reporting_interval, int is_stolen)
|
||||
{
|
||||
super(sc_id, imei, lp, name, driver_id, time_route, GPS_reporting_interval,
|
||||
is_stolen);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public void SetDataFromLastPos(Double _lat,Double _lng,long _time,int _speed,String _Address,Boolean _isON)
|
||||
{
|
||||
try
|
||||
{
|
||||
lat = _lat;
|
||||
lng = _lng;
|
||||
timeGMT = _time;
|
||||
speed = _speed;
|
||||
Address = _Address;
|
||||
isON = _isON;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.d("Erorr", "Contert Error:"+ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void SetNewPosition(Double _lat,Double _lng,long _time,int _speed)
|
||||
{
|
||||
try
|
||||
{
|
||||
lat = _lat;
|
||||
lng = _lng;
|
||||
timeGMT = _time;
|
||||
speed = _speed;
|
||||
isON = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.d("Erorr", "Contert Error:"+ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public String GetUnixTimeDisplay()
|
||||
{
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd-MMM");
|
||||
|
||||
return sdf.format(timeGMT*1000);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "name: " + name + "imei: " + imei + " | LAT: " + lat + " | LNG: " + lng + " | speed: " + speed + " | timeGMT: " + timeGMT + " | Address: " + Address + " | isON: " + isON;
|
||||
}
|
||||
}
|
87
libSafeMobile/src/main/java/com/safemobile/lib/TCPmsg.java
Normal file
87
libSafeMobile/src/main/java/com/safemobile/lib/TCPmsg.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class TCPmsg
|
||||
{
|
||||
public boolean OK;
|
||||
public int msgLen;
|
||||
public String seqID;
|
||||
public int opCode;
|
||||
public String data;
|
||||
public String error;
|
||||
public String allData;
|
||||
|
||||
public String leftOver="";
|
||||
|
||||
private char[] _rawdata;
|
||||
private int _len;
|
||||
public TCPmsg(char[] rawdata, int len)
|
||||
{
|
||||
_rawdata = rawdata;
|
||||
_len = len;
|
||||
OK = Parse();
|
||||
}
|
||||
|
||||
public TCPmsg(TCPmsg tcp)
|
||||
{
|
||||
_rawdata =tcp._rawdata;
|
||||
_len = tcp._len;
|
||||
OK = Parse();
|
||||
}
|
||||
|
||||
public TCPmsg(char[] msg)
|
||||
{
|
||||
_rawdata = msg;
|
||||
_len = msg.length;
|
||||
OK = Parse();
|
||||
}
|
||||
|
||||
private boolean Parse()
|
||||
{
|
||||
char[] temp = new char[_len];
|
||||
for(int i=0;i<_len;i++) temp[i] = _rawdata[i];
|
||||
data =new String(temp);
|
||||
//SM.Debug("multi RX: " + data);
|
||||
this.allData = data;
|
||||
|
||||
String[] tempArr = data.split("#");
|
||||
if ((tempArr.length == 0) || (tempArr.length == 1))
|
||||
{
|
||||
SM.Debug("incorect messagebuss message=" + data);
|
||||
return false;
|
||||
}
|
||||
//get msg len
|
||||
int messLen = -1;
|
||||
try
|
||||
{
|
||||
messLen = Integer.parseInt(tempArr[1]);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("incorect msg len =" + tempArr[1]);
|
||||
return false;
|
||||
}
|
||||
//messLen not int
|
||||
if(messLen ==-1) return false;
|
||||
|
||||
if (_len != messLen)
|
||||
{
|
||||
SM.Debug("message length("+messLen+") != actual length("+_len+")");
|
||||
return false;
|
||||
}
|
||||
|
||||
seqID = tempArr[2];
|
||||
opCode = Integer.parseInt(tempArr[3]);
|
||||
data = "";
|
||||
for (int i = 4; i < tempArr.length; i++)
|
||||
{
|
||||
if(tempArr[i] !="")
|
||||
data += tempArr[i]+"#";
|
||||
}
|
||||
|
||||
// add sequence ID to data when ack message
|
||||
if(opCode == OperationCodes.TM_ACK || opCode == OperationCodes.TM_ACK_SD)
|
||||
data+= seqID + "#";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
47
libSafeMobile/src/main/java/com/safemobile/lib/User.java
Normal file
47
libSafeMobile/src/main/java/com/safemobile/lib/User.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class User {
|
||||
public int id;
|
||||
public String firstname;
|
||||
public String lastname;
|
||||
public String login;
|
||||
public String password;
|
||||
public int user_type;
|
||||
public int ison = 0;
|
||||
public Vehicle vehValue;
|
||||
|
||||
public User()
|
||||
{
|
||||
this.id = -1;
|
||||
this.user_type = 1;
|
||||
}
|
||||
|
||||
public User(int id, String firstname, String lastname, String login, String password, int user_type, int ison)
|
||||
{
|
||||
this.id = id;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.login = login;
|
||||
this.password = password;
|
||||
this.user_type = user_type;
|
||||
this.ison = ison;
|
||||
this.vehValue =null;
|
||||
}
|
||||
|
||||
public User(int id, String firstname, String lastname, String login, String password, int user_type, int ison,Vehicle _vehValue)
|
||||
{
|
||||
this.id = id;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.login = login;
|
||||
this.password = password;
|
||||
this.user_type = user_type;
|
||||
this.ison = ison;
|
||||
vehValue =_vehValue;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "id: " + id + " | login: " + login + " | password: " + password + " | user_type: " + user_type;
|
||||
}
|
||||
}
|
46
libSafeMobile/src/main/java/com/safemobile/lib/VehMSG.java
Normal file
46
libSafeMobile/src/main/java/com/safemobile/lib/VehMSG.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
public class VehMSG extends TCPmsg{
|
||||
|
||||
public ArrayList<Vehicle> vehList;
|
||||
|
||||
public VehMSG(TCPmsg m) {
|
||||
super(m);
|
||||
|
||||
vehList = new ArrayList<Vehicle>();
|
||||
String date4parsing = super.data;
|
||||
SM.Debug("date4parsing:"+date4parsing);
|
||||
String[] tempArr = date4parsing.split(";");
|
||||
|
||||
SM.Debug("tempArr.length:" +tempArr.length);
|
||||
for(int i =0; i<tempArr.length;i++)
|
||||
{
|
||||
//SM.Debug("i:" + i+"Data :"+tempArr[i]);
|
||||
String[] tempVeh = tempArr[i].split("&");
|
||||
//SM.Debug("split len:"+tempVeh.length);
|
||||
|
||||
if(tempVeh.length<7)
|
||||
continue;
|
||||
int sc_id = Integer.parseInt(tempVeh[0]);
|
||||
String imei = tempVeh[1];
|
||||
//String serialNumber = tempVeh[2];
|
||||
String name = tempVeh[3];
|
||||
//String groupName = tempVeh[4];
|
||||
int lp = Integer.parseInt(tempVeh[5]);
|
||||
//String userName = tempVeh[6];
|
||||
boolean status = (Integer.parseInt(tempVeh[7])==1);
|
||||
|
||||
Vehicle veh = new Vehicle(sc_id, imei, lp, name, lp, 0, 0, 0);
|
||||
veh.status = status;
|
||||
vehList.add(veh);
|
||||
//SM.Debug("added veh to list:" +name);
|
||||
//SM.Debug("vehList new size:" +this.vehList.size());
|
||||
}
|
||||
|
||||
SM.Debug("vehList vehList:" +this.vehList.size());
|
||||
}
|
||||
}
|
162
libSafeMobile/src/main/java/com/safemobile/lib/Vehicle.java
Normal file
162
libSafeMobile/src/main/java/com/safemobile/lib/Vehicle.java
Normal file
@ -0,0 +1,162 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
public class Vehicle {
|
||||
public long id;
|
||||
public long sc_id;
|
||||
public long lp;
|
||||
public String name;
|
||||
public long driver_id;
|
||||
public int time_route = 0;
|
||||
public int GPS_reporting_interval = 50;
|
||||
public int is_stolen = 0;
|
||||
|
||||
public String imei;
|
||||
|
||||
public boolean checked = false, status = true;
|
||||
|
||||
public Vehicle()
|
||||
{
|
||||
this.sc_id = -1;
|
||||
this.lp = -1;
|
||||
}
|
||||
|
||||
public Vehicle(long sc_id, String imei, long lp, String name, long driver_id, int time_route, int GPS_reporting_interval, int is_stolen)
|
||||
{
|
||||
this.sc_id = sc_id;
|
||||
this.imei = imei;
|
||||
this.lp = lp;
|
||||
this.name = name;
|
||||
this.driver_id = driver_id;
|
||||
this.time_route = time_route;
|
||||
this.GPS_reporting_interval = GPS_reporting_interval;
|
||||
this.is_stolen = is_stolen;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "sc_id: " + sc_id + "imei: " + imei + "name: " + name + " | driver_id: " + driver_id + " | GPS: " + GPS_reporting_interval + " | checked: " + checked + " | status: " + (status ? "ON" : "OFF");
|
||||
}
|
||||
|
||||
public int getSmallIcon()
|
||||
{
|
||||
return getSmallIconPRV(driver_id);
|
||||
}
|
||||
|
||||
private int getSmallIconPRV(long driver_id)
|
||||
{
|
||||
switch ((int)driver_id)
|
||||
{
|
||||
case 1: return R.drawable.peopleblue;
|
||||
case 2: return R.drawable.peoplegreen;
|
||||
case 3: return R.drawable.peoplegrey;
|
||||
case 4: return R.drawable.peoplepink;
|
||||
case 5: return R.drawable.peoplepurple;
|
||||
case 78: return R.drawable.ambulance;
|
||||
case 79: return R.drawable.army;
|
||||
case 80: return R.drawable.bigcar0;
|
||||
case 81: return R.drawable.bigcar1;
|
||||
case 82: return R.drawable.bigcar2;
|
||||
case 83: return R.drawable.bus;
|
||||
case 84: return R.drawable.bus0;
|
||||
case 85: return R.drawable.bus2;
|
||||
case 86: return R.drawable.cabrioletred;
|
||||
case 87: return R.drawable.car0;
|
||||
case 88: return R.drawable.car1;
|
||||
case 89: return R.drawable.car2;
|
||||
case 90: return R.drawable.car3;
|
||||
case 91: return R.drawable.cargrey;
|
||||
case 92: return R.drawable.classiccar;
|
||||
case 93: return R.drawable.classycar;
|
||||
case 94: return R.drawable.dodge;
|
||||
case 95: return R.drawable.fireescape;
|
||||
case 96: return R.drawable.firefighters2;
|
||||
case 97: return R.drawable.firetruck1;
|
||||
case 98: return R.drawable.firetruck2;
|
||||
case 99: return R.drawable.jeep;
|
||||
case 100: return R.drawable.longhaul;
|
||||
case 101: return R.drawable.lorrygreen;
|
||||
case 102: return R.drawable.minibus;
|
||||
case 103: return R.drawable.minicar;
|
||||
case 104: return R.drawable.minicar2;
|
||||
case 105: return R.drawable.police;
|
||||
case 106: return R.drawable.police1;
|
||||
case 107: return R.drawable.schoolbus;
|
||||
case 108: return R.drawable.schoolbus2;
|
||||
case 109: return R.drawable.taxi;
|
||||
case 110: return R.drawable.towtruckyellow;
|
||||
case 111: return R.drawable.tractorunitblack;
|
||||
case 112: return R.drawable.truck0;
|
||||
case 113: return R.drawable.truck1;
|
||||
case 114: return R.drawable.truck2;
|
||||
case 115: return R.drawable.truck3;
|
||||
case 116: return R.drawable.truck4;
|
||||
case 117: return R.drawable.truck5;
|
||||
case 118: return R.drawable.truck6;
|
||||
case 119: return R.drawable.truckyellow;
|
||||
case 120: return R.drawable.wagon;
|
||||
default: return R.drawable.peopleblue;
|
||||
}
|
||||
}
|
||||
|
||||
public int getLargeIcon()
|
||||
{
|
||||
return getLargeIconPRV(driver_id);
|
||||
}
|
||||
|
||||
private int getLargeIconPRV(long driver_id)
|
||||
{
|
||||
switch((int)driver_id)
|
||||
{
|
||||
case 1: return R.drawable.peopleblue_large;
|
||||
case 2: return R.drawable.peoplegreen_large;
|
||||
case 3: return R.drawable.peoplegrey_large;
|
||||
case 4: return R.drawable.peoplepink_large;
|
||||
case 5: return R.drawable.peoplepurple_large;
|
||||
case 78: return R.drawable.ambulance_large;
|
||||
case 79: return R.drawable.army_large;
|
||||
case 80: return R.drawable.bigcar0_large;
|
||||
case 81: return R.drawable.bigcar1_large;
|
||||
case 82: return R.drawable.bigcar2_large;
|
||||
case 83: return R.drawable.bus_large;
|
||||
case 84: return R.drawable.bus0_large;
|
||||
case 85: return R.drawable.bus2_large;
|
||||
case 86: return R.drawable.cabrioletred_large;
|
||||
case 87: return R.drawable.car0_large;
|
||||
case 88: return R.drawable.car1_large;
|
||||
case 89: return R.drawable.car2_large;
|
||||
case 90: return R.drawable.car3_large;
|
||||
case 91: return R.drawable.cargrey_large;
|
||||
case 92: return R.drawable.classiccar_large;
|
||||
case 93: return R.drawable.classycar_large;
|
||||
case 94: return R.drawable.dodge_large;
|
||||
case 95: return R.drawable.fireescape_large;
|
||||
case 96: return R.drawable.firefighters2_large;
|
||||
case 97: return R.drawable.firetruck1_large;
|
||||
case 98: return R.drawable.firetruck2_large;
|
||||
case 99: return R.drawable.jeep_large;
|
||||
case 100: return R.drawable.longhaul_large;
|
||||
case 101: return R.drawable.lorrygreen_large;
|
||||
case 102: return R.drawable.minibus_large;
|
||||
case 103: return R.drawable.minicar_large;
|
||||
case 104: return R.drawable.minicar2_large;
|
||||
case 105: return R.drawable.police_large;
|
||||
case 106: return R.drawable.police1_large;
|
||||
case 107: return R.drawable.schoolbus_large;
|
||||
case 108: return R.drawable.schoolbus2_large;
|
||||
case 109: return R.drawable.taxi_large;
|
||||
case 110: return R.drawable.towtruckyellow_large;
|
||||
case 111: return R.drawable.tractorunitblack_large;
|
||||
case 112: return R.drawable.truck0_large;
|
||||
case 113: return R.drawable.truck1_large;
|
||||
case 114: return R.drawable.truck2_large;
|
||||
case 115: return R.drawable.truck3_large;
|
||||
case 116: return R.drawable.truck4_large;
|
||||
case 117: return R.drawable.truck5_large;
|
||||
case 118: return R.drawable.truck6_large;
|
||||
case 119: return R.drawable.truckyellow;
|
||||
case 120: return R.drawable.wagon;
|
||||
default: return R.drawable.peopleblue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
333
libSafeMobile/src/main/java/com/safemobile/lib/XMLParser.java
Normal file
333
libSafeMobile/src/main/java/com/safemobile/lib/XMLParser.java
Normal file
@ -0,0 +1,333 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.safemobile.lib.radio.Channel;
|
||||
import com.safemobile.lib.radio.Zone;
|
||||
|
||||
public class XMLParser {
|
||||
private ConfigFile config;
|
||||
private ArrayList<String> xmlPath;
|
||||
|
||||
public XMLParser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<String> getXMLPath()
|
||||
{
|
||||
// reset xmlPath
|
||||
xmlPath = new ArrayList<String>();
|
||||
File file[] = Environment.getExternalStorageDirectory().listFiles();
|
||||
recursiveFileFind(file);
|
||||
|
||||
return xmlPath;
|
||||
}
|
||||
|
||||
public ConfigFile parseXML(InputStream input)
|
||||
{
|
||||
XmlPullParser parser = Xml.newPullParser();
|
||||
ArrayList<Contact> contacts = new ArrayList<Contact>();
|
||||
ArrayList<Zone> zones = new ArrayList<Zone>();
|
||||
Radio radio = new Radio();
|
||||
try
|
||||
{
|
||||
parser.setInput(input, null);
|
||||
Contact contact = null;
|
||||
Zone zone = null;
|
||||
Channel channel = null;
|
||||
int eventType = parser.getEventType();
|
||||
boolean done = false;
|
||||
while (eventType != XmlPullParser.END_DOCUMENT && !done){
|
||||
String name = null;
|
||||
switch (eventType){
|
||||
// build config object on xml start
|
||||
case XmlPullParser.START_DOCUMENT:
|
||||
config = new ConfigFile();
|
||||
break;
|
||||
// if start tag (ex. <configuration>, <contact>, <channel>)
|
||||
case XmlPullParser.START_TAG:
|
||||
name = parser.getName();
|
||||
if (name.equalsIgnoreCase("contact"))
|
||||
{
|
||||
|
||||
try {
|
||||
String section = parser.getAttributeValue(3);
|
||||
if(section.equalsIgnoreCase("Digital"))
|
||||
{
|
||||
/* <contact name='Call1' call-type='Group Call' call-id='1' section='Digital' /> */
|
||||
contact = new Contact(0,"", 0,1,1);
|
||||
// get id and name for Contact
|
||||
contact.name = parser.getAttributeValue(0);
|
||||
String type = parser.getAttributeValue(1);
|
||||
|
||||
if(type.equals("Private Call"))
|
||||
contact.contactType = Contact.PRIVATE;
|
||||
else if (type.equals("Group Call"))
|
||||
contact.contactType = Contact.GROUP;
|
||||
contact.id = Integer.parseInt(parser.getAttributeValue(2));
|
||||
}
|
||||
else
|
||||
contact = null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
SM.Exception(e.toString());
|
||||
contact.id = 0;
|
||||
}
|
||||
}
|
||||
else if (name.equalsIgnoreCase("radio-id"))
|
||||
{
|
||||
/* <radio-id>101</radio-id> */
|
||||
try {
|
||||
// get radio id
|
||||
radio.id = Integer.parseInt(parser.nextText());
|
||||
}
|
||||
catch(Exception ex) {
|
||||
SM.Debug(ex.toString());
|
||||
}
|
||||
}
|
||||
else if (name.equalsIgnoreCase("radio-ip"))
|
||||
{
|
||||
/* <radio-ip>192.168.10.1</radio-ip> */
|
||||
// get radio ip
|
||||
radio.ip = parser.nextText();
|
||||
}
|
||||
else if (name.equalsIgnoreCase("zone"))
|
||||
{
|
||||
/* <zone position='1' name='zone1'> */
|
||||
zone = new Zone();
|
||||
try {
|
||||
// set zone Id, Number and Name
|
||||
zone.dbID = Integer.valueOf(parser.getAttributeValue(0));
|
||||
zone.id = Integer.valueOf(parser.getAttributeValue(0));
|
||||
zone.ZoneName = parser.getAttributeValue(1);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
SM.Debug(ex.toString());
|
||||
}
|
||||
}
|
||||
else if(name.equalsIgnoreCase("channel"))
|
||||
{
|
||||
/* <channel position='1' name='Channel1' /> */
|
||||
channel = new Channel();
|
||||
try {
|
||||
// set channel Id, Number and Name
|
||||
channel.chName = parser.getAttributeValue(1);
|
||||
channel.dbID = Integer.valueOf(parser.getAttributeValue(0));
|
||||
channel.id = Integer.valueOf(parser.getAttributeValue(0));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
SM.Debug(ex.toString());
|
||||
}
|
||||
}
|
||||
break;
|
||||
// if end tag (ex. </contacts>, </contact>, </channel>)
|
||||
case XmlPullParser.END_TAG:
|
||||
name = parser.getName();
|
||||
if (name.equalsIgnoreCase("contact") && contact != null)
|
||||
{
|
||||
if(contact.contactType == Contact.PRIVATE || contact.contactType == Contact.GROUP)
|
||||
contacts.add(contact); // add contact to Contacts list
|
||||
}
|
||||
else if (name.equalsIgnoreCase("channel"))
|
||||
zone.channelList.add(channel); // add channel to Channels List
|
||||
else if (name.equalsIgnoreCase("zone"))
|
||||
zones.add(zone); // add zone to Zones List
|
||||
else if (name.equalsIgnoreCase("configuration"))
|
||||
done = true; // flag finish parsing
|
||||
break;
|
||||
}
|
||||
eventType = parser.next();
|
||||
}
|
||||
|
||||
// add Lists to config
|
||||
config.contacts = contacts;
|
||||
config.radio = radio;
|
||||
|
||||
// check if every zone has at least a channel and if not, create one
|
||||
for(Zone zn :zones)
|
||||
{
|
||||
if(zn.channelList==null || (zn.channelList!=null && zn.channelList.size()== 0))
|
||||
{
|
||||
zn.channelList = new ArrayList<Channel>();
|
||||
Channel ch = new Channel();
|
||||
ch.dbID = 0;
|
||||
ch.chName = "N/A";
|
||||
ch.id = 0;
|
||||
zn.channelList.add(ch);
|
||||
}
|
||||
}
|
||||
|
||||
config.zones = zones;
|
||||
|
||||
//SM.Debug("CONFIG", config.toLongString());
|
||||
}
|
||||
catch (XmlPullParserException e) {
|
||||
//e.printStackTrace();
|
||||
SM.Exception(e.toString());
|
||||
|
||||
config = null;
|
||||
}
|
||||
catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
SM.Exception(e.toString());
|
||||
|
||||
config = null;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
// get files and directory for crt Directory (file1)
|
||||
private void recursiveFileFind(File[] crtFile){
|
||||
int i = 0;
|
||||
String filePath="";
|
||||
if(crtFile!=null)
|
||||
{
|
||||
while(i != crtFile.length)
|
||||
{
|
||||
// get absolute path for crtFile
|
||||
filePath = crtFile[i].getPath();
|
||||
if(crtFile[i].isDirectory()){
|
||||
// if crt file is a Directory get files for new file
|
||||
File file[] = crtFile[i].listFiles();
|
||||
recursiveFileFind(file);
|
||||
}
|
||||
i++;
|
||||
// if crtFile path extension is xml, add to ArrayList
|
||||
if(filePath.substring(filePath.length()-4, filePath.length()).equalsIgnoreCase(".xml"))
|
||||
{
|
||||
xmlPath.add(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean downloadXMLFile(String Path)
|
||||
{
|
||||
try {
|
||||
//set the download URL, a url that points to a file on the internet
|
||||
//this is the file to be downloaded
|
||||
//Path = "http://www.safemobile.com/upload/codeplugs/037TMA2140.xml";
|
||||
URL url = new URL(Path);
|
||||
//create the new connection
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
//set up some things on the connection
|
||||
urlConnection.setRequestMethod("GET");
|
||||
urlConnection.setDoOutput(true);
|
||||
|
||||
//and connect!
|
||||
urlConnection.connect();
|
||||
|
||||
//set the path where we want to save the file
|
||||
//in this case, going to save it on the root directory of the
|
||||
//sd card.
|
||||
File SDCardRoot = Environment.getExternalStorageDirectory();
|
||||
//create a new file, specifying the path, and the filename
|
||||
//which we want to save the file as.
|
||||
File file = new File(SDCardRoot,"radioConfigFile.xml");
|
||||
|
||||
//this will be used to write the downloaded data into the file we created
|
||||
FileOutputStream fileOutput = new FileOutputStream(file);
|
||||
|
||||
//this will be used in reading the data from the internet
|
||||
InputStream inputStream = urlConnection.getInputStream();
|
||||
|
||||
//this is the total size of the file
|
||||
//int totalSize = urlConnection.getContentLength();
|
||||
//variable to store total downloaded bytes
|
||||
int downloadedSize = 0;
|
||||
|
||||
//create a buffer...
|
||||
byte[] buffer = new byte[1024];
|
||||
int bufferLength = 0; //used to store a temporary size of the buffer
|
||||
|
||||
//now, read through the input buffer and write the contents to the file
|
||||
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
|
||||
//add the data in the buffer to the file in the file output stream (the file on the sd card
|
||||
fileOutput.write(buffer, 0, bufferLength);
|
||||
//add up the size so we know how much is downloaded
|
||||
downloadedSize += bufferLength;
|
||||
}
|
||||
//close the output stream when done
|
||||
fileOutput.close();
|
||||
SM.Debug(" ############## FINISH " + downloadedSize);
|
||||
return true;
|
||||
|
||||
//catch some possible errors...
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
SM.Exception(e.toString());
|
||||
|
||||
File SDCardRoot = Environment.getExternalStorageDirectory();
|
||||
//delete file is failed to download
|
||||
File file = new File(SDCardRoot,"radioConfigFile.xml");
|
||||
Boolean result = file.delete();
|
||||
SM.Debug("DELETE FILE: " + result);
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
SM.Exception(e.toString());
|
||||
|
||||
File SDCardRoot = Environment.getExternalStorageDirectory();
|
||||
//delete file is failed to download
|
||||
File file = new File(SDCardRoot,"radioConfigFile.xml");
|
||||
Boolean result = file.delete();
|
||||
SM.Debug("DELETE FILE: " + result);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
private InputStream getTextFile(FileInputStream inputStream)
|
||||
{
|
||||
InputStream input = inputStream;
|
||||
|
||||
int read;
|
||||
FileOutputStream fos = new FileOutputStream(new File(path + ".tmp"));
|
||||
|
||||
//DataOutputStream os = new DataOutputStream(new FileOutputStream("\\data\\data\\com.safemobile.radiopadd\\files\\"));
|
||||
try {
|
||||
input = new DataInputStream(new FileInputStream("c:\\binary.smc"));
|
||||
while (true) { // exception deals catches EOF
|
||||
read = input.r
|
||||
fos.write(read);
|
||||
//os.writeInt(is.readByte());
|
||||
}
|
||||
} catch (EOFException eof) {
|
||||
System.out.println("Normal program termination.");
|
||||
} catch (FileNotFoundException noFile) {
|
||||
System.err.println("File not found! " + noFile);
|
||||
} catch (IOException io) {
|
||||
System.err.println("I/O error occurred: " + io);
|
||||
} catch (Throwable anything) {
|
||||
System.err.println("Abnormal exception caught !: " + anything);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
os.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.safemobile.lib.radio;
|
||||
|
||||
public class Channel {
|
||||
|
||||
public int dbID;
|
||||
public int id;
|
||||
public String chName;
|
||||
|
||||
public Channel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Channel(int dbId, int id, String chName) {
|
||||
this.dbID = dbId;
|
||||
this.id = id;
|
||||
this.chName = chName;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "dbID: " + dbID + " | id: " + id + " | chName: " + chName ;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.safemobile.lib.radio;
|
||||
|
||||
public class Emerg {
|
||||
public int function = 0;
|
||||
public int status = 0;
|
||||
|
||||
public Emerg(){
|
||||
|
||||
}
|
||||
public String toString()
|
||||
{
|
||||
return "function: " + function + " | status: " + status ;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.safemobile.lib.radio;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Mic;
|
||||
|
||||
public class IncCall {
|
||||
public int gwID;
|
||||
public int rgwID;
|
||||
public long Imei;
|
||||
public int callStatus;
|
||||
public int callType;
|
||||
public int groupId;
|
||||
public int userID;
|
||||
public int opCode;
|
||||
public Mic mic = null;
|
||||
|
||||
public long callerID = 0;
|
||||
public long callDestID = 0;
|
||||
|
||||
public IncCall(){
|
||||
|
||||
}
|
||||
public String toString()
|
||||
{
|
||||
return " Imei: " + Imei + " | opCode: " + opCode
|
||||
+ " | callStatus: " + callStatus+ " | callType: " + callType
|
||||
+ " | groupId: " + groupId + " | userID: " + userID;
|
||||
}
|
||||
|
||||
public static String getCallTypeAsString(int type) {
|
||||
switch (type) {
|
||||
case AppParams.MotoAllCall: return "All Call";
|
||||
case AppParams.MotoGroup: return "Group Call";
|
||||
case AppParams.MotoPrivate: return "Private Call";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCallStatusAsString(int status) {
|
||||
switch (status) {
|
||||
case AppParams.InProgress: return "In Progress";
|
||||
case AppParams.Initiated: return "Initiated";
|
||||
case AppParams.Decoded: return "Decoded";
|
||||
case AppParams.Hangtime: return "Hangtime";
|
||||
case AppParams.Ended: return "Ended";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCallInitiatorAsString(final long myID, int userID) {
|
||||
if(userID == myID)
|
||||
return "my Android";
|
||||
else if (userID == 0)
|
||||
return "Portable";
|
||||
else
|
||||
return "other Android";
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.safemobile.lib.radio;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RadioGW {
|
||||
public int ID;
|
||||
public int GW_ID;
|
||||
public String IP;
|
||||
public String IMEI;
|
||||
public ArrayList<Zone> zoneList;
|
||||
public int lastZoneNr = 0;
|
||||
public int lastChannelNr = 0;
|
||||
public boolean isOnline = false;
|
||||
|
||||
public RadioGW(){zoneList = new ArrayList<Zone>();}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "ID: " + ID + " | GW_ID: " + GW_ID + " | IP: " + IP
|
||||
+ " | IMEI: " + IMEI ;
|
||||
}
|
||||
|
||||
public String getChannelName() {
|
||||
for(Zone zone: zoneList) {
|
||||
if(zone.id == lastZoneNr) {
|
||||
for(Channel ch: zone.channelList) {
|
||||
if(ch.id == lastChannelNr)
|
||||
return ch.chName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getZoneName() {
|
||||
for(Zone zone: zoneList) {
|
||||
if(zone.id == lastZoneNr)
|
||||
return zone.ZoneName;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.safemobile.lib.radio;
|
||||
|
||||
public class RadioStatus {
|
||||
public int gwID = 0;
|
||||
public int rgwID = 0;
|
||||
public int status = 0;
|
||||
|
||||
public IncCall incCall = new IncCall();
|
||||
|
||||
public RadioStatus(){
|
||||
|
||||
}
|
||||
public String toString()
|
||||
{
|
||||
return "gwID: " + gwID + " | rgwID: " + rgwID + " | status: " + status;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.safemobile.lib.radio;
|
||||
|
||||
public class SUstatus {
|
||||
public int imei;
|
||||
public int status;
|
||||
|
||||
public SUstatus(){
|
||||
|
||||
}
|
||||
public String toString()
|
||||
{
|
||||
return "imei: " + imei + " | status: " + status ;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.safemobile.lib.radio;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class Zone {
|
||||
public int dbID;
|
||||
public int id;
|
||||
public String ZoneName="";
|
||||
|
||||
public ArrayList<Channel> channelList = new ArrayList<Channel>();
|
||||
public Zone()
|
||||
{
|
||||
channelList = new ArrayList<Channel>();
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "zoneDbID: " + id +" |zoneID: " + dbID + " | ZoneName: " + ZoneName ;
|
||||
}
|
||||
|
||||
/**
|
||||
* sort the list of channels based on their names
|
||||
*/
|
||||
public void sortChannelListByName() {
|
||||
//Sorting
|
||||
Collections.sort(channelList, new Comparator<Channel>() {
|
||||
@Override
|
||||
public int compare(Channel channel1, Channel channel2)
|
||||
{
|
||||
return channel1.chName.compareTo(channel2.chName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sort the list of channels based on their ids
|
||||
*/
|
||||
public void sortChannelListByChannelID() {
|
||||
//Sorting
|
||||
Collections.sort(channelList, new Comparator<Channel>() {
|
||||
@Override
|
||||
public int compare(Channel channel1, Channel channel2)
|
||||
{
|
||||
return (channel1.id < channel2.id ? 1 : 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.safemobile.lib.radio;
|
||||
|
||||
public class ZoneChannel {
|
||||
|
||||
private Zone zone;
|
||||
private Channel channel;
|
||||
private boolean isSection = false;
|
||||
|
||||
public ZoneChannel(Zone zone) {
|
||||
setZone(zone);
|
||||
setSection(true);
|
||||
}
|
||||
|
||||
public ZoneChannel(Zone zone, Channel channel) {
|
||||
setZone(zone);
|
||||
setChannel(channel);
|
||||
if(channel != null)
|
||||
setSection(false);
|
||||
else
|
||||
setSection(true);
|
||||
}
|
||||
|
||||
public Zone getZone() {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void setZone(Zone zone) {
|
||||
this.zone = zone;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void setChannel(Channel channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public boolean isSection() {
|
||||
return isSection;
|
||||
}
|
||||
|
||||
public void setSection(boolean isSection) {
|
||||
this.isSection = isSection;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.safemobile.lib.radio;
|
||||
|
||||
public class Zone_and_channel {
|
||||
public int gwID = 0;
|
||||
public int rgwID = 0;
|
||||
public int zoneNr = 0;
|
||||
public int channelNr = 0;
|
||||
|
||||
public Zone_and_channel(){
|
||||
|
||||
}
|
||||
public String toString()
|
||||
{
|
||||
return "gwID: " + gwID + " | rgwID: " + rgwID + " | zoneNr: " + zoneNr
|
||||
+ " | mechannelNrss: " + channelNr ;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.safemobile.libpad;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
|
||||
public class PadRecording implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7819490854198306882L;
|
||||
public int dbID = 0;
|
||||
public int userID = 0;
|
||||
public long radioID = 0;
|
||||
public long initRadioID = 0;
|
||||
public int callType = 0;
|
||||
public boolean isOutgoing = false;
|
||||
public long timeGMT = 0;
|
||||
public int duration = 0;
|
||||
|
||||
|
||||
public long bytes_length = 0;
|
||||
public long bytes_received = 0;
|
||||
public int result = 0;
|
||||
|
||||
public PadRecording() {
|
||||
|
||||
}
|
||||
|
||||
public PadRecording(int dbID, int userID, long radioID, boolean isOutgoing, long initRadioID, int callType, long timeGMT, int duration) {
|
||||
this.dbID = dbID;
|
||||
this.userID = userID;
|
||||
this.radioID = radioID;
|
||||
this.isOutgoing = isOutgoing;
|
||||
this.initRadioID = initRadioID;
|
||||
this.callType = callType;
|
||||
this.timeGMT = timeGMT;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public static ArrayList<PadRecording> parseTCPMsg(String msg) {
|
||||
|
||||
ArrayList<PadRecording> recordings = new ArrayList<PadRecording>();
|
||||
try
|
||||
{
|
||||
msg = msg.replace("#", "");
|
||||
// split payload to get contacts
|
||||
|
||||
// split contact by /
|
||||
String[] contArr = msg.split("/");
|
||||
PadRecording rec = new PadRecording();
|
||||
rec.dbID = Integer.parseInt(contArr[0]);
|
||||
rec.userID = Integer.parseInt(contArr[1]);
|
||||
rec.radioID = Long.parseLong(contArr[2]);
|
||||
rec.initRadioID = Long.parseLong(contArr[3]);
|
||||
rec.callType = Integer.parseInt(contArr[4]);
|
||||
rec.isOutgoing = (Integer.parseInt(contArr[5]) == 1 ? true: false);
|
||||
rec.timeGMT = Long.parseLong(contArr[6]);
|
||||
rec.duration = Integer.parseInt(contArr[7]);
|
||||
|
||||
recordings.add(rec);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("Exception parse Recording", ex.toString());
|
||||
}
|
||||
|
||||
return recordings;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.safemobile.libpad;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class PadTextMessage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public long dbID = 0;
|
||||
public int userID = 0;
|
||||
public long radioID = 0;
|
||||
public String message = "";
|
||||
public boolean isOutgoing = false;
|
||||
public long timeGMT = 0;
|
||||
public int status = 0;
|
||||
public String seqID = "";
|
||||
public Integer tmSeqID = 0;
|
||||
|
||||
public PadTextMessage() {
|
||||
|
||||
}
|
||||
|
||||
public PadTextMessage(long dbID, int usedID, long radioId, boolean isOutgoing, String msg, long timeGMT, int status, String seqID) {
|
||||
this.dbID = dbID;
|
||||
this.userID = usedID;
|
||||
this.radioID = radioId;
|
||||
this.isOutgoing = isOutgoing;
|
||||
this.message = msg;
|
||||
this.timeGMT = timeGMT;
|
||||
this.status = status;
|
||||
this.seqID = seqID;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return dbID + "." + radioID + "[" + message + "]";
|
||||
}
|
||||
|
||||
public static ArrayList<PadTextMessage> parseTCPMsg(String msg) {
|
||||
|
||||
ArrayList<PadTextMessage> messages = new ArrayList<PadTextMessage>();
|
||||
try
|
||||
{
|
||||
msg = msg.replace("#", "");
|
||||
// split payload to get contacts
|
||||
|
||||
// split contact by /
|
||||
String[] contArr = msg.split("/");
|
||||
PadTextMessage message = new PadTextMessage();
|
||||
message.dbID = Integer.parseInt(contArr[0]);
|
||||
message.userID = Integer.parseInt(contArr[1]);
|
||||
message.radioID = Long.parseLong(contArr[2]);
|
||||
message.message = contArr[3];
|
||||
message.timeGMT = Long.parseLong(contArr[4]);
|
||||
message.isOutgoing = (Integer.parseInt(contArr[5]) == 1 ? true: false);
|
||||
message.status = Integer.parseInt(contArr[6]);
|
||||
|
||||
messages.add(message);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("Exception parse Message", ex.toString());
|
||||
}
|
||||
|
||||
return messages;
|
||||
|
||||
}
|
||||
|
||||
}
|
172
libSafeMobile/src/main/java/com/safemobile/maps/MapGoogle.java
Normal file
172
libSafeMobile/src/main/java/com/safemobile/maps/MapGoogle.java
Normal file
@ -0,0 +1,172 @@
|
||||
package com.safemobile.maps;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.safemobile.enums.MapType;
|
||||
import com.safemobile.interfaces.IMap;
|
||||
import com.safemobile.lib.Position;
|
||||
import com.safenet.lib.Geofence;
|
||||
import com.safenet.lib.Landmark;
|
||||
import com.safenet.lib.Unit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MapGoogle implements
|
||||
IMap,
|
||||
GoogleMap.OnCameraIdleListener,
|
||||
GoogleMap.OnCameraMoveStartedListener,
|
||||
GoogleMap.OnMarkerClickListener,
|
||||
GoogleMap.OnInfoWindowClickListener,
|
||||
GoogleMap.OnInfoWindowLongClickListener,
|
||||
GoogleMap.OnInfoWindowCloseListener,
|
||||
GoogleMap.OnCameraMoveListener {
|
||||
@Override
|
||||
public void onCameraIdle() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraMove() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraMoveStarted(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInfoWindowClick(@NonNull Marker marker) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInfoWindowClose(@NonNull Marker marker) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInfoWindowLongClick(@NonNull Marker marker) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClick(@NonNull Marker marker) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMapInteractionListener(MapInteraction delegate) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showContactsOnMap(ArrayList<Unit> units) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMarkerPosition(Unit unit) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMapType(MapType mapType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMapType(String mapType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void centerZoomContact(Unit unit) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void centerZoomMapOnLocation(LatLng mapLocation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void centerZoomMapOnLocation(LatLng mapLocation, float zoomLevel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMyselfOnMap(Position position, boolean shouldOpenInfoBubble, boolean shouldCenterNow) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideMyselfFromMap() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInfoBubbleForMarker(Long markerKey) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInfoBubble() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowLandmarksChangedHandler(boolean isShown, ArrayList<Landmark> landmarks) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowGeofencesChangedHandler(boolean isShown, ArrayList<Geofence> geofences) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowTrafficChangedHandler(boolean isShown) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReceived(Object map, LayoutInflater layoutInflater) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReceived(Object map, String tileServer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panZoomMap() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMapAvailable() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
package com.safemobile.services;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import com.safemobile.interfaces.ITCPListener;
|
||||
import com.safemobile.lib.AppParams;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class TCPService extends Service {
|
||||
|
||||
private int[] startModes = {START_STICKY, START_NOT_STICKY, START_REDELIVER_INTENT};
|
||||
private int mStartMode = startModes[0]; // indicates how to behave if the service is killed
|
||||
private IBinder mBinder = new TCPBinder(); // interface for clients that bind
|
||||
private boolean mAllowRebind = true; // indicates whether onRebind should be used
|
||||
private TCPhandler tcp = null;
|
||||
private TCPmsgParser tcpParser = null;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// create a TCP connection and a TCP msg Parser
|
||||
int port = 13589;
|
||||
try {
|
||||
port = Integer.parseInt(AppParams.PORT);
|
||||
}
|
||||
catch(Exception ex) { }
|
||||
|
||||
tcpParser = new TCPmsgParser();
|
||||
|
||||
if(tcp == null && !AppParams.IP.equalsIgnoreCase("n/a"))
|
||||
{
|
||||
tcp = new TCPhandler(getApplicationContext(), AppParams.IP, port);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
// The service is starting, due to a call to startService()
|
||||
return mStartMode;
|
||||
}
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// A client is binding to the service with bindService()
|
||||
return mBinder;
|
||||
}
|
||||
@Override
|
||||
public boolean onUnbind(Intent intent) {
|
||||
// All clients have unbound with unbindService()
|
||||
return mAllowRebind;
|
||||
}
|
||||
@Override
|
||||
public void onRebind(Intent intent) {
|
||||
// A client is binding to the service with bindService(),
|
||||
// after onUnbind() has already been called
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
// The service is no longer used and is being destroyed
|
||||
Toast.makeText(this, "service done", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/** get TCP Connection in order to send messages through TCP */
|
||||
public TCPhandler getTCPConnection()
|
||||
{
|
||||
return tcp;
|
||||
}
|
||||
|
||||
/** Add TCP Listener to TCPmsgParser */
|
||||
public boolean addITCPListener(ITCPListener listener)
|
||||
{
|
||||
if(tcpParser != null)
|
||||
tcpParser.addTCPListener(listener);
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** remove all TCP Listeners */
|
||||
public boolean clearITCPListeners()
|
||||
{
|
||||
if(tcpParser != null)
|
||||
tcpParser.clearITCPListeners();
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/** get TCP msg Parser in order to add a new TCP Listener */
|
||||
public TCPmsgParser getTCPmsgParser()
|
||||
{
|
||||
if(tcpParser == null)
|
||||
tcpParser = new TCPmsgParser();
|
||||
|
||||
return tcpParser;
|
||||
}
|
||||
|
||||
|
||||
/** Stop TCP Connection */
|
||||
public void stopTCPConnection()
|
||||
{
|
||||
if(tcp != null)
|
||||
{
|
||||
tcp.Stop();
|
||||
tcp = null;
|
||||
}
|
||||
}
|
||||
|
||||
/** restart the TCP Connection after the connection parameters had been changed */
|
||||
public void recreateTCPConnection()
|
||||
{
|
||||
/*
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000*2);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
*/
|
||||
// create a tcp connection
|
||||
int port = 13589;
|
||||
try {
|
||||
port = Integer.parseInt(AppParams.PORT);
|
||||
}
|
||||
catch(Exception ex) { }
|
||||
tcp = new TCPhandler(getApplicationContext(), AppParams.IP, port);
|
||||
/* }
|
||||
});
|
||||
t.start();
|
||||
*/
|
||||
}
|
||||
|
||||
public void recreateTCPConnection(String _ip, String _port)
|
||||
{
|
||||
// create a tcp connection
|
||||
int port = 13589;
|
||||
try {
|
||||
port = Integer.parseInt(_port);
|
||||
}
|
||||
catch(Exception ex) { }
|
||||
tcp = new TCPhandler(getApplicationContext(), _ip, port);
|
||||
}
|
||||
|
||||
public void updateTCPparameters(String ip, String _port)
|
||||
{
|
||||
if(tcp!=null)
|
||||
tcp.updateTCPparameters(ip, _port);
|
||||
else
|
||||
recreateTCPConnection();
|
||||
}
|
||||
|
||||
/** recreate a TCPmsgParser */
|
||||
public void recreateTCPmsgParser()
|
||||
{
|
||||
tcpParser = new TCPmsgParser();
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public String getCurrentTime() {
|
||||
SimpleDateFormat dateformat =
|
||||
new SimpleDateFormat("HH:mm:ss MM/dd/yyyy");
|
||||
return (dateformat.format(new Date()));
|
||||
}
|
||||
|
||||
/** get TCPService Binder */
|
||||
public class TCPBinder extends Binder {
|
||||
public TCPService getService() {
|
||||
return TCPService.this;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,704 @@
|
||||
package com.safemobile.services;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.LinkedList;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.TCPmsg;
|
||||
|
||||
|
||||
public class TCPhandler implements Runnable
|
||||
{
|
||||
private boolean alive = true;
|
||||
|
||||
public String serverHostname = new String ("10.120.1.114");//
|
||||
private int port = 13579;
|
||||
private Thread listenThread;
|
||||
private Socket soc =null;
|
||||
|
||||
//private BufferedReader recv;
|
||||
//private PrintWriter writer;
|
||||
|
||||
private DataInputStream input;
|
||||
private DataOutputStream output;
|
||||
private Timer timer;
|
||||
|
||||
private String leftOver = "";
|
||||
|
||||
public static LinkedList<TCPmsg> msgList;
|
||||
private volatile int n=0;
|
||||
|
||||
public Boolean isConnectionUP = false;
|
||||
public Boolean previousConnectionWasUP = false;
|
||||
|
||||
private Context context;
|
||||
private boolean isWiFiOn = true;
|
||||
|
||||
public TCPhandler(Context context, String hostName, int p)
|
||||
{
|
||||
|
||||
this.context = context;
|
||||
serverHostname=hostName;
|
||||
port=p;
|
||||
|
||||
msgList = new LinkedList<TCPmsg>();
|
||||
SM.Debug("---TCPhandler constructor [" + hostName + "," + p + "] ---");
|
||||
listenThread = new Thread(this, "TCPlisten");
|
||||
listenThread.start(); // (2) Start the thread.
|
||||
|
||||
|
||||
// create timer to check socket status
|
||||
timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//Looper.prepare();
|
||||
//mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
// get if is authenticated
|
||||
//Write("0.0", "d");
|
||||
previousConnectionWasUP = isConnectionUP;
|
||||
|
||||
// try to send something
|
||||
TCPmsgParser._fireonTCPConnectionStatusEvent(isConnectionUP, previousConnectionWasUP);
|
||||
}
|
||||
catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
SM.Exception("TIMERException", e.toString());
|
||||
}
|
||||
}
|
||||
}, 0, 3000);
|
||||
|
||||
// get WiFi state
|
||||
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
if(mWifi.isConnectedOrConnecting())
|
||||
isWiFiOn = true;
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
context.registerReceiver(mReceived, intentFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(soc!=null)
|
||||
soc.close();
|
||||
|
||||
soc = new Socket();
|
||||
soc.connect(new InetSocketAddress(serverHostname, port), 5000);
|
||||
|
||||
//soc.setSoTimeout(3000);
|
||||
//SM.Debug("Socket timeout:" + soc.getSoTimeout() );
|
||||
//soc.setSoTimeout(5000);
|
||||
|
||||
input = new DataInputStream(soc.getInputStream());
|
||||
output = new DataOutputStream(soc.getOutputStream());
|
||||
|
||||
//recv= new BufferedReader(new InputStreamReader(soc.getInputStream()));
|
||||
//writer =new PrintWriter(soc.getOutputStream()) ;
|
||||
|
||||
|
||||
if(soc !=null) {
|
||||
//previousConnectionWasUP = isConnectionUP;
|
||||
isConnectionUP = true;
|
||||
triggerTCPConnectionStateEvent();
|
||||
}
|
||||
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
SM.Debug("UnknownHostException", "TCPhandler break:"+e.toString());
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
SM.Debug("IllegalArgumentException", "TCPhandler break:"+e.toString());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
SM.Debug("IOException", "TCPhandler break:"+e.toString());
|
||||
}
|
||||
|
||||
while(alive)
|
||||
{
|
||||
//SM.Debug("Waiting for data...");
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
SM.Debug("TCPhandler Crash1 on sleep:"+e.toString());
|
||||
}
|
||||
|
||||
while(isConnectionUP)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(100);
|
||||
//SM.Debug("Waiting for data...");
|
||||
//process leftover
|
||||
try
|
||||
{
|
||||
boolean FinishLeftOver =true;
|
||||
while (FinishLeftOver)
|
||||
{
|
||||
// add this replacement if message length doesn't contain the last #
|
||||
// leftOver = leftOver.replace("##", "#");
|
||||
String[] tempArr2 = leftOver.split("#");
|
||||
if (tempArr2.length > 1)
|
||||
{
|
||||
int messLen;
|
||||
try
|
||||
{
|
||||
messLen = Integer.parseInt(tempArr2[1]);
|
||||
|
||||
//TODO talk to Gaby to fix this on Bridge
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SM.Debug("leftovers", "incorect msg len leftOver =" + tempArr2[1]);
|
||||
messLen =-1;
|
||||
}
|
||||
|
||||
if(messLen>leftOver.length())
|
||||
{
|
||||
FinishLeftOver =false;
|
||||
break;
|
||||
}
|
||||
else if(messLen==leftOver.length())
|
||||
{
|
||||
TCPmsg msg = new TCPmsg(leftOver.toCharArray());
|
||||
SM.Debug("leftovers", "RX from leftOver:"+msg.allData);
|
||||
|
||||
if(msg.allData.contains("#92#"))
|
||||
prioritizePongReceived();
|
||||
|
||||
msgList.add(msg);
|
||||
leftOver ="";
|
||||
FinishLeftOver =false;
|
||||
break;
|
||||
}
|
||||
else // we have more message in leftover
|
||||
{
|
||||
TCPmsg msg = new TCPmsg(leftOver.substring(0,messLen).toCharArray());
|
||||
SM.Debug("leftovers", "RX from leftOver:"+msg.allData);
|
||||
|
||||
if(msg.allData.contains("#92#"))
|
||||
prioritizePongReceived();
|
||||
|
||||
msgList.add(msg);
|
||||
leftOver = leftOver.substring(messLen,leftOver.length());
|
||||
}
|
||||
}
|
||||
else FinishLeftOver = false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SM.Debug("leftovers", "Error on process leftover"+e.toString());
|
||||
}
|
||||
//end process leftover
|
||||
|
||||
String data ="";
|
||||
n=0;
|
||||
//char[] buf = new char[1024];
|
||||
//n = recv.read(buf);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
// read data into buffer
|
||||
n = input.read(buf);
|
||||
//connection closed by server
|
||||
if(n==-1)
|
||||
{
|
||||
SM.Debug("TCP Client", "Connection closed by server!");
|
||||
soc.close();
|
||||
//previousConnectionWasUP = isConnectionUP;
|
||||
isConnectionUP = false;
|
||||
triggerTCPConnectionStateEvent();
|
||||
soc = null;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
byte[] temp = new byte[n];
|
||||
for(int i=0;i<n;i++) temp[i] = buf[i];
|
||||
//String data =new String(temp);
|
||||
|
||||
// decryptData
|
||||
temp = decryptTEA(temp);
|
||||
|
||||
data = new String(temp);
|
||||
|
||||
//if we have any leftovers from previous message add them
|
||||
if(leftOver.length()>1) // avoid case with only one #
|
||||
{
|
||||
data = leftOver+data;
|
||||
leftOver = "";
|
||||
}
|
||||
|
||||
//search for overflow message
|
||||
String[] tempArr = data.split("#");
|
||||
if ((tempArr.length == 0) || (tempArr.length == 1))
|
||||
{
|
||||
SM.Debug("TCP Client", "incorect messagebuss message=" + data);
|
||||
continue;
|
||||
}
|
||||
//get msg len
|
||||
// for(int i=0;i<tempArr.length;i++)
|
||||
// SM.Debug("I:"+i+" tempArr[i]:"+tempArr[i]);
|
||||
int messLen;
|
||||
try {
|
||||
messLen = Integer.parseInt(tempArr[1]);
|
||||
} catch (Exception e) {
|
||||
SM.Debug("TCP Client", "incorect msg len =" + tempArr[1]);
|
||||
continue;
|
||||
}
|
||||
//messLen not int
|
||||
if(messLen == -1)
|
||||
{
|
||||
//SM.Debug("messLen not int=" + messLen +" tempArr[1]:" +tempArr[1]);
|
||||
continue;
|
||||
}
|
||||
char[] temMSG = data.toCharArray();
|
||||
//SM.Debug("MessLen:"+messLen+" Data len:"+data.length()+"IF:"+(data.length() != messLen));
|
||||
if (data.length() != messLen)
|
||||
{
|
||||
//if expected string message is smaller then actual string then exit processing;
|
||||
if(messLen>data.length())
|
||||
//if(messLen>n)
|
||||
{
|
||||
//SM.Debug("duda","messLen=" + messLen +" data.length():" +data.length()+"n:"+n);
|
||||
leftOver = data; // Add by bigu
|
||||
continue;
|
||||
}
|
||||
//perform cut
|
||||
//SM.Debug("We got leftover ....message length("+messLen+") != actual length("+data.length()+")");
|
||||
temMSG = data.substring(0,messLen).toCharArray();
|
||||
//SM.Debug("temMSG:"+temMSG.toString());
|
||||
leftOver = data.substring(messLen,data.length());
|
||||
//SM.Debug("leftOver:"+leftOver);
|
||||
//leftOver = data.substring(messLen,n);
|
||||
//SM.Debug("left over string:"+leftOver);
|
||||
}
|
||||
//decode TCP msg
|
||||
TCPmsg msg = new TCPmsg(temMSG);
|
||||
|
||||
SM.Debug("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", msg.allData);
|
||||
|
||||
if(msg.allData.contains("#92#"))
|
||||
prioritizePongReceived();
|
||||
|
||||
msgList.add(msg);
|
||||
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Debug("TCPHandler", "TCPhandler/run/break:"+ex.toString());
|
||||
//previousConnectionWasUP = isConnectionUP;
|
||||
isConnectionUP = false;
|
||||
triggerTCPConnectionStateEvent();
|
||||
}
|
||||
}//while(connOK)
|
||||
|
||||
|
||||
//
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
SM.Debug("TCPhandler Crash2 on sleep:"+e.toString());
|
||||
//previousConnectionWasUP = isConnectionUP;
|
||||
}
|
||||
|
||||
//try to restart connection
|
||||
if(alive && isWiFiOn)
|
||||
RestartTCP();
|
||||
|
||||
}//while(alive)
|
||||
SM.Debug("==================================");
|
||||
SM.Debug("TCP listenThread stoped!! alive = false");
|
||||
SM.Debug("==================================");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a bypass in order to trigger the ping received event
|
||||
*/
|
||||
private void prioritizePongReceived() {
|
||||
TCPmsgParser._firePONGReceivedEvent();
|
||||
}
|
||||
|
||||
|
||||
/* Broadcast Received for WiFi Connect/Disconnect */
|
||||
public BroadcastReceiver mReceived = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
SM.Debug("WIFI STATE", action);
|
||||
|
||||
if(action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){
|
||||
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
// close socket if the wifi is disconnecting or disconnected
|
||||
if(!info.isConnectedOrConnecting()) {
|
||||
closeSocket();
|
||||
isWiFiOn = false;
|
||||
}
|
||||
else
|
||||
isWiFiOn = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Send a message through the TCP Socket
|
||||
* @param seqID The messages's sequence ID (a number of order)
|
||||
* @param msg The messages which will be sent
|
||||
* @return True if the message was sent
|
||||
*/
|
||||
public boolean Write(String seqID, String msg)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
/*
|
||||
if(writer != null)
|
||||
{
|
||||
String cmdok = "#" + seqID + msg;
|
||||
Integer tmp = cmdok.length() + 1;
|
||||
//SM.Debug("tmp:"+tmp);
|
||||
|
||||
tmp += Integer.toString(tmp).length();// tmp.ToString().Length;
|
||||
if((tmp==10)||(tmp==100)||(tmp==1000)) tmp++;
|
||||
cmdok = "#" + Integer.toString(tmp) + cmdok;
|
||||
writer.write(encryptTEA(cmdok));
|
||||
writer.flush();
|
||||
SM.Debug("TX:"+encryptTEA(cmdok));
|
||||
return true;
|
||||
}*/
|
||||
|
||||
if(output != null)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
String cmdok = "#" + seqID + msg;
|
||||
Integer tmp = cmdok.length() + 1;
|
||||
//SM.Debug("tmp:"+tmp);
|
||||
|
||||
tmp += Integer.toString(tmp).length();// tmp.ToString().Length;
|
||||
if((tmp==10)||(tmp==100)||(tmp==1000)) tmp++;
|
||||
cmdok = "#" + Integer.toString(tmp) + cmdok;
|
||||
|
||||
byte[] mess = encryptTEA(cmdok);
|
||||
|
||||
|
||||
output.write(mess);
|
||||
output.flush();
|
||||
|
||||
// show only notACK messages
|
||||
//if(mess[3] != 0x0C)
|
||||
SM.Debug(" ", new String(mess));
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
SM.Exception("TCPClient[Send]", e.toString());
|
||||
} catch (InterruptedException e) {
|
||||
SM.Exception("TCPClient[Send]", e.toString());
|
||||
} catch (NoSuchElementException e) {
|
||||
SM.Exception("TCPClient[Send]", e.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SM.Debug("TCPhandler Write Procedure:"+e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void setConnectionIsDown() {
|
||||
if(input != null) {
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
finally {
|
||||
input = null;
|
||||
}
|
||||
}
|
||||
|
||||
isConnectionUP = false;
|
||||
}
|
||||
|
||||
/* Encrypt a string using an encryption algorithm,
|
||||
* in this case TEA */
|
||||
public static byte[] encryptTEA(String toEncryptData) {
|
||||
byte[] encryptedByteArray = new byte[]{};
|
||||
|
||||
/*
|
||||
//encrypt message using TEA
|
||||
try {
|
||||
encryptedByteArray = TEA.encrypt(toEncryptData);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
SM.Exception("encryptTEA Exception(UEE): " + e.toString());
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
SM.Exception("encryptTEA Exception(IOoBE): " + e.toString());
|
||||
} catch (NullPointerException e) {
|
||||
SM.Exception("encryptTEA Exception(NPE): " + e.toString());
|
||||
}
|
||||
//*/
|
||||
|
||||
// no encryption
|
||||
encryptedByteArray = toEncryptData.getBytes();
|
||||
|
||||
return encryptedByteArray;
|
||||
}
|
||||
|
||||
/* Decrypt a string using an encryption algorithm,
|
||||
* in this case TEA */
|
||||
public static byte[] decryptTEA(byte[] toDecryptData) {
|
||||
byte[] decryptedByteArray = new byte[]{};
|
||||
|
||||
/*
|
||||
String sm = "";
|
||||
for(int i=0; i<toDecryptData.length; i++)
|
||||
sm+=toDecryptData[i] + " ";
|
||||
|
||||
SM.Debug("DDDDDD: " + sm);
|
||||
//*/
|
||||
/*
|
||||
//decrypt message using TEA
|
||||
try {
|
||||
decryptedByteArray = TEA.decrypt(toDecryptData);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
SM.Exception("encryptTEA Exception(UEE): " + e.toString());
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
SM.Exception("encryptTEA Exception(IOoBE): " + e.toString());
|
||||
} catch (NullPointerException e) {
|
||||
SM.Exception("encryptTEA Exception(NPE): " + e.toString());
|
||||
}
|
||||
|
||||
String sm = "";
|
||||
for(int i=0; i<decryptedByteArray.length; i++)
|
||||
sm+= (int)decryptedByteArray[i] + " ";
|
||||
//sm = new String(decryptedByteArray.toString());
|
||||
try {
|
||||
SM.Debug("##### " + new String(decryptedByteArray, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
SM.Debug("DEcrypted: " + decryptedByteArray.toString());
|
||||
|
||||
//*/
|
||||
|
||||
// no decryption
|
||||
decryptedByteArray = toDecryptData;
|
||||
|
||||
return decryptedByteArray;
|
||||
}
|
||||
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void updateTCPparameters(String ip, String _port)
|
||||
{
|
||||
|
||||
// stop socket
|
||||
try {
|
||||
if(soc != null)
|
||||
soc.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
serverHostname = ip;
|
||||
try
|
||||
{
|
||||
port = Integer.parseInt(_port);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
port = 13589;
|
||||
}
|
||||
}
|
||||
|
||||
public void triggerTCPConnectionStateEvent() {
|
||||
if(!isConnectionUP)
|
||||
TCPmsgParser._fireTCPConnectionDownEvent(previousConnectionWasUP);
|
||||
else
|
||||
TCPmsgParser._fireTCPConnectionUpEvent(previousConnectionWasUP);
|
||||
}
|
||||
|
||||
private void RestartTCP()
|
||||
{
|
||||
try
|
||||
{
|
||||
isConnectionUP = false;
|
||||
previousConnectionWasUP = false;
|
||||
|
||||
SM.Debug("Restarting TCP...ip:"+serverHostname + ":" + port);
|
||||
soc = new Socket();
|
||||
soc.connect(new InetSocketAddress(serverHostname, port), 5000);
|
||||
|
||||
input = new DataInputStream(soc.getInputStream());
|
||||
//input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
//output stream
|
||||
output = new DataOutputStream(soc.getOutputStream());
|
||||
|
||||
//recv= new BufferedReader(new InputStreamReader(soc.getInputStream()));
|
||||
//writer =new PrintWriter(soc.getOutputStream()) ;
|
||||
if(soc !=null)
|
||||
{
|
||||
//previousConnectionWasUP = isConnectionUP;
|
||||
isConnectionUP = true;
|
||||
//triggerTCPConnectionStateEvent();
|
||||
|
||||
/*
|
||||
//init connection
|
||||
boolean res = Write("0.0", "#19#" + AppParams.crtRadio.ip + "&"
|
||||
+ AppParams.crtRadio.id + "#");
|
||||
if(res){
|
||||
SM.Debug("Message (AirPadInit) sent to controller");
|
||||
}else{
|
||||
SM.Debug("Could not send message(AirPadInit)!!");
|
||||
}
|
||||
|
||||
//get
|
||||
res = Write("0.0", "#30#104#0#0#0#0#");
|
||||
if(res){
|
||||
SM.Debug("Message (GetSetZoneAndChannel) sent to app server zoneNR:"+0+ " channelNR:"+0);
|
||||
}else{
|
||||
SM.Debug("Could not send message(GetSetZoneAndChannel)!!!");
|
||||
}
|
||||
*/
|
||||
//init audio
|
||||
//AudioHandle.b_SendinitUDP = true;
|
||||
}
|
||||
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
SM.Exception("RestartTCP break:"+e.toString());
|
||||
isConnectionUP = false;
|
||||
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
SM.Debug("IllegalArgumentException", "RestartTCP break:"+e.toString());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
SM.Exception("RestartTCP break:"+e.toString());
|
||||
isConnectionUP = false;
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
SM.Exception("RestartTCP break:"+e.toString());
|
||||
isConnectionUP = false;
|
||||
}
|
||||
|
||||
triggerTCPConnectionStateEvent();
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return alive;
|
||||
}
|
||||
|
||||
public void setAlive(boolean alive) {
|
||||
this.alive = alive;
|
||||
}
|
||||
|
||||
/** close Socket when unReachable */
|
||||
public void closeSocket() {
|
||||
|
||||
try {
|
||||
input = null;
|
||||
output = null;
|
||||
if(soc!=null)
|
||||
soc.close();
|
||||
soc = null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
SM.Debug("Stopping TCP", "TCP Connection is stopping on " + AppParams.IP + ":" + port);
|
||||
alive = false;
|
||||
|
||||
|
||||
if(mReceived!= null)
|
||||
try{ context.unregisterReceiver(mReceived); } catch(Exception ex) {/* receiver not registered //*/};
|
||||
|
||||
// stop thread
|
||||
if(listenThread != null)
|
||||
{
|
||||
Thread moribund = listenThread;
|
||||
listenThread = null;
|
||||
moribund.interrupt();
|
||||
}
|
||||
|
||||
|
||||
if(input!=null)
|
||||
{
|
||||
try {
|
||||
input.close();
|
||||
input = null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(output!=null)
|
||||
{
|
||||
try {
|
||||
output.close();
|
||||
output = null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(soc !=null)
|
||||
{
|
||||
try {
|
||||
soc.close();
|
||||
soc = null;
|
||||
}
|
||||
catch (IOException e) {
|
||||
SM.Exception("TCPClient[STOP]", "Stop break:"+e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,459 @@
|
||||
package com.safemobile.services;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import com.safemobile.interfaces.ITCPListener;
|
||||
import com.safemobile.interfaces.TCPEvent;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.TCPmsg;
|
||||
import com.safemobile.services.TCPhandler;
|
||||
|
||||
|
||||
public class TCPmsgParser implements Runnable{
|
||||
|
||||
|
||||
public boolean run = true;
|
||||
private TCPmsg _msg;
|
||||
private static List<ITCPListener> _listeners = new ArrayList<ITCPListener>();
|
||||
private Thread TCPmsgParserThread;
|
||||
|
||||
public TCPmsgParser()
|
||||
{
|
||||
TCPmsgParserThread = new Thread(this, "TCPmsgParserThread");
|
||||
TCPmsgParserThread.start(); // (2) Start the thread.
|
||||
}
|
||||
|
||||
public synchronized void addTCPListener( ITCPListener l ) {
|
||||
_listeners.add( l );
|
||||
}
|
||||
|
||||
public synchronized void removeTCPListener( ITCPListener l ) {
|
||||
_listeners.remove( l );
|
||||
}
|
||||
|
||||
public synchronized void clearITCPListeners() {
|
||||
_listeners.clear();
|
||||
}
|
||||
|
||||
public int getListenersSize()
|
||||
{
|
||||
return _listeners.size();
|
||||
}
|
||||
|
||||
private synchronized void _fireLoginEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onLoginReceived( event );
|
||||
}
|
||||
}
|
||||
private synchronized void _fireGPSEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onGPSReceived(event);
|
||||
}
|
||||
}
|
||||
private synchronized void _fireSMSEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onSMSReceived( event );
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireLastSMSEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onLastSMSsReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireVehEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onVehiclesReceived( event );
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireNewSMS() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onNewSMSReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireSMSconfirm() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onSMSAckReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireLastPos() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onLastPositionsReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireRadioEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onRadioMsgReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireHistPos() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onHistoryPositionsReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireHistCount() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onHistoryPositionsCountReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireAlarmList() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onAlarmsReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireAlarmACK() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).onAlarmAckReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireAlarmLive() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next() ).alarmLiveRecv(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireRecordList() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onRecordingsListReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireRecordPlay() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onRecordingPlayReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _firePOLLEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onPollReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireConnectionReplyEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onConnectionReplyReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireContactsReceivedEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onContactsListReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireRecordingsReceivedEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onRecordingsListReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void _fireTextMessagesReceivedEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onTextMessagesListReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private synchronized void _fireRecordingPlayReceivedEvent() {
|
||||
TCPEvent event = new TCPEvent( this, _msg );
|
||||
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onRecordingPlayReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static synchronized void _fireTCPConnectionDownEvent(boolean previuosWasConnectionUp) {
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onTCPConnectionDown(previuosWasConnectionUp);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void _fireTCPConnectionUpEvent(boolean previuosWasConnectionUp) {
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onTCPConnectionUp(previuosWasConnectionUp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static synchronized void _fireonTCPConnectionStatusEvent(boolean isConnectionUp, boolean previuosWasConnectionUp) {
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onTCPConnectionStatusReceived(isConnectionUp, previuosWasConnectionUp);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void _firePONGReceivedEvent() {
|
||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPListener) listeners.next()).onPONGReceived();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while(run)
|
||||
{
|
||||
//SM.Debug("TCPmsgParser waiting for data...");
|
||||
sleep(1);
|
||||
|
||||
if(TCPhandler.msgList==null)
|
||||
continue;
|
||||
if(!TCPhandler.msgList.isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
_msg = TCPhandler.msgList.poll();
|
||||
if(_msg == null)
|
||||
continue;
|
||||
if(_msg.OK == false)
|
||||
continue;
|
||||
//parse the rest of the message;
|
||||
|
||||
switch(_msg.opCode)
|
||||
{
|
||||
case 40:{
|
||||
_fireLoginEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case 41:{
|
||||
_fireVehEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case 42:{
|
||||
_fireSMSEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case 43:{
|
||||
_fireLastSMSEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.TM_ACK:{
|
||||
_fireSMSconfirm();
|
||||
break;
|
||||
}
|
||||
case OperationCodes.TM_ACK_SD:{
|
||||
_fireSMSconfirm();
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.RECEIVED_TM:{
|
||||
_fireNewSMS();
|
||||
break;
|
||||
}
|
||||
|
||||
case 45:{
|
||||
_fireLastPos();
|
||||
break;
|
||||
}
|
||||
|
||||
case 131:{
|
||||
_fireGPSEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case 231:{
|
||||
_firePOLLEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case 50:{
|
||||
_fireRadioEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case 46:{
|
||||
_fireHistPos();
|
||||
break;
|
||||
}
|
||||
|
||||
case 86:{
|
||||
_fireHistCount();
|
||||
break;
|
||||
}
|
||||
|
||||
case 47:{
|
||||
_fireAlarmList();
|
||||
break;
|
||||
}
|
||||
|
||||
case 48:{
|
||||
_fireAlarmACK();
|
||||
break;
|
||||
}
|
||||
|
||||
case 49:{
|
||||
_fireRecordList();
|
||||
break;
|
||||
}
|
||||
|
||||
case 38:{
|
||||
_fireRecordPlay();
|
||||
break;
|
||||
}
|
||||
|
||||
case 135:
|
||||
case 136:
|
||||
case 137:
|
||||
case 138:
|
||||
case 140:{
|
||||
_fireAlarmLive();
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.PONG: {
|
||||
//_firePONGReceivedEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.CONNECTION_REP: {
|
||||
_fireConnectionReplyEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.CONTACTS_REP: {
|
||||
sleep(15);
|
||||
_fireContactsReceivedEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.TM_LIST_REP: {
|
||||
_fireTextMessagesReceivedEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.RECORDINGS_LIST_REP: {
|
||||
_fireRecordingsReceivedEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
case OperationCodes.RECORDING_REP: {
|
||||
_fireRecordingPlayReceivedEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
try {
|
||||
if(TCPhandler.msgList.size() > 0)
|
||||
_msg = TCPhandler.msgList.remove(0);
|
||||
}
|
||||
catch(NoSuchElementException exe)
|
||||
{
|
||||
SM.Exception("TCP msg Parser", "NoSuchElementException");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
catch (Exception e)
|
||||
{
|
||||
SM.Debug("Error on fire Event:"+e.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
}*/
|
||||
SM.Debug("TCPmsgParser listen thread stoped.");
|
||||
}
|
||||
|
||||
private void sleep(int miliseconds) {
|
||||
try {
|
||||
Thread.sleep(miliseconds);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void clearMsgList()
|
||||
{
|
||||
TCPhandler.msgList.clear();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
run = false;
|
||||
// stop thread
|
||||
if(TCPmsgParserThread != null)
|
||||
{
|
||||
Thread moribund = TCPmsgParserThread;
|
||||
TCPmsgParserThread = null;
|
||||
moribund.interrupt();
|
||||
}
|
||||
SM.Debug("Stoping TCPmsgParser");
|
||||
}
|
||||
|
||||
}
|
280
libSafeMobile/src/main/java/com/safemobile/services/TEA.java
Normal file
280
libSafeMobile/src/main/java/com/safemobile/services/TEA.java
Normal file
@ -0,0 +1,280 @@
|
||||
package com.safemobile.services;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class TEA {
|
||||
|
||||
private final static long DELTA = 0x9E3779B9L;
|
||||
private final static long STEPS = 32;
|
||||
private final static long UNDELTA = 0xC6EF3720L;
|
||||
private static final String password = "SafeMobileBridge";
|
||||
private static String encoding = "UTF-8";
|
||||
private static long[] encrypted;
|
||||
private static long[] decrypted;
|
||||
private static long[] key;
|
||||
|
||||
public TEA(String password, String encoding) throws UnsupportedEncodingException {
|
||||
// convert key to long
|
||||
key = convertByteArrayToLongArray(password.getBytes(encoding));
|
||||
TEA.encoding = encoding;
|
||||
}
|
||||
|
||||
public TEA(String password) throws UnsupportedEncodingException {
|
||||
// convert key to long
|
||||
key = convertByteArrayToLongArray(password.getBytes(encoding));
|
||||
}
|
||||
|
||||
|
||||
public static byte[] encrypt(String toEncrypt) throws UnsupportedEncodingException {
|
||||
encrypted = new long[200];
|
||||
|
||||
key = convertByteArrayToLongArray(password.getBytes(encoding));
|
||||
|
||||
// convert String to long array
|
||||
long[] values = convertByteArrayToLongArray(toEncrypt.getBytes(encoding));
|
||||
|
||||
encrypted = new long[values.length];
|
||||
|
||||
// encipher the long array
|
||||
for(int i=0; i<values.length; i=i+2) {
|
||||
//System.out.println("v[" + i + "]=" + values[i]);
|
||||
//System.out.println("v[" + (i+1) + "]=" + values[i+1]);
|
||||
|
||||
// get the long values that will be enciphered
|
||||
long[] v = new long[2];
|
||||
long[] w = new long[2];
|
||||
v[0] = values[i];
|
||||
v[1] = values[i+1];
|
||||
|
||||
// ENCRYPT
|
||||
encipher(v, w, key);
|
||||
|
||||
// save the encrypted values in the big string
|
||||
encrypted[i] = w[0];
|
||||
encrypted[i+1] = w[1];
|
||||
//System.out.println("\nEncrypted: " + w[0] + " | " + w[1]);
|
||||
}
|
||||
return convertLongArrayToByteArray(encrypted, false);
|
||||
}
|
||||
|
||||
/*
|
||||
public static byte[] decrypt(long[] toDecrypt) {
|
||||
// convert String to long array
|
||||
long[] values = toDecrypt;
|
||||
|
||||
decrypted = new long[values.length];
|
||||
|
||||
for(int i=0; i<values.length; i=i+2) {
|
||||
//System.out.println("v[" + i + "]=" + values[i]);
|
||||
//System.out.println("v[" + (i+1) + "]=" + values[i+1]);
|
||||
|
||||
long[] v = new long[2];
|
||||
long[] w = new long[2];
|
||||
v[0] = values[i];
|
||||
v[1] = values[i+1];
|
||||
|
||||
|
||||
// ENCRYPT
|
||||
decipher(v, w, key);
|
||||
|
||||
// save the encrypted values in the big string
|
||||
decrypted[i] = w[0];
|
||||
decrypted[i+1] = w[1];
|
||||
//System.out.println("\nEncrypted: " + w[0] + " | " + w[1]);
|
||||
}
|
||||
|
||||
return convertLongArrayToByteArray(decrypted);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
public static byte[] decrypt(byte[] toDecrypt) throws UnsupportedEncodingException {
|
||||
// convert String containing encrypted data to long array
|
||||
long[] values = convertByteArrayToLongArray(toDecrypt);
|
||||
|
||||
decrypted = new long[values.length];
|
||||
|
||||
key = convertByteArrayToLongArray(password.getBytes(encoding));
|
||||
|
||||
for(int i=0; i<values.length; i=i+2) {
|
||||
//System.out.println("v[" + i + "]=" + values[i]);
|
||||
//System.out.println("v[" + (i+1) + "]=" + values[i+1]);
|
||||
|
||||
long[] v = new long[2];
|
||||
long[] w = new long[2];
|
||||
v[0] = values[i];
|
||||
v[1] = values[i+1];
|
||||
|
||||
// DECRYPT
|
||||
decipher(v, w, key);
|
||||
|
||||
// save the encrypted values in the big string
|
||||
decrypted[i] = w[0];
|
||||
decrypted[i+1] = w[1];
|
||||
//System.out.println("\nEncrypted: " + w[0] + " | " + w[1]);
|
||||
}
|
||||
|
||||
return convertLongArrayToByteArray(decrypted, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void encipher(long v[], long w[], long k[])
|
||||
{
|
||||
long y=v[0],z=v[1],sum=0, a=k[0],b=k[1],c=k[2],d=k[3],n=STEPS;
|
||||
|
||||
//System.out.printf("\nv[0] = %d | v[1] = %d\n", y, z);
|
||||
//System.out.printf("a=%d | b=%d | c=%d | d=%d\n", a,b,c,d);
|
||||
|
||||
while(n-- > 0)
|
||||
{
|
||||
/*
|
||||
sum += DELTA;
|
||||
y += ((z << 4)+a) ^ (z+sum) ^ ((z >> 5)+b);
|
||||
z += ((y << 4)+c) ^ (y+sum) ^ ((y >> 5)+d);
|
||||
*/
|
||||
sum = (long)((int)(sum + DELTA) & 0xFFFFFFFFL);
|
||||
|
||||
/*
|
||||
System.out.println("left: " + (ctu(z<<4) + a));
|
||||
System.out.println("center: " + ctu(z + sum));
|
||||
System.out.println("right: " + (ctu(z>>>5) + b));
|
||||
*/
|
||||
y = ctu(y + ((ctu(z<<4) + a) ^ (z + sum) ^ (ctu(z>>>5) + b)));
|
||||
z = ctu(z + ((ctu(y<<4) + c) ^ (y + sum) ^ (ctu(y>>>5) + d)));
|
||||
|
||||
//System.out.println("Y = " + y + " | " + "Z = " + z) ;
|
||||
}
|
||||
w[0]=y; w[1]=z;
|
||||
|
||||
//System.out.println("Encrypted: " + y + " | " + z);
|
||||
}
|
||||
|
||||
private static void decipher(long v[], long w[], long k[])
|
||||
{
|
||||
long y=v[0],z=v[1],sum=UNDELTA, a=k[0],b=k[1], c=k[2],d=k[3],n=STEPS;
|
||||
/* sum = delta<<5, in general sum = delta * n */
|
||||
while(n-->0)
|
||||
{
|
||||
z = ctu(z - ((ctu(y << 4)+c) ^ (y+sum) ^ (ctu(y >>> 5)+d)));
|
||||
y = ctu(y - ((ctu(z << 4)+a) ^ (z+sum) ^ (ctu(z >>> 5)+b)));
|
||||
|
||||
//System.out.println("Y = " + y + " | " + "Z = " + z) ;
|
||||
|
||||
sum -= DELTA;
|
||||
}
|
||||
w[0]=y; w[1]=z;
|
||||
//System.out.println("Y = " + y + " | " + "Z = " + z) ;
|
||||
}
|
||||
|
||||
/*
|
||||
private long convertToUnsigned(long value) {
|
||||
return (((int) value) & 0xFFFFFFFFL);
|
||||
}
|
||||
*/
|
||||
|
||||
private static long ctu (long value) {
|
||||
return (((int) value) & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
|
||||
private static long[] convertByteArrayToLongArray(byte[] toConvert) {
|
||||
// convert string in an array of bytes
|
||||
byte[] by = toConvert;
|
||||
|
||||
|
||||
// get the size of long array considering that a long has 4bytes
|
||||
int size = (int) Math.ceil(by.length / 4);
|
||||
|
||||
// if the size of the array is an odd number I should increase it because
|
||||
// encryption needs an array of two long values
|
||||
if(size % 2 != 0)
|
||||
size++;
|
||||
|
||||
long[] values = new long[size];
|
||||
|
||||
// convert every string value to a long one by shifting 4 chars
|
||||
// a long is 4 bytes
|
||||
for(int i=0; i<by.length; i=i+4) {
|
||||
|
||||
//
|
||||
byte c4 = ((i+3 >= by.length ) ? 0 : (byte) by[i+3]);
|
||||
byte c3 = ((i+2 >= by.length ) ? 0 : (byte) by[i+2] );
|
||||
byte c2 = ((i+1 >= by.length ) ? 0 : (byte) by[i+1] );
|
||||
byte c1 = ((i >= by.length ) ? 0 : (byte) by[i] );
|
||||
|
||||
//System.out.println("###" + c4 + " | " + c3 + " | " + c2 + " | " + c1);
|
||||
|
||||
values[i/4] = ctu(((c4 & 0x00FFL) << 24) + ((c3 & 0x00FFL) << 16) + ((c2 & 0x00FFL) << 8) + ((c1 & 0x00FFL)));
|
||||
//System.out.println("##### " + (encrypted == null ? 0 : encrypted[i/4]) + " | " + values[i/4]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
private static byte[] convertLongArrayToByteArray(long[] array, boolean isDecrypt) {
|
||||
//String myString = "";
|
||||
byte[] byteArray = new byte[array.length * 4];
|
||||
byte[] byteArrayReduced;
|
||||
int sizeToReduce = 0;
|
||||
|
||||
// convert every bytes from a long into a char using masks
|
||||
for(int i=0; i<array.length; i++) {
|
||||
byte c1 = (byte) (array[i] & 0xFF);
|
||||
byte c2 = (byte) ((array[i] & 0x0000FF00) >> 8);
|
||||
byte c3 = (byte) ((array[i] & 0x00FF0000) >> 16);
|
||||
byte c4 = (byte) ((array[i] & 0xFF000000) >> 24);
|
||||
|
||||
//System.out.println("###" + array[i] + " | c4: " + c4 + " | " + c3 + " | " + c2 + " | " + c1);
|
||||
//*
|
||||
// remove last bytes containing 0 because they are unwanted information
|
||||
if(array.length > 1 && i==(array.length-1) && isDecrypt)
|
||||
{
|
||||
System.out.println("LAST Chunck of four");
|
||||
if (c4 != 0)
|
||||
byteArray[i*4+3] = c4;
|
||||
else
|
||||
sizeToReduce++;
|
||||
if (c3 != 0)
|
||||
byteArray[i*4+2] = c3;
|
||||
else
|
||||
sizeToReduce++;
|
||||
if (c2 != 0)
|
||||
byteArray[i*4+1] = c2;
|
||||
else
|
||||
sizeToReduce++;
|
||||
if (c1 != 0)
|
||||
byteArray[i*4] = c1;
|
||||
else
|
||||
sizeToReduce++;
|
||||
}
|
||||
// add value because it's not the last long value
|
||||
|
||||
else //*/
|
||||
{
|
||||
byteArray[i*4] = c1;
|
||||
byteArray[i*4+1] = c2;
|
||||
byteArray[i*4+2] = c3;
|
||||
byteArray[i*4+3] = c4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// remove the 0's from the string, they were added when converting long
|
||||
//System.out.println("#### Syze to reduce : " + sizeToReduce);
|
||||
byteArrayReduced = new byte[byteArray.length - sizeToReduce];
|
||||
for(int i=0; i<(byteArray.length - sizeToReduce); i++)
|
||||
byteArrayReduced[i] = byteArray[i];
|
||||
|
||||
/*
|
||||
try {
|
||||
myString = new String ( byteArray, encoding);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
|
||||
//myString = new String(byteArray);
|
||||
|
||||
return byteArrayReduced;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user