Explorar el Código

apex arm 1.11

Ray Zhang hace 7 años
padre
commit
e8e9e26a80
Se han modificado 34 ficheros con 776 adiciones y 285 borrados
  1. 20 4
      ApexDrivers/apexcrm/build.gradle
  2. 244 0
      ApexDrivers/apexcrm/proguard-project.txt
  3. 11 9
      ApexDrivers/apexcrm/src/main/AndroidManifest.xml
  4. BIN
      ApexDrivers/apexcrm/src/main/ic_launcher-web.png
  5. 264 63
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/MainActivity.java
  6. 20 4
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/RAJSInterface.java
  7. 76 24
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/application/ApexCRMApp.java
  8. 22 6
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/dataProvider/DataProvider.java
  9. 40 5
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/receiver/AlarmReceiver.java
  10. 5 0
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/service/CRMService.java
  11. BIN
      ApexDrivers/apexcrm/src/main/res/drawable-hdpi/ic_action_bar_o.png
  12. BIN
      ApexDrivers/apexcrm/src/main/res/drawable-mdpi/ic_action_bar_o.png
  13. BIN
      ApexDrivers/apexcrm/src/main/res/drawable-xhdpi/ic_action_bar_o.png
  14. BIN
      ApexDrivers/apexcrm/src/main/res/drawable-xxhdpi/ic_action_bar_o.png
  15. BIN
      ApexDrivers/apexcrm/src/main/res/drawable-xxxhdpi/ic_action_bar_o.png
  16. 70 166
      ApexDrivers/apexcrm/src/main/res/drawable/ic_launcher_background.xml
  17. BIN
      ApexDrivers/apexcrm/src/main/res/drawable/ic_notification_large.png
  18. 2 2
      ApexDrivers/apexcrm/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
  19. 2 2
      ApexDrivers/apexcrm/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
  20. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-hdpi/ic_launcher.png
  21. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
  22. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-hdpi/ic_launcher_round.png
  23. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-mdpi/ic_launcher.png
  24. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
  25. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-mdpi/ic_launcher_round.png
  26. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-xhdpi/ic_launcher.png
  27. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
  28. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-xhdpi/ic_launcher_round.png
  29. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-xxhdpi/ic_launcher.png
  30. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
  31. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
  32. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  33. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
  34. BIN
      ApexDrivers/apexcrm/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png

+ 20 - 4
ApexDrivers/apexcrm/build.gradle

@@ -14,18 +14,34 @@ android {
     compileSdkVersion 26
     defaultConfig {
         applicationId "com.usai.apex.apexcrm"
-        minSdkVersion 21
+        minSdkVersion 23
         targetSdkVersion 26
         versionCode 1
-        versionName "1.0.39847"
+        versionName "1.11.39847"
 
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
 
     }
     buildTypes {
         release {
-            minifyEnabled false
-            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+            minifyEnabled true
+            zipAlignEnabled true
+            shrinkResources true
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
+            debuggable false
+        }
+        debug {
+        }
+    }
+    gradle.projectsEvaluated {
+        tasks.withType(JavaCompile) {
+//            options.compilerArgs << "-Xlint:deprecation"
+//            options.compilerArgs << "--stacktrace"
+//            options.compilerArgs << "--info"
+//            options.compilerArgs << "--debug"
+//            options.compilerArgs << "--scan"
+            options.compilerArgs << "-Xlint:unchecked"
+
         }
     }
 }

+ 244 - 0
ApexDrivers/apexcrm/proguard-project.txt

