|
|
@@ -1,22 +1,29 @@
|
|
|
package com.usai.apex.apexcrm;
|
|
|
|
|
|
import android.Manifest;
|
|
|
+import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.content.PermissionChecker;
|
|
|
+import android.support.v7.app.ActionBar;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
|
|
import android.util.Log;
|
|
|
+import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
import android.webkit.ValueCallback;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
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.camera.CameraHelper;
|
|
|
import com.usai.redant.rautils.email.EmailHelper;
|
|
|
+import com.usai.redant.rautils.fileViewer.FileViewerActivity;
|
|
|
import com.usai.redant.rautils.map.MapHelper;
|
|
|
import com.usai.redant.rautils.preview.RAPDFPreviewActivity;
|
|
|
import com.usai.redant.rautils.utils.FileManager;
|
|
|
@@ -35,6 +42,7 @@ import java.util.Date;
|
|
|
|
|
|
|
|
|
import static com.usai.apex.apexcrm.RAWebView.RALocalFileScheme;
|
|
|
+import static com.usai.redant.rautils.InfinitePhoto.InfinitePhotoItem.PlaceHolderResIdNone;
|
|
|
import static com.usai.redant.rautils.utils.Network.RESULT_TRUE;
|
|
|
|
|
|
|
|
|
@@ -57,7 +65,6 @@ public class MainActivity extends AppCompatActivity {
|
|
|
private JSONArray mExcuteJSArray;
|
|
|
private RAJSInterface mJSInterface;
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
@@ -77,11 +84,31 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
} else {
|
|
|
mExcuteJSArray = new JSONArray();
|
|
|
- mWebView.loadUrl("http://192.168.0.138:8080/backend_test/index.html");
|
|
|
+
|
|
|
+ String url = "http://192.168.0.138:8080/backend_test/index.html";
|
|
|
+ Intent intent = getIntent();
|
|
|
+ if (intent != null) {
|
|
|
+ String tmpUrl = intent.getStringExtra("url");
|
|
|
+ if (tmpUrl != null) {
|
|
|
+ url = tmpUrl;
|
|
|
+
|
|
|
+ enableActionBarBackItem();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mWebView.loadUrl(url);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void enableActionBarBackItem() {
|
|
|
+
|
|
|
+ ActionBar actionBar = getSupportActionBar();
|
|
|
+ if (actionBar != null) {
|
|
|
+ actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
+ actionBar.setHomeButtonEnabled(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
super.onRestoreInstanceState(savedInstanceState);
|
|
|
@@ -103,6 +130,17 @@ public class MainActivity extends AppCompatActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+
|
|
|
+ if (item.getItemId() == android.R.id.home) {
|
|
|
+ finish();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected void onRestart() {
|
|
|
super.onRestart();
|
|
|
@@ -213,12 +251,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
saveExcuteJS(js);
|
|
|
|
|
|
- mWebView.evaluateJavascript(js, new ValueCallback<String>() {
|
|
|
- @Override
|
|
|
- public void onReceiveValue(String value) {
|
|
|
- Log.d(TAG, "onReceiveValue: " + value);
|
|
|
- }
|
|
|
- });
|
|
|
+ evaluateJavaScript(js);
|
|
|
}
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
@@ -233,6 +266,28 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void evaluateJavaScript(final String js) {
|
|
|
+
|
|
|
+ if (js != null) {
|
|
|
+
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+
|
|
|
+ mWebView.evaluateJavascript(js, new ValueCallback<String>() {
|
|
|
+ @Override
|
|
|
+ public void onReceiveValue(String value) {
|
|
|
+ Log.d(TAG, "onReceiveValue: " + value);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void setWebImageWithBase64(String imageWithBase64) {
|
|
|
|
|
|
if (imageWithBase64 != null) {
|
|
|
@@ -263,6 +318,35 @@ public class MainActivity extends AppCompatActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void startActivityWithURL(String className, String url) {
|
|
|
+
|
|
|
+ if (className == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ className = String.format("%s.%s",getPackageName(),className);
|
|
|
+ Class cls = Class.forName(className);
|
|
|
+
|
|
|
+ // a.isAssignableFrom(b); a 是 b的父类,或a == b
|
|
|
+ if (Activity.class.isAssignableFrom(cls)) {
|
|
|
+ Intent intent = new Intent(self, cls);
|
|
|
+ if (url != null) {
|
|
|
+ intent.putExtra("url",url);
|
|
|
+ }
|
|
|
+ startActivity(intent);
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (ClassNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ RAUtil.alertMessage(self,getString(R.string.ra_title_warning),getString(R.string.method_not_found));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Result
|
|
|
* */
|
|
|
@@ -382,17 +466,92 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
@Override
|
|
|
public void JumpTo(String msg) {
|
|
|
+ Log.d(TAG, "JumpTo: " + msg);
|
|
|
+ if (msg != null) {
|
|
|
|
|
|
+ try {
|
|
|
+
|
|
|
+ JSONObject json = new JSONObject(msg);
|
|
|
+ String className = json.getString("android_module");
|
|
|
+ String url = json.getString("url");
|
|
|
+
|
|
|
+ startActivityWithURL(className, url);
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void ViewImage(String msg) {
|
|
|
|
|
|
+ if (msg != null) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ JSONObject json = new JSONObject(msg);
|
|
|
+ JSONArray images = json.getJSONArray("images");
|
|
|
+
|
|
|
+ int index = json.getInt("index");
|
|
|
+
|
|
|
+ JSONArray imageArr = new JSONArray();
|
|
|
+ for (int i = 0; i < images.length(); i++) {
|
|
|
+
|
|
|
+ String url = images.getString(1 - i);
|
|
|
+// String url = String.format("http://192.168.0.130:8080/MyWeb/images/%d.png",i + 1);
|
|
|
+
|
|
|
+ JSONObject imageJson = InfinitePhotoActivity.buildPhotoItem(url,false,PlaceHolderResIdNone);
|
|
|
+ imageArr.put(imageJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ InfinitePhotoActivity.startInfinitePhotoActivity(self, imageArr, index);
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void PostDialog(String msg) {
|
|
|
|
|
|
+ if (msg != null) {
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ final JSONObject json = new JSONObject(msg);
|
|
|
+ String title = json.getString("title");
|
|
|
+ String message = json.getString("message");
|
|
|
+ JSONArray buttons = json.getJSONArray("buttons");
|
|
|
+
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(self);
|
|
|
+ builder.setTitle(title);
|
|
|
+ builder.setMessage(message);
|
|
|
+ for (int i = 0; i < buttons.length(); i++) {
|
|
|
+ JSONObject buttonJson = buttons.getJSONObject(i);
|
|
|
+
|
|
|
+ String text = buttonJson.getString("text");
|
|
|
+ final String value = buttonJson.getString("value");
|
|
|
+
|
|
|
+ builder.setPositiveButton(text, new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ String js = mJSInterface.returnToWebPage(json, value);
|
|
|
+ evaluateJavaScript(js);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ builder.show();
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -518,6 +677,25 @@ public class MainActivity extends AppCompatActivity {
|
|
|
@Override
|
|
|
public void Signature(String msg) {
|
|
|
|
|
|
+ new AlertDialog.Builder(self)
|
|
|
+ .setTitle("Select Directory")
|
|
|
+ .setSingleChoiceItems(new String[]{"Files", "Cache"}, -1, new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+
|
|
|
+ String path;
|
|
|
+ if (which == 0) {
|
|
|
+ path = FileManager.internalStorageFileDir(mCtx);
|
|
|
+ } else {
|
|
|
+ path = FileManager.internalStorageTempDir(mCtx);
|
|
|
+ }
|
|
|
+
|
|
|
+ File file = new File(path);
|
|
|
+ FileViewerActivity.start(mCtx,file);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .show();
|
|
|
+
|
|
|
}
|
|
|
};
|
|
|
}
|