|
@@ -13,6 +13,7 @@ import android.net.http.SslError;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
import android.os.Handler;
|
|
|
|
|
+import android.support.v4.app.ActivityCompat;
|
|
|
import android.support.v4.content.PermissionChecker;
|
|
import android.support.v4.content.PermissionChecker;
|
|
|
import android.support.v7.app.ActionBar;
|
|
import android.support.v7.app.ActionBar;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
import android.support.v7.app.AlertDialog;
|
|
@@ -24,7 +25,6 @@ import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.webkit.SslErrorHandler;
|
|
import android.webkit.SslErrorHandler;
|
|
|
import android.webkit.ValueCallback;
|
|
import android.webkit.ValueCallback;
|
|
|
-import android.webkit.WebResourceError;
|
|
|
|
|
import android.webkit.WebResourceRequest;
|
|
import android.webkit.WebResourceRequest;
|
|
|
import android.webkit.WebResourceResponse;
|
|
import android.webkit.WebResourceResponse;
|
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebView;
|
|
@@ -35,19 +35,20 @@ import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.usai.apex.apexcrm.application.ApexCRMApp;
|
|
import com.usai.apex.apexcrm.application.ApexCRMApp;
|
|
|
import com.usai.apex.apexcrm.dataProvider.DataProvider;
|
|
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.actionsheet.ActionSheet;
|
|
|
import com.usai.redant.rautils.calendar_event.CalendarEventManager;
|
|
import com.usai.redant.rautils.calendar_event.CalendarEventManager;
|
|
|
import com.usai.redant.rautils.camera.CameraHelper;
|
|
import com.usai.redant.rautils.camera.CameraHelper;
|
|
|
import com.usai.redant.rautils.contacts.ContactsManager;
|
|
import com.usai.redant.rautils.contacts.ContactsManager;
|
|
|
import com.usai.redant.rautils.datetimepicker.DateTimePickerDialog;
|
|
import com.usai.redant.rautils.datetimepicker.DateTimePickerDialog;
|
|
|
import com.usai.redant.rautils.email.EmailHelper;
|
|
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.map.MapHelper;
|
|
|
import com.usai.redant.rautils.preview.RAPDFPreviewActivity;
|
|
import com.usai.redant.rautils.preview.RAPDFPreviewActivity;
|
|
|
import com.usai.redant.rautils.signature.SignatureActivity;
|
|
import com.usai.redant.rautils.signature.SignatureActivity;
|
|
|
import com.usai.redant.rautils.utils.FileManager;
|
|
import com.usai.redant.rautils.utils.FileManager;
|
|
|
import com.usai.redant.rautils.utils.ImageUtil;
|
|
import com.usai.redant.rautils.utils.ImageUtil;
|
|
|
import com.usai.redant.rautils.utils.RAUtil;
|
|
import com.usai.redant.rautils.utils.RAUtil;
|
|
|
|
|
+import com.usai.redant.rautils.utils.dbgUtil;
|
|
|
import com.usai.redant.rautils.zxing.codescanner.CaptureActivity;
|
|
import com.usai.redant.rautils.zxing.codescanner.CaptureActivity;
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
@@ -101,6 +102,9 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
setContentView(R.layout.activity_main);
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
|
|
Log.d(TAG, "onCreate: ");
|
|
Log.d(TAG, "onCreate: ");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
if (actionBar != null) {
|
|
if (actionBar != null) {
|
|
|
actionBar.hide();
|
|
actionBar.hide();
|
|
@@ -143,17 +147,40 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
mCurrentActionString = savedInstanceState.getString(CurrentActionStringKey);
|
|
mCurrentActionString = savedInstanceState.getString(CurrentActionStringKey);
|
|
|
|
|
|
|
|
mWebView.restoreState(savedInstanceState);
|
|
mWebView.restoreState(savedInstanceState);
|
|
|
|
|
+ loading = true;
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
mExcuteJSArray = new JSONArray();
|
|
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();
|
|
|
|
|
+
|
|
|
|
|
+// 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) {
|
|
if (intent != null) {
|
|
|
String tmpUrl = intent.getStringExtra("url");
|
|
String tmpUrl = intent.getStringExtra("url");
|
|
|
if (tmpUrl != null) {
|
|
if (tmpUrl != null) {
|
|
@@ -165,9 +192,86 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
mWebView.loadUrl(url);
|
|
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() {
|
|
private void enableActionBarBackItem() {
|
|
|
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
ActionBar actionBar = getSupportActionBar();
|
|
@@ -383,7 +487,7 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
onSelectContactResult(resultCode, data);
|
|
onSelectContactResult(resultCode, data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- mCurrentActionString = null;
|
|
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
|
// webView还未加载完,此时需要延后执行
|
|
// webView还未加载完,此时需要延后执行
|
|
@@ -456,6 +560,8 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
// saveExcuteJS(js);
|
|
// saveExcuteJS(js);
|
|
|
|
|
|
|
|
evaluateJavaScript(js);
|
|
evaluateJavaScript(js);
|
|
|
|
|
+
|
|
|
|
|
+ mCurrentActionString = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
@@ -478,6 +584,8 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ dbgUtil.fileLog(MainActivity.this,"evaluateJavaScript: "+js);
|
|
|
mWebView.evaluateJavascript(js, new ValueCallback<String>() {
|
|
mWebView.evaluateJavascript(js, new ValueCallback<String>() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onReceiveValue(String value) {
|
|
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);
|
|
// setWebImageWithBase64(imgBase64);
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 加载本地文件需要将文件路径转换以下,然后在WebView中拦截响应替换
|
|
|
|
|
- * 如果直接写file://xxxx 那么webview不会加载
|
|
|
|
|
- * 建议写为http://local/file://
|
|
|
|
|
- * */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 加载本地文件需要将文件路径转换以下,然后在WebView中拦截响应替换
|
|
|
|
|
+ * 如果直接写file://xxxx 那么webview不会加载
|
|
|
|
|
+ * 建议写为http://local/file://
|
|
|
|
|
+ * */
|
|
|
// evaluateCurrentAction(String.format("%s%s",RALocalFileScheme,path));
|
|
// 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) {
|
|
private void setWebImageForUri(Uri uri) {
|
|
@@ -578,14 +706,20 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
|
|
|
|
|
private void onCameraResult(int resultCode, Intent data) {
|
|
private void onCameraResult(int resultCode, Intent data) {
|
|
|
|
|
|
|
|
|
|
+ dbgUtil.fileLog(this,"onCameraResult");
|
|
|
|
|
+ dbgUtil.fileLog(this,"resultCode"+resultCode);
|
|
|
if (resultCode == RESULT_OK) {
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
|
|
|
|
if (mCameraFile != null && mCameraFile.exists()) {
|
|
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());
|
|
self.setWebImageForPath(mCameraFile.getAbsolutePath());
|
|
|
- }
|
|
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -859,6 +993,7 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
if (msg != null) {
|
|
if (msg != null) {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
+ Log.d(TAG, "PostDialog: "+msg);
|
|
|
|
|
|
|
|
final JSONObject json = new JSONObject(msg);
|
|
final JSONObject json = new JSONObject(msg);
|
|
|
String title = json.getString("title");
|
|
String title = json.getString("title");
|
|
@@ -1164,8 +1299,28 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
ContactsManager.startContactPickerActivity(self, REQUEST_SELECT_CONTACT_CODE);
|
|
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
|
|
@Override
|
|
|
- public void RequestAppVersion(String msg) {
|
|
|
|
|
|
|
+ public void RequestAppInfo(String msg) {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
PackageManager pm = mCtx.getPackageManager();
|
|
PackageManager pm = mCtx.getPackageManager();
|
|
@@ -1174,8 +1329,12 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
int ver_code = pi.versionCode;
|
|
int ver_code = pi.versionCode;
|
|
|
String appVer = "Ver:" + ver_name + " build " + ver_code;
|
|
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);
|
|
JSONObject json = new JSONObject(msg);
|
|
|
- String js = mJSInterface.returnToWebPage(json, appVer);
|
|
|
|
|
|
|
+ String js = mJSInterface.returnToWebPage(json, strinfo);
|
|
|
evaluateJavaScript(js);
|
|
evaluateJavaScript(js);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -1254,7 +1413,7 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
@Override
|
|
@Override
|
|
|
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
|
|
|
|
|
- Log.d(TAG, "onPageStarted: 0");
|
|
|
|
|
|
|
+ Log.d(TAG, "onPageStarted: 0 "+url);
|
|
|
|
|
|
|
|
mURL = url;
|
|
mURL = url;
|
|
|
synchronized (self) {
|
|
synchronized (self) {
|
|
@@ -1271,7 +1430,7 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
@Override
|
|
@Override
|
|
|
public void onPageFinished(WebView view, String url) {
|
|
public void onPageFinished(WebView view, String url) {
|
|
|
|
|
|
|
|
- Log.d(TAG, "onPageFinished: 0");
|
|
|
|
|
|
|
+ Log.d(TAG, "onPageFinished: 0 "+url);
|
|
|
|
|
|
|
|
synchronized (self) {
|
|
synchronized (self) {
|
|
|
loading = false;
|
|
loading = false;
|
|
@@ -1281,8 +1440,8 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
mProgressbar.setVisibility(View.GONE);
|
|
mProgressbar.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
if (!error) {
|
|
if (!error) {
|
|
|
- handleNotificationByJS(notificationId);
|
|
|
|
|
- notificationId = -1;
|
|
|
|
|
|
|
+ handleNotificationByJS(Notificationstr);
|
|
|
|
|
+ Notificationstr = null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1327,28 +1486,28 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
|
|
|
|
|
// region Notification
|
|
// 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;
|
|
return;
|
|
|
}
|
|
}
|
|
|
String user = ApexCRMApp.sharedCRM().getUser();
|
|
String user = ApexCRMApp.sharedCRM().getUser();
|
|
@@ -1357,7 +1516,8 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
user = RAUtil.ra_stringByEscapingForJavascriptWithDelimiter(user,'\'',true);
|
|
user = RAUtil.ra_stringByEscapingForJavascriptWithDelimiter(user,'\'',true);
|
|
|
password = RAUtil.ra_stringByEscapingForJavascriptWithDelimiter(password,'\'',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>() {
|
|
mWebView.evaluateJavascript(js, new ValueCallback<String>() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onReceiveValue(String value) {
|
|
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) {
|
|
if (activity != null) {
|
|
|
|
|
|
|
|
Intent intent = new Intent(activity, MainActivity.class);
|
|
Intent intent = new Intent(activity, MainActivity.class);
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
|
- intent.putExtra(NotificationIdKey, id);
|
|
|
|
|
|
|
+ intent.putExtra(Notificationkey, notificationstr);
|
|
|
activity.startActivity(intent);
|
|
activity.startActivity(intent);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1381,29 +1541,70 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
|
|
|
protected void onNewIntent(Intent intent) {
|
|
protected void onNewIntent(Intent intent) {
|
|
|
super.onNewIntent(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);
|
|
setIntent(intent);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private int notificationId = -1;
|
|
|
|
|
|
|
+// private int notificationId = -1;
|
|
|
|
|
|
|
|
|
|
+ String Notificationstr=null;
|
|
|
@Override
|
|
@Override
|
|
|
protected void onStart() {
|
|
protected void onStart() {
|
|
|
super.onStart();
|
|
super.onStart();
|
|
|
|
|
|
|
|
Intent intent = getIntent();
|
|
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正在加载,那么在加载完成回调中处理通知
|
|
// 如果webView正在加载,那么在加载完成回调中处理通知
|
|
|
// 否则立即处理通知
|
|
// 否则立即处理通知
|
|
|
if (!loading) {
|
|
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
|
|
// endregion
|
|
|
}
|
|
}
|