@@ -0,0 +1,244 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+-dontwarn android.support.v4.**
+-dontwarn javax.naming.**
+
+
+
+
+#-keep class com.usai.redant.camera.CameraManager
+#-keep class javax.naming.*
+-keep class com.usai.apex.apexcrm.RAJSInterface {*;}
+
+
+# 保持哪些类不被混淆
+#继承activity,application,service,broadcastReceiver,contentprovider....不进行混淆
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.support.multidex.MultiDexApplication
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class * extends android.view.View
+-keep class android.support.** {*;}## 保留support下的所有类及其内部类
+
+-keep public class com.google.vending.licensing.ILicensingService
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keep class * extends com.usai.redant.apexdrivers.base.NoProguard {*;}
+-keep class javax.naming.*
+#表示不混淆上面声明的类,最后这两个类我们基本也用不上,是接入Google原生的一些服务时使用的。
+#----------------------------------------------------
+
+# 保留继承的
+-keep public class * extends android.support.v4.**
+-keep public class * extends android.support.v7.**
+-keep public class * extends android.support.annotation.**
+
+
+# Remove all Verbose/Debug logging
+
+-optimizations code/removal/simple,code/removal/advanced
+-dontobfuscate
+-assumenosideeffects class android.util.Log {
+#    public static *** d(...);
+#    public static *** v(...);
+#    public static *** i(...);
+}
+
+##
+##-------------------------------------------基本不用动区域----------------------------------------------
+##
+##
+## -----------------------------基本 -----------------------------
+##
+#
+## 指定代码的压缩级别 0 - 7(指定代码进行迭代优化的次数,在Android里面默认是5,这条指令也只有在可以优化时起作用。)
+#-optimizationpasses 5
+## 混淆时不会产生形形色色的类名(混淆时不使用大小写混合类名)
+#-dontusemixedcaseclassnames
+## 指定不去忽略非公共的库类(不跳过library中的非public的类)
+#-dontskipnonpubliclibraryclasses
+## 指定不去忽略包可见的库类的成员
+#-dontskipnonpubliclibraryclassmembers
+##不进行优化,建议使用此选项,
+#-dontoptimize
+# # 不进行预校验,Android不需要,可加快混淆速度。
+#-dontpreverify
+#
+#
+## 屏蔽警告
+#-ignorewarnings
+## 指定混淆是采用的算法,后面的参数是一个过滤器
+## 这个过滤器是谷歌推荐的算法,一般不做更改
+#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+## 保护代码中的Annotation不被混淆
+#-keepattributes *Annotation*
+## 避免混淆泛型, 这在JSON实体映射时非常重要
+#-keepattributes Signature
+## 抛出异常时保留代码行号
+#-keepattributes SourceFile,LineNumberTable
+# #优化时允许访问并修改有修饰符的类和类的成员,这可以提高优化步骤的结果。
+## 比如,当内联一个公共的getter方法时,这也可能需要外地公共访问。
+## 虽然java二进制规范不需要这个,要不然有的虚拟机处理这些代码会有问题。当有优化和使用-repackageclasses时才适用。
+##指示语:不能用这个指令处理库中的代码,因为有的类和类成员没有设计成public ,而在api中可能变成public
+#-allowaccessmodification
+##当有优化和使用-repackageclasses时才适用。
+##-repackageclasses com.test
+#
+# # 混淆时记录日志(打印混淆的详细信息)
+# # 这句话能够使我们的项目混淆后产生映射文件
+# # 包含有类名->混淆后类名的映射关系
+#-verbose
+#
+##
+## ----------------------------- 默认保留 -----------------------------
+##
+##----------------------------------------------------
+## 保持哪些类不被混淆
+##继承activity,application,service,broadcastReceiver,contentprovider....不进行混淆
+#-keep public class * extends android.app.Activity
+#-keep public class * extends android.app.Application
+#-keep public class * extends android.support.multidex.MultiDexApplication
+#-keep public class * extends android.app.Service
+#-keep public class * extends android.content.BroadcastReceiver
+#-keep public class * extends android.content.ContentProvider
+#-keep public class * extends android.app.backup.BackupAgentHelper
+#-keep public class * extends android.preference.Preference
+#-keep public class * extends android.view.View
+#-keep class android.support.** {*;}## 保留support下的所有类及其内部类
+#
+#-keep public class com.google.vending.licensing.ILicensingService
+#-keep public class com.android.vending.licensing.ILicensingService
+#
+#-keep class * extends com.usai.redant.apexdrivers.base.NoProguard {*;}
+#-keep class javax.naming.*
+##表示不混淆上面声明的类,最后这两个类我们基本也用不上,是接入Google原生的一些服务时使用的。
+##----------------------------------------------------
+#
+## 保留继承的
+#-keep public class * extends android.support.v4.**
+#-keep public class * extends android.support.v7.**
+#-keep public class * extends android.support.annotation.**
+#
+#
+##表示不混淆任何包含native方法的类的类名以及native方法名,这个和我们刚才验证的结果是一致
+#-keepclasseswithmembernames class * {
+#    native <methods>;
+#}
+#
+#
+##这个主要是在layout 中写的onclick方法android:onclick="onClick",不进行混淆
+##表示不混淆Activity中参数是View的方法,因为有这样一种用法,在XML中配置android:onClick=”buttonClick”属性,
+##当用户点击该按钮时就会调用Activity中的buttonClick(View view)方法,如果这个方法被混淆的话就找不到了
+#-keepclassmembers class * extends android.app.Activity{
+#    public void *(android.view.View);
+#}
+#
+##表示不混淆枚举中的values()和valueOf()方法,枚举我用的非常少,这个就不评论了
+#-keepclassmembers enum * {
+#    public static **[] values();
+#    public static ** valueOf(java.lang.String);
+#}
+#
+##表示不混淆任何一个View中的setXxx()和getXxx()方法,
+##因为属性动画需要有相应的setter和getter的方法实现,混淆了就无法工作了。
+#-keep public class * extends android.view.View{
+#    *** get*();
+#    void set*(***);
+#    public <init>(android.content.Context);
+#    public <init>(android.content.Context, android.util.AttributeSet);
+#    public <init>(android.content.Context, android.util.AttributeSet, int);
+#}
+#-keepclasseswithmembers class * {
+#    public <init>(android.content.Context, android.util.AttributeSet);
+#    public <init>(android.content.Context, android.util.AttributeSet, int);
+#}
+#
+##表示不混淆Parcelable实现类中的CREATOR字段,
+##毫无疑问,CREATOR字段是绝对不能改变的,包括大小写都不能变,不然整个Parcelable工作机制都会失败。
+#-keep class * implements android.os.Parcelable {
+#  public static final android.os.Parcelable$Creator *;
+#}
+## 这指定了继承Serizalizable的类的如下成员不被移除混淆
+#-keepclassmembers class * implements java.io.Serializable {
+#    static final long serialVersionUID;
+#    private static final java.io.ObjectStreamField[] serialPersistentFields;
+#    private void writeObject(java.io.ObjectOutputStream);
+#    private void readObject(java.io.ObjectInputStream);
+#    java.lang.Object writeReplace();
+#    java.lang.Object readResolve();
+#}
+## 保留R下面的资源
+#-keep class **.R$* {
+# *;
+#}
+##不混淆资源类下static的
+#-keepclassmembers class **.R$* {
+#    public static <fields>;
+#}
+#
+#
+#
+## 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆
+#-keepclassmembers class * {
+#    void *(**On*Event);
+#    void *(**On*Listener);
+#}
+#
+## 保留我们自定义控件(继承自View)不被混淆
+#-keep public class * extends android.view.View{
+#    *** get*();
+#    void set*(***);
+#    public <init>(android.content.Context);
+#    public <init>(android.content.Context, android.util.AttributeSet);
+#    public <init>(android.content.Context, android.util.AttributeSet, int);
+#}
+#
+##
+##----------------------------- WebView(项目中没有可以忽略) -----------------------------
+##
+##webView需要进行特殊处理
+#-keepclassmembers class fqcn.of.javascript.interface.for.Webview {
+#   public *;
+#}
+#-keepclassmembers class * extends android.webkit.WebViewClient {
+#    public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);
+#    public boolean *(android.webkit.WebView, java.lang.String);
+#}
+#-keepclassmembers class * extends android.webkit.WebViewClient {
+#    public void *(android.webkit.WebView, jav.lang.String);
+#}
+##在app中与HTML5的JavaScript的交互进行特殊处理
+##我们需要确保这些js要调用的原生方法不能够被混淆,于是我们需要做如下处理:
+#-keepclassmembers class com.ljd.example.JSInterface {
+#    <methods>;
+#}
+#
+##(可选)避免Log打印输出
+#-assumenosideeffects class android.util.Log {
+#   public static *** v(...);
+#   public static *** d(...);
+#   public static *** i(...);
+#   public static *** w(...);
+# }

+ 11 - 9
ApexDrivers/apexcrm/src/main/AndroidManifest.xml

@@ -41,18 +41,18 @@
 
 
         <!-- Service -->
-
+        <!--android:directBootAware="true"-->
         <service android:name=".service.CRMService"
                  android:enabled="true"
                  android:exported="true"
-                 android:directBootAware="true"
+
                  android:label="ApexCRM Background Service"
             />
 
         <!-- Receiver -->
