1st version that works
54
safeDispatch/build.gradle
Normal file
@ -0,0 +1,54 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
|
||||
|
||||
android {
|
||||
compileSdkVersion 31
|
||||
buildToolsVersion "31.0.0"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.safemobile.dispatch"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 31
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding false
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation project(':libSafeMobile')
|
||||
|
||||
// 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.appcompat:appcompat:1.4.1'
|
||||
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'
|
||||
|
||||
// define a BOM and its version
|
||||
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.3"))
|
||||
|
||||
// define any required OkHttp artifacts without version
|
||||
implementation("com.squareup.okhttp3:okhttp")
|
||||
implementation("com.squareup.okhttp3:logging-interceptor")
|
||||
|
||||
// add Gson
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
|
||||
//retrofit
|
||||
}
|
119
safeDispatch/lint.xml
Normal file
@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<lint>
|
||||
<issue id="AdapterViewChildren" severity="ignore" />
|
||||
<issue id="AllowBackup" severity="ignore" />
|
||||
<issue id="AlwaysShowAction" severity="ignore" />
|
||||
<issue id="ButtonCase" severity="ignore" />
|
||||
<issue id="ButtonOrder" severity="ignore" />
|
||||
<issue id="CommitPrefEdits" severity="ignore" />
|
||||
<issue id="ContentDescription" severity="ignore" />
|
||||
<issue id="DalvikOverride" severity="ignore" />
|
||||
<issue id="DefaultLocale" severity="ignore" />
|
||||
<issue id="Deprecated" severity="ignore" />
|
||||
<issue id="DisableBaselineAlignment" severity="ignore" />
|
||||
<issue id="DrawAllocation" severity="ignore" />
|
||||
<issue id="DuplicateActivity" severity="ignore" />
|
||||
<issue id="DuplicateIds" severity="ignore" />
|
||||
<issue id="DuplicateIncludedIds" severity="ignore" />
|
||||
<issue id="EnforceUTF8" severity="ignore" />
|
||||
<issue id="ExportedActivity" severity="ignore" />
|
||||
<issue id="ExportedContentProvider" severity="ignore" />
|
||||
<issue id="ExportedReceiver" severity="ignore" />
|
||||
<issue id="ExportedService" severity="ignore" />
|
||||
<issue id="ExtraText" severity="ignore" />
|
||||
<issue id="ExtraTranslation" severity="ignore" />
|
||||
<issue id="FloatMath" severity="ignore" />
|
||||
<issue id="GifUsage" severity="ignore" />
|
||||
<issue id="GrantAllUris" severity="ignore" />
|
||||
<issue id="GridLayout" severity="ignore" />
|
||||
<issue id="HandlerLeak" severity="ignore" />
|
||||
<issue id="HardcodedDebugMode" severity="ignore" />
|
||||
<issue id="HardcodedText" severity="ignore" />
|
||||
<issue id="IconColors" severity="ignore" />
|
||||
<issue id="IconDensities" severity="ignore" />
|
||||
<issue id="IconDipSize" severity="ignore" />
|
||||
<issue id="IconDuplicates" severity="ignore" />
|
||||
<issue id="IconDuplicatesConfig" severity="ignore" />
|
||||
<issue id="IconExtension" severity="ignore" />
|
||||
<issue id="IconLocation" severity="ignore" />
|
||||
<issue id="IconMissingDensityFolder" severity="ignore" />
|
||||
<issue id="IconNoDpi" severity="ignore" />
|
||||
<issue id="InOrMmUsage" severity="ignore" />
|
||||
<issue id="InconsistentArrays" severity="ignore" />
|
||||
<issue id="InefficientWeight" severity="ignore" />
|
||||
<issue id="InnerclassSeparator" severity="ignore" />
|
||||
<issue id="Instantiatable" severity="ignore" />
|
||||
<issue id="LabelFor" severity="ignore" />
|
||||
<issue id="LibraryCustomView" severity="ignore" />
|
||||
<issue id="LocalSuppress" severity="ignore" />
|
||||
<issue id="MangledCRLF" severity="ignore" />
|
||||
<issue id="ManifestOrder" severity="ignore" />
|
||||
<issue id="MenuTitle" severity="ignore" />
|
||||
<issue id="MergeRootFrame" severity="ignore" />
|
||||
<issue id="MissingId" severity="ignore" />
|
||||
<issue id="MissingPrefix" severity="ignore" />
|
||||
<issue id="MissingRegistered" severity="ignore" />
|
||||
<issue id="MissingTranslation" severity="ignore" />
|
||||
<issue id="MultipleUsesSdk" severity="ignore" />
|
||||
<issue id="NamespaceTypo" severity="ignore" />
|
||||
<issue id="NestedScrolling" severity="ignore" />
|
||||
<issue id="NestedWeights" severity="ignore" />
|
||||
<issue id="NewApi" severity="ignore" />
|
||||
<issue id="ObsoleteLayoutParam" severity="ignore" />
|
||||
<issue id="OldTargetApi" severity="ignore" />
|
||||
<issue id="OnClick" severity="ignore" />
|
||||
<issue id="Overdraw" severity="ignore" />
|
||||
<issue id="PackagedPrivateKey" severity="ignore" />
|
||||
<issue id="PrivateResource" severity="ignore" />
|
||||
<issue id="Proguard" severity="ignore" />
|
||||
<issue id="ProguardSplit" severity="ignore" />
|
||||
<issue id="ProtectedPermissons" severity="ignore" />
|
||||
<issue id="PxUsage" severity="ignore" />
|
||||
<issue id="Registered" severity="ignore" />
|
||||
<issue id="RequiredSize" severity="ignore" />
|
||||
<issue id="ResourceAsColor" severity="ignore" />
|
||||
<issue id="ScrollViewCount" severity="ignore" />
|
||||
<issue id="ScrollViewSize" severity="ignore" />
|
||||
<issue id="SdCardPath" severity="ignore" />
|
||||
<issue id="SecureRandom" severity="ignore" />
|
||||
<issue id="SetJavaScriptEnabled" severity="ignore" />
|
||||
<issue id="ShowToast" severity="ignore" />
|
||||
<issue id="SimpleDateFormat" severity="ignore" />
|
||||
<issue id="SpUsage" severity="ignore" />
|
||||
<issue id="StateListReachable" severity="ignore" />
|
||||
<issue id="StringFormatCount" severity="ignore" />
|
||||
<issue id="StringFormatInvalid" severity="ignore" />
|
||||
<issue id="StringFormatMatches" severity="ignore" />
|
||||
<issue id="StyleCycle" severity="ignore" />
|
||||
<issue id="SuspiciousImport" severity="ignore" />
|
||||
<issue id="TextFields" severity="ignore" />
|
||||
<issue id="TextViewEdits" severity="ignore" />
|
||||
<issue id="TooDeepLayout" severity="ignore" />
|
||||
<issue id="TooManyViews" severity="ignore" />
|
||||
<issue id="TypographyDashes" severity="ignore" />
|
||||
<issue id="TypographyEllipsis" severity="ignore" />
|
||||
<issue id="TypographyFractions" severity="ignore" />
|
||||
<issue id="TypographyOther" severity="ignore" />
|
||||
<issue id="Typos" severity="ignore" />
|
||||
<issue id="UniquePermission" severity="ignore" />
|
||||
<issue id="UnknownId" severity="ignore" />
|
||||
<issue id="UnknownIdInLayout" severity="ignore" />
|
||||
<issue id="UnlocalizedSms" severity="ignore" />
|
||||
<issue id="UnusedNamespace" severity="ignore" />
|
||||
<issue id="UnusedResources" severity="ignore" />
|
||||
<issue id="UseCompoundDrawables" severity="ignore" />
|
||||
<issue id="UseSparseArrays" severity="ignore" />
|
||||
<issue id="UseValueOf" severity="ignore" />
|
||||
<issue id="UselessLeaf" severity="ignore" />
|
||||
<issue id="UselessParent" severity="ignore" />
|
||||
<issue id="UsesMinSdkAttributes" severity="ignore" />
|
||||
<issue id="ValidFragment" severity="ignore" />
|
||||
<issue id="ViewConstructor" severity="ignore" />
|
||||
<issue id="ViewTag" severity="ignore" />
|
||||
<issue id="Wakelock" severity="ignore" />
|
||||
<issue id="WorldReadableFiles" severity="ignore" />
|
||||
<issue id="WorldWriteableFiles" severity="ignore" />
|
||||
<issue id="WrongFolder" severity="ignore" />
|
||||
<issue id="WrongManifestParent" severity="ignore" />
|
||||
<issue id="WrongViewCast" severity="ignore" />
|
||||
</lint>
|
97
safeDispatch/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.safemobile.dispatch"
|
||||
android:versionCode="9"
|
||||
android:versionName="1.0.9">
|
||||
|
||||
<!-- 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" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<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"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.android.geo.API_KEY"
|
||||
android:value="${MAPS_API_KEY}" />
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
|
||||
<service android:name="com.safemobile.services.TCPService" />
|
||||
|
||||
<activity
|
||||
android:name=".SDMobileActivity"
|
||||
android:configChanges="orientation"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name_demo"
|
||||
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"
|
||||
android:screenOrientation="landscape" />
|
||||
<activity
|
||||
android:name=".TabLayoutActivity"
|
||||
android:configChanges="orientation"
|
||||
android:screenOrientation="landscape" />
|
||||
<activity
|
||||
android:name=".LiveActivity"
|
||||
android:exported="false"
|
||||
android:configChanges="orientation"
|
||||
android:screenOrientation="landscape"
|
||||
android:label="@string/title_activity_google_maps" />
|
||||
<activity
|
||||
android:name=".HistoryActivity"
|
||||
android:configChanges="orientation"
|
||||
android:screenOrientation="landscape" />
|
||||
<activity
|
||||
android:name=".MessagesActivity"
|
||||
android:configChanges="orientation"
|
||||
android:screenOrientation="landscape" />
|
||||
<activity
|
||||
android:name=".AlarmActivity"
|
||||
android:configChanges="orientation"
|
||||
android:screenOrientation="landscape" />
|
||||
<activity
|
||||
android:name=".RadioActivity"
|
||||
android:configChanges="orientation"
|
||||
android:screenOrientation="landscape" />
|
||||
<activity
|
||||
android:name=".RecordingsActivity"
|
||||
android:configChanges="orientation"
|
||||
android:screenOrientation="landscape" />
|
||||
<activity
|
||||
android:name=".NotificationActivity"
|
||||
android:configChanges="orientation"
|
||||
android:screenOrientation="landscape" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
BIN
safeDispatch/src/main/assets/Sketch_Block.ttf
Normal file
105
safeDispatch/src/main/assets/demo_positions.txt
Normal file
@ -0,0 +1,105 @@
|
||||
#30.1038811728358#-95.6229997426271#47#800-804 Sandy Ln, Tomball, TX 77375, USA#
|
||||
#30.1070692716166#-95.6243698485196#29#810-892 Sandy Ln Tomball TX 77375 USA#
|
||||
#30.1081125671044#-95.6244441960007#11#Lee Ann Tomball TX 77375 USA#
|
||||
#30.1077824877575#-95.6234199274331#11#915 Sandy Ln Tomball TX 77375 USA#
|
||||
#30.1073509873822#-95.624167593196#11#881 Sandy Ln, Tomball, TX 77375, USA#
|
||||
#30.107178571634#-95.6247316952795#18#906-1028 Sandy Ln Tomball TX 77375 USA#
|
||||
#30.1078599784523#-95.627732751891#36#1023-1109 Sandy Ln Tomball TX 77375 USA#
|
||||
#30.1073052641004#-95.6291790492833#36#Quinn Rd Tomball TX 77375 USA#
|
||||
#30.1038054842502#-95.6291277520359#43#Quinn Rd Tomball TX 77375 USA#
|
||||
#30.1027863705531#-95.6310868542641#43#Brown Huffsmith Tomball TX 77375 USA#
|
||||
#30.1038420712575#-95.6351295299828#47#Brown Huffsmith Tomball TX 77375 USA#
|
||||
#30.1037284964696#-95.6383207719773#22#Brown Huffsmith Tomball TX 77375 USA#
|
||||
#30.1033505983651#-95.6423987355083#47#14414 Brown Rd Tomball TX 77377 USA#
|
||||
#30.101920561865#-95.6474291346967#43#14714 Brown Rd Tomball TX 77377 USA#
|
||||
#30.1045657647774#-95.6499252654612#29#29764-29782 Kingbird Dr Tomball TX 77377 USA#
|
||||
#30.1065424690023#-95.6498967669904#22#14807-14923 Hermit Thrush Ln Tomball TX 77377 USA#
|
||||
#30.1078060828149#-95.6498815957457#18#29822 Kingbird Dr Tomball TX 77377 USA#
|
||||
#30.1096951961517#-95.6499102618545#14#29838-29854 Kingbird Dr Tomball TX 77377 USA#
|
||||
#30.1106302812696#-95.649914033711#22#29856-29870 Kingbird Dr Tomball TX 77377 USA#
|
||||
#30.1127856876701#-95.6499348208308#18#29890-29902 Kingbird Dr Tomball TX 77377 USA#
|
||||
#30.1135092973709#-95.6499343179166#14#29902 Kingbird Dr Tomball TX 77377 USA#
|
||||
#30.1123635750264#-95.6499817594886#36#14901 Rock Elm Dr Tomball TX 77377 USA#
|
||||
#30.1098355930299#-95.6499674264342#29#29839-29853 Kingbird Dr Tomball TX 77377 USA#
|
||||
#30.1070419885218#-95.6499653309584#43#29805-29819 Kingbird Dr Tomball TX 77377 USA#
|
||||
#30.1040194742382#-95.6499856989831#36#29755-29769 Kingbird Dr Tomball TX 77377 USA#
|
||||
#30.1019107969478#-95.6469845585525#50#14707 Brown Rd Tomball TX 77377 USA#
|
||||
#30.1032698806375#-95.6426190957427#58#14422 Brown Rd Tomball TX 77377 USA#
|
||||
#30.1034989999607#-95.638874899596#14#14301-14325 Brown Rd, Tomball, TX 77375, USA#
|
||||
#30.1030826708302#-95.6386199221015#40#30042 State Highway 249 Tomball TX 77375 USA#
|
||||
#30.098564280197#-95.6376449391246#65#State Highway 249 Business, Northwest Harris, TX 77375, USA#
|
||||
#30.0936247827485#-95.6360663753003#65#State Highway 249 Business Tomball TX 77375 USA#
|
||||
#30.0898658763617#-95.6362883280963#14#14118 FM 2920 Rd Tomball TX 77377 USA#
|
||||
#30.0892848847434#-95.6361206900328#25#State Highway 249 Business Tomball TX 77375 USA#
|
||||
#30.0881543755531#-95.6321874819696#47#28505 State Highway 249, Tomball, TX 77375, USA#
|
||||
#30.0844461796805#-95.6312056258321#32#28300 Tomball Pkwy Tomball TX 77375 USA#
|
||||
#30.0845081638545#-95.6283603888005#40#13700 Medical Complex Dr Tomball TX 77375 USA#
|
||||
#30.0844980636612#-95.625959476456#11#716-798 Lawrence St Tomball TX 77375 USA#
|
||||
#30.0824133586138#-95.6266013626009#22#13604-13612 Michel Rd Tomball TX 77375 USA#
|
||||
#30.0824242969975#-95.629511475563#36#13636 Michel Rd Tomball TX 77375 USA#
|
||||
#30.0848942762241#-95.6259192433208#25#615-799 Lawrence St Tomball TX 77375 USA#
|
||||
#30.0880231987685#-95.6260203290731#40#602 Lawrence St Tomball TX 77375 USA#
|
||||
#30.0885672681034#-95.6261594686657#14#1016 Graham Dr Tomball TX 77375 USA#
|
||||
#30.0882335845381#-95.6284199841321#22#1221 Graham Dr Tomball TX 77375 USA#
|
||||
#30.0878770602867#-95.6314713321626#25#1414 Graham Dr Tomball TX 77375 USA#
|
||||
#30.0847491854802#-95.6313169375062#54#28317 Tomball Pkwy, Tomball, TX 77375, USA#
|
||||
#30.080287498422#-95.6298328377306#65#27802-28048 Tomball Pkwy Tomball TX 77375 USA#
|
||||
#30.0726691866294#-95.6262452993542#65#27195-27225 Tomball Pkwy, Tomball, TX 77377, USA#
|
||||
#30.0687036663294#-95.6245866883546#18#Tomball Pkwy, Tomball, TX 77375, USA#
|
||||
#30.0668030697852#-95.6233791913837#32#13131-13149 Holderrieth Rd, Tomball, TX 77375, USA#
|
||||
#30.0668518943712#-95.6216025631875#43#13022-13124 Holderrieth Rd Tomball TX 77375 USA#
|
||||
#30.0669317739084#-95.6164774484932#61#12791-12969 Holderrieth Rd Tomball TX 77375 USA#
|
||||
#30.0669909920543#-95.6114780623466#25#12790 Holderrieth Rd Tomball TX 77375 USA#
|
||||
#30.0740579841658#-95.6113490648568#61#2206-2266 S Cherry St, Tomball, TX 77375, USA#
|
||||
#30.0786141771823#-95.6114214845002#58#1700-1898 S Cherry St Tomball TX 77375 USA#
|
||||
#30.0858608772978#-95.6115463748574#40#1131-1399 S Cherry St Tomball TX 77375 USA#
|
||||
#30.0888565694913#-95.611600773409#22#1118-1126 S Cherry St, Tomball, TX 77375, USA#
|
||||
#30.0895934645087#-95.6136170402169#11#918 Juniper Ct Tomball TX 77375 USA#
|
||||
#30.0887714931741#-95.6136962492019#11#1100 S Cherry St Tomball TX 77375 USA#
|
||||
#30.0880771782249#-95.6132849492133#14#1100 S Cherry St Tomball TX 77375 USA#
|
||||
#30.086738797836#-95.6116090714931#36#1248 S Cherry St Tomball TX 77375 USA#
|
||||
#30.0830443901941#-95.6115429382771#54#1681 S Cherry St Tomball TX 77375 USA#
|
||||
#30.0787175679579#-95.6114772241563#54#1719-1819 S Cherry St Tomball TX 77375 USA#
|
||||
#30.0742001831532#-95.6114100851119#58#2207-2289 S Cherry St Tomball TX 77375 USA#
|
||||
#30.0695944949985#-95.611331127584#61#2510 S Cherry St Tomball TX 77375 USA#
|
||||
#30.0669590989128#-95.6114313751459#14#12790 Holderrieth Rd Tomball TX 77375 USA#
|
||||
#30.0669326959178#-95.6152523495257#58#12791-12969 Holderrieth Rd Tomball TX 77375 USA#
|
||||
#30.0668948935345#-95.6203508935869#54#13022-13124 Holderrieth Rd, Tomball, TX 77375, USA#
|
||||
#30.06693336647#-95.6230170931667#25#Aggie Expy Tomball TX 77377 USA#
|
||||
#30.0649807602167#-95.6221639830619#58#26511-26899 Tomball Pkwy Tomball TX 77375 USA#
|
||||
#30.0605678977445#-95.6195416208357#65#Tomball Pkwy Tomball TX 77375 USA#
|
||||
#30.0560060888529#-95.6171602383256#61#26049 State Highway 249 Tomball TX 77375 USA#
|
||||
#30.0541836954653#-95.6177280284464#36#13215 Boudreaux Rd Tomball TX 77377 USA#
|
||||
#30.0548273837194#-95.6234616693109#40#13057-13199 Boudreaux Estates Dr Tomball TX 77377 USA#
|
||||
#30.0554253906012#-95.6256067659706#29#13230-13336 Boudreaux Estates Dr Tomball TX 77377 USA#
|
||||
#30.0551302637905#-95.628422498703#32#13339-13475 Boudreaux Estates Dr Tomball TX 77377 USA#
|
||||
#30.056142588146#-95.6297978851944#32#25601-25899 Bourgain Dr Tomball TX 77377 USA#
|
||||
#30.0580881955102#-95.6306262686849#11#13502-13598 Chateau Dr Tomball TX 77377 USA#
|
||||
#30.058539477177#-95.6290103215724#14#26018 Orleans Ave Tomball TX 77375 USA#
|
||||
#30.0569307804108#-95.6278732325882#22#25915 Orleans Ave Tomball TX 77377 USA#
|
||||
#30.0561902811751#-95.6273104716092#18#25914 Orleans Ave Tomball TX 77377 USA#
|
||||
#30.0554083753377#-95.6264045555145#25#13231-13337 Boudreaux Estates Dr Tomball TX 77377 USA#
|
||||
#30.0551795912907#-95.6248366367072#22#13056-13198 Boudreaux Estates Dr Tomball TX 77377 USA#
|
||||
#30.0544594600797#-95.622240928933#32#13000-13054 Boudreaux Estates Dr Tomball TX 77377 USA#
|
||||
#30.0541649619117#-95.6183345429599#32#13215 Boudreaux Rd Tomball TX 77377 USA#
|
||||
#30.0541812647134#-95.6163169350475#29#12814 Boudreaux Rd Tomball TX 77375 USA#
|
||||
#30.0548394955695#-95.6156456284225#40#26000-26398 Tomball Pkwy Tomball TX 77375 USA#
|
||||
#30.0587797863409#-95.6172499246895#61#26022 State Highway 249 Tomball TX 77375 USA#
|
||||
#30.063119684346#-95.6200637295842#68#26400-26898 Tomball Pkwy Tomball TX 77375 USA#
|
||||
#30.0670028943568#-95.6225595250726#50#26902 State Highway 249 Tomball TX 77375 USA#
|
||||
#30.0707885809243#-95.6248711701483#58#Tomball Pkwy Tomball TX 77375 USA#
|
||||
#30.074630593881#-95.6271268241107#54#27652-27676 Tomball Pkwy Tomball TX 77375 USA#
|
||||
#30.0784160709009#-95.6288631353527#54#27708-27720 Tomball Pkwy Tomball TX 77375 USA#
|
||||
#30.0824288651347#-95.6305284518749#43#13680-13698 Michel Rd Tomball TX 77375 USA#
|
||||
#30.0857110926881#-95.6313936319202#43#28310-28378 State Highway 249 Tomball TX 77375 USA#
|
||||
#30.0884892744944#-95.6321135535836#32#28520 State Highway 249 Tomball TX 77375 USA#
|
||||
#30.0901297805831#-95.630494421348#36#1335-1399 Farm to Market 2920 Tomball TX 77375 USA#
|
||||
#30.0916665606201#-95.6277060974389#11#1200-1262 Farm to Market 2920 Tomball TX 77375 USA#
|
||||
#30.0925761647522#-95.6274783611298#32#101-299 Quinn Rd Tomball TX 77375 USA#
|
||||
#30.0980335799977#-95.6283390987664#29#29619 Quinn Rd Tomball TX 77375 USA#
|
||||
#30.1010427670553#-95.6285911425948#40#29610 Quinn Rd Tomball TX 77375 USA#
|
||||
#30.1043387828395#-95.6290560867637#47#Quinn Rd Tomball TX 77375 USA#
|
||||
#30.1073376601562#-95.6290665641427#32#Quinn Rd Tomball TX 77375 USA#
|
||||
#30.1077843736857#-95.6273911893368#32#1023-1109 Sandy Ln Tomball TX 77375 USA#
|
||||
#30.1070042699575#-95.6268194597214#14#1030-1198 Sandy Ln Tomball TX 77375 USA#
|
||||
#30.1065399963409#-95.6278602406383#14#1055 Sandy Ln Tomball TX 77375 USA#
|
BIN
safeDispatch/src/main/assets/exitwindows.mp3
Normal file
BIN
safeDispatch/src/main/assets/grenade.mp3
Normal file
BIN
safeDispatch/src/main/assets/mike.mp3
Normal file
BIN
safeDispatch/src/main/assets/mikee.mp3
Normal file
BIN
safeDispatch/src/main/assets/startwindows.mp3
Normal file
31
safeDispatch/src/main/assets/xmldmr.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<configuration>
|
||||
<radio-id>104</radio-id>
|
||||
<radio-ip>192.168.10.40</radio-ip>
|
||||
<contacts>
|
||||
<contact name="UNIT101" call-type="Private Call" call-id="101" section="Digital" />
|
||||
<contact name="UNIT105" call-type="Private Call" call-id="105" section="Digital" />
|
||||
<contact name="UNIT110" call-type="Private Call" call-id="110" section="Digital" />
|
||||
<contact name="UNIT102" call-type="Private Call" call-id="102" section="Digital" />
|
||||
<contact name="UNIT106" call-type="Private Call" call-id="106" section="Digital" />
|
||||
<contact name="UNIT107" call-type="Private Call" call-id="107" section="Digital" />
|
||||
<contact name="UNIT103" call-type="Private Call" call-id="103" section="Digital" />
|
||||
<contact name="UNIT108" call-type="Private Call" call-id="108" section="Digital" />
|
||||
<contact name="UNIT109" call-type="Private Call" call-id="109" section="Digital" />
|
||||
<contact name="UNIT111" call-type="Private Call" call-id="111" section="Digital" />
|
||||
<contact name="Call1" call-type="Group Call" call-id="1" section="Digital" />
|
||||
<contact name="Call2" call-type="Group Call" call-id="2" section="Digital" />
|
||||
</contacts>
|
||||
<zones>
|
||||
<zone position="1" name="Zone1">
|
||||
<channel position="1" name="Channel1" />
|
||||
<channel position="2" name="Channel2" />
|
||||
<channel position="3" name="Channel3" />
|
||||
<channel position="4" name="Channel4" />
|
||||
</zone>
|
||||
<zone position="3" name="Zone2">
|
||||
<channel position="1" name="Ch1 ZN2" />
|
||||
<channel position="2" name="Ch2 ZN2" />
|
||||
<channel position="3" name="Ch3 ZN2" />
|
||||
</zone>
|
||||
</zones>
|
||||
</configuration>
|
@ -0,0 +1,259 @@
|
||||
package com.safemobile.dispatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
/** fix import*/
|
||||
import com.safemobile.adapters.AlertGridViewAdapter;
|
||||
import com.safemobile.adapters.AlertGridViewAdapter.ViewHolder;
|
||||
|
||||
import com.safemobile.lib.Alarm;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.GridView;
|
||||
|
||||
public class AlarmActivity extends Activity {
|
||||
private Context context;
|
||||
public TabLayoutActivity parentTab;
|
||||
public ArrayList<Alarm> allAlarms = new ArrayList<Alarm>();
|
||||
private ArrayList<Boolean> acknowledged = new ArrayList<Boolean>();
|
||||
private AlertGridViewAdapter adapter;
|
||||
|
||||
/* Visual resources */
|
||||
private GridView gridView;
|
||||
public View convertViewAlarm;
|
||||
|
||||
private int ack_position;
|
||||
|
||||
public Bundle savedInstanceState;
|
||||
|
||||
// Need handler for callbacks to the UI thread
|
||||
private final Handler myHandler = new Handler();
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
// get parentTab
|
||||
parentTab = (TabLayoutActivity)getParent();
|
||||
|
||||
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
getBaseContext().getResources().updateConfiguration(config,
|
||||
getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
|
||||
context = this;
|
||||
setContentView(R.layout.tabalarm);
|
||||
|
||||
gridView = (GridView) findViewById(R.id.gridViewAlarms);
|
||||
adapter = new AlertGridViewAdapter(this, allAlarms, context, acknowledged);
|
||||
gridView.setAdapter(adapter);
|
||||
|
||||
gridView.setOnItemClickListener(onItemClickListener);
|
||||
|
||||
// change tab header fontface
|
||||
TextView textView1 = (TextView) findViewById(R.id.textView1);
|
||||
textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textView1.setTextSize(24);
|
||||
|
||||
parentTab.alarmActivity = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.logout);
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.exit);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
SM.Debug("onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if(!AppParams.DEMO)
|
||||
GetAlarms();
|
||||
else if (AppParams.DEMO)
|
||||
{
|
||||
for(int i=allAlarms.size()-1; i>=0; i--)
|
||||
{
|
||||
Alarm alarm = allAlarms.get(i);
|
||||
if(alarm.ack==1)
|
||||
allAlarms.remove(i);
|
||||
}
|
||||
|
||||
acknowledged = new ArrayList<Boolean>();
|
||||
|
||||
for(int i=0;i<allAlarms.size();i++)
|
||||
acknowledged.add(false);
|
||||
updateResultsInUi("alarm");
|
||||
}
|
||||
SM.Debug("onResume");
|
||||
}
|
||||
|
||||
|
||||
private OnItemClickListener onItemClickListener = new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
|
||||
long arg3) {
|
||||
SM.Debug(" ### CLICK Alarm : " + position);
|
||||
convertViewAlarm = arg1;
|
||||
// save position
|
||||
ack_position = position;
|
||||
//Toast.makeText(context, "SETACK " + idx, 1000).show();
|
||||
if(!AppParams.DEMO)
|
||||
setACK(allAlarms.get(position).idx,allAlarms.get(position).type);
|
||||
else
|
||||
{
|
||||
allAlarms.get(position).ack = 1;
|
||||
updateResultsInUi("else");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Update Alarms received from AppServer
|
||||
public void UpdateAlarms(ArrayList<Alarm> list)
|
||||
{
|
||||
SM.Debug("## UpdateAlarms: " + list.size());
|
||||
allAlarms = list;
|
||||
acknowledged = new ArrayList<Boolean>();
|
||||
// set acknowledged based on alarm.ack value
|
||||
|
||||
for(Alarm alarm: allAlarms)
|
||||
{
|
||||
acknowledged.add((alarm.ack == 1)? true: false);
|
||||
SM.Debug("ALARM", "SC_ID> " + alarm.sc_id + " | "
|
||||
+ (parentTab.VehHashbySc_id.get(alarm.sc_id) == null ? "null" : parentTab.VehHashbySc_id.get(alarm.sc_id).name ));
|
||||
|
||||
|
||||
if (parentTab.VehHashbySc_id.get(alarm.sc_id)!=null)
|
||||
alarm.unitName = parentTab.VehHashbySc_id.get(alarm.sc_id).name;
|
||||
|
||||
|
||||
|
||||
/*Enumeration<Long> keylist = parentTab.SuperVehHash.keys();
|
||||
while(keylist.hasMoreElements())
|
||||
{
|
||||
SuperVehicle tmp = (SuperVehicle)((parentTab.SuperVehHash.get((long)keylist.nextElement())));
|
||||
if (tmp.sc_id==alarm.sc_id)
|
||||
{
|
||||
alarm.unitName = tmp.name;
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
myHandler.post(UpdateResultsRUN);
|
||||
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable UpdateResultsRUN = new Runnable() {
|
||||
public void run() {
|
||||
updateResultsInUi("alarm");
|
||||
}
|
||||
};
|
||||
|
||||
private void updateResultsInUi(String param)
|
||||
{
|
||||
if(param.equals("alarm"))
|
||||
{
|
||||
// set adapter
|
||||
adapter = new AlertGridViewAdapter(this, allAlarms, context, acknowledged);
|
||||
gridView.setAdapter(adapter);
|
||||
}
|
||||
else
|
||||
{
|
||||
adapter.changeACK(ack_position);
|
||||
SM.Debug("Set ACK: " + ack_position + " | " + (acknowledged.get(ack_position) ? "true": "false"));
|
||||
|
||||
ViewHolder viewAlarm = new ViewHolder();
|
||||
viewAlarm = (ViewHolder) convertViewAlarm.getTag();
|
||||
|
||||
switch(acknowledged.get(ack_position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
viewAlarm.imageViewAlert.setImageResource(R.drawable.alert_off);
|
||||
//view.imgViewIcon.setImageDrawable(adapter.convertToGrayscale(activity.getResources().getDrawable(liveVehicle.get(position).getSmallIcon())));
|
||||
break;
|
||||
case 0:
|
||||
//view.imgViewAlarm.setImageResource(R.drawable.siren);
|
||||
//view.imgViewIcon.setImageResource(liveVehicle.get(position).getSmallIcon());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update ACK received from AppServer
|
||||
public void UpdateACK()
|
||||
{
|
||||
myHandler.post(UpdateAckRUN);
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable UpdateAckRUN = new Runnable() {
|
||||
public void run() {
|
||||
SM.Debug(" UpdateACK: ");
|
||||
updateResultsInUi("adapter");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// send to AppServer
|
||||
private void GetAlarms()
|
||||
{
|
||||
parentTab.executeNetworkStuff(new String[]{OperationCodes.GetAlarms +"", AppParams.USERID + ""});
|
||||
//parentTab.getAlarms(AppParams.USERID);
|
||||
}
|
||||
|
||||
// send ACK to AppServer
|
||||
private void setACK(int idx, int type)
|
||||
{
|
||||
parentTab.executeNetworkStuff(new String[]{OperationCodes.SendAlarmAcknoledge +"", idx + "", type + ""});
|
||||
//parentTab.sendAlarmAcknoledge(idx, type);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.safemobile.dispatch;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class HistoryActivity extends AppCompatActivity {
|
||||
|
||||
public Bundle savedInstanceState;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
setContentView(R.layout.tabhistory);
|
||||
}
|
||||
|
||||
public void UpdateMap() {
|
||||
SM.Debug("Do the updateMAP post");
|
||||
}
|
||||
|
||||
public void UpdateUnableDisp() {
|
||||
SM.Debug("Do Cancelwindow");
|
||||
}
|
||||
|
||||
public void UpdateCancel() {
|
||||
SM.Debug("Do Cancelwindow");
|
||||
}
|
||||
|
||||
public void UpdateNrPos(int size) {
|
||||
SM.Debug("Do Cancelwindow");
|
||||
}
|
||||
}
|
@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Tani Group
|
||||
* http://android-demo.blogspot.com/
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
package com.safemobile.dispatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* @author nguyendt
|
||||
*
|
||||
*/
|
||||
public class IconContextMenu implements DialogInterface.OnCancelListener,
|
||||
DialogInterface.OnDismissListener{
|
||||
|
||||
private static final int LIST_PREFERED_HEIGHT = 65;
|
||||
|
||||
private IconMenuAdapter menuAdapter = null;
|
||||
private Activity parentActivity = null;
|
||||
private int dialogId = 0;
|
||||
|
||||
private IconContextMenuOnClickListener clickHandler = null;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param parent
|
||||
* @param id
|
||||
*/
|
||||
public IconContextMenu(Activity parent, int id) {
|
||||
this.parentActivity = parent;
|
||||
this.dialogId = id;
|
||||
|
||||
menuAdapter = new IconMenuAdapter(parentActivity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu item
|
||||
* @param menuItem
|
||||
*/
|
||||
public void addItem(Resources res, CharSequence title,
|
||||
int imageResourceId, int actionTag) {
|
||||
menuAdapter.addItem(new IconContextMenuItem(res, title, imageResourceId, actionTag));
|
||||
}
|
||||
|
||||
public void addItem(Resources res, int textResourceId,
|
||||
int imageResourceId, int actionTag) {
|
||||
menuAdapter.addItem(new IconContextMenuItem(res, textResourceId, imageResourceId, actionTag));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set menu onclick listener
|
||||
* @param listener
|
||||
*/
|
||||
public void setOnClickListener(IconContextMenuOnClickListener listener) {
|
||||
clickHandler = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create menu
|
||||
* @return
|
||||
*/
|
||||
public Dialog createMenu(String menuItitle) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
||||
builder.setTitle(menuItitle);
|
||||
builder.setAdapter(menuAdapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialoginterface, int i) {
|
||||
IconContextMenuItem item = (IconContextMenuItem) menuAdapter.getItem(i);
|
||||
|
||||
if (clickHandler != null) {
|
||||
clickHandler.onClick(item.actionTag);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
builder.setInverseBackgroundForced(true);
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setOnCancelListener(this);
|
||||
dialog.setOnDismissListener(this);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
parentActivity.dismissDialog(dialogId);
|
||||
}
|
||||
|
||||
/**
|
||||
* IconContextMenu On Click Listener interface
|
||||
*/
|
||||
public interface IconContextMenuOnClickListener {
|
||||
public abstract void onClick(int menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu-like list adapter with icon
|
||||
*/
|
||||
protected class IconMenuAdapter extends BaseAdapter {
|
||||
private Context context = null;
|
||||
|
||||
private ArrayList<IconContextMenuItem> mItems = new ArrayList<IconContextMenuItem>();
|
||||
|
||||
public IconMenuAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* add item to adapter
|
||||
* @param menuItem
|
||||
*/
|
||||
public void addItem(IconContextMenuItem menuItem) {
|
||||
mItems.add(menuItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
IconContextMenuItem item = (IconContextMenuItem) getItem(position);
|
||||
return item.actionTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
IconContextMenuItem item = (IconContextMenuItem) getItem(position);
|
||||
|
||||
Resources res = parentActivity.getResources();
|
||||
|
||||
if (convertView == null) {
|
||||
TextView temp = new TextView(context);
|
||||
AbsListView.LayoutParams param = new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT,
|
||||
AbsListView.LayoutParams.WRAP_CONTENT);
|
||||
temp.setLayoutParams(param);
|
||||
temp.setPadding((int)toPixel(res, 15), 0, (int)toPixel(res, 15), 0);
|
||||
temp.setGravity(android.view.Gravity.CENTER_VERTICAL);
|
||||
|
||||
Theme th = context.getTheme();
|
||||
TypedValue tv = new TypedValue();
|
||||
|
||||
if (th.resolveAttribute(android.R.attr.textAppearanceLargeInverse, tv, true)) {
|
||||
temp.setTextAppearance(context, tv.resourceId);
|
||||
}
|
||||
|
||||
temp.setMinHeight(LIST_PREFERED_HEIGHT);
|
||||
temp.setCompoundDrawablePadding((int)toPixel(res, 14));
|
||||
convertView = temp;
|
||||
}
|
||||
|
||||
TextView textView = (TextView) convertView;
|
||||
textView.setTag(item);
|
||||
textView.setText(item.text);
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(item.image, null, null, null);
|
||||
|
||||
return textView;
|
||||
}
|
||||
|
||||
private float toPixel(Resources res, int dip) {
|
||||
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, res.getDisplayMetrics());
|
||||
return px;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* menu-like list item with icon
|
||||
*/
|
||||
protected class IconContextMenuItem {
|
||||
public final CharSequence text;
|
||||
public final Drawable image;
|
||||
public final int actionTag;
|
||||
|
||||
/**
|
||||
* public constructor
|
||||
*
|
||||
* @param res
|
||||
* resource handler
|
||||
* @param textResourceId
|
||||
* id of title in resource
|
||||
* @param imageResourceId
|
||||
* id of icon in resource
|
||||
* @param actionTag
|
||||
* indicate action of menu item
|
||||
*/
|
||||
public IconContextMenuItem(Resources res, int textResourceId,
|
||||
int imageResourceId, int actionTag) {
|
||||
text = res.getString(textResourceId);
|
||||
if (imageResourceId != -1) {
|
||||
image = res.getDrawable(imageResourceId);
|
||||
} else {
|
||||
image = null;
|
||||
}
|
||||
this.actionTag = actionTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* public constructor
|
||||
* @param res
|
||||
* resource handler
|
||||
* @param title
|
||||
* menu item title
|
||||
* @param imageResourceId
|
||||
* id of icon in resource
|
||||
* @param actionTag
|
||||
* indicate action of menu item
|
||||
*/
|
||||
public IconContextMenuItem(Resources res, CharSequence title,
|
||||
int imageResourceId, int actionTag) {
|
||||
text = title;
|
||||
if (imageResourceId != -1) {
|
||||
image = res.getDrawable(imageResourceId);
|
||||
} else {
|
||||
image = null;
|
||||
}
|
||||
this.actionTag = actionTag;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,726 @@
|
||||
package com.safemobile.dispatch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
import com.safemobile.activities.AbstractLiveActivity;
|
||||
import com.safemobile.activities.AbstractSDParentActivity;
|
||||
import com.safemobile.adapters.VehiclesGridViewAdapter;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.SuperVehicle;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCallback {
|
||||
|
||||
private GoogleMap googleMap;
|
||||
|
||||
/* Context Menu */
|
||||
private static final int MENU_ENABLE = 150;
|
||||
private static final int MENU_DISABLE = 151;
|
||||
private static final int MENU_REMOTE = 161;
|
||||
private static final int MENU_POLL = 154;
|
||||
private static final double LAT_OUTLIMIT = 91;
|
||||
private static final double LNG_OUTLIMIT = 181;
|
||||
private IconContextMenu iconContextMenu = null;
|
||||
|
||||
/* Dialog */
|
||||
private Dialog loadingDialog;
|
||||
|
||||
// Need handler for callbacks to the UI thread
|
||||
private final Handler myHandler = new Handler(Looper.getMainLooper());
|
||||
private Thread threadUI;
|
||||
|
||||
/* Misc */
|
||||
private Context context;
|
||||
private Resources res;
|
||||
private Activity activity;
|
||||
|
||||
/* Visual Elements */
|
||||
private ImageButton imageViewCheckAll;
|
||||
private Button displayButton;
|
||||
private boolean isFirstRun = true;
|
||||
private boolean isFirstMap = true;
|
||||
private boolean isAck = false;
|
||||
private boolean showVehicle = true;
|
||||
private int contextMenuPosition;
|
||||
private int vehStatus;
|
||||
private int position; // vehStatus = vehicle status received from apps
|
||||
|
||||
/* Live Vehicle GridView */
|
||||
private GridView gridVehicle;
|
||||
private ArrayList<Vehicle> liveVehicle = new ArrayList<>();
|
||||
private ArrayList<Boolean> displayedVehicles = new ArrayList<>();
|
||||
private ArrayList<Boolean> disabledVehicles = new ArrayList<>();
|
||||
private VehiclesGridViewAdapter adapter;
|
||||
private final HashMap<Integer, ArrayList<SuperVehicle>> tableHashOverlay = new HashMap<>();
|
||||
|
||||
//value poll
|
||||
private double latPoll = 0;
|
||||
private double lngPoll = 0;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setSavedInstanceState(savedInstanceState);
|
||||
// get parentTab
|
||||
setParentTab((AbstractSDParentActivity) getParent());
|
||||
try {
|
||||
((TabLayoutActivity) getParentTab()).liveActivity = this;
|
||||
} catch (Exception ignored) {
|
||||
// ignored
|
||||
}
|
||||
context = this;
|
||||
activity = this;
|
||||
res = getResources();
|
||||
|
||||
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
// get mapView only when creating first time
|
||||
if (isFirstMap) {
|
||||
setContentView(R.layout.tablive);
|
||||
isFirstMap = false;
|
||||
}
|
||||
|
||||
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
|
||||
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.map);
|
||||
if (mapFragment != null) {
|
||||
mapFragment.getMapAsync(this);
|
||||
}
|
||||
|
||||
|
||||
// create on vehicle long click menu
|
||||
createIconContextMenu();
|
||||
|
||||
// image View for changing map type satellite or map
|
||||
ImageView changeMapTypeImageView = (ImageView) findViewById(R.id.changeMapType);
|
||||
changeMapTypeImageView.setOnClickListener(v -> {
|
||||
if (googleMap.getMapType() == GoogleMap.MAP_TYPE_SATELLITE) {
|
||||
changeMapTypeImageView.setImageResource(R.drawable.satellite);
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
|
||||
} else {
|
||||
changeMapTypeImageView.setImageResource(R.drawable.map);
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
|
||||
}
|
||||
});
|
||||
|
||||
ImageView changeTrafficImageView = (ImageView) findViewById(R.id.changeTraffic);
|
||||
changeTrafficImageView.setOnClickListener(v -> {
|
||||
if (googleMap.isTrafficEnabled()) {
|
||||
changeTrafficImageView.setImageResource(R.drawable.traffic_off);
|
||||
googleMap.setTrafficEnabled(false);
|
||||
} else {
|
||||
changeTrafficImageView.setImageResource(R.drawable.traffic);
|
||||
googleMap.setTrafficEnabled(true);
|
||||
}
|
||||
});
|
||||
|
||||
// change tab header font
|
||||
TextView textView1 = (TextView) findViewById(R.id.textView1);
|
||||
textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textView1.setTextSize(24);
|
||||
|
||||
// get grid view and set empty data adapter
|
||||
gridVehicle = (GridView) findViewById(R.id.gridVehicle);
|
||||
|
||||
if (AppParams.DEMO) {
|
||||
disabledVehicles = new ArrayList<>();
|
||||
for (Vehicle veh : getParentTab().allVehicle)
|
||||
disabledVehicles.add(!veh.status);
|
||||
}
|
||||
|
||||
|
||||
adapter = new VehiclesGridViewAdapter(activity, context, getParentTab().allVehicle, disabledVehicles);
|
||||
adapter.notifyDataSetChanged();
|
||||
gridVehicle.setAdapter(adapter);
|
||||
|
||||
// get vehicle display click
|
||||
gridVehicle.setOnItemClickListener((parent, view, position, id) -> {
|
||||
threadUI = new Thread(() -> {
|
||||
myHandler.post(() -> itemClick(position, view));
|
||||
threadUI.interrupt();
|
||||
});
|
||||
threadUI.start();
|
||||
});
|
||||
|
||||
|
||||
// get vehicle menu creation
|
||||
gridVehicle.setOnItemLongClickListener(itemLongClickHandler);
|
||||
|
||||
|
||||
LinearLayout slideLayout = (LinearLayout) findViewById(R.id.slidelayout);
|
||||
ImageView slideLayoutImageView = (ImageView) findViewById(R.id.slideLayoutImage);
|
||||
LinearLayout linearLayoutVehicles = (LinearLayout) findViewById(R.id.layoutBig);
|
||||
slideLayout.setOnClickListener(v -> {
|
||||
if (showVehicle) {
|
||||
linearLayoutVehicles.setVisibility(View.GONE);
|
||||
slideLayoutImageView.setImageResource(R.drawable.arrow_right);
|
||||
showVehicle = false;
|
||||
} else {
|
||||
linearLayoutVehicles.setVisibility(View.VISIBLE);
|
||||
slideLayoutImageView.setImageResource(R.drawable.arrow_left);
|
||||
showVehicle = true;
|
||||
}
|
||||
});
|
||||
|
||||
imageViewCheckAll = (ImageButton) findViewById(R.id.imageCheckAll);
|
||||
imageViewCheckAll.setSelected(false);
|
||||
imageViewCheckAll.setOnClickListener(arg0 -> {
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, true);
|
||||
|
||||
adapter.changeDisplayAll(!imageViewCheckAll.isSelected());
|
||||
|
||||
|
||||
VehiclesGridViewAdapter.ViewHolder viewLive = (VehiclesGridViewAdapter.ViewHolder) gridVehicle.getChildAt(0).getTag();
|
||||
|
||||
if (!imageViewCheckAll.isSelected())
|
||||
viewLive.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
viewLive.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
|
||||
Enumeration<Long> keyList = getParentTab().SuperVehHash.keys();
|
||||
while (keyList.hasMoreElements()) {
|
||||
(Objects.requireNonNull(getParentTab().SuperVehHash.get((long) keyList.nextElement()))).needUpdate = true;
|
||||
}
|
||||
|
||||
// change button title
|
||||
if (!imageViewCheckAll.isSelected()) {
|
||||
imageViewCheckAll.setSelected(true);
|
||||
imageViewCheckAll.setBackgroundResource(R.drawable.check_all);
|
||||
displayButton.setText(getString(R.string.hideAll));
|
||||
// set all vehicles to be displayed
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, true);
|
||||
} else {
|
||||
imageViewCheckAll.setSelected(false);
|
||||
imageViewCheckAll.setBackgroundResource(R.drawable.uncheck_all);
|
||||
displayButton.setText(getString(R.string.displayAll));
|
||||
// set all vehicles to not be displayed
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, false);
|
||||
}
|
||||
|
||||
// refresh UI
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
});
|
||||
|
||||
displayButton = (Button) findViewById(R.id.buttonDisplay);
|
||||
displayButton.setText(getString(R.string.displayAll));
|
||||
|
||||
|
||||
displayButton.setOnClickListener(v -> {
|
||||
// set all displayed vehicles to true
|
||||
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, true);
|
||||
|
||||
Enumeration<Long> keyList = getParentTab().SuperVehHash.keys();
|
||||
while (keyList.hasMoreElements())
|
||||
(Objects.requireNonNull(getParentTab().SuperVehHash.get((long) keyList.nextElement()))).needUpdate = true;
|
||||
|
||||
// change button title
|
||||
if (displayButton.getText().toString().equals(getString(R.string.displayAll))) {
|
||||
displayButton.setText(getString(R.string.hideAll));
|
||||
// set all vehicles to be displayed
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, true);
|
||||
} else {
|
||||
displayButton.setText(getString(R.string.displayAll));
|
||||
// set all vehicles to not be displayed
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, false);
|
||||
}
|
||||
|
||||
// refresh UI
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
});
|
||||
|
||||
// display Vehicles
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
|
||||
// register to receive broadcasts
|
||||
registerBroadcastIntents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manipulates the map once available.
|
||||
* This callback is triggered when the map is ready to be used.
|
||||
* This is where we can add markers or lines, add listeners or move the camera. In this case,
|
||||
* we just add a marker near Sydney, Australia.
|
||||
* If Google Play services is not installed on the device, the user will be prompted to install
|
||||
* it inside the SupportMapFragment. This method will only be triggered once the user has
|
||||
* installed Google Play services and returned to the app.
|
||||
*/
|
||||
@Override
|
||||
public void onMapReady(@NonNull GoogleMap googleMap) {
|
||||
this.googleMap = googleMap;
|
||||
|
||||
// Add a marker in Sydney and move the camera
|
||||
LatLng sydney = new LatLng(-34, 151);
|
||||
this.googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
|
||||
this.googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// cancel loading dialog if showing
|
||||
if (loadingDialog.isShowing()) {
|
||||
cancelLoadingDialog();
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), (dialog, id) -> getParentTab().whenBackPressed(AppParams.ActivityResult.logout))
|
||||
.setPositiveButton(getString(R.string.ext), (dialog, id) -> getParentTab().whenBackPressed(AppParams.ActivityResult.exit))
|
||||
.setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel());
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (isFirstRun) {
|
||||
// show loading dialog
|
||||
showLoadingDialog("Getting vehicles from database...");
|
||||
// send liveActivity
|
||||
getParentTab().setLiveActivity((AbstractLiveActivity) activity);
|
||||
// get all vehicles
|
||||
isAck = false;
|
||||
// start a thread to wait 3 seconds for ack
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
SM.Exception(e.toString());
|
||||
// Restore interrupted state
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// if not getVehicle not isAck
|
||||
if (!isAck)
|
||||
myHandler.post(cancelLoadingDialogRUN);
|
||||
}).start();
|
||||
|
||||
SM.Debug("GetVehs");
|
||||
isFirstRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
SM.Debug("onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// clear previous vehicles
|
||||
SM.Debug("onResume");
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
}
|
||||
|
||||
final Runnable cancelLoadingDialogRUN = LiveActivity.this::cancelLoadingDialog;
|
||||
|
||||
// cancel loading dialog and show sending error message
|
||||
private void cancelLoadingDialog() {
|
||||
// cancel loading dialog
|
||||
try {
|
||||
loadingDialog.cancel();
|
||||
} catch (Exception ex) {
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
if (!isAck) {
|
||||
// show connection error
|
||||
Toast.makeText(context, "Could not get Vehicles... ", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void createIconContextMenu() {
|
||||
iconContextMenu = new IconContextMenu(this, 1);
|
||||
iconContextMenu.addItem(res, R.string.enable, R.drawable.enable, MENU_ENABLE);
|
||||
iconContextMenu.addItem(res, R.string.disable, R.drawable.disable, MENU_DISABLE);
|
||||
iconContextMenu.addItem(res, R.string.poll, R.drawable.poll, MENU_POLL);
|
||||
|
||||
//set onclick listener for context menu
|
||||
iconContextMenu.setOnClickListener(menuId -> {
|
||||
int radioCode = 30;
|
||||
switch (menuId) {
|
||||
case MENU_ENABLE: {
|
||||
// send change to AppServer
|
||||
optionForUnit(radioCode, MENU_ENABLE, liveVehicle.get(contextMenuPosition).id + "");
|
||||
if (AppParams.DEMO)
|
||||
vehicleStatusReceived(liveVehicle.get(contextMenuPosition).id, 101, 1);
|
||||
SM.Debug("MENU: Enable for " + liveVehicle.get(contextMenuPosition).id);
|
||||
break;
|
||||
}
|
||||
case MENU_DISABLE: {
|
||||
// send change to AppServer
|
||||
optionForUnit(radioCode, MENU_DISABLE, liveVehicle.get(contextMenuPosition).id + "");
|
||||
if (AppParams.DEMO)
|
||||
vehicleStatusReceived(liveVehicle.get(contextMenuPosition).id, 101, 0);
|
||||
SM.Debug("MENU: Disable for " + liveVehicle.get(contextMenuPosition).id);
|
||||
break;
|
||||
}
|
||||
case MENU_REMOTE: {
|
||||
// send change to AppServer
|
||||
optionForUnit(radioCode, MENU_REMOTE, liveVehicle.get(contextMenuPosition).id + "");
|
||||
SM.Debug("MENU: Remote for " + liveVehicle.get(contextMenuPosition).id);
|
||||
break;
|
||||
}
|
||||
case MENU_POLL: {
|
||||
// send change to AppServer
|
||||
optionForUnit(radioCode, MENU_POLL, liveVehicle.get(contextMenuPosition).id + "");
|
||||
if (AppParams.DEMO) {
|
||||
getParentTab().imei = liveVehicle.get(contextMenuPosition).sc_id + "";
|
||||
getParentTab().updateDemoPosition();
|
||||
getParentTab().updateResultsPollInUi("realpha");
|
||||
}
|
||||
|
||||
SM.Debug("MENU: P for " + liveVehicle.get(contextMenuPosition).id);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + menuId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* create context menu
|
||||
*/
|
||||
@Override
|
||||
public Dialog onCreateDialog(int id) {
|
||||
if (id == 1) {
|
||||
return iconContextMenu.createMenu(getString(R.string.options));
|
||||
}
|
||||
return super.onCreateDialog(id);
|
||||
}
|
||||
|
||||
|
||||
/* list item long click handler
|
||||
* used to show the context menu
|
||||
*/
|
||||
private final AdapterView.OnItemLongClickListener itemLongClickHandler = ((parent, view, position, id) -> {
|
||||
// save position
|
||||
contextMenuPosition = position;
|
||||
showDialog(1);
|
||||
return true;
|
||||
});
|
||||
|
||||
public void displayVehicle(boolean withZoom, double latZoom, double lngZoom) {
|
||||
//TODO: add makers for vehicles
|
||||
}
|
||||
|
||||
public void showOpenedBalloon(boolean demo) {
|
||||
//TODO: add show balloon
|
||||
}
|
||||
|
||||
public void showLoadingDialog(String message) {
|
||||
loadingDialog = new Dialog(context);
|
||||
loadingDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
loadingDialog.setContentView(R.layout.dialogloading);
|
||||
loadingDialog.setCancelable(true);
|
||||
loadingDialog.setCanceledOnTouchOutside(false);
|
||||
|
||||
Button cancel = (Button) loadingDialog.findViewById(R.id.buttonCancel);
|
||||
cancel.setVisibility(View.GONE);
|
||||
TextView textView1 = (TextView) loadingDialog.findViewById(R.id.textView1);
|
||||
textView1.setText(message);
|
||||
|
||||
loadingDialog.show();
|
||||
}
|
||||
|
||||
// save Vehicles
|
||||
@Override
|
||||
public void vehiclesReceived(ArrayList<Vehicle> list) {
|
||||
|
||||
SM.Debug("vehiclesReceived");
|
||||
isAck = true;
|
||||
liveVehicle = list;
|
||||
disabledVehicles = new ArrayList<>();
|
||||
displayedVehicles = new ArrayList<>();
|
||||
// set displayed to false and add icons to hashTable
|
||||
int i = 0;
|
||||
SM.Debug("DISPLAY LIVE VEHICLE");
|
||||
for (Vehicle veh : list) {
|
||||
|
||||
SM.Debug(veh.toString());
|
||||
liveVehicle.get(i).id = veh.sc_id;
|
||||
i++;
|
||||
// set vehicle to false
|
||||
displayedVehicles.add(AppParams.DEMO && (veh.sc_id == 101 || veh.sc_id == 102));
|
||||
// set disable to false
|
||||
disabledVehicles.add(!veh.status);
|
||||
|
||||
// add vehicle to hash Table according to driver_id
|
||||
if (tableHashOverlay.get((int) veh.driver_id) == null) // if doesn't exist
|
||||
{
|
||||
ArrayList<SuperVehicle> array = new ArrayList<>();
|
||||
SuperVehicle superVehicle = new SuperVehicle(veh.sc_id, veh.imei, veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen);
|
||||
array.add(superVehicle);
|
||||
tableHashOverlay.put((int) veh.driver_id, array);
|
||||
} else {
|
||||
// another vehicle with same driver_id exists
|
||||
ArrayList<SuperVehicle> array = tableHashOverlay.get((int) veh.driver_id);
|
||||
SuperVehicle superVehicle = new SuperVehicle(veh.sc_id, veh.imei, veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen);
|
||||
// add vehicle to array
|
||||
if (array != null) {
|
||||
array.add(superVehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set adapter
|
||||
|
||||
adapter = new VehiclesGridViewAdapter(activity, context, list, disabledVehicles);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
// Update UI
|
||||
myHandler.post(updateResultsRUN);
|
||||
|
||||
// hide loading dialog
|
||||
loadingDialog.cancel();
|
||||
if (!AppParams.DEMO)
|
||||
getLastPos();
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable updateResultsRUN = this::updateResultsUI;
|
||||
|
||||
// show vehicles in gridView
|
||||
private void updateResultsUI() {
|
||||
gridVehicle.setAdapter(adapter);
|
||||
|
||||
try {
|
||||
// hide loading dialog
|
||||
loadingDialog.cancel();
|
||||
} catch (Exception e) {
|
||||
SM.Exception(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshMap() {
|
||||
// Update UI
|
||||
myHandler.post(updateMapResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pollReceived(int position, double lat, double lng) {
|
||||
// Update UI
|
||||
latPoll = lat;
|
||||
lngPoll = lng;
|
||||
this.position = position;
|
||||
myHandler.post(updatePollResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void vehicleStatusReceived(long imei, int opCode, int status) {
|
||||
vehStatus = status;
|
||||
SM.Debug("UpdateOptions from APP with-> imei: " + imei + " | opCode: " + opCode + " | status: " + vehStatus);
|
||||
contextMenuPosition = getPositionFromImei(imei);
|
||||
// Update UI
|
||||
myHandler.post(updateOptionsRUN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emergencyAlarmReceived(int position, double lat, double lng) {
|
||||
pollReceived(position,lat,lng);
|
||||
}
|
||||
|
||||
|
||||
public void updatePosition(int pos) {
|
||||
contextMenuPosition = pos;
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable updateMapResults = () -> displayVehicle(false, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable updatePollResults = () -> {
|
||||
if (position != -1) {
|
||||
SM.Debug("updatePosition :" + position + " last value:" + displayedVehicles.get(position));
|
||||
// change in adapter
|
||||
adapter.changeDisplayed(position, true);
|
||||
}
|
||||
|
||||
displayVehicle(true, latPoll, lngPoll); };
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable updateOptionsRUN = this::updateOptionsUI;
|
||||
|
||||
private void updateOptionsUI() {
|
||||
|
||||
SM.Debug("REFRESHDisableEnable" + (Boolean.TRUE.equals(disabledVehicles.get(contextMenuPosition)) ? "true" : "false"));
|
||||
// change Enable/Disable in adapter
|
||||
adapter.changeDisabled(contextMenuPosition, disabledVehicles.get(contextMenuPosition));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* visual modifications when a vehicle is clicked
|
||||
*
|
||||
* @param position position in grid that was clicked
|
||||
* @param view View in which will do the modifications
|
||||
*/
|
||||
private void itemClick(int position, View view) {
|
||||
// change displayed state
|
||||
displayedVehicles.set(position, !Boolean.TRUE.equals(displayedVehicles.get(position)));
|
||||
|
||||
// change in the adapter
|
||||
adapter.changeDisplayed(position, displayedVehicles.get(position));
|
||||
|
||||
// change check image for selected value
|
||||
VehiclesGridViewAdapter.ViewHolder viewLive = (VehiclesGridViewAdapter.ViewHolder) view.getTag();
|
||||
|
||||
if (Boolean.TRUE.equals(displayedVehicles.get(position)))
|
||||
viewLive.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
viewLive.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
|
||||
// check if all values are identical
|
||||
boolean identical = true;
|
||||
for (Boolean displ : displayedVehicles)
|
||||
if (!Objects.equals(displ, displayedVehicles.get(0))) {
|
||||
identical = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// change image when all values are identical
|
||||
if (identical && Boolean.TRUE.equals(displayedVehicles.get(0))) {
|
||||
imageViewCheckAll.setSelected(true);
|
||||
imageViewCheckAll.setBackgroundResource(R.drawable.check_all);
|
||||
} else if (identical && Boolean.TRUE.equals(!displayedVehicles.get(0))) {
|
||||
imageViewCheckAll.setSelected(false);
|
||||
imageViewCheckAll.setBackgroundResource(R.drawable.uncheck_all);
|
||||
}
|
||||
|
||||
// display vehicle
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* get last position for all vehicles
|
||||
*/
|
||||
private void getLastPos() {
|
||||
getParentTab().executeNetworkStuff(new String[]{OperationCodes.GetLastPositions + "", AppParams.USERID + ""});
|
||||
}
|
||||
|
||||
/**
|
||||
* send a command that enable/disable a vehicle or request a poll
|
||||
*
|
||||
* @param radioCode is a hardcoded values set to 30
|
||||
* @param opCode the operation code. It can be :
|
||||
* MENU_ENABLE = 150,
|
||||
* MENU_DISABLE = 151,
|
||||
* MENU_REMOTE = 161,
|
||||
* MENU_POLL = 154;
|
||||
* @param scId vehicle imei for which we do the operation
|
||||
*/
|
||||
public void optionForUnit(int radioCode, int opCode, String scId) {
|
||||
// last values is set to 0 for disable and 1 for others
|
||||
getParentTab().executeNetworkStuff(new String[]{OperationCodes.Option4Unit + "", radioCode + "", (opCode == MENU_DISABLE ? MENU_ENABLE : opCode) + "", scId,
|
||||
(opCode == MENU_DISABLE ? 0 : 1) + ""});
|
||||
}
|
||||
|
||||
/**
|
||||
* return the position in the grid for a Vehicle specified by imei
|
||||
*
|
||||
* @param imei vehicle's imei
|
||||
*/
|
||||
private int getPositionFromImei(long imei) {
|
||||
int positionFromImei = -1;
|
||||
for (int i = 0; i < liveVehicle.size(); i++)
|
||||
if (liveVehicle.get(i).imei.equalsIgnoreCase(imei + ""))
|
||||
positionFromImei = i;
|
||||
SM.Debug("Position: " + positionFromImei);
|
||||
return positionFromImei;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register for broadcasts
|
||||
*/
|
||||
private void registerBroadcastIntents() {
|
||||
// zone and channel change intent
|
||||
IntentFilter intentFilter = new IntentFilter(OperationCodes.UNIT_STATUS_UPDATE + "");
|
||||
this.registerReceiver(mReceiver, intentFilter);
|
||||
|
||||
}
|
||||
|
||||
//The BroadcastReceiver that listens for Notification broadcasts
|
||||
public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
final String action = intent.getAction();
|
||||
|
||||
if (action.equals(OperationCodes.UNIT_STATUS_UPDATE + "")) {
|
||||
try {
|
||||
final String[] extra = intent.getStringExtra("unitStatus").split("#");
|
||||
|
||||
SM.Debug("extra has " + extra.length + " objects");
|
||||
Toast.makeText(context, "Unit was " + (Integer.parseInt(extra[1]) == 0 ? "DISABLED" : "ENABLED"), Toast.LENGTH_LONG).show();
|
||||
|
||||
myHandler.post(() -> {
|
||||
vehStatus = Integer.parseInt(extra[1]);
|
||||
contextMenuPosition = getPositionFromImei(Integer.parseInt(extra[0]));
|
||||
disabledVehicles.remove(contextMenuPosition);
|
||||
// invert logic is used
|
||||
disabledVehicles.add(contextMenuPosition, vehStatus != 1);
|
||||
adapter.changeDisabled(contextMenuPosition, disabledVehicles.get(contextMenuPosition));
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
SM.Exception("Exception in live BroadCastReceived" + ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.safemobile.dispatch;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
public class MapDemo extends FragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.mapdemo);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,871 @@
|
||||
/*
|
||||
* Author : ErVaLt / techwavedev.com
|
||||
* Description : TabLayout Andorid App
|
||||
*/
|
||||
package com.safemobile.dispatch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.safemobile.adapters.ConversationGridViewAdapter;
|
||||
import com.safemobile.adapters.MessagesGridViewAdapter;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Msg;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.SMS;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* fix import
|
||||
*/
|
||||
|
||||
public class MessagesActivity extends Activity {
|
||||
/** Called when the activity is first created. */
|
||||
|
||||
private MessagesGridViewAdapter mAdapter;
|
||||
private ConversationGridViewAdapter convAdapter;
|
||||
private ArrayList<Msg> listLastMessages = new ArrayList<Msg>();
|
||||
private ArrayList<Msg> listSpecificConversation = new ArrayList<Msg>();
|
||||
private ArrayList<Boolean> dispatcher_positions = new ArrayList<Boolean>();
|
||||
|
||||
private GridView gridView;
|
||||
private Context context;
|
||||
private Activity activity;
|
||||
//private IconContextMenu iconContextMenu = null;
|
||||
|
||||
private Hashtable<Long, ArrayList<SMS>> tableSMS = new Hashtable<Long, ArrayList<SMS>>();
|
||||
private Hashtable<String, Long> seqIDSMSHash = new Hashtable<String, Long>();
|
||||
|
||||
// Need handler for callbacks to the UI thread
|
||||
private final Handler myHandler = new Handler();
|
||||
|
||||
/* Visual resources */
|
||||
private LinearLayout layoutSend, layoutHeader, layoutHeaderConversation;
|
||||
private TextView textViewSelectedContact;
|
||||
private ImageView imageViewSelectedContact, imageBarcode;
|
||||
|
||||
/* Buttons and EditBoxes */
|
||||
private ImageButton imageButtonAdd, imageButtonBack;
|
||||
private Button imageButtonSend;
|
||||
private EditText editTextMsg;
|
||||
|
||||
private TabLayoutActivity parentTab;
|
||||
|
||||
/* Message args */
|
||||
private int ACTION, MSGUpdate = 0;
|
||||
|
||||
private ArrayList<String> allVehicleNames = new ArrayList<String>();
|
||||
public ArrayList<Vehicle> allVehicle = new ArrayList<Vehicle>();
|
||||
private Msg selectedVehicle;
|
||||
|
||||
// tip of Messages and flag first load
|
||||
public boolean LASTMESSAGES = true;
|
||||
private boolean FIRST = true;
|
||||
|
||||
// store selected sc_id and selected unit_type
|
||||
public long sc_id=0;
|
||||
public int unit_type=0;
|
||||
|
||||
private String seqID; // store sms seqId to set to ACK in adapter
|
||||
|
||||
public Bundle savedInstanceState;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
|
||||
// get parentTab
|
||||
parentTab = (TabLayoutActivity)getParent();
|
||||
|
||||
context = this;
|
||||
activity = this;
|
||||
|
||||
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
getBaseContext().getResources().updateConfiguration(config,
|
||||
getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
setContentView(R.layout.tabtext);
|
||||
|
||||
// get LayoutSend and hide
|
||||
layoutSend = (LinearLayout) findViewById(R.id.layoutSendMsg);
|
||||
layoutSend.setVisibility(View.GONE);
|
||||
// get header layout
|
||||
layoutHeader = (LinearLayout) findViewById(R.id.layoutHeader);
|
||||
layoutHeaderConversation = (LinearLayout) findViewById(R.id.layoutHeaderConversation);
|
||||
// show only header layout
|
||||
layoutHeaderConversation.setVisibility(View.GONE);
|
||||
|
||||
// get SelectedContact TextView and ImageView
|
||||
textViewSelectedContact = (TextView) findViewById(R.id.textViewSelectedContact);
|
||||
imageViewSelectedContact = (ImageView) findViewById(R.id.imageViewSelectedContact);
|
||||
|
||||
imageBarcode = (ImageView) findViewById(R.id.imageBarcode);
|
||||
imageBarcode.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try
|
||||
{
|
||||
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
|
||||
// intent.putExtra("SCAN_MODE", "ONE_D_MODE");
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
showErrorDialog(getResources().getString(R.string.barcodeError));
|
||||
//Log.d("Error",e.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// change tab header fontface
|
||||
TextView textView1 = (TextView) findViewById(R.id.textView1);
|
||||
textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textView1.setTextSize(24);
|
||||
|
||||
// prepared arraylist and passed it to the Adapter class
|
||||
//mAdapter = new GridviewAdapter(this,listFrom, listMessages, listReceived);
|
||||
mAdapter = new MessagesGridViewAdapter(this, listLastMessages, context);
|
||||
convAdapter = new ConversationGridViewAdapter(this, listSpecificConversation, context, sc_id, unit_type, dispatcher_positions, new ArrayList<Boolean>());
|
||||
// Set custom adapter to gridview
|
||||
gridView = (GridView) findViewById(R.id.gridView1);
|
||||
gridView.setAdapter(mAdapter);
|
||||
|
||||
// Implement On Item click listener
|
||||
gridView.setOnItemClickListener(new OnItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
|
||||
long arg3) {
|
||||
//if (layoutHeader.getVisibility() == View.VISIBLE)
|
||||
if(LASTMESSAGES)
|
||||
{
|
||||
// get position
|
||||
Msg item = mAdapter.getItem(position);
|
||||
// get Specific Conversation
|
||||
sc_id = item.from.sc_id;
|
||||
SM.Debug("Selected sc_id: " + sc_id);
|
||||
// set Conversation type
|
||||
LASTMESSAGES = false;
|
||||
// call get SMS
|
||||
GetSMS4unit(sc_id);
|
||||
// create crt_Vehicle
|
||||
unit_type = (int)item.from.driver_id;
|
||||
// save selected vehicle
|
||||
selectedVehicle = item;
|
||||
|
||||
}
|
||||
|
||||
if(AppParams.DEMO)
|
||||
{
|
||||
// modify UI
|
||||
ACTION = MSGUpdate;
|
||||
updateResultsInUi();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// button create message
|
||||
imageButtonAdd = (ImageButton) findViewById(R.id.imageButtonAdd);
|
||||
imageButtonAdd.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDialog();
|
||||
}
|
||||
});
|
||||
|
||||
// button send message
|
||||
imageButtonSend = (Button) findViewById(R.id.imageButtonSend);
|
||||
imageButtonSend.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
//SM.Debug("SC ID:" + sc_id);
|
||||
|
||||
SendSMS(sc_id, editTextMsg.getText().toString());
|
||||
Toast.makeText(context, "Sending message...", 500).show();
|
||||
/*
|
||||
// show busy indicator
|
||||
dialogHandler.handleMessage(new Message());
|
||||
|
||||
ACTION = SHOWLoading;
|
||||
myHandler.post(UpdateResults);
|
||||
*/
|
||||
// disable send button and editBox
|
||||
editTextMsg.setEnabled(false);
|
||||
imageButtonSend.setEnabled(false);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
myHandler.post(enableButtonRUN);
|
||||
|
||||
//LASTMESSAGES = false;
|
||||
if(AppParams.DEMO)
|
||||
{
|
||||
Thread.sleep(5500);
|
||||
myHandler.post(demoReceveidSMSRUN);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// button back to conversations
|
||||
imageButtonBack = (ImageButton) findViewById(R.id.imageButtonBack);
|
||||
imageButtonBack.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// set LastMessage conversation type
|
||||
LASTMESSAGES = true;
|
||||
// refresh Grid
|
||||
GetLastSMS();
|
||||
if(AppParams.DEMO)
|
||||
updateResultsInUi();
|
||||
}
|
||||
});
|
||||
|
||||
// get Message editText
|
||||
editTextMsg = (EditText) findViewById(R.id.editTextMsg);
|
||||
|
||||
gridView.setId(1); // id needed for IconContextMenu
|
||||
registerForContextMenu(gridView);
|
||||
parentTab.messageActivity = this;
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable demoReceveidSMSRUN = new Runnable() {
|
||||
public void run() {
|
||||
parentTab.imei = sc_id + "";
|
||||
parentTab.updateResultsInUi("realpha");
|
||||
|
||||
int timeGMT = (int) (System.currentTimeMillis() / 1000L);
|
||||
String SendSMSSeqID = "1."+timeGMT;
|
||||
// add mess to not ack list
|
||||
seqIDSMSHash.put(SendSMSSeqID, sc_id);
|
||||
// get sc_id conversation and add message
|
||||
ArrayList<SMS> crtSMSlist = tableSMS.get(sc_id);
|
||||
SMS sms = new SMS(0, 0, timeGMT, "i got your sms", 0, sc_id);
|
||||
sms.seq_idx = SendSMSSeqID;
|
||||
crtSMSlist.add(sms);
|
||||
|
||||
// add message to listLast
|
||||
boolean exists = false;
|
||||
for (Msg msg : listLastMessages)
|
||||
// if conversation exists in lastMessages
|
||||
if(msg.from.sc_id == sc_id)
|
||||
{
|
||||
exists = true;
|
||||
msg.message = "i got your sms";
|
||||
msg.received = Calendar.getInstance().getTime();
|
||||
}
|
||||
|
||||
// if last messages doesn't contain this conversation
|
||||
if(!exists)
|
||||
{
|
||||
Vehicle sentVehicle = null;
|
||||
for(Vehicle veh : allVehicle)
|
||||
if(veh.sc_id == sc_id)
|
||||
sentVehicle = veh;
|
||||
|
||||
listLastMessages.add(new Msg(sentVehicle, "i got your sms", Calendar.getInstance().getTime(), SendSMSSeqID));
|
||||
}
|
||||
SM.Debug("time: " + timeGMT + " | " + Calendar.getInstance().getTime().toString() );
|
||||
|
||||
updateResultsInUi();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.logout);
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.exit);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
SM.Debug("onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if(parentTab.getTCPState() != null){
|
||||
if(FIRST)
|
||||
{
|
||||
UpdateVehs(parentTab.allVehicle);
|
||||
FIRST = false;
|
||||
if(LASTMESSAGES)
|
||||
parentTab.executeNetworkStuff(new String[] {OperationCodes.GetLastSMS + "", AppParams.USERID + ""});
|
||||
}
|
||||
|
||||
//GetLastSMS();
|
||||
}
|
||||
SM.Debug("onResume");
|
||||
}
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
if (requestCode == 0) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
String contents = intent.getStringExtra("SCAN_RESULT");
|
||||
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
|
||||
editTextMsg.setText(editTextMsg.getText().toString() + contents);
|
||||
// Handle successful scan
|
||||
Toast.makeText(this, getResources().getString(R.string.barcodeContent) + ":"+contents+" with format:"+format, 6000).show();
|
||||
} else if (resultCode == RESULT_CANCELED) {
|
||||
// Handle cancel
|
||||
//Toast.makeText(this, "TRY AGAIN", 6000).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Request SMS 4 Unit from AppServer
|
||||
private void GetSMS4UnitWithTime(long sc_id, long time) {
|
||||
if(!AppParams.DEMO) {
|
||||
parentTab.executeNetworkStuff(new String[] {OperationCodes.GetRecentSMSs + "", sc_id + "", time + ""});
|
||||
|
||||
SM.Debug(" #### GetSMS4uni:" + sc_id);
|
||||
}
|
||||
}
|
||||
|
||||
private void GetSMS4unit(long sc_id)
|
||||
{
|
||||
if(!AppParams.DEMO)
|
||||
{
|
||||
SM.Debug("GetSMS4unit : " + sc_id);
|
||||
ArrayList<SMS> listSMS = tableSMS.get(sc_id);
|
||||
long timeGMT = 0;
|
||||
if(!listSMS.isEmpty())
|
||||
timeGMT = listSMS.get(listSMS.size()-1).timeGMT;
|
||||
|
||||
// error in DB
|
||||
if(String.valueOf(timeGMT).contains("."))
|
||||
{
|
||||
try {
|
||||
// remove the dot and the parse it to String
|
||||
timeGMT = Long.parseLong(String.valueOf(timeGMT).split(".")[1]);
|
||||
}
|
||||
catch (Exception e) {
|
||||
timeGMT = Long.parseLong(String.valueOf(timeGMT).replace(".",""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
parentTab.executeNetworkStuff(new String[] {OperationCodes.GetRecentSMSs + "", sc_id + "", timeGMT + ""});
|
||||
|
||||
//parent.getRecentSMSs(sc_id, timeGMT);
|
||||
SM.Debug(" #### GetSMS4uni:" + sc_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Request Last SMS from AppServer
|
||||
public void GetLastSMS()
|
||||
{
|
||||
if(!AppParams.DEMO)
|
||||
{
|
||||
if(LASTMESSAGES)
|
||||
parentTab.executeNetworkStuff(new String[] {OperationCodes.GetLastSMS + "", AppParams.USERID + ""});
|
||||
//parent.getLastSMSs(AppParams.USERID);
|
||||
else
|
||||
{
|
||||
ArrayList<SMS> listSMS = tableSMS.get(sc_id);
|
||||
long timeGMT = 0;
|
||||
if(listSMS!= null && !listSMS.isEmpty())
|
||||
timeGMT = listSMS.get(listSMS.size()-1).timeGMT;
|
||||
//parent.getRecentSMSs(sc_id, timeGMT);
|
||||
parentTab.executeNetworkStuff(new String[] {OperationCodes.GetRecentSMSs + "", sc_id + "", timeGMT + ""});
|
||||
}
|
||||
}
|
||||
else
|
||||
updateResultsInUi();
|
||||
}
|
||||
|
||||
|
||||
private void SendSMS(long sc_id, String txt)
|
||||
{
|
||||
if(!AppParams.DEMO)
|
||||
{
|
||||
int timeGMT = (int) (System.currentTimeMillis() / 1000L);
|
||||
String SendSMSSeqID = "1."+timeGMT;
|
||||
// add mess to not ack list
|
||||
seqIDSMSHash.put(SendSMSSeqID, sc_id);
|
||||
// get sc_id conversation and add message
|
||||
SMS sms = new SMS(0, 0, timeGMT, txt, sc_id, 0);
|
||||
sms.seq_idx = SendSMSSeqID;
|
||||
tableSMS.get(sc_id).add(sms);
|
||||
//parent.sendSMS(SendSMSSeqID,sc_id, txt);
|
||||
parentTab.executeNetworkStuff(new String[] {OperationCodes.SEND_TM + "", SendSMSSeqID, sc_id + "", txt});
|
||||
|
||||
updateResultsInUi();
|
||||
}
|
||||
else
|
||||
{
|
||||
int timeGMT = (int) (System.currentTimeMillis() / 1000L);
|
||||
String SendSMSSeqID = "1."+timeGMT;
|
||||
// add mess to not ack list
|
||||
seqIDSMSHash.put(SendSMSSeqID, sc_id);
|
||||
// get sc_id conversation and add message
|
||||
ArrayList<SMS> crtSMSlist = tableSMS.get(sc_id);
|
||||
SMS sms = new SMS(0, 0, timeGMT, txt, sc_id, 0);
|
||||
sms.seq_idx = SendSMSSeqID;
|
||||
crtSMSlist.add(sms);
|
||||
|
||||
|
||||
// add message to listLast
|
||||
boolean exists = false;
|
||||
for (Msg msg : listLastMessages)
|
||||
// if conversation exists in lastMessages
|
||||
if(msg.from.sc_id == sc_id)
|
||||
{
|
||||
exists = true;
|
||||
msg.message = txt;
|
||||
msg.received = Calendar.getInstance().getTime();
|
||||
}
|
||||
|
||||
// if last messages doesn't contain this conversation
|
||||
if(!exists)
|
||||
{
|
||||
Vehicle sentVehicle = null;
|
||||
for(Vehicle veh : allVehicle)
|
||||
if(veh.sc_id == sc_id)
|
||||
sentVehicle = veh;
|
||||
|
||||
listLastMessages.add(new Msg(sentVehicle, txt, Calendar.getInstance().getTime(), SendSMSSeqID));
|
||||
}
|
||||
SM.Debug("time: " + timeGMT + " | " + Calendar.getInstance().getTime().toString() );
|
||||
LASTMESSAGES = false;
|
||||
|
||||
updateResultsInUi();
|
||||
}
|
||||
}
|
||||
|
||||
// Update Vehicles received from AppServer
|
||||
public void UpdateVehs(ArrayList<Vehicle> list)
|
||||
{
|
||||
SM.Debug("## UpdateVehs: " + list.size());
|
||||
allVehicle = list;
|
||||
allVehicleNames = new ArrayList<String>();
|
||||
for(Vehicle v: allVehicle)
|
||||
allVehicleNames.add(v.name);
|
||||
|
||||
if(tableSMS.size() == 0)
|
||||
{
|
||||
for(Vehicle veh: allVehicle)
|
||||
{
|
||||
ArrayList<SMS> lista = new ArrayList<SMS>();
|
||||
// populate conversation list if demo
|
||||
if(AppParams.DEMO)
|
||||
lista = getDemoConversation(veh.sc_id);
|
||||
|
||||
tableSMS.put(veh.sc_id, lista);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// gets DEMO conversations
|
||||
private ArrayList<SMS> getDemoConversation(long sc_id)
|
||||
{
|
||||
ArrayList<SMS> lista = new ArrayList<SMS>();
|
||||
if(sc_id == 101)
|
||||
lista.add(new SMS(1, 2, 1324016412, "Only one left", 101, 0));
|
||||
else if (sc_id == 102)
|
||||
lista.add(new SMS(1, 2, 1328060100, "i'm at the train station", 0, 102));
|
||||
else if (sc_id == 103) {
|
||||
lista.add(new SMS(1, 2, 1121016637, "Where are you now?", 103, 0));
|
||||
lista.add(new SMS(2, 2, 1121016693, "Near Elementary School 81", 0, 103));
|
||||
lista.add(new SMS(3, 2, 1121016693, "We have a client on Belmont Ave", 103, 0));
|
||||
lista.add(new SMS(4, 2, 1121016724, "It's only 4 blocks away", 103, 0));
|
||||
lista.add(new SMS(5, 2, 1121016693, "Can you take him?", 103, 0));
|
||||
lista.add(new SMS(6, 2, 1121016818, "I'll be right there", 0, 103));
|
||||
}
|
||||
else if (sc_id == 105)
|
||||
lista.add(new SMS(1, 2, 1328061660, "Thanks", 0, 105));
|
||||
return lista;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void UpdateSMS(ArrayList<SMS> list)
|
||||
{
|
||||
SM.Debug("## UpdateSMS: " + list.size() + " [LASTMESSAGES:" + LASTMESSAGES + "]");
|
||||
|
||||
// populate listLastMessages
|
||||
if(LASTMESSAGES)
|
||||
{
|
||||
listLastMessages = new ArrayList<Msg>();
|
||||
for(SMS sms: list)
|
||||
{
|
||||
// get for sender
|
||||
long id_sender = sms.sc_id_dest;
|
||||
if (id_sender == 0)
|
||||
id_sender = sms.sc_id_sour;
|
||||
//SM.Debug(sms.toString());
|
||||
// get vehicle with sender id
|
||||
Vehicle messageVeh= null;
|
||||
messageVeh = getVehicleById(id_sender);
|
||||
listLastMessages.add(0,new Msg(messageVeh, sms.mess, new Date((long)sms.timeGMT * 1000), sms.seq_idx));
|
||||
}
|
||||
|
||||
// update GridView
|
||||
|
||||
//SM.Debug(" ########### " + parentTab.allVehicle.size() + " ||| " + listLastMessages.size());
|
||||
|
||||
mAdapter = new MessagesGridViewAdapter(activity, listLastMessages, context);
|
||||
//SM.Debug("list count : " + listLastMessages.size());
|
||||
//gridView.setAdapter(mAdapter);
|
||||
//mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
// add new values to hashTable for key = sc_id
|
||||
ArrayList<SMS> listScId = tableSMS.get(sc_id);
|
||||
if(list.size() != 0)
|
||||
for(SMS sms:list)
|
||||
{
|
||||
// compare last item in hashList with first elem in arrived list
|
||||
// protect is listSc_Id size = 0
|
||||
if ((listScId.size()>0)&&(sms.sc_id_dest == listScId.get(listScId.size()-1).sc_id_dest && sms.sc_id_sour == listScId.get(listScId.size()-1).sc_id_sour && sms.mess == listScId.get(listScId.size()-1).mess))
|
||||
// drop element
|
||||
;
|
||||
else
|
||||
listScId.add(sms);
|
||||
}
|
||||
}
|
||||
// modify UI
|
||||
ACTION = MSGUpdate;
|
||||
myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateResultsInUi();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Confirmation for sending message
|
||||
public void ConfirmSMS(String data, final String seqID)
|
||||
{
|
||||
SM.Debug("ConfirmSMS");
|
||||
if(data.equals("0"))
|
||||
{
|
||||
SM.Debug("Error on sending SMS");
|
||||
showErrorDialog("Error on sending message.");
|
||||
}
|
||||
else
|
||||
{
|
||||
SM.Debug("ACK received for text message");
|
||||
|
||||
//get sc_id for crt message
|
||||
long sc_id = seqIDSMSHash.get(seqID);
|
||||
// get SMS list for crt sc_id
|
||||
ArrayList<SMS> crtSMSList = tableSMS.get(sc_id);
|
||||
for(SMS sms: crtSMSList)
|
||||
{
|
||||
|
||||
if(sms.seq_idx.equals(seqID))
|
||||
{
|
||||
SM.Debug("######### AM SCHIMBAT STATUSUL pt: " + sms.mess + " | " + sc_id + " | " + seqID + " || " + sms.seq_idx);
|
||||
// set ACK
|
||||
sms.status = 2;
|
||||
}
|
||||
}
|
||||
// remove message from seqIDSMS Hash = don't wait confirmation for it
|
||||
seqIDSMSHash.remove(seqID);
|
||||
|
||||
// refresh MSG List
|
||||
//GetSMS4unit(sc_id);
|
||||
|
||||
/*
|
||||
// TODO -> this is a small bug fix, should talk with Bigu to change it
|
||||
// remove message from list because it will be brought back by GetSMS4Unit, and it will have different time
|
||||
ArrayList<SMS> listWithTextMessage = tableSMS.get(sc_id);
|
||||
if(listWithTextMessage.size() > 0)
|
||||
listWithTextMessage.remove(listWithTextMessage.size() - 1); // remove last message
|
||||
*/
|
||||
|
||||
// store sms seqId to set to ACK in adapter
|
||||
this.seqID = seqID;
|
||||
myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
convAdapter.setACK(seqID);
|
||||
convAdapter.changeView(seqID);
|
||||
convAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
myHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// clear text
|
||||
editTextMsg.setText("");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void NewSMS(String imei, String message, final long time)
|
||||
{
|
||||
SM.Debug(" ## NewSMS: " + imei + " | " + message);
|
||||
if(!LASTMESSAGES)
|
||||
{
|
||||
// if received message from current conversation
|
||||
if(getVehicleByImei(imei).sc_id == sc_id)
|
||||
GetSMS4UnitWithTime(sc_id, time); // refresh MSG List
|
||||
//else
|
||||
// parentTab.myHandler.post(parentTab.showPopUpRUN); // show PopUp
|
||||
}
|
||||
else
|
||||
GetLastSMS(); // get last SMS
|
||||
}
|
||||
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable enableButtonRUN = new Runnable() {
|
||||
public void run() {
|
||||
updateEnableButtonsUI();
|
||||
}
|
||||
};
|
||||
|
||||
// enable buttons in UI after 200ms from send
|
||||
private void updateEnableButtonsUI()
|
||||
{
|
||||
// enable buttons
|
||||
imageButtonSend.setEnabled(true);
|
||||
editTextMsg.setEnabled(true);
|
||||
editTextMsg.setText("");
|
||||
}
|
||||
|
||||
private void updateResultsInUi()
|
||||
{
|
||||
if(allVehicle == null)
|
||||
UpdateVehs(parentTab.allVehicle);
|
||||
|
||||
//SM.Debug("updateResultsInUi: " + ACTION);
|
||||
if(ACTION == MSGUpdate)
|
||||
{
|
||||
if(LASTMESSAGES)
|
||||
{
|
||||
// show Header Layout
|
||||
layoutHeader.setVisibility(View.VISIBLE);
|
||||
// hide Conversation Header Layout
|
||||
layoutHeaderConversation.setVisibility(View.GONE);
|
||||
// hide Send Layout
|
||||
layoutSend.setVisibility(View.GONE);
|
||||
// change GridView adapter
|
||||
gridView.setAdapter(mAdapter);
|
||||
gridView.invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
SM.Debug(" #### Modify adapter for SMS4unit");
|
||||
// populate specific conversation
|
||||
listSpecificConversation = new ArrayList<Msg>();
|
||||
dispatcher_positions = new ArrayList<Boolean>();
|
||||
ArrayList<Boolean> ackPosition = new ArrayList<Boolean>();
|
||||
ArrayList<SMS> list;
|
||||
list = tableSMS.get(sc_id);
|
||||
for(SMS sms: list)
|
||||
{
|
||||
// get for sender
|
||||
long id_sender = sms.sc_id_dest;
|
||||
if (id_sender == 0)
|
||||
id_sender = sms.sc_id_sour;
|
||||
// get vehicle with sender id
|
||||
Vehicle messageVeh= null;
|
||||
messageVeh = getVehicleById(id_sender);
|
||||
// flag dispatcher message when source is 0
|
||||
dispatcher_positions.add(sms.sc_id_sour==0 ? true : false);
|
||||
if(sms.status == 2)
|
||||
ackPosition.add(true);
|
||||
else
|
||||
ackPosition.add(false);
|
||||
|
||||
listSpecificConversation.add(new Msg(messageVeh, sms.mess, new Date((long)sms.timeGMT * 1000), sms.seq_idx));
|
||||
}
|
||||
|
||||
|
||||
convAdapter = new ConversationGridViewAdapter(activity, listSpecificConversation, context, sc_id, unit_type, dispatcher_positions, ackPosition);
|
||||
gridView.setAdapter(convAdapter);
|
||||
if(listSpecificConversation.size() > 0)
|
||||
gridView.setSelection(listSpecificConversation.size()-1);
|
||||
|
||||
// set unit name and image in Header Conversation
|
||||
textViewSelectedContact.setText(getVehicleBySc_Id(sc_id).name);
|
||||
imageViewSelectedContact.setImageResource(getVehicleBySc_Id(sc_id).getLargeIcon());
|
||||
|
||||
// clear editText
|
||||
editTextMsg.setText("");
|
||||
|
||||
// change layouts visibility
|
||||
layoutSend.setVisibility(View.VISIBLE);
|
||||
layoutHeader.setVisibility(View.GONE);
|
||||
layoutHeaderConversation.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
gridView.invalidate();
|
||||
// hide dialog
|
||||
try
|
||||
{
|
||||
//dialogLoading.cancel();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// show new message after layoutNewMessage Click
|
||||
public void showSMS4unit(int sc_id)
|
||||
{
|
||||
// show dialog
|
||||
//dialogLoading = ProgressDialog.show(activity, "", "Loading messages. Please wait...", true);
|
||||
|
||||
ACTION = MSGUpdate;
|
||||
LASTMESSAGES = false;
|
||||
GetSMS4unit(sc_id);
|
||||
}
|
||||
|
||||
// gets Vehicle from id
|
||||
public Vehicle getVehicleById(long id_vehicle)
|
||||
{
|
||||
for(Vehicle vehicle: allVehicle)
|
||||
if(vehicle.sc_id == id_vehicle)
|
||||
return vehicle;
|
||||
return null;
|
||||
}
|
||||
|
||||
// get Vehicle from imei
|
||||
public Vehicle getVehicleByImei(String imei)
|
||||
{
|
||||
for(Vehicle vehicle: allVehicle)
|
||||
if(vehicle.imei.equalsIgnoreCase(imei))
|
||||
return vehicle;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Vehicle getVehicleBySc_Id(long sc_id)
|
||||
{
|
||||
for(Vehicle vehicle: allVehicle)
|
||||
if(vehicle.sc_id == sc_id)
|
||||
return vehicle;
|
||||
return null;
|
||||
}
|
||||
|
||||
// show a dialog
|
||||
public void showDialog()
|
||||
{
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.template_simple_list_item, allVehicleNames);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(getString(R.string.selectVehicle));
|
||||
builder.setAdapter(adapter , new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// get position
|
||||
Vehicle item = allVehicle.get(which);
|
||||
// get Specific Conversation
|
||||
sc_id = item.sc_id;
|
||||
SM.Debug("Selected sc_id: " + sc_id);
|
||||
// set Conversation type
|
||||
LASTMESSAGES = false;
|
||||
// call get SMS
|
||||
GetSMS4unit(sc_id);
|
||||
// create crt_Vehicle
|
||||
unit_type = (int) item.driver_id;
|
||||
|
||||
SM.Debug("AM SELECTAT: " + sc_id + " | " + item.name + " | " + unit_type + "\n\t " + item.toString());
|
||||
selectedVehicle = new Msg(item, "", Calendar.getInstance().getTime(), "");
|
||||
|
||||
if(AppParams.DEMO)
|
||||
updateResultsInUi();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
|
||||
public void showErrorDialog(String errorMsg)
|
||||
{
|
||||
Dialog dialog = new Dialog(context);
|
||||
dialog.setTitle(getString(R.string.sendingError));
|
||||
dialog.setContentView(R.layout.dialog);
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
TextView text = (TextView) dialog.findViewById(R.id.text);
|
||||
ImageView image = (ImageView) dialog.findViewById(R.id.image);
|
||||
|
||||
image.setImageResource(R.drawable.error);
|
||||
text.setText(errorMsg);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.safemobile.dispatch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
|
||||
public class NotificationActivity extends Activity{
|
||||
|
||||
public static final String NOTIFICATION_MESSAGE_INTENT = "notification_message_clicked_intent";
|
||||
public static final String NOTIFICATION_ALERT_INTENT = "notification_alert_clicked_intent";
|
||||
public static final String NOTIFICATION_POLL_INTENT = "notification_poll_clicked_intent";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// get notification type
|
||||
int key = getIntent().getExtras().getInt("key");
|
||||
|
||||
// broadcast intent
|
||||
Intent i = new Intent();
|
||||
switch(key)
|
||||
{
|
||||
case AppParams.messageNotif: i.setAction(NOTIFICATION_MESSAGE_INTENT); break;
|
||||
case AppParams.alertNotif: i.setAction(NOTIFICATION_ALERT_INTENT); break;
|
||||
case AppParams.pollNotif: i.setAction(NOTIFICATION_POLL_INTENT); break;
|
||||
}
|
||||
|
||||
getBaseContext().sendBroadcast(i);
|
||||
|
||||
/* Set activity result and send intent data */
|
||||
setResult(RESULT_OK, getIntent());
|
||||
/* Finish activity and return to parent activity */
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,411 @@
|
||||
package com.safemobile.dispatch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Typeface;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.safemobile.adapters.RecordingsGridViewAdapter;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.Recording;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.radio.RadioGW;
|
||||
import com.safemobile.lib.sound.RecordingHandle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* fix import
|
||||
*/
|
||||
|
||||
public class RecordingsActivity extends Activity {
|
||||
private Context context;
|
||||
private Activity activity;
|
||||
public TabLayoutActivity parentTab;
|
||||
public ArrayList<Recording> allRecordings = new ArrayList<Recording>();
|
||||
private ArrayList<Boolean> playingPositions = new ArrayList<Boolean>();
|
||||
private ArrayList<String> allGWsIP = new ArrayList<String>();
|
||||
private GridView gridView;
|
||||
private RecordingsGridViewAdapter adapter;
|
||||
public View convertViewRecording;
|
||||
|
||||
public int playingPosition = -1;
|
||||
|
||||
// Need handler for callbacks to the UI thread
|
||||
private final Handler myHandler = new Handler();
|
||||
|
||||
//recoding TCP and audio
|
||||
private RecordingHandle recHandle = null;
|
||||
|
||||
/* Dialog */
|
||||
private TextView textViewCount, textViewGateway;
|
||||
|
||||
public Bundle savedInstanceState;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
// get parentTab
|
||||
parentTab = (TabLayoutActivity)getParent();
|
||||
|
||||
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
getBaseContext().getResources().updateConfiguration(config,
|
||||
getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
setContentView(R.layout.tabrecordings);
|
||||
|
||||
|
||||
// get context
|
||||
context = this;
|
||||
activity = this;
|
||||
|
||||
|
||||
// change tab header fontface
|
||||
TextView textView1 = (TextView) findViewById(R.id.textViewTitle);
|
||||
textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textView1.setTextSize(24);
|
||||
|
||||
gridView = (GridView) findViewById(R.id.gridViewRecordings);
|
||||
adapter = new RecordingsGridViewAdapter(activity, context, allRecordings, playingPositions);
|
||||
gridView.setAdapter(adapter);
|
||||
|
||||
gridView.setOnItemClickListener(onItemClickListener);
|
||||
|
||||
if(recHandle == null && !AppParams.DEMO)
|
||||
recHandle = new RecordingHandle(AppParams.IP);
|
||||
|
||||
|
||||
textViewCount = (TextView) findViewById(R.id.textViewCount);
|
||||
updateNumberOfRecordings();
|
||||
|
||||
textViewGateway = (TextView) findViewById(R.id.textViewGateway);
|
||||
textViewGateway.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textViewGateway.setTextSize(24);
|
||||
textViewGateway.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
allGWsIP.clear();
|
||||
for(RadioGW radio: AppParams.listRadios)
|
||||
allGWsIP.add(radio.IP);
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.template_simple_list_item,
|
||||
allGWsIP);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||
context);
|
||||
builder.setTitle("Select RadioGW");
|
||||
builder.setAdapter(adapter,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// change gateway
|
||||
textViewGateway.setText(allGWsIP.get(which));
|
||||
Toast.makeText(context, getString(R.string.loadingRecordings), Toast.LENGTH_SHORT).show();
|
||||
GetRecordings(parentTab.allRadios.get(which).GW_ID, parentTab.allRadios.get(which).ID);
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
});
|
||||
textViewGateway.setVisibility(View.INVISIBLE);
|
||||
|
||||
|
||||
parentTab.recordingsActivity = this;
|
||||
|
||||
// register to receive broadcasts
|
||||
registerBroadcastIntents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.logout);
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.exit);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
|
||||
/** Update the number of recordings displayed on the top layout */
|
||||
private void updateNumberOfRecordings() {
|
||||
textViewCount.setText("[" + AppParams.recordings.size() + "]");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void showDialog(String errorMsg)
|
||||
{
|
||||
Dialog dialog = new Dialog(context);
|
||||
dialog.setContentView(R.layout.dialog);
|
||||
dialog.setTitle("Message");
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
TextView text = (TextView) dialog.findViewById(R.id.text);
|
||||
ImageView image = (ImageView) dialog.findViewById(R.id.image);
|
||||
|
||||
image.setImageResource(R.drawable.ic_launcher);
|
||||
text.setText(errorMsg);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
SM.Debug("onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if(parentTab.getTCPState() != null && !AppParams.DEMO){
|
||||
|
||||
Toast.makeText(context, getString(R.string.moreRecordings), Toast.LENGTH_SHORT).show();
|
||||
|
||||
if(parentTab.crtRadio != null)
|
||||
textViewGateway.setText(parentTab.crtRadio.IP);
|
||||
|
||||
/*
|
||||
if(parentTab.allRadios == null)
|
||||
GetGWRadios();
|
||||
*/
|
||||
if(playingPosition < 0 && parentTab.crtRadio != null)
|
||||
{
|
||||
SM.Debug("GetRecordings resume + crtRadio:"+parentTab.crtRadio.toString());
|
||||
GetRecordings(parentTab.crtRadio.GW_ID, parentTab.crtRadio.ID);
|
||||
}
|
||||
|
||||
}
|
||||
SM.Debug("onResume");
|
||||
}
|
||||
|
||||
private OnItemClickListener onItemClickListener = new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
|
||||
|
||||
// disable grid scrolling and item click
|
||||
gridView.setEnabled(false);
|
||||
convertViewRecording = view;
|
||||
|
||||
// change background to playing
|
||||
adapter.changePlaying(position, true);
|
||||
|
||||
// if no recording is playing and not DEMO
|
||||
if(playingPosition<0 && !AppParams.DEMO)
|
||||
{
|
||||
// send recording request to App Server
|
||||
SendPlayRequest(allRecordings.get(position).ID);
|
||||
// flag that sound is needed
|
||||
recHandle.StartSound();
|
||||
recHandle.soundNeeded = true;
|
||||
}
|
||||
// no recording is playing and DEMO
|
||||
else if(playingPosition<0 && AppParams.DEMO)
|
||||
{
|
||||
// create player which will play demo recordings
|
||||
MediaPlayer player = new MediaPlayer();
|
||||
|
||||
AssetFileDescriptor afd;
|
||||
try {
|
||||
switch(position)
|
||||
{
|
||||
case 1: afd = getAssets().openFd("startwindows.mp3"); break;
|
||||
case 2: afd = getAssets().openFd("exitwindows.mp3"); break;
|
||||
default : afd = getAssets().openFd("mike.mp3"); break;
|
||||
};
|
||||
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
|
||||
player.prepare();
|
||||
player.start();
|
||||
|
||||
} catch (IOException e) { }
|
||||
}
|
||||
|
||||
// save playing position
|
||||
playingPosition = position;
|
||||
|
||||
// start the timer which will reset the UI to 'no recording playing'
|
||||
startRecordingStoperTimer(allRecordings.get(playingPosition).endGMT - allRecordings.get(playingPosition).startGMT);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** create Timer which will stop the recording after a specific time */
|
||||
private void startRecordingStoperTimer(final int seconds) {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// sleep for at least 1 second
|
||||
final int ms = (seconds > 1 ? seconds * 1000 : 1000);
|
||||
|
||||
// sleep for amount of time
|
||||
try {
|
||||
Thread.sleep(ms);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// modify the UI after the recording is done playing
|
||||
myHandler.post(stopRecordingRUN);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable stopRecordingRUN = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateStopRecording();
|
||||
}
|
||||
};
|
||||
|
||||
private void updateStopRecording()
|
||||
{
|
||||
// change playing icon
|
||||
adapter.changePlaying(playingPosition, false);
|
||||
|
||||
// enable grid
|
||||
gridView.setEnabled(true);
|
||||
|
||||
// set playing Recording position to -1
|
||||
playingPosition = -1;
|
||||
|
||||
}
|
||||
|
||||
// Update Recordings received from AppServer
|
||||
public void UpdateRecordings(ArrayList<Recording> list)
|
||||
{
|
||||
//SM.Debug("## UpdateRecordings: " + list.size());
|
||||
allRecordings = new ArrayList<Recording>();
|
||||
for(Recording rec : list)
|
||||
{
|
||||
if(rec.typeID == 1 && rec.subID == AppParams.USERID)
|
||||
allRecordings.add(rec);
|
||||
else if (rec.typeID != 1)
|
||||
allRecordings.add(rec);
|
||||
}
|
||||
myHandler.post(UpdateResultsRUN);
|
||||
|
||||
}
|
||||
|
||||
// PlayRecording received from AppServer
|
||||
public void PlayRecording(long id)
|
||||
{
|
||||
// change adapter image
|
||||
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable UpdateResultsRUN = new Runnable() {
|
||||
public void run() {
|
||||
updateResultsInUi();
|
||||
}
|
||||
};
|
||||
|
||||
private void updateResultsInUi()
|
||||
{
|
||||
// clear played items
|
||||
playingPositions = new ArrayList<Boolean>();
|
||||
for(int i=0; i<allRecordings.size(); i++)
|
||||
playingPositions.add(true);
|
||||
// set adapter - where playingPositions stores exists values
|
||||
adapter = new RecordingsGridViewAdapter(activity, context, allRecordings, playingPositions);
|
||||
|
||||
// playing positions need to be false because no recording is played
|
||||
playingPositions.clear();
|
||||
for(int i=0; i<allRecordings.size(); i++)
|
||||
playingPositions.add(false);
|
||||
|
||||
updateNumberOfRecordings();
|
||||
|
||||
gridView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
// send
|
||||
private void GetRecordings(int radioGWID, int radioID)
|
||||
{
|
||||
parentTab.getRecordings(radioGWID, radioID);
|
||||
}
|
||||
|
||||
public void SendPlayRequest(long record_id)
|
||||
{
|
||||
parentTab.sendPlayRecordingRequest(record_id);
|
||||
}
|
||||
|
||||
|
||||
/** Register for broadcasts */
|
||||
private void registerBroadcastIntents() {
|
||||
IntentFilter intentFilter = new IntentFilter(OperationCodes.RECORDINGS_LIST_REP+"");
|
||||
this.registerReceiver(mReceiver, intentFilter);
|
||||
|
||||
intentFilter = new IntentFilter(OperationCodes.RADIOID_CHANGED+"");
|
||||
this.registerReceiver(mReceiver, intentFilter);
|
||||
|
||||
}
|
||||
|
||||
//The BroadcastReceiver that listens for Notification broadcasts
|
||||
public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
//SM.Debug("### NOTIFICATION ###", "Radio: " + intent.getAction());
|
||||
|
||||
final String action = intent.getAction();
|
||||
// zone and/or channel changed
|
||||
if (action.equals(OperationCodes.RECORDINGS_LIST_REP+"")) {
|
||||
UpdateRecordings(AppParams.recordings);
|
||||
updateNumberOfRecordings();
|
||||
}
|
||||
else if (action.equals(OperationCodes.RADIOID_CHANGED+"")) {
|
||||
textViewGateway.setText(parentTab.crtRadio.IP);
|
||||
GetRecordings(parentTab.crtRadio.GW_ID, parentTab.crtRadio.ID);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,295 @@
|
||||
package com.safemobile.dispatch;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/** fix import */
|
||||
import com.safemobile.adapters.LanguageSpinnerAdapter;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class SetupActivity extends Activity {
|
||||
|
||||
/* Preferences */
|
||||
private SharedPreferences.Editor editor;
|
||||
//private String IP, PORT, AUDIOPORT, COMPORT, LANGUAGE;
|
||||
|
||||
/* Visual Elements */
|
||||
private EditText appServerIP, appServerPort;
|
||||
private LinearLayout layoutPath;
|
||||
private Button btn_save;
|
||||
|
||||
/* Misc */
|
||||
private Context context;
|
||||
private TabLayoutActivity parentTab;
|
||||
|
||||
/* Language */
|
||||
private String[] Languages = {"English", "German", "Turkish", "Romanian", "Russian", "Spanish"};
|
||||
private ImageView imageLanguage;
|
||||
private LinearLayout layoutSpinnerLanguage;
|
||||
private TextView textViewSpinnerLanguage;
|
||||
|
||||
private Bundle savedInstanceState;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
context = this;
|
||||
|
||||
// get parentTab
|
||||
parentTab = (TabLayoutActivity)getParent();
|
||||
|
||||
// get settings
|
||||
loadSettings();
|
||||
|
||||
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
getBaseContext().getResources().updateConfiguration(config,
|
||||
getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
Languages = new String[] {getString(R.string.en), getString(R.string.de), getString(R.string.tr), getString(R.string.ro), getString(R.string.ru), getString(R.string.es)};
|
||||
// set contextView
|
||||
setContentView(R.layout.tabsetup);
|
||||
|
||||
|
||||
layoutSpinnerLanguage = (LinearLayout) findViewById(R.id.layoutSpinnerLanguage);
|
||||
layoutSpinnerLanguage.setOnClickListener(LanguageListener);
|
||||
imageLanguage = (ImageView) findViewById(R.id.imageLanguage);
|
||||
textViewSpinnerLanguage = (TextView) findViewById(R.id.textViewSpinnerLanguage);
|
||||
|
||||
// change spinner icon and selected language according to tmpLanguage
|
||||
if (AppParams.LANGUAGETMP.equals("en")){
|
||||
imageLanguage.setImageResource(R.drawable.en);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.en));
|
||||
}
|
||||
else if (AppParams.LANGUAGETMP.equals("de")){
|
||||
imageLanguage.setImageResource(R.drawable.de);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.de));
|
||||
}
|
||||
else if (AppParams.LANGUAGETMP.equals("tr")){
|
||||
imageLanguage.setImageResource(R.drawable.tr);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.tr));
|
||||
}
|
||||
else if (AppParams.LANGUAGETMP.equals("ro")){
|
||||
imageLanguage.setImageResource(R.drawable.ro);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.ro));
|
||||
}
|
||||
else if(AppParams.LANGUAGETMP.equals("es")){
|
||||
imageLanguage.setImageResource(R.drawable.es);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.es));
|
||||
}
|
||||
else if(AppParams.LANGUAGETMP.equals("ru")){
|
||||
imageLanguage.setImageResource(R.drawable.ru);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.ru));
|
||||
}
|
||||
|
||||
// get visual elements
|
||||
appServerIP = (EditText) findViewById(R.id.appServerIP);
|
||||
appServerPort = (EditText) findViewById(R.id.appServerPort);
|
||||
|
||||
// hide path layout used only on Pad/Pod
|
||||
layoutPath = (LinearLayout) findViewById(R.id.layoutPath);
|
||||
layoutPath.setVisibility(View.GONE);
|
||||
btn_save = (Button) findViewById(R.id.btn_save);
|
||||
|
||||
btn_save.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
saveSettings();
|
||||
}
|
||||
});
|
||||
|
||||
// set values
|
||||
if(!AppParams.IP.equals("n/a"))
|
||||
appServerIP.setText(AppParams.IP);
|
||||
if(!AppParams.PORT.equals("n/a"))
|
||||
appServerPort.setText(AppParams.PORT);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.logout);
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.exit);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
// listener when select language pressed
|
||||
private OnClickListener LanguageListener = new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final LanguageSpinnerAdapter adapter = new LanguageSpinnerAdapter(context, android.R.layout.simple_spinner_item, Languages, getLayoutInflater());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(getString(R.string.selLanguage));
|
||||
builder.setAdapter(adapter , new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
textViewSpinnerLanguage.setText(adapter.getItem(which));
|
||||
switch(which)
|
||||
{
|
||||
case 0: imageLanguage.setImageResource(R.drawable.en); AppParams.LANGUAGETMP = "en"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 1: imageLanguage.setImageResource(R.drawable.de); AppParams.LANGUAGETMP = "de"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 2: imageLanguage.setImageResource(R.drawable.tr); AppParams.LANGUAGETMP = "tr"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 3: imageLanguage.setImageResource(R.drawable.ro); AppParams.LANGUAGETMP = "ro"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 4: imageLanguage.setImageResource(R.drawable.ru); AppParams.LANGUAGETMP = "ru"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 5: imageLanguage.setImageResource(R.drawable.es); AppParams.LANGUAGETMP = "es"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// load settings
|
||||
public void loadSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
// get Preferences for SafeDispatch
|
||||
AppParams.prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE);
|
||||
// get default IP
|
||||
AppParams.IP = AppParams.prefs.getString("ip", "n/a");
|
||||
// get default communication port
|
||||
AppParams.PORT = AppParams.prefs.getString("port", "n/a");
|
||||
// get default audio port
|
||||
//AUDIOPORT = prefs.getString("audioport", "n/a");
|
||||
// get default com port
|
||||
//COMPORT = prefs.getString("comport", "n/a");
|
||||
// get Language
|
||||
AppParams.LANGUAGE = AppParams.prefs.getString("language", parentTab.databaseLanguage);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.e("Exception", "loadSettings exception");
|
||||
}
|
||||
}
|
||||
|
||||
public void saveSettings()
|
||||
{
|
||||
// get editor
|
||||
editor = AppParams.prefs.edit();
|
||||
// save old IP and PORT values
|
||||
String oldIP = AppParams.IP;
|
||||
String oldPort = AppParams.PORT;
|
||||
|
||||
editor.putString("ip", appServerIP.getText().toString());
|
||||
editor.putString("port", appServerPort.getText().toString());
|
||||
editor.putString("language", AppParams.LANGUAGETMP);
|
||||
Boolean result = editor.commit();
|
||||
// saved completed
|
||||
if(result)
|
||||
Toast.makeText(context, "Settings saved successfully.", Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(context, "Settings failed to complete!", Toast.LENGTH_LONG).show();
|
||||
// if port or IP changed
|
||||
if((!appServerIP.getText().toString().equalsIgnoreCase(AppParams.IP) ||
|
||||
!appServerPort.getText().toString().equalsIgnoreCase(AppParams.PORT)) && !AppParams.DEMO)
|
||||
{
|
||||
SM.Debug("### SETTINGS ###", "IP and/or PORT had been changed");
|
||||
// load new settings
|
||||
parentTab.loadSettings();
|
||||
|
||||
|
||||
parentTab.removeITCPListener();
|
||||
|
||||
// recreateTCP
|
||||
parentTab.stopTCP();
|
||||
parentTab.recreateTCPConnection();
|
||||
|
||||
/*
|
||||
// stop old TCP
|
||||
parentTab.stopTCP();
|
||||
parentTab.stopTCPParser();
|
||||
// recreate TCP with new settings
|
||||
parentTab.loadSettings();
|
||||
parentTab.TCPinit();
|
||||
*/
|
||||
// start thread to add listener
|
||||
/*
|
||||
SM.Debug("##### initTCPRUN");
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
parentTab.myHandler.post(parentTab.initTCPRUN);
|
||||
}
|
||||
}).start();*/
|
||||
}
|
||||
// show dialog
|
||||
//showDialog(result);
|
||||
}
|
||||
|
||||
public void showDialog(Boolean result)
|
||||
{
|
||||
Dialog dialog = new Dialog(context);
|
||||
if(result)
|
||||
dialog.setTitle("Save Completed");
|
||||
else
|
||||
dialog.setTitle("Save Failed");
|
||||
dialog.setContentView(R.layout.dialog);
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
TextView text = (TextView) dialog.findViewById(R.id.text);
|
||||
ImageView image = (ImageView) dialog.findViewById(R.id.image);
|
||||
if(result)
|
||||
{
|
||||
image.setImageResource(R.drawable.error);
|
||||
text.setText("Settings saved successfully.");
|
||||
}
|
||||
else
|
||||
{
|
||||
image.setImageResource(R.drawable.error);
|
||||
text.setText("Settings failed to complete!");
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.radio.Zone;
|
||||
|
||||
public class Configuration {
|
||||
public ArrayList<Contact> contacts;
|
||||
public Radio radio;
|
||||
public ArrayList<Zone> zones;
|
||||
|
||||
public Configuration()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
48
safeDispatch/src/main/java/com/safemobile/lib/TCPclient.java
Normal file
@ -0,0 +1,48 @@
|
||||
package com.safemobile.lib;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class TCPclient implements Runnable
|
||||
{
|
||||
private String serverHostname = new String ("127.0.0.1");
|
||||
private int port = 13579;
|
||||
private Thread runner;
|
||||
private BufferedReader input =null;
|
||||
char[] buf = new char[1024];
|
||||
Boolean _shouldStop=false;
|
||||
Socket sock = null;
|
||||
|
||||
public TCPclient(BufferedReader Paraminput)
|
||||
{
|
||||
input = Paraminput;
|
||||
runner = new Thread(this, "a lu bigu");
|
||||
runner.start(); // (2) Start the thread.
|
||||
try
|
||||
{
|
||||
sock = new Socket(serverHostname, port);
|
||||
InputStream recv= sock.getInputStream();
|
||||
OutputStream writer = sock.getOutputStream();
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
Log.d("tcp rec error","break:"+e.toString());
|
||||
} catch (IOException e) {
|
||||
Log.d("tcp rec error","break:"+e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void RequestStop()
|
||||
{
|
||||
_shouldStop = true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,201 @@
|
||||
package com.safemobile.lib.sound;
|
||||
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.AudioTrack;
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
public class AudioHandle implements Runnable{
|
||||
|
||||
private final int SAMPLE_RATE = 8000;
|
||||
|
||||
public Boolean isAlive = false;
|
||||
public Boolean soundNeeded = false;
|
||||
private AudioRecord recDev =null;
|
||||
private AudioTrack playDev =null;
|
||||
private int bufferSize;
|
||||
private DataOutputStream outData =null;
|
||||
private Thread t_micListner;
|
||||
private UDPclient udp;
|
||||
private TCPaudioClient tcp;
|
||||
private int audioport = 50001;
|
||||
|
||||
public int typeUDP;
|
||||
public AudioHandle(String IP, int _typeUDP)
|
||||
{
|
||||
typeUDP = _typeUDP;
|
||||
SM.Debug("---AudioHandle construcort---" +_typeUDP);
|
||||
if(typeUDP==1)
|
||||
{
|
||||
try
|
||||
{
|
||||
udp = new UDPclient(IP);
|
||||
bufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
|
||||
int bufsize = AudioTrack.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
|
||||
//init play device
|
||||
//playDev = new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate,AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT,bufsize, AudioTrack.MODE_STREAM);
|
||||
playDev = new AudioTrack(AudioManager.STREAM_MUSIC, SAMPLE_RATE,
|
||||
AudioFormat.CHANNEL_OUT_MONO,
|
||||
AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STREAM);
|
||||
|
||||
//init mic listener
|
||||
recDev = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize * 2);
|
||||
//recDev = findAudioRecord();
|
||||
recDev.startRecording();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("audioH = 1", ex.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
tcp = new TCPaudioClient(IP,audioport);
|
||||
bufferSize = AudioTrack.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
|
||||
|
||||
|
||||
//init play device
|
||||
playDev = new AudioTrack(AudioManager.STREAM_MUSIC,SAMPLE_RATE,AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT,bufferSize, AudioTrack.MODE_STREAM);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
SM.Exception("audioH = 0 record", ex.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
//init mic listener
|
||||
int bufsize = AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
|
||||
recDev = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufsize);
|
||||
//recDev = findAudioRecord();
|
||||
if(recDev.getState() == AudioRecord.STATE_INITIALIZED)
|
||||
recDev.startRecording();
|
||||
/*
|
||||
else
|
||||
Toast.makeText(context, "Could not start Recording device (you will not be able to send voice)", Toast.LENGTH_SHORT).show();*/
|
||||
}
|
||||
catch(Exception ex) {
|
||||
SM.Exception("audioH = 0", ex.toString());
|
||||
//Toast.makeText(context, "Could not start Recording device (you will not be able to send voice)", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
isAlive = true;
|
||||
t_micListner = new Thread(this, "micListener");
|
||||
t_micListner.start();
|
||||
|
||||
|
||||
if(typeUDP==1)
|
||||
{
|
||||
udp.addUDPListener(new IUDPListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void dataRecv(UDPevent event) {
|
||||
byte[] data = event.data();
|
||||
int len = event.len();
|
||||
SM.Debug("recv b:"+len+" data.length:"+data.length);
|
||||
if(data!=null)
|
||||
PlaySound(data, len);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
tcp.addTCPListener(new ITCPaudioLis()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void dataRecv(TCPaudioEvent event) {
|
||||
byte[] data = event.data();
|
||||
int len = event.len();
|
||||
|
||||
if(data!=null)
|
||||
PlaySound(data, len);
|
||||
else
|
||||
SM.Debug("data ==null");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
//playDev.p
|
||||
SM.Debug("=====AudioHandle construcort ===END====");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
byte[] tempBuffer;
|
||||
|
||||
int bRead=0;
|
||||
while(isAlive)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (soundNeeded)
|
||||
{
|
||||
//SM.Debug("sending b:"+bRead);
|
||||
if(typeUDP==1)
|
||||
{
|
||||
tempBuffer = new byte[512];//128];//invers3.bufferSize];
|
||||
bRead = recDev.read(tempBuffer, 0, 512);// 128);//invers3.bufferSize);
|
||||
udp.Send(tempBuffer,bRead);
|
||||
SM.Debug("UDP sending b:"+bRead);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempBuffer = new byte[2048];//128];//invers3.bufferSize];
|
||||
bRead = recDev.read(tempBuffer, 0, 2048);// 128);//invers3.bufferSize);
|
||||
/*
|
||||
tempBuffer = new byte[16384];//128];//invers3.bufferSize];
|
||||
bRead = recDev.read(tempBuffer, 0,16384);// 128);//invers3.bufferSize);*/
|
||||
tcp.Send(tempBuffer,bRead);
|
||||
SM.Debug("TCP sending b:"+bRead);
|
||||
}
|
||||
}
|
||||
else Thread.sleep(1);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SM.Debug("break:"+e.toString());
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void PlaySound(byte[] data, int len)
|
||||
{
|
||||
if(playDev.getState() == playDev.STATE_INITIALIZED)
|
||||
{
|
||||
playDev.write(data, 0 , len);
|
||||
playDev.play();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SM.Debug("Cannot play sound playDev NOT init corectly");
|
||||
}
|
||||
}
|
||||
|
||||
public void StopSound()
|
||||
{
|
||||
if(playDev.getState() == playDev.STATE_INITIALIZED)
|
||||
{
|
||||
if(playDev.getPlayState() == playDev.PLAYSTATE_PLAYING)
|
||||
playDev.stop();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SM.Debug("Cannot STOP playDev");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.safemobile.lib.sound;
|
||||
|
||||
public interface ITCPaudioLis {
|
||||
public void dataRecv( TCPaudioEvent event ) ;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.safemobile.lib.sound;
|
||||
|
||||
public interface IUDPListener {
|
||||
public void dataRecv( UDPevent event );
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.safemobile.lib.sound;
|
||||
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.AudioTrack;
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
public class RecordingHandle {
|
||||
public Boolean isAlive = false;
|
||||
public Boolean soundNeeded = false;
|
||||
private AudioTrack playDev =null;
|
||||
private int bufferSize;
|
||||
private TCPaudioClient tcp;
|
||||
private int recport = 50002;
|
||||
|
||||
public RecordingHandle(String IP)
|
||||
{
|
||||
try {
|
||||
tcp = new TCPaudioClient(IP,recport);
|
||||
int sampleRate = 8000;
|
||||
int bufsize = AudioTrack.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
|
||||
//init play device
|
||||
playDev = new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate,AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT,bufsize, AudioTrack.MODE_STREAM);
|
||||
|
||||
tcp.addTCPListener(new ITCPaudioLis()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void dataRecv(TCPaudioEvent event) {
|
||||
byte[] data = event.data();
|
||||
int len = event.len();
|
||||
SM.Debug("recv b:"+len+" data.length:"+data.length);
|
||||
if(data!=null)
|
||||
PlaySound(data, len);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception ex) {
|
||||
SM.Exception("recordings", ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void PlaySound(byte[] data, int len)
|
||||
{
|
||||
if(soundNeeded)
|
||||
{
|
||||
if(playDev.getState() == playDev.STATE_INITIALIZED)
|
||||
{
|
||||
playDev.write(data, 0 , data.length);
|
||||
playDev.play();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SM.Debug("Cannot play sound playDev NOT init corectly");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StartSound()
|
||||
{
|
||||
|
||||
soundNeeded = true;
|
||||
}
|
||||
|
||||
public void StopSound()
|
||||
{
|
||||
if(playDev.getState() == playDev.STATE_INITIALIZED)
|
||||
{
|
||||
if(playDev.getPlayState() == playDev.PLAYSTATE_PLAYING)
|
||||
playDev.stop();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SM.Debug("Cannot STOP playDev");
|
||||
}
|
||||
soundNeeded= false;
|
||||
}
|
||||
}
|
@ -0,0 +1,200 @@
|
||||
package com.safemobile.lib.sound;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.TCPmsg;
|
||||
|
||||
public class TCPaudioClient implements Runnable{
|
||||
private boolean alive = true;
|
||||
|
||||
public String serverHostname = new String ("10.120.1.114");//
|
||||
private int port = 50001;
|
||||
private Thread listenThread;
|
||||
private Socket soc =null;
|
||||
|
||||
private InputStream recv;
|
||||
private OutputStream writer;
|
||||
|
||||
private volatile int n=0;
|
||||
|
||||
public Boolean connOK=false;
|
||||
byte[] buffer = new byte[16384];
|
||||
private List<ITCPaudioLis> _listeners = new ArrayList<ITCPaudioLis>();
|
||||
|
||||
public TCPaudioClient(String hostName, int _port)
|
||||
{
|
||||
serverHostname=hostName;
|
||||
this.port = _port;
|
||||
SM.Debug("---TCPhandler construcort--- port:"+_port);
|
||||
listenThread = new Thread(this, "TCPlisten");
|
||||
listenThread.start(); // (2) Start the thread.
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
soc = new Socket(serverHostname, port);
|
||||
SM.Debug("Socket timeout:" + soc.getSoTimeout() );
|
||||
//soc.setSoTimeout(5000);
|
||||
recv= soc.getInputStream();
|
||||
writer =soc.getOutputStream() ;
|
||||
if(soc !=null)
|
||||
connOK = true;
|
||||
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
SM.Debug("UnknownHostException", "break:"+e.toString());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
SM.Debug("IOException", "break:"+e.toString());
|
||||
}
|
||||
|
||||
while(alive)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
SM.Debug(e.toString());
|
||||
}
|
||||
while(connOK)
|
||||
{
|
||||
try
|
||||
{
|
||||
buffer = new byte[16384];
|
||||
n = recv.read(buffer);
|
||||
if(n==-1)
|
||||
break;
|
||||
_fireDataArrived(buffer,n);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Debug("break:"+ex.toString());
|
||||
connOK = false;
|
||||
}
|
||||
}//while(connOK)
|
||||
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
SM.Debug(e.toString());
|
||||
}
|
||||
if(alive)RestartTCP();
|
||||
}//while(alive)
|
||||
SM.Debug("==================================");
|
||||
SM.Debug("TCP listenThread stoped!! alive = false");
|
||||
SM.Debug("==================================");
|
||||
}
|
||||
|
||||
public boolean Send(byte[] data,int len)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if(writer != null)
|
||||
{
|
||||
writer.write(data,0,len);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
SM.Debug(e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void RestartTCP()
|
||||
{
|
||||
try
|
||||
{
|
||||
SM.Debug("Restarting TCP...ip:"+serverHostname);
|
||||
soc = new Socket(serverHostname, port);
|
||||
recv= soc.getInputStream();
|
||||
writer =soc.getOutputStream();
|
||||
if(soc !=null)
|
||||
connOK = true;
|
||||
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
SM.Debug("break:"+e.toString());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
SM.Debug("break:"+e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return alive;
|
||||
}
|
||||
|
||||
public void setAlive(boolean alive) {
|
||||
this.alive = alive;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
|
||||
this.alive = false;
|
||||
if(soc !=null)
|
||||
{
|
||||
try {
|
||||
soc.close();
|
||||
soc = null;
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
SM.Debug("break:"+e.toString());
|
||||
}
|
||||
connOK = false;
|
||||
}
|
||||
// stop thread
|
||||
if(listenThread != null)
|
||||
{
|
||||
Thread moribund = listenThread;
|
||||
listenThread = null;
|
||||
moribund.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addTCPListener( ITCPaudioLis l ) {
|
||||
_listeners.add( (ITCPaudioLis) l );
|
||||
}
|
||||
|
||||
public synchronized void removeTCPListener( ITCPaudioLis l ) {
|
||||
_listeners.remove( l );
|
||||
}
|
||||
|
||||
private synchronized void _fireDataArrived(byte[] data, int len) {
|
||||
TCPaudioEvent event = new TCPaudioEvent( this, data, len );
|
||||
Iterator<ITCPaudioLis> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (ITCPaudioLis) listeners.next() ).dataRecv(event);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.safemobile.lib.sound;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
public class TCPaudioEvent extends EventObject{
|
||||
private byte[] data;
|
||||
private int len;
|
||||
public TCPaudioEvent(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,109 @@
|
||||
package com.safemobile.lib.sound;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class UDPclient implements Runnable{
|
||||
|
||||
public String serverHostname = new String ("10.120.1.114");//
|
||||
private int UDP_SERVER_PORT_IN = 50002;
|
||||
private int UDP_SERVER_PORT_OUT = 50001;
|
||||
private DatagramSocket ds = null;
|
||||
private Thread listenThread;
|
||||
|
||||
private InetAddress serverAddr=null;
|
||||
private DatagramPacket dp_send = null;
|
||||
private DatagramPacket dp_recv = null;
|
||||
byte[] buffer = new byte[4096];
|
||||
|
||||
public Boolean isAlive = false;
|
||||
private List<IUDPListener> _listeners = new ArrayList<IUDPListener>();
|
||||
|
||||
public UDPclient(String ip)
|
||||
{
|
||||
SM.Debug("---UDPclient construcort---IP:"+ip);
|
||||
serverHostname = ip;
|
||||
try {
|
||||
serverAddr = InetAddress.getByName(serverHostname);
|
||||
ds = new DatagramSocket(UDP_SERVER_PORT_IN);
|
||||
dp_recv = new DatagramPacket(buffer, buffer.length);
|
||||
isAlive = true;
|
||||
} catch (UnknownHostException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (SocketException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
listenThread = new Thread(this, "UDPclient");
|
||||
listenThread.start(); // (2) Start the thread.
|
||||
Send(new byte[]{1}, 1);
|
||||
SM.Debug("=====UDPclient construcort ===END====");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(isAlive)
|
||||
{
|
||||
try
|
||||
{
|
||||
ds.receive(dp_recv);
|
||||
//String msg = new String(buffer, 0, dp_recv.getLength());
|
||||
//SM.Debug("UDPclient recv b:"+dp_recv.getLength());
|
||||
_fireDataArrived(buffer,dp_recv.getLength());
|
||||
}
|
||||
catch (IOException e) {
|
||||
SM.Debug("break:"+e.toString());
|
||||
}
|
||||
/*
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
SM.Debug("break:"+e.toString());
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean Send(byte[] data,int len)
|
||||
{
|
||||
Boolean ret = true;
|
||||
|
||||
try
|
||||
{
|
||||
dp_send = new DatagramPacket(data, len, serverAddr, UDP_SERVER_PORT_OUT);
|
||||
ds.send(dp_send);
|
||||
}
|
||||
catch (IOException e) {
|
||||
SM.Debug("break:"+e.toString());
|
||||
ret = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public synchronized void addUDPListener( IUDPListener l ) {
|
||||
_listeners.add( l );
|
||||
}
|
||||
|
||||
public synchronized void removeUDPListener( IUDPListener l ) {
|
||||
_listeners.remove( l );
|
||||
}
|
||||
|
||||
private synchronized void _fireDataArrived(byte[] data, int len) {
|
||||
UDPevent event = new UDPevent( this, data, len );
|
||||
Iterator<IUDPListener> listeners = _listeners.iterator();
|
||||
while( listeners.hasNext() ) {
|
||||
( (IUDPListener) listeners.next() ).dataRecv(event);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.safemobile.lib.sound;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
public class UDPevent extends EventObject {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
9
safeDispatch/src/main/res/anim/alpha.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:fromAlpha="0.0"
|
||||
android:startOffset="2000"
|
||||
android:toAlpha="1.0"
|
||||
android:duration="5000" />
|
||||
</set>
|
9
safeDispatch/src/main/res/anim/realpha.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:fromAlpha="1.0"
|
||||
android:startOffset="2000"
|
||||
android:toAlpha="0.0"
|
||||
android:duration="5000" />
|
||||
</set>
|
BIN
safeDispatch/src/main/res/drawable-hdpi/addbutton.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/addbutton_over.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/alert_message.9.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/arrow_down.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/arrow_left.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/arrow_right.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/arrow_up.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/back.png
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/back_over.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/backgroundgreen.jpg
Normal file
After Width: | Height: | Size: 64 KiB |
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_pressed="true"
|
||||
android:drawable="@drawable/balloon_overlay_close_over" />
|
||||
<item
|
||||
android:state_pressed="false"
|
||||
android:drawable="@drawable/balloon_overlay_close" />
|
||||
</selector>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_pressed="true"
|
||||
android:drawable="@drawable/balloon_overlay_focused" />
|
||||
<item
|
||||
android:state_pressed="false"
|
||||
android:drawable="@drawable/balloon_overlay_unfocused" />
|
||||
</selector>
|
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 4.2 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/barcode.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/barcode_over.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/bg_sd.png
Normal file
After Width: | Height: | Size: 134 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/bg_sd2.jpg
Normal file
After Width: | Height: | Size: 134 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/bg_sn.jpg
Normal file
After Width: | Height: | Size: 129 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/bg_snn.png
Normal file
After Width: | Height: | Size: 148 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/bluebullet.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/calendar_48.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/calendar_48_red.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/change_ip.png
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/check_all.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/checked.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/datepicker.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/disable.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/enable.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/exclamation.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/ic_tab_live_selected.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/ic_tab_logo_selected.png
Normal file
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 9.8 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 6.5 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 1.9 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/ic_tab_text_selected.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_demo.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_original.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopad.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopad2.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopad_blue.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopad_red.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopad_trim.png
Normal file
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 30 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopod.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopod_blue.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopod_red.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopod_trim.png
Normal file
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 6.3 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/icon_radiopoddd.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/img01.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
safeDispatch/src/main/res/drawable-hdpi/img02.png
Normal file
After Width: | Height: | Size: 50 KiB |