|
|
@@ -3,6 +3,7 @@ package com.usai.apex.apexcrm;
|
|
|
import android.Manifest;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Looper;
|
|
|
@@ -10,18 +11,26 @@ import android.support.v4.content.PermissionChecker;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
|
|
import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
import android.webkit.ValueCallback;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
+import com.usai.redant.rautils.actionSheet.ActionSheet;
|
|
|
+import com.usai.redant.rautils.camera.CameraHelper;
|
|
|
+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.zxing.codescanner.CaptureActivity;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
+import java.io.File;
|
|
|
+import java.net.URI;
|
|
|
+import java.net.URL;
|
|
|
+
|
|
|
|
|
|
-//import android.webkit.WebView;
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
private static final String TAG = "MainActivity";
|
|
|
@@ -31,6 +40,9 @@ public class MainActivity extends AppCompatActivity {
|
|
|
private RAWebView mWebView;
|
|
|
|
|
|
private static final int REQUEST_SCANNER_CODE = 100;
|
|
|
+ private static final int REQUEST_CAMERA_CODE = 101;
|
|
|
+ private static final int REQUEST_PHOTO_LIBRARY_CODE = 102;
|
|
|
+ private static final int REQUEST_SIGNATURE_CODE = 103;
|
|
|
|
|
|
private static final String CurrentActionStringKey = "CurrentActionStringKey";
|
|
|
private static final String ExcuteJSArrayKey = "ExcuteJSArrayKey";
|
|
|
@@ -120,35 +132,16 @@ public class MainActivity extends AppCompatActivity {
|
|
|
Log.d(TAG, "onActivityResult: ");
|
|
|
if (requestCode == REQUEST_SCANNER_CODE) {
|
|
|
|
|
|
- if (resultCode == RESULT_OK) {
|
|
|
-
|
|
|
- Bundle bundle = data.getExtras();
|
|
|
- String pid = bundle.getString("pid");
|
|
|
-
|
|
|
- Log.d(TAG, "onActivityResult: Scanner Value " + pid);
|
|
|
+ onScannerResult(resultCode, data);
|
|
|
|
|
|
- if (mCurrentActionString != null) {
|
|
|
- try {
|
|
|
- JSONObject json = new JSONObject(mCurrentActionString);
|
|
|
- String js = mJSInterface.returnToWebPage(json, pid);
|
|
|
- if (js != null) {
|
|
|
+ } else if (requestCode == REQUEST_CAMERA_CODE) {
|
|
|
|
|
|
- saveExcuteJS(js);
|
|
|
-
|
|
|
- mWebView.evaluateJavascript(js, new ValueCallback<String>() {
|
|
|
- @Override
|
|
|
- public void onReceiveValue(String value) {
|
|
|
- Log.d(TAG, "onReceiveValue: " + value);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ onCameraResult(resultCode, data);
|
|
|
+ } else if (requestCode == REQUEST_PHOTO_LIBRARY_CODE) {
|
|
|
|
|
|
+ onPhotoLibraryResult(resultCode, data);
|
|
|
+ } else if (requestCode == REQUEST_SIGNATURE_CODE) {
|
|
|
+ onSignatureResult(resultCode, data);
|
|
|
}
|
|
|
|
|
|
mCurrentActionString = null;
|
|
|
@@ -185,6 +178,122 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void checkCameraPermission() {
|
|
|
+
|
|
|
+ String[] permissions = {Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE};
|
|
|
+
|
|
|
+ RAUtil.checkPermissions(self,permissions);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * Private
|
|
|
+ * */
|
|
|
+
|
|
|
+ private void evaluateCurrentAction(String value) {
|
|
|
+
|
|
|
+ if (mCurrentActionString != null && value != null) {
|
|
|
+ try {
|
|
|
+ JSONObject json = new JSONObject(mCurrentActionString);
|
|
|
+ String js = mJSInterface.returnToWebPage(json, value);
|
|
|
+ if (js != null) {
|
|
|
+
|
|
|
+ saveExcuteJS(js);
|
|
|
+
|
|
|
+ mWebView.evaluateJavascript(js, new ValueCallback<String>() {
|
|
|
+ @Override
|
|
|
+ public void onReceiveValue(String value) {
|
|
|
+ Log.d(TAG, "onReceiveValue: " + value);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setImageForPath(String path) {
|
|
|
+ if (path != null) {
|
|
|
+ String imgBase64 = FileManager.base64StringFromFile(path));
|
|
|
+
|
|
|
+ if (imgBase64 != null) {
|
|
|
+ String base64 = String.format("data:image/jpg;base64,%s",imgBase64);
|
|
|
+ evaluateCurrentAction(base64);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Result
|
|
|
+ * */
|
|
|
+
|
|
|
+ private void onScannerResult(int resultCode, Intent data) {
|
|
|
+
|
|
|
+ if (resultCode == RESULT_OK) {
|
|
|
+
|
|
|
+ Bundle bundle = data.getExtras();
|
|
|
+ String pid = bundle.getString("pid");
|
|
|
+
|
|
|
+ Log.d(TAG, "onActivityResult: Scanner Value " + pid);
|
|
|
+ evaluateCurrentAction(pid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onCameraResult(int resultCode, Intent data) {
|
|
|
+
|
|
|
+ if (resultCode == RESULT_OK) {
|
|
|
+
|
|
|
+ if (mCameraFile != null && mCameraFile.exists()) {
|
|
|
+ mCameraFile = ImageUtil.compressImageFile(self, mCameraFile);
|
|
|
+
|
|
|
+ if (mCameraFile != null) {
|
|
|
+ self.setImageForPath(mCameraFile.getAbsolutePath());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ mCameraFile = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onPhotoLibraryResult(int resultCode, Intent data) {
|
|
|
+
|
|
|
+ if (resultCode == RESULT_OK) {
|
|
|
+ Uri uri = CameraHelper.getImageUriFromData(data);
|
|
|
+ if (uri != null) {
|
|
|
+ String path = uri.getPath();
|
|
|
+ if (path != null) {
|
|
|
+ setImageForPath(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onSignatureResult(int resultCode, Intent data) {
|
|
|
+
|
|
|
+ if (resultCode == RESULT_OK) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Private Action
|
|
|
+ * */
|
|
|
+
|
|
|
+ private File mCameraFile;
|
|
|
+
|
|
|
+ private void openCamera(String msg) {
|
|
|
+ mCurrentActionString = msg;
|
|
|
+ mCameraFile = CameraHelper.startCamera(self,REQUEST_CAMERA_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void openPhotoLibrary(String msg) {
|
|
|
+ mCurrentActionString = msg;
|
|
|
+ CameraHelper.pickImageFromAlbum2(self, REQUEST_PHOTO_LIBRARY_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Action
|
|
|
* */
|
|
|
@@ -213,7 +322,23 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
@Override
|
|
|
public void Share(String msg) {
|
|
|
+ if (msg != null) {
|
|
|
+ try {
|
|
|
+ JSONObject json = new JSONObject(msg);
|
|
|
+ String urlStr = json.getString("url");
|
|
|
+ URL url = new URL(urlStr);
|
|
|
+
|
|
|
+ Intent share = new Intent();
|
|
|
+ share.setAction(Intent.ACTION_SEND);
|
|
|
+ share.setType("text/plain");
|
|
|
+ share.putExtra(Intent.EXTRA_STREAM, url);
|
|
|
|
|
|
+ self.startActivity(Intent.createChooser(share, "Share"));
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -232,13 +357,37 @@ public class MainActivity extends AppCompatActivity {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void Photo(String msg) {
|
|
|
+ public void Photo(final String msg) {
|
|
|
+
|
|
|
+ ActionSheet actionSheet = new ActionSheet(self);
|
|
|
+ actionSheet.addAction(self.getString(R.string.wb_photo_library_action), ActionSheet.ActionType.ActionTypeDefault, new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ openPhotoLibrary(msg);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ actionSheet.addAction(self.getString(R.string.wb_camera_action), ActionSheet.ActionType.ActionTypeDefault, new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ openCamera(msg);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ actionSheet.addAction(self.getString(R.string.btn_cancel), ActionSheet.ActionType.ACtionTypeCancel, new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ actionSheet.show();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void Email(String msg) {
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|