-
+        <!--android:directBootAware="true"-->
         <receiver android:name=".receiver.AlarmReceiver"
-                  android:directBootAware="true"
+
                   android:enabled="true"
                   android:exported="true"
                   android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
@@ -61,19 +61,20 @@
                 <action android:name="REDANT.BROADCAST.ACTION_REDANT_INIT_ALARM" />
                 <action android:name="REDANT.BROADCAST.ACTION_REDANT_ALARM" />
                 <action android:name="android.intent.action.BOOT_COMPLETED"/>
-                <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"/>
+                <!--<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"/>-->
             </intent-filter>
         </receiver>
-
+        <!--android:directBootAware="true"-->
         <receiver android:name=".receiver.BootReceiver"
-                  android:directBootAware="true"
+
                   android:enabled="true"
                   android:exported="false"
                   android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
 
             <intent-filter>
                 <action android:name="android.intent.action.BOOT_COMPLETED"/>
-                <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"/>
+                <!--<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"-->
+                    />
             </intent-filter>
 
         </receiver>
@@ -82,6 +83,7 @@
 
         <activity android:name=".MainActivity"
             android:launchMode="singleTask"
+            android:screenOrientation="portrait"
             >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -90,7 +92,7 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-        <activity android:name=".Main2Activity"></activity>
+        <!--<activity android:name=".Main2Activity"></activity>-->
     </application>
 
 </manifest>

BIN
ApexDrivers/apexcrm/src/main/ic_launcher-web.png


+ 264 - 63
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/MainActivity.java

@@ -13,6 +13,7 @@ import android.net.http.SslError;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
+import android.support.v4.app.ActivityCompat;
 import android.support.v4.content.PermissionChecker;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AlertDialog;
@@ -24,7 +25,6 @@ import android.view.MenuItem;
 import android.view.View;
 import android.webkit.SslErrorHandler;
 import android.webkit.ValueCallback;
-import android.webkit.WebResourceError;
 import android.webkit.WebResourceRequest;
 import android.webkit.WebResourceResponse;
 import android.webkit.WebView;
@@ -35,19 +35,20 @@ import android.widget.Toast;
 
 import com.usai.apex.apexcrm.application.ApexCRMApp;
 import com.usai.apex.apexcrm.dataProvider.DataProvider;
-import com.usai.redant.rautils.infinitephoto.InfinitePhotoActivity;
 import com.usai.redant.rautils.actionsheet.ActionSheet;
 import com.usai.redant.rautils.calendar_event.CalendarEventManager;
 import com.usai.redant.rautils.camera.CameraHelper;
 import com.usai.redant.rautils.contacts.ContactsManager;
 import com.usai.redant.rautils.datetimepicker.DateTimePickerDialog;
 import com.usai.redant.rautils.email.EmailHelper;
+import com.usai.redant.rautils.infinitephoto.InfinitePhotoActivity;
 import com.usai.redant.rautils.map.MapHelper;
 import com.usai.redant.rautils.preview.RAPDFPreviewActivity;
 import com.usai.redant.rautils.signature.SignatureActivity;
 import com.usai.redant.rautils.utils.FileManager;
 import com.usai.redant.rautils.utils.ImageUtil;
 import com.usai.redant.rautils.utils.RAUtil;
+import com.usai.redant.rautils.utils.dbgUtil;
 import com.usai.redant.rautils.zxing.codescanner.CaptureActivity;
 
 import org.json.JSONArray;
@@ -101,6 +102,9 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
         setContentView(R.layout.activity_main);
 
         Log.d(TAG, "onCreate: ");
+
+
+
         ActionBar actionBar = getSupportActionBar();
         if (actionBar != null) {
             actionBar.hide();
@@ -143,17 +147,40 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
             mCurrentActionString = savedInstanceState.getString(CurrentActionStringKey);
 
             mWebView.restoreState(savedInstanceState);
+            loading = true;
 
         } else {
             mExcuteJSArray = new JSONArray();
 
 
 
-//            String url = "http://www.dcloud.io/hellomui/";
-//            String url = "http://192.168.1.151:8080/MyWeb/html/test.html";
-            String url = "http://192.168.1.108:8081/j/crm/mobile/login";
-//            String url = "https://ra.apexshipping.com/apexcrm/crm/mobile/login";
+//            String url = "http://192.168.1.108:8081/j/crm/mobile/login";
+            String url = DataProvider.URL_LOGIN;//"https://ra.apexshipping.com/apexcrm/crm/mobile/login";
             Intent intent = getIntent();
+
+//            Intent intent = getIntent();
+            if (intent.hasExtra("aps")) {
+
+                String notifistr = intent.getStringExtra("aps");
+                try {
+                    JSONObject notificationobj = new JSONObject(notifistr);
+                    notificationobj.put("launch_app",true);
+                    Notificationstr = notificationobj.toString();
+                    intent.removeExtra("aps");
+                } catch (JSONException e) {
+                    e.printStackTrace();
+                }
+//                Notificationstr =
+
+
+                // 如果webView正在加载,那么在加载完成回调中处理通知
+                // 否则立即处理通知
+//            if (!loading) {
+//                handleNotificationByJS(Notificationstr);
+//                this.Notificationstr = null;
+//            }
+            }
+
             if (intent != null) {
                 String tmpUrl = intent.getStringExtra("url");
                 if (tmpUrl != null) {
@@ -165,9 +192,86 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
             mWebView.loadUrl(url);
         }
 
-        checkCameraPermission();
+//        checkCameraPermission();
+
+        checkPermissions();
     }
+    private void checkPermissions() {
+
+//        String[] permissions = {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE};
+
+        String[] permissions = {
+                Manifest.permission.CAMERA,
+//                Manifest.permission.VIBRATE,
+//                Manifest.permission.READ_CONTACTS,
+//                Manifest.permission.READ_PHONE_STATE,
+                Manifest.permission.WRITE_EXTERNAL_STORAGE,
+                Manifest.permission.READ_EXTERNAL_STORAGE,
+                Manifest.permission.RECEIVE_BOOT_COMPLETED,
+//                Manifest.permission.ACCESS_NETWORK_STATE,
+//                Manifest.permission.ACCESS_WIFI_STATE,
+                Manifest.permission.INTERNET,
+//                Manifest.permission.ACCESS_FINE_LOCATION,
+//                Manifest.permission.ACCESS_COARSE_LOCATION
+//
+//                Manifest.permission.CHANGE_CONFIGURATION
+
+
 
+        };
+
+        RAUtil.checkPermissions(this,permissions);
+    }
+    @Override
+    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
+    {
+
+        if (requestCode == RAUtil.MY_PERMISSIONS_REQUEST)
+        {
+            boolean missing=false;
+            boolean request = false;
+            for(int i=0;i<grantResults.length;i++)
+            {
+
+                if(grantResults[i]!= PackageManager.PERMISSION_GRANTED)
+                    missing=true;
+                boolean bshow= ActivityCompat.shouldShowRequestPermissionRationale(this,permissions[i]);
+                if(bshow)
+                    request = true;
+            }
+
+            String msg=null;
+            if(request)
+                msg=getString(R.string.app_name) + "Apex CRM needs some essential permissions.";
+            else
+                msg=getString(R.string.app_name) + "App will quit because missing some essential permissions.\\nPlease check your system setting.";
+
+            if(missing) {
+                final boolean finalRequest = request;
+                new android.app.AlertDialog.Builder(this)
+                        .setTitle("Warning")
+                        .setMessage(msg)
+                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialog, int which) {
+//                                checkAllPermission();
+                                if (finalRequest)
+                                    checkPermissions();
+                                else
+                                    finish();
+                            }
+                        })
+                        .show();
+            }
+            else
+            {
+//                ApexCRMApp.sharedApplication().initLocation();
+            }
+
+            return;
+        }
+        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+    }
     private void enableActionBarBackItem() {
 
         ActionBar actionBar = getSupportActionBar();
@@ -383,7 +487,7 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
                 onSelectContactResult(resultCode, data);
             }
 
-            mCurrentActionString = null;
+
         } else {
 
             // webView还未加载完,此时需要延后执行
@@ -456,6 +560,8 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
 //                                saveExcuteJS(js);
 
                                 evaluateJavaScript(js);
+
+                                mCurrentActionString = null;
                             }
 
                         } catch (JSONException e) {
@@ -478,6 +584,8 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
                 @Override
                 public void run() {
 
+
+                    dbgUtil.fileLog(MainActivity.this,"evaluateJavaScript: "+js);
                     mWebView.evaluateJavascript(js, new ValueCallback<String>() {
                         @Override
                         public void onReceiveValue(String value) {
@@ -500,29 +608,49 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
         }
     }
 
-    private void setWebImageForPath(String path) {
-        if (path != null) {
-            File imgFile = ImageUtil.compressImageFile(self, new File(path));
-            if (imgFile != null) {
-                path = imgFile.getAbsolutePath();
-            }
-        }
+    private void setWebImageForPath(final String path) {
+
+
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+
+                String cPath = null;
+                if (path != null) {
+                    File imgFile = ImageUtil.compressImageFile(self, new File(path));
+                    if (imgFile != null) {
+                        cPath = imgFile.getAbsolutePath();
+
+
+                        dbgUtil.fileLog(MainActivity.this,"setWebImageForPath origin path:"+path);
+                        dbgUtil.fileLog(MainActivity.this,"setWebImageForPath path:"+imgFile.getAbsolutePath());
+                        dbgUtil.fileLog(MainActivity.this,"setWebImageForPath size:"+imgFile.length());
+                    }
+                }
+
+                if (cPath != null) {
+
+                    String imgBase64 = FileManager.base64StringFromFile(cPath);
+
+                    dbgUtil.fileLog(MainActivity.this,"setWebImageForPath imgBase64: "+imgBase64);
 
-        if (path != null) {
 
-            String imgBase64 = FileManager.base64StringFromFile(path);
 //            setWebImageWithBase64(imgBase64);
 
-            /**
-             * 加载本地文件需要将文件路径转换以下,然后在WebView中拦截响应替换
-             * 如果直接写file://xxxx 那么webview不会加载
-             * 建议写为http://local/file://
-             * */
+                    /**
+                     * 加载本地文件需要将文件路径转换以下,然后在WebView中拦截响应替换
+                     * 如果直接写file://xxxx 那么webview不会加载
+                     * 建议写为http://local/file://
+                     * */
 //            evaluateCurrentAction(String.format("%s%s",RALocalFileScheme,path));
 
-            String base64 = String.format("data:image/jpg;base64,%s",imgBase64);
-            evaluateCurrentAction(base64);
-        }
+                    String base64 = String.format("data:image/jpg;base64,%s",imgBase64);
+                    evaluateCurrentAction(base64);
+                }
+
+            }
+        }).start();
+
     }
 
     private void setWebImageForUri(Uri uri) {
@@ -578,14 +706,20 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
 
     private void onCameraResult(int resultCode, Intent data) {
 
+        dbgUtil.fileLog(this,"onCameraResult");
+        dbgUtil.fileLog(this,"resultCode"+resultCode);
         if (resultCode == RESULT_OK) {
 
             if (mCameraFile != null && mCameraFile.exists()) {
-                mCameraFile = ImageUtil.compressImageFile(self, mCameraFile);
 
-                if (mCameraFile != null) {
+//                mCameraFile = ImageUtil.compressImageFile(self, mCameraFile);
+
+//                if (mCameraFile != null) {
+                dbgUtil.fileLog(this,"mCameraFile path:"+mCameraFile.getAbsolutePath());
+                dbgUtil.fileLog(this,"mCameraFile size:"+mCameraFile.length());
+                    dbgUtil.fileLog(this,"return path to web");
                     self.setWebImageForPath(mCameraFile.getAbsolutePath());
-                }
+//                }
             }
 
         }
@@ -859,6 +993,7 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
             if (msg != null) {
 
                 try {
+                    Log.d(TAG, "PostDialog: "+msg);
 
                     final JSONObject json = new JSONObject(msg);
                     String title = json.getString("title");
@@ -1164,8 +1299,28 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
             ContactsManager.startContactPickerActivity(self, REQUEST_SELECT_CONTACT_CODE);
         }
 
+//        @Override
+//        public void RequestAppVersion(String msg) {
+//
+//            try {
+//                PackageManager pm = mCtx.getPackageManager();
+//                PackageInfo pi = pm.getPackageInfo(mCtx.getApplicationContext().getPackageName(), 0);
+//                String ver_name = pi.versionName;
+//                int ver_code = pi.versionCode;
+//                String appVer = "Ver:" + ver_name + " build " + ver_code;
+//
+//                JSONObject json = new JSONObject(msg);
+//                String js = mJSInterface.returnToWebPage(json, appVer);
+//                evaluateJavaScript(js);
+//
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//            }
+//        }
+
+
         @Override
-        public void RequestAppVersion(String msg) {
+        public void RequestAppInfo(String msg) {
 
             try {
                 PackageManager pm = mCtx.getPackageManager();
@@ -1174,8 +1329,12 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
                 int ver_code = pi.versionCode;
                 String appVer = "Ver:" + ver_name + " build " + ver_code;
 
+                JSONObject appinfo= new JSONObject();
+                appinfo.put("appVer",appVer);
+                appinfo.put("appToken",DataProvider.getToken());
+                String strinfo=appinfo.toString();
                 JSONObject json = new JSONObject(msg);
-                String js = mJSInterface.returnToWebPage(json, appVer);
+                String js = mJSInterface.returnToWebPage(json, strinfo);
                 evaluateJavaScript(js);
 
             } catch (Exception e) {
@@ -1254,7 +1413,7 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
     @Override
     public void onPageStarted(WebView view, String url, Bitmap favicon) {
 
-        Log.d(TAG, "onPageStarted: 0");
+        Log.d(TAG, "onPageStarted: 0 "+url);
 
         mURL = url;
         synchronized (self) {
@@ -1271,7 +1430,7 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
     @Override
     public void onPageFinished(WebView view, String url) {
 
-        Log.d(TAG, "onPageFinished: 0");
+        Log.d(TAG, "onPageFinished: 0 "+url);
         
        synchronized (self) {
            loading = false;
@@ -1281,8 +1440,8 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
            mProgressbar.setVisibility(View.GONE);
 
            if (!error) {
-               handleNotificationByJS(notificationId);
-               notificationId = -1;
+               handleNotificationByJS(Notificationstr);
+               Notificationstr = null;
            }
        }
 
@@ -1327,28 +1486,28 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
 
     // region Notification
 
-    public void readNotificationNow(int notificationId) {
-        if (!ApexCRMApp.sharedCRM().isLogin()) {
-
-            new AlertDialog.Builder(self)
-                    .setTitle("Warning")
-                    .setMessage("you should login first")
-                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
-                        @Override
-                        public void onClick(DialogInterface dialog, int which) {
-
-                        }
-                    })
-                    .show();
-
-            return;
-        }
+    public void readNotificationNow(String  notificationstr) {
+//        if (!ApexCRMApp.sharedCRM().isLogin()) {
+//
+//            new AlertDialog.Builder(self)
+//                    .setTitle("Warning")
+//                    .setMessage("you should login first")
+//                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+//                        @Override
+//                        public void onClick(DialogInterface dialog, int which) {
+//
+//                        }
+//                    })
+//                    .show();
+//
+//            return;
+//        }
 
-        handleNotificationByJS(notificationId);
+        handleNotificationByJS(notificationstr);
     }
 
-    private void handleNotificationByJS(int notificationId) {
-        if (notificationId == -1) {
+    private void handleNotificationByJS(String notificationstr) {
+        if (TextUtils.isEmpty(notificationstr)) {
             return;
         }
         String user = ApexCRMApp.sharedCRM().getUser();
@@ -1357,7 +1516,8 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
         user = RAUtil.ra_stringByEscapingForJavascriptWithDelimiter(user,'\'',true);
         password = RAUtil.ra_stringByEscapingForJavascriptWithDelimiter(password,'\'',true);
 
-        String js = String.format("showPageForNotification(%s, %s, %d)", user, password, notificationId);
+        String js = String.format("showPageForNotification(%s, %s, %s)", user, password, notificationstr);
+        Log.d(TAG, "handleNotificationByJS: send notification to webview"+notificationstr);
         mWebView.evaluateJavascript(js, new ValueCallback<String>() {
             @Override
             public void onReceiveValue(String value) {
@@ -1366,13 +1526,13 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
         });
     }
 
-    private final static String NotificationIdKey = "NotificationIdKey";
-    public static void startActivityForNotification(Activity activity, int id) {
+    private final static String Notificationkey = "Notificationkey";
+    public static void startActivityForNotification(Activity activity, String notificationstr) {
         if (activity != null) {
 
             Intent intent = new Intent(activity, MainActivity.class);
             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
-            intent.putExtra(NotificationIdKey, id);
+            intent.putExtra(Notificationkey, notificationstr);
             activity.startActivity(intent);
         }
     }
@@ -1381,29 +1541,70 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
     protected void onNewIntent(Intent intent) {
         super.onNewIntent(intent);
 
+
+
+        if (intent.hasExtra("aps")) {
+
+            Notificationstr = intent.getStringExtra("aps");
+            intent.removeExtra("aps");
+
+            // 如果webView正在加载,那么在加载完成回调中处理通知
+            // 否则立即处理通知
+            if (!loading) {
+                handleNotificationByJS(Notificationstr);
+                this.Notificationstr = null;
+            }
+        }
         setIntent(intent);
     }
 
-    private int notificationId = -1;
+//    private int notificationId = -1;
 
+    String Notificationstr=null;
     @Override
     protected void onStart() {
         super.onStart();
 
         Intent intent = getIntent();
-        if (intent.hasExtra(NotificationIdKey)) {
+        if (intent.hasExtra("aps")) {
 
-            notificationId = intent.getIntExtra(NotificationIdKey, -1);
-            intent.removeExtra(NotificationIdKey);
+            Notificationstr = intent.getStringExtra("aps");
+            intent.removeExtra("aps");
 
             // 如果webView正在加载,那么在加载完成回调中处理通知
             // 否则立即处理通知
             if (!loading) {
-                handleNotificationByJS(notificationId);
-                this.notificationId = -1;
+                handleNotificationByJS(Notificationstr);
+                this.Notificationstr = null;
             }
         }
     }
 
+//    @Override
+//    protected void onResume() {
+//        super.onResume();
+//
+////        if (ApexDriverApplication.sharedApplication().isLogin() && ApexDriverApplication.sharedApplication().isAuthExpired()) {
+////
+////            logout();
+////
+////            return;
+////        }
+//
+//        Intent intent = getIntent();
+//        if (intent.hasExtra("aps")) {
+//
+//            Notificationstr = intent.getStringExtra("aps");
+//            intent.removeExtra("aps");
+//
+//            // 如果webView正在加载,那么在加载完成回调中处理通知
+//            // 否则立即处理通知
+//            if (!loading) {
+//                handleNotificationByJS(Notificationstr);
+//                this.Notificationstr = null;
+//            }
+//        }
+//    }
+
     // endregion
 }

+ 20 - 4
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/RAJSInterface.java

@@ -21,7 +21,8 @@ public class RAJSInterface extends Object {
         void Signature(String msg);
         void DatetimePicker(String msg);
         void SelectContact(String msg);
-        void RequestAppVersion(String msg);
+//        void RequestAppVersion(String msg);
+        void RequestAppInfo(String msg);
         void CleanCache(String msg);
         String FileBase64(String msg);
         void Login(String user, String password);
@@ -34,6 +35,16 @@ public class RAJSInterface extends Object {
     }
 
     // region WebKit
+    @android.webkit.JavascriptInterface
+    public void UpdateBadge(String msg) {
+
+        System.out.println("android UpdateBadge ");
+//        if (delegate != null) {
+//            delegate.CamScan(msg);
+//        }
+
+    }
+
     @android.webkit.JavascriptInterface
     public void CamScan(String msg) {
 
@@ -139,13 +150,18 @@ public class RAJSInterface extends Object {
         }
     }
 
+//    @android.webkit.JavascriptInterface
+//    public void requestApplicationVersion(String msg) {
+//        if (delegate != null) {
+//            delegate.RequestAppVersion(msg);
+//        }
+//    }
     @android.webkit.JavascriptInterface
-    public void requestApplicationVersion(String msg) {
+    public void requestApplicationInfo(String msg) {
         if (delegate != null) {
-            delegate.RequestAppVersion(msg);
+            delegate.RequestAppInfo(msg);
         }
     }
-
     @android.webkit.JavascriptInterface
     public void cleanCache(String msg) {
         if (delegate != null) {

+ 76 - 24
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/application/ApexCRMApp.java

@@ -1,12 +1,10 @@
 package com.usai.apex.apexcrm.application;
 
 import android.app.Activity;
-import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Handler;
 import android.os.Looper;
-import android.support.v7.app.AlertDialog;
 import android.text.TextUtils;
 
 import com.usai.apex.apexcrm.MainActivity;
@@ -29,6 +27,7 @@ public class ApexCRMApp extends ApexApplication implements RAProviderHelper.Prov
     // region Service
     public static String CHANNEL_ID = "ApexCRM";
     public static String CHANNEL_NAME = "ApexCRM";
+    private boolean bLogin = false;
 
     // endregion
 
@@ -63,6 +62,11 @@ public class ApexCRMApp extends ApexApplication implements RAProviderHelper.Prov
     public void onCreate() {
         super.onCreate();
 
+        SharedPreferences pref = sharedPreferences(PreferenceKey);
+
+        user = decryptString(pref.getString("user", ""));
+        password = decryptString(pref.getString("password", ""));
+
         startService(CRMService.class);
         initAlarm(AlarmReceiver.class);
     }
@@ -99,6 +103,24 @@ public class ApexCRMApp extends ApexApplication implements RAProviderHelper.Prov
     }
 
     public void login(String user, String password) {
+        bLogin = true;
+
+        SharedPreferences pref = sharedPreferences(PreferenceKey);
+        SharedPreferences.Editor editor = pref.edit();
+        String key = user + "_notification_id";
+        try {
+
+
+            editor.putString("user", encryptString(user));
+            editor.putString("password",  encryptString(password));
+
+        } catch (Exception e) {
+            editor.putString(key, null);
+            e.printStackTrace();
+        }
+        editor.commit();
+
+
         setUser(user);
         setPassword(password);
 
@@ -108,10 +130,33 @@ public class ApexCRMApp extends ApexApplication implements RAProviderHelper.Prov
     public void logout() {
         setUser(null);
         setPassword(null);
+        bLogin = false;
+
+        SharedPreferences pref = sharedPreferences(PreferenceKey);
+        SharedPreferences.Editor editor = pref.edit();
+        String key = user + "_notification_id";
+        try {
+
+
+            editor.remove("user");
+            editor.remove("password");
+
+
+        } catch (Exception e) {
+            editor.putString(key, null);
+            e.printStackTrace();
+        }
+        editor.commit();
     }
 
     public boolean isLogin() {
-        return user != null && password != null;
+        return bLogin;
+//        return user != null && password != null;
+    }
+
+    public boolean noAccount()
+    {
+        return TextUtils.isEmpty(ApexCRMApp.sharedCRM().getUser())||TextUtils.isEmpty(ApexCRMApp.sharedCRM().getPassword());
     }
 
     // endregion
@@ -163,32 +208,39 @@ public class ApexCRMApp extends ApexApplication implements RAProviderHelper.Prov
 
     private void receiveNotification(JSONObject notification) {
 
+//        Log.e("debug", "receiveNotification: "+notification.toString());
         if (notification != null) {
 
-            JSONObject aps = notification.optJSONObject("aps");
-            if (aps != null) {
+//            JSONObject aps = notification.optJSONObject("aps");
+//            if (aps != null)
+            {
+
+//                final int id = notification.optInt("id");
 
-                final int id = aps.optInt("id");
+                final int id = notification.optInt("notificationId");
                 boolean isActive = !isBackground(); // 程序是否在前台
                 if (isActive) {
+                   // 直接转发给网页处理
+                    readNotificationNow(notification.toString());
 
                     // 弹窗提示
-                    AlertDialog.Builder builder = new AlertDialog.Builder(getCurrentActivity());
-                    builder.setTitle("Warning");
-                    builder.setMessage("you have a message, read it now?");
-                    builder.setNegativeButton("Cancel",null);
-                    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
-                        @Override
-                        public void onClick(DialogInterface dialog, int which) {
-                            readNotificationNow(id);
-                        }
-                    });
-                    builder.show();
+//                    AlertDialog.Builder builder = new AlertDialog.Builder(getCurrentActivity());
+//                    builder.setTitle("Warning");
+//                    builder.setMessage("you have a message, read it now?");
+//                    builder.setNegativeButton("Cancel",null);
+//                    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
+//                        @Override
+//                        public void onClick(DialogInterface dialog, int which) {
+//                            readNotificationNow(id);
+//                        }
+//                    });
+//                    builder.show();
 
                 } else {
                     // 发通知
 
-                    JSONObject alert = aps.optJSONObject("alert");
+//                    Log.e("debug", "not active send notification");
+                    JSONObject alert = notification.optJSONObject("alert");
                     String title = null,body = null;
                     if (alert != null) {
 
@@ -196,7 +248,7 @@ public class ApexCRMApp extends ApexApplication implements RAProviderHelper.Prov
                         body = alert.optString("body");
                     }
 
-                    NotificationContent notificationContent = new NotificationContent(id, title, body, R.drawable.small_icon_clear, R.drawable.large_notification_icon_clear , aps.toString());
+                    NotificationContent notificationContent = new NotificationContent(id, title, body, R.drawable.ic_action_bar_o, R.drawable.ic_notification_large , notification.toString());
 
                     showNotification(notificationContent, CHANNEL_ID, CHANNEL_NAME, MainActivity.class);
                 }
@@ -205,18 +257,18 @@ public class ApexCRMApp extends ApexApplication implements RAProviderHelper.Prov
         }
     }
 
-    private void readNotificationNow(int notificationID) {
+    private void readNotificationNow(String notificationstr) {
 
         Activity activity = getCurrentActivity();
 
         if (activity instanceof MainActivity) {
 
             MainActivity mainActivity = (MainActivity)activity;
-            mainActivity.readNotificationNow(notificationID);
+            mainActivity.readNotificationNow(notificationstr);
 
         } else {
 
-            MainActivity.startActivityForNotification(activity, notificationID);
+            MainActivity.startActivityForNotification(activity, notificationstr);
         }
     }
 
@@ -225,14 +277,14 @@ public class ApexCRMApp extends ApexApplication implements RAProviderHelper.Prov
     // region Private
 
     public String encryptString(String string) {
-        if (string == null) {
+        if (TextUtils.isEmpty(string)) {
             return null;
         }
         return AESUtil.encrypt256(SecretKey,string);
     }
 
     public String decryptString(String string) {
-        if (string == null) {
+        if (TextUtils.isEmpty(string)) {
             return null;
         }
         return AESUtil.decrypt256(SecretKey, string);

+ 22 - 6
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/dataProvider/DataProvider.java

@@ -23,8 +23,14 @@ public class DataProvider {
     public static final int PUSH_TIME_OUT_INTERVAL = 5 * 1000;
     // region URL
 
-    private static final String URL_PULL_NOTIFICATION = "http://192.168.1.151:8080/MyWeb/Test";
-    private static final String URL_UPLOAD_DEVICEID = "";
+//    private static final String URL_PULL_NOTIFICATION = "http://192.168.1.108:8081/j/crm/mobile/getAndroidNotifications.mo/";
+//    private static final String URL_UPLOAD_DEVICEID = "http://192.168.1.108:8081/j/crm/mobile/token.mo/";
+//private static final String URL_LOGIN = "http://192.168.1.108:8081/j/crm/mobile/login";
+
+    public static final String URL_PULL_NOTIFICATION = "https://ra.apexshipping.com/apexcrm/crm/mobile/getAndroidNotifications.mo/";
+    public static final String URL_UPLOAD_DEVICEID = "https://ra.apexshipping.com/apexcrm/crm/mobile/token.mo/";
+    public static final String URL_LOGIN = "https://ra.apexshipping.com/apexcrm/crm/mobile/login";
+
 
     // endregion
 
@@ -102,14 +108,14 @@ public class DataProvider {
         if (user == null) {
             user = ApexCRMApp.sharedCRM().getUser();
             if (!TextUtils.isEmpty(user)) {
-                params.putString("name",ApexCRMApp.sharedCRM().encryptString(user));
+                params.putString("name",user);
             }
         }
 
         if (password == null) {
             password = ApexCRMApp.sharedCRM().getPassword();
             if (!TextUtils.isEmpty(password)) {
-                params.putString("password",ApexCRMApp.sharedCRM().encryptString(password));
+                params.putString("password",password);
             }
         }
 
@@ -177,7 +183,11 @@ public class DataProvider {
 
     public static void pullNotification(final DataProviderCompletion completion) {
 
-        if (!ApexCRMApp.sharedCRM().isLogin()) {
+//        if(1==1)
+//        return;
+        if (ApexCRMApp.sharedCRM().noAccount())
+        {
+            //如果没有账号密码,返回
             if (completion != null) {
                 JSONObject json = new JSONObject();
                 try {
@@ -195,6 +205,7 @@ public class DataProvider {
         final long notificationId = ApexCRMApp.sharedCRM().getNotificationID();
         final String deviceId = RAUtil.getDeviceId(ApexCRMApp.sharedCRM().getApplicationContext());
 
+
         OperationQueue.sharedQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
 
             @Override
@@ -234,6 +245,7 @@ public class DataProvider {
 
                     Bundle params = new Bundle();
                     params.putString("token", deviceId);
+                    params.putString("platform","Android");
                     getJson(URL_UPLOAD_DEVICEID, params);
 
                     return null;
@@ -247,6 +259,10 @@ public class DataProvider {
             },null);
         }
     }
-
+    public static String getToken()
+    {
+        final String deviceId = RAUtil.getDeviceId(ApexCRMApp.sharedCRM().getApplicationContext());
+        return deviceId;
+    }
     // end region
 }

+ 40 - 5
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/receiver/AlarmReceiver.java

@@ -7,15 +7,14 @@ import android.content.Context;
 import android.content.Intent;
 import android.os.Build;
 import android.os.SystemClock;
-import android.util.Log;
 
 import com.usai.apex.apexcrm.application.ApexCRMApp;
 import com.usai.apex.apexcrm.dataProvider.DataProvider;
-import com.usai.redant.rautils.operationqueue.OperationQueue;
 import com.usai.redant.rautils.receiver.RABroadcast;
 import com.usai.redant.rautils.utils.dbgUtil;
 
 import org.json.JSONArray;
+import org.json.JSONException;
 import org.json.JSONObject;
 
 import static com.usai.redant.rautils.utils.Network.RESULT_TRUE;
@@ -161,15 +160,51 @@ public class AlarmReceiver extends com.usai.redant.rautils.receiver.AlarmReceive
                         JSONArray notifications = json.optJSONArray("notifications");
                         if (notifications != null) {
 
-                            for (int i = 0; i < notifications.length(); i++) {
+                            if(ApexCRMApp.sharedApplication().isBackground())
+                            {
+                                for (int i = 0; i < notifications.length(); i++) {
+                                    JSONObject notification = notifications.optJSONObject(i);
+                                    if (notification != null) {
+                                        JSONObject aps = notification.optJSONObject("aps");
+                                        if(aps!=null)
+                                        {
+                                            try {
+                                                aps.put("foreground",false);
+                                                aps.put("notificationId",notificationId);
+                                            } catch (JSONException e) {
+                                                e.printStackTrace();
+                                            }
+                                            ApexCRMApp.sharedCRM().receiveNotificationOnMainThread(aps);
+                                        }
+                                    }
+                                }
+
+                            }
+                            else
+                            {
+                                int i = notifications.length()-1;
+                                if(i<0)
+                                    return;
                                 JSONObject notification = notifications.optJSONObject(i);
                                 if (notification != null) {
-                                    ApexCRMApp.sharedCRM().receiveNotificationOnMainThread(notification);
+
+                                    JSONObject aps = notification.optJSONObject("aps");
+                                    if(aps!=null)
+                                    {
+                                        try {
+                                            aps.put("foreground",true);
+                                        } catch (JSONException e) {
+                                            e.printStackTrace();
+                                        }
+                                        ApexCRMApp.sharedCRM().receiveNotificationOnMainThread(aps);
+                                    }
+
                                 }
-                            }
 
+                            }
                         }
 
+
                     }
                 }
             }

+ 5 - 0
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/service/CRMService.java

@@ -1,5 +1,6 @@
 package com.usai.apex.apexcrm.service;
 
+import com.usai.apex.apexcrm.R;
 import com.usai.apex.apexcrm.application.ApexCRMApp;
 import com.usai.redant.rautils.service.RAService;
 
@@ -12,5 +13,9 @@ public class CRMService extends RAService {
 
         CHANNEL_ID = ApexCRMApp.CHANNEL_ID;
         CHANNEL_NAME = ApexCRMApp.CHANNEL_NAME;
+
+        LAUNCH_MSG="Apex CRM is running.";
+        FOREGROUND_ICON= R.drawable.ic_action_bar_o;;
+//        BACKGROUND_ICON=ApexDriverApplication.sharedApplication().BACKGROUND_ICON;
     }
 }

BIN
ApexDrivers/apexcrm/src/main/res/drawable-hdpi/ic_action_bar_o.png


BIN
ApexDrivers/apexcrm/src/main/res/drawable-mdpi/ic_action_bar_o.png


BIN
ApexDrivers/apexcrm/src/main/res/drawable-xhdpi/ic_action_bar_o.png


BIN
ApexDrivers/apexcrm/src/main/res/drawable-xxhdpi/ic_action_bar_o.png


BIN
ApexDrivers/apexcrm/src/main/res/drawable-xxxhdpi/ic_action_bar_o.png


+ 70 - 166
ApexDrivers/apexcrm/src/main/res/drawable/ic_launcher_background.xml

@@ -1,170 +1,74 @@
 <?xml version="1.0" encoding="utf-8"?>
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="108dp"
+<vector
     android:height="108dp"
+    android:width="108dp"
     android:viewportHeight="108"
-    android:viewportWidth="108">
-    <path
-        android:fillColor="#26A69A"
-        android:pathData="M0,0h108v108h-108z" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M9,0L9,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M19,0L19,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M29,0L29,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M39,0L39,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M49,0L49,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M59,0L59,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M69,0L69,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M79,0L79,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M89,0L89,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M99,0L99,108"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,9L108,9"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,19L108,19"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,29L108,29"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,39L108,39"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,49L108,49"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,59L108,59"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,69L108,69"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,79L108,79"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,89L108,89"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M0,99L108,99"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M19,29L89,29"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M19,39L89,39"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M19,49L89,49"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M19,59L89,59"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M19,69L89,69"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M19,79L89,79"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M29,19L29,89"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M39,19L39,89"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M49,19L49,89"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M59,19L59,89"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M69,19L69,89"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
-    <path
-        android:fillColor="#00000000"
-        android:pathData="M79,19L79,89"
-        android:strokeColor="#33FFFFFF"
-        android:strokeWidth="0.8" />
+    android:viewportWidth="108"
+    xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#008577"
+          android:pathData="M0,0h108v108h-108z"/>
+    <path android:fillColor="#00000000" android:pathData="M9,0L9,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M19,0L19,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M29,0L29,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M39,0L39,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M49,0L49,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M59,0L59,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M69,0L69,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M79,0L79,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M89,0L89,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M99,0L99,108"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,9L108,9"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,19L108,19"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,29L108,29"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,39L108,39"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,49L108,49"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,59L108,59"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,69L108,69"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,79L108,79"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,89L108,89"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M0,99L108,99"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M19,29L89,29"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M19,39L89,39"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M19,49L89,49"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M19,59L89,59"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M19,69L89,69"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M19,79L89,79"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M29,19L29,89"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M39,19L39,89"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M49,19L49,89"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M59,19L59,89"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M69,19L69,89"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
+    <path android:fillColor="#00000000" android:pathData="M79,19L79,89"
+          android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
 </vector>

BIN
ApexDrivers/apexcrm/src/main/res/drawable/ic_notification_large.png


+ 2 - 2
ApexDrivers/apexcrm/src/main/res/mipmap-anydpi-v26/ic_launcher.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
-    <background android:drawable="@drawable/ic_launcher_background" />
-    <foreground android:drawable="@drawable/ic_launcher_foreground" />
+    <background android:drawable="@drawable/ic_launcher_background"/>
+    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
 </adaptive-icon>

+ 2 - 2
ApexDrivers/apexcrm/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
-    <background android:drawable="@drawable/ic_launcher_background" />
-    <foreground android:drawable="@drawable/ic_launcher_foreground" />
+    <background android:drawable="@drawable/ic_launcher_background"/>
+    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
 </adaptive-icon>

BIN
ApexDrivers/apexcrm/src/main/res/mipmap-hdpi/ic_launcher.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-hdpi/ic_launcher_foreground.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-hdpi/ic_launcher_round.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-mdpi/ic_launcher.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-mdpi/ic_launcher_foreground.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-mdpi/ic_launcher_round.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-xhdpi/ic_launcher.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-xhdpi/ic_launcher_round.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-xxhdpi/ic_launcher.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-xxhdpi/ic_launcher_round.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-xxxhdpi/ic_launcher.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png


BIN
ApexDrivers/apexcrm/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png