Browse Source

1.修改Android Apex CRM文件预览及分享。

Pen Li 7 years ago
parent
commit
cc7fe50c33
32 changed files with 1169 additions and 45 deletions
  1. 1 0
      ApexDrivers/RAUtilsLibrary/build.gradle
  2. 4 4
      ApexDrivers/RAUtilsLibrary/src/main/AndroidManifest.xml
  3. 1 1
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/camera/CameraHelper.java
  4. 74 0
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/email/EmailHelper.java
  5. 9 1
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/fileViewer/FileViewerActivity.java
  6. 46 0
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/map/MapHelper.java
  7. 92 0
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/operationQueue/OperationQueue.java
  8. 272 0
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/preview/RAPDFPreviewActivity.java
  9. 88 0
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/FileManager.java
  10. 70 0
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/Network.java
  11. 9 0
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/RAProviderHelper.java
  12. 32 0
      ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/RAUtil.java
  13. 24 0
      ApexDrivers/RAUtilsLibrary/src/main/res/layout/actionbar_customtitle.xml
  14. 14 0
      ApexDrivers/RAUtilsLibrary/src/main/res/layout/pdf_preview_activity.xml
  15. 17 0
      ApexDrivers/RAUtilsLibrary/src/main/res/menu/pdf_preview_menu.xml
  16. 12 0
      ApexDrivers/RAUtilsLibrary/src/main/res/values-zh/strings.xml
  17. 2 0
      ApexDrivers/RAUtilsLibrary/src/main/res/values/colors.xml
  18. 12 0
      ApexDrivers/RAUtilsLibrary/src/main/res/values/strings.xml
  19. 0 0
      ApexDrivers/RAUtilsLibrary/src/main/res/xml/ra_provider_paths.xml
  20. 1 0
      ApexDrivers/apexcrm/build.gradle
  21. 17 1
      ApexDrivers/apexcrm/src/main/AndroidManifest.xml
  22. 147 32
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/MainActivity.java
  23. 1 0
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/RAJSInterface.java
  24. 56 1
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/RAWebView.java
  25. 13 0
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/application/ApexCRMApp.java
  26. 72 0
      ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/dataProvider/DataProvider.java
  27. 36 0
      ApexDrivers/apexcrm/src/main/res/xml/apex_crm_provider_paths.xml
  28. 1 1
      ApexDrivers/apexdriverscn/src/main/AndroidManifest.xml
  29. 2 2
      ApexDrivers/apexdriversi/src/main/AndroidManifest.xml
  30. 7 1
      ApexDrivers/apexdriversi/src/main/java/com/usai/apex/apexdriversi/ApplicationI.java
  31. 36 0
      ApexDrivers/apexdriversi/src/main/res/xml/apex_driver_provider_paths.xml
  32. 1 1
      ApexDrivers/build.gradle

+ 1 - 0
ApexDrivers/RAUtilsLibrary/build.gradle

@@ -57,6 +57,7 @@ dependencies {
     implementation files('libs/httpmime-4.1.1.jar')
     api 'com.google.android.gms:play-services-location:16.0.0'
     implementation files('libs/core-2.3.0.jar')
+    implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'
 }
 
 

+ 4 - 4
ApexDrivers/RAUtilsLibrary/src/main/AndroidManifest.xml

@@ -52,14 +52,12 @@
         <!--Android 7.0 以后文件操作-->
         <!--<provider-->
             <!--android:name="android.support.v4.content.FileProvider"-->
-            <!--android:authorities="com.usai.apex.driver.fileprovider"-->
+            <!--android:authorities="com.usai.apex.radant.utils.fileprovider"-->
             <!--android:exported="false"-->
             <!--android:grantUriPermissions="true">-->
-
             <!--<meta-data-->
                 <!--android:name="android.support.FILE_PROVIDER_PATHS"-->
-                <!--android:resource="@xml/paths"/>-->
-
+                <!--android:resource="@xml/ra_provider_paths" />-->
         <!--</provider>-->
 
         <receiver
@@ -83,6 +81,8 @@
             android:theme="@style/CaptureTheme"
             android:windowSoftInputMode="stateAlwaysHidden"/>
 
+        <activity android:name=".preview.RAPDFPreviewActivity"/>
+
     </application>
 
 </manifest>

+ 1 - 1
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/camera/CameraHelper.java

@@ -147,7 +147,7 @@ public class CameraHelper {
     }
 
     public static Uri getImageUriFromData(Intent data) {
-        if (data == null) {
+        if (data != null) {
             Uri imageUri = data.getData();
             return imageUri;
         }

+ 74 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/email/EmailHelper.java

@@ -0,0 +1,74 @@
+package com.usai.redant.rautils.email;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.net.Uri;
+import android.widget.Toast;
+
+import com.usai.redant.rautils.R;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+public class EmailHelper {
+
+    public static void sendEmail(Context context, String[] to, String[] cc, String[] bcc, String subject ,String content, ArrayList<File> attachments) {
+
+        if (context == null) {
+            return;
+        }
+
+        if (to == null && cc == null && bcc == null && subject == null && content == null && (attachments == null || attachments.size() == 0)) {
+            return;
+        }
+
+        Intent intent = new Intent(Intent.ACTION_SEND);
+
+        if (to != null) {
+            intent.putExtra(Intent.EXTRA_EMAIL, to);
+        }
+        if (cc != null) {
+            intent.putExtra(Intent.EXTRA_CC, cc);
+        }
+        if (bcc != null) {
+            intent.putExtra(Intent.EXTRA_BCC, bcc);
+        }
+        if (content != null) {
+            intent.putExtra(Intent.EXTRA_TEXT, content);
+        }
+        if (subject != null) {
+            intent.putExtra(Intent.EXTRA_SUBJECT, subject);
+        }
+
+        if (attachments != null && attachments.size() > 0) {
+
+            ArrayList<Uri> fileUris = new ArrayList<>();
+
+
+            for (File f : attachments) {
+                fileUris.add(Uri.parse(String.format("file://%s",f.getAbsolutePath())));
+            }
+
+            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris);
+
+        }
+
+        intent.setType("message/rfc882");
+        Intent.createChooser(intent, "Choose Email Client");
+
+        PackageManager packageManager = context.getPackageManager();
+        List<ResolveInfo> appList = packageManager.queryIntentActivities(intent, 0);
+
+        if (appList == null || appList.isEmpty()) {
+            Toast.makeText(context, context.getString(R.string.ra_email_no_email), Toast.LENGTH_LONG).show();
+            return;
+        }
+
+        context.startActivity(intent);
+
+    }
+
+}

+ 9 - 1
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/fileViewer/FileViewerActivity.java

@@ -1,5 +1,6 @@
 package com.usai.redant.rautils.fileViewer;
 
+import android.app.Application;
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
@@ -14,6 +15,7 @@ import android.widget.ListView;
 
 import com.usai.redant.rautils.R;
 import com.usai.redant.rautils.utils.FileManager;
+import com.usai.redant.rautils.utils.RAProviderHelper;
 import com.usai.redant.rautils.utils.RAUtil;
 
 import java.io.File;
@@ -131,7 +133,13 @@ public class FileViewerActivity extends AppCompatActivity {
             String newPath = newDir  + File.separator + name;
             FileManager.copyFile(oldPath, newPath);
 
-            FileManager.openFile(getApplicationContext(), "com.usai.apex.apexdriversi.fileprovider", new File(newPath));
+            Application application = getApplication();
+            if (application != null && application instanceof RAProviderHelper.ProviderHelperDelegate) {
+
+                String authority = ((RAProviderHelper.ProviderHelperDelegate) application).getProviderAuthorities();
+                FileManager.openFile(getApplicationContext(), authority, new File(newPath));
+            }
+
 
         }
     }

+ 46 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/map/MapHelper.java

@@ -0,0 +1,46 @@
+package com.usai.redant.rautils.map;
+
+import android.content.Context;
+import android.content.Intent;
+import android.location.Location;
+import android.net.Uri;
+import android.widget.Toast;
+
+import com.usai.redant.rautils.R;
+
+public class MapHelper {
+
+    public static void navigate(Context context, String street) {
+
+        if (context == null || street == null) {
+            return;
+        }
+
+        Uri gmmIntentUri = Uri.parse("google.navigation:q=" + street + "&mode=d");
+        Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
+        mapIntent.setPackage("com.google.android.apps.maps");
+        if (mapIntent.resolveActivity(context.getPackageManager()) != null) {
+            context.startActivity(mapIntent);
+        } else {
+            Toast.makeText(context, context.getString(R.string.ra_map_alert_no_google_map), Toast.LENGTH_LONG).show();
+        }
+    }
+
+    public static void showMapOnLocation(Context context, Location location) {
+
+        if (context == null || location == null) {
+            return;
+        }
+
+        Uri gmmIntentUri = Uri.parse("geo:" + location.getLatitude() + "," + location.getLongitude() + "?mode=d");
+        Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
+        mapIntent.setPackage("com.google.android.apps.maps");
+        if (mapIntent.resolveActivity(context.getPackageManager()) != null) {
+            context.startActivity(mapIntent);
+        } else {
+            Toast.makeText(context, context.getString(R.string.ra_map_alert_no_google_map), Toast.LENGTH_LONG).show();
+        }
+
+    }
+
+}

+ 92 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/operationQueue/OperationQueue.java

@@ -0,0 +1,92 @@
+package com.usai.redant.rautils.operationQueue;
+
+import android.os.AsyncTask;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class OperationQueue {
+
+    /**
+     * 根据CPU核心数控制线程数
+     * */
+    private static final int count = Runtime.getRuntime().availableProcessors() * 3;
+
+    private static ExecutorService limitedTaskExecutor = null;
+
+    private static volatile OperationQueue instance;
+
+    public static OperationQueue sharedQueue() {
+        if (instance == null) {
+            synchronized (OperationQueue.class) {
+                if (instance == null) {
+                    instance = new OperationQueue();
+                }
+            }
+        }
+        return instance;
+    }
+
+    private OperationQueue() {
+        limitedTaskExecutor = Executors.newFixedThreadPool(count);
+    }
+
+    public void addOperationTask(OperationBackgroundCallBack backgroundCallBack, OperationCompletionCallBack completion, OperationCancelCallBack cancelCallBack) {
+
+        OperationTask task = new OperationTask(backgroundCallBack,completion,cancelCallBack);
+        task.executeOnExecutor(limitedTaskExecutor);
+    }
+
+    private class OperationTask extends AsyncTask<Void, Void, Object> {
+
+        private OperationBackgroundCallBack mBackgroundCallBack;
+        private OperationCompletionCallBack mCompletion;
+        private OperationCancelCallBack mCancelCallBack;
+
+        OperationTask(OperationBackgroundCallBack backgroundCallBack, OperationCompletionCallBack completion, OperationCancelCallBack cancelCallBack) {
+            mBackgroundCallBack = backgroundCallBack;
+            mCompletion = completion;
+            mCancelCallBack = cancelCallBack;
+        }
+
+        @Override
+        protected Object doInBackground(Void... voids) {
+
+            if (mBackgroundCallBack != null) {
+                return mBackgroundCallBack.operationDoInBackground();
+            }
+
+            return null;
+        }
+
+        @Override
+        protected void onPostExecute(Object object) {
+
+            if (mCompletion != null) {
+                mCompletion.operationCompletion(object);
+            }
+        }
+
+        @Override
+        protected void onCancelled() {
+            super.onCancelled();
+
+            if (mCancelCallBack != null) {
+                mCancelCallBack.operationCancelled();
+            }
+        }
+    }
+
+    public interface OperationBackgroundCallBack {
+        Object operationDoInBackground();
+    }
+
+    public interface OperationCompletionCallBack {
+        void operationCompletion(Object object);
+    }
+
+    public interface OperationCancelCallBack {
+        void operationCancelled();
+    }
+
+}

+ 272 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/preview/RAPDFPreviewActivity.java

@@ -0,0 +1,272 @@
+package com.usai.redant.rautils.preview;
+
+import android.app.AlertDialog;
+import android.app.Application;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.graphics.Color;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Bundle;
+import android.support.v4.content.FileProvider;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
+
+import com.github.barteksc.pdfviewer.PDFView;
+import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
+import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
+import com.github.barteksc.pdfviewer.listener.OnPageErrorListener;
+import com.github.barteksc.pdfviewer.util.FitPolicy;
+import com.shockwave.pdfium.PdfDocument;
+import com.usai.redant.rautils.R;
+import com.usai.redant.rautils.utils.FileManager;
+import com.usai.redant.rautils.utils.RAProviderHelper;
+
+import java.io.File;
+import java.util.List;
+
+public class RAPDFPreviewActivity extends AppCompatActivity implements OnPageChangeListener, OnLoadCompleteListener,OnPageErrorListener {
+
+    private static final String FilePathKey = "file";
+
+    public static void test() {
+
+    }
+
+    public static void startPreviewActivity(Context context, String filePath) {
+        if (context == null || filePath == null) {
+            return;
+        }
+        Intent intent = new Intent(context, RAPDFPreviewActivity.class);
+        intent.putExtra(FilePathKey, filePath);
+        context.startActivity(intent);
+    }
+
+    private static final String TAG = RAPDFPreviewActivity.class.getSimpleName();
+
+    private PDFView pdfView;
+    private Integer pageNumber = 0;
+
+    protected void openFile() {
+
+        File file = new File(mFilePath);
+        if (file == null || !file.exists()) {
+            return;
+        }
+
+        Uri uri = null;
+        String type = FileManager.getMimeType(file.getPath());
+
+        // type "application/pdf"
+        Intent intent = new Intent(Intent.ACTION_VIEW);
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+
+            // "com.usai.apex.fileprovider"即是在Manifest文件中配置的authorities
+
+            Application application = getApplication();
+            if (application != null && application instanceof RAProviderHelper.ProviderHelperDelegate) {
+
+                String authority = ((RAProviderHelper.ProviderHelperDelegate) application).getProviderAuthorities();
+
+                uri = FileProvider.getUriForFile(this, authority, file);
+                // 给目标应用一个临时授权
+                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+            }
+
+
+        } else {
+            uri = Uri.fromFile(file);
+        }
+
+        intent.setDataAndType(uri, type);
+
+        if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
+            // someone knows how to handle this mime type with this scheme, don't download.
+            try {
+                startActivity(intent);
+                return;
+            } catch (Exception ex) {
+                Log.d("Open File", "activity not found for " + type + " over " + uri, ex);
+            }
+
+        } else {
+            Log.d("Open File", "openFileAtPath: " + "No App " + uri);
+
+
+            AlertDialog.Builder builder = new AlertDialog.Builder(RAPDFPreviewActivity.this);
+            builder.setMessage("Can not open PDF file, no external App found." );
+
+            builder.setTitle("Open PDF");
+
+            builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener()
+            {
+
+                @Override
+                public void onClick(DialogInterface dialog, int which)
+                {
+                    dialog.dismiss();
+
+
+                }
+            });
+
+            builder.create().show();
+        }
+
+    }
+
+    protected void shareFile() {
+
+        File file = new File(mFilePath);
+        if (file == null || !file.exists()) {
+            return;
+        }
+
+        Uri uri = null;
+        String type = FileManager.getMimeType(file.getPath());
+
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+
+            Application application = getApplication();
+            if (application != null && application instanceof RAProviderHelper.ProviderHelperDelegate) {
+
+                String authority = ((RAProviderHelper.ProviderHelperDelegate) application).getProviderAuthorities();
+
+                // "com.usai.apex.fileprovider"即是在Manifest文件中配置的authorities
+                uri = FileProvider.getUriForFile(this, authority, file);
+                // 给目标应用一个临时授权
+            }
+
+        } else {
+            uri = Uri.fromFile(file);
+        }
+
+        Intent share = new Intent();
+        share.setAction(Intent.ACTION_SEND);
+        share.putExtra(Intent.EXTRA_STREAM, uri);
+        share.setType(type);
+
+        startActivity(Intent.createChooser(share, "Share"));
+    }
+
+    private String mFilePath;
+    private void setCustomActionBar() {
+
+        ActionBar.LayoutParams lp =new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
+        View mActionBarView = LayoutInflater.from(this).inflate(R.layout.actionbar_customtitle, null);
+
+        String title=new File(mFilePath).getName();
+        TextView mTitleView= mActionBarView.findViewById(R.id.title);
+
+        mTitleView.setText(title);
+        setTitle(title);
+
+        ActionBar actionBar = getSupportActionBar();
+        if (actionBar != null) {
+            actionBar.setCustomView(mActionBarView, lp);
+            actionBar.setDisplayHomeAsUpEnabled(true);
+            actionBar.setDisplayShowTitleEnabled(true);
+        }
+
+    }
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+
+        int id = item.getItemId();
+
+        if (id == android.R.id.home) {
+            finish();
+        } else if (id == R.id.pdf_preview_action_open) {
+            openFile();
+        } else if (id == R.id.pdf_preview_action_send) {
+            shareFile();
+        }
+
+        return super.onOptionsItemSelected(item);
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu)
+    {
+        // Inflate the menu; this adds items to the action bar if it is present.
+        getMenuInflater().inflate(R.menu.pdf_preview_menu, menu);
+        return true;
+    }
+
+    @Override
+    protected void onDestroy()
+    {
+        super.onDestroy();
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.pdf_preview_activity);
+
+        mFilePath = getIntent().getStringExtra(FilePathKey);
+
+        setCustomActionBar();
+
+        pdfView = findViewById(R.id.pdfView);
+        pdfView.setBackgroundColor(Color.LTGRAY);
+        pdfView.setPadding(10,10,10,10);
+        pdfView.fromFile(new File(mFilePath))
+                .defaultPage(pageNumber)
+                .onPageChange(this)
+                .enableAnnotationRendering(true)
+                .onLoad(this)
+                .spacing(10) // in dp
+                .onPageError(this)
+                .pageFitPolicy(FitPolicy.BOTH)
+                .load();
+
+    }
+
+    @Override
+    public void loadComplete(int nbPages) {
+        PdfDocument.Meta meta = pdfView.getDocumentMeta();
+        Log.e(TAG, "title = " + meta.getTitle());
+        Log.e(TAG, "author = " + meta.getAuthor());
+        Log.e(TAG, "subject = " + meta.getSubject());
+        Log.e(TAG, "keywords = " + meta.getKeywords());
+        Log.e(TAG, "creator = " + meta.getCreator());
+        Log.e(TAG, "producer = " + meta.getProducer());
+        Log.e(TAG, "creationDate = " + meta.getCreationDate());
+        Log.e(TAG, "modDate = " + meta.getModDate());
+
+        printBookmarksTree(pdfView.getTableOfContents(), "-");
+    }
+
+    @Override
+    public void onPageChanged(int page, int pageCount) {
+
+    }
+
+    @Override
+    public void onPageError(int page, Throwable t) {
+
+    }
+
+    public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
+        for (PdfDocument.Bookmark b : tree) {
+
+            Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));
+
+            if (b.hasChildren()) {
+                printBookmarksTree(b.getChildren(), sep + "-");
+            }
+        }
+    }
+}

+ 88 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/FileManager.java

@@ -16,6 +16,7 @@ import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -99,6 +100,38 @@ public class FileManager {
 
     }
 
+    public static String SDApplicationFolder(Context context) {
+        if (context == null) {
+            return null;
+        }
+        String name = RAUtil.getApplicationName(context);
+
+        String sdRoot = SDCardRoot();
+
+        File appF = new File(sdRoot, name);
+        if (appF.exists() && appF.isFile()) {
+            appF.delete();
+        }
+
+        if (!appF.exists()) {
+            appF.mkdir();
+        }
+        return appF.getAbsolutePath();
+    }
+
+    public static String SDApplicationTempFolder(Context context) {
+        if (context == null) {
+            return null;
+        }
+
+        String appDir = SDApplicationFolder(context);
+        File tmpF = new File(appDir, "temp");
+        if (!tmpF.exists()) {
+            tmpF.mkdirs();
+        }
+        return tmpF.getAbsolutePath();
+    }
+
 
     public static String SDCardRoot() {
         return Environment.getExternalStorageDirectory()+ File.separator;
@@ -561,6 +594,35 @@ public class FileManager {
         return bytes;
     }
 
+    public static byte[] getBytesOfUri(Context context, Uri uri) {
+
+        if (context == null || uri == null) {
+            return null;
+        }
+
+        byte[] bytes = null;
+        InputStream is = null;
+        try {
+
+            is = context.getContentResolver().openInputStream(uri);
+            bytes = new byte[is.available()];
+            is.read(bytes);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return bytes;
+
+    }
+
     public static String base64StringFromFile(String path) {
         if (path == null) {
             return null;
@@ -586,4 +648,30 @@ public class FileManager {
         return null;
     }
 
+    public static String base64StringFromUri(Context context, Uri uri) {
+        if (context == null || uri == null) {
+            return null;
+        }
+
+        byte[] bytes = getBytesOfUri(context, uri);
+        if (bytes != null) {
+
+            String base64Str = Base64.encodeToString(bytes,Base64.DEFAULT);
+
+            return base64Str;
+        }
+        return null;
+    }
+
+    public static void copyFileFromUri(Context context, Uri srcUri, String dest) {
+        if (context == null || srcUri == null || dest == null) {
+            return;
+        }
+
+        byte[] bytes = getBytesOfUri(context, srcUri);
+        if (bytes != null) {
+            saveBytes2Path(bytes, dest);
+        }
+    }
+
 }

+ 70 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/Network.java

@@ -548,6 +548,69 @@ public class Network {
         return null;
     }
 
+    public static File GET_DownloadFile(String download_url,String dir) {
+
+        HttpURLConnection connection = null;
+
+        File returnFile = null;
+        try {
+
+            String fileName = UUID.randomUUID().toString();
+            if (dir == null) {
+                dir = Environment.getExternalStorageDirectory() + File.separator + "download";
+            }
+
+            if (FileManager.isFileExist(fileName,dir)) {
+                returnFile = new File(dir + File.separator + fileName);
+            } else {
+                // 创建一个URL对象
+                URL url=new URL(download_url);
+                // 创建一个HTTP链接
+                connection=(HttpURLConnection)url.openConnection();
+                connection.setRequestMethod("GET");
+                connection.setUseCaches(false);
+                connection.setConnectTimeout(REQUEST_TIMEOUT);
+                connection.setReadTimeout(REQUEST_TIMEOUT);
+
+                // 获取响应
+                JSONObject responseHeader = getResponseHeader(connection);
+                String suggestedFileName = getResponsesuggestedFilename(responseHeader);
+
+                if (suggestedFileName == null) {
+                    suggestedFileName = UUID.randomUUID().toString();
+                }
+                Log.d("Download", "download_query: " + suggestedFileName);
+
+                if (suggestedFileName != null && !suggestedFileName.isEmpty()) {
+                    fileName = suggestedFileName;
+                }
+
+                // 使用IO流获取数据
+                InputStream inputStream=connection.getInputStream();
+                // 写文件
+                File downloadFile = FileManager.write2SDFromInput(fileName,dir,inputStream);
+
+                if (downloadFile == null) {
+                    returnFile = null;
+                } else {
+                    returnFile = downloadFile;
+                }
+            }
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (connection != null) {
+                connection.disconnect();
+            }
+        }
+
+
+
+        return returnFile;
+
+    }
+
     public static File downloadFile(Bundle params, String download_url,String dir) {
 
         if (params == null) {
@@ -588,7 +651,14 @@ public class Network {
                 // 获取响应
                 JSONObject responseHeader = getResponseHeader(connection);
                 String suggestedFileName = getResponsesuggestedFilename(responseHeader);
+
+                if (suggestedFileName == null) {
+                    suggestedFileName = UUID.randomUUID().toString();
+                }
+
                 Log.d("Download", "download_query: " + suggestedFileName);
+
+
                 if (suggestedFileName != null && !suggestedFileName.isEmpty()) {
                     fileName = suggestedFileName;
                 }

+ 9 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/RAProviderHelper.java

@@ -0,0 +1,9 @@
+package com.usai.redant.rautils.utils;
+
+public class RAProviderHelper {
+
+    public interface ProviderHelperDelegate {
+        String getProviderAuthorities();
+    }
+
+}

+ 32 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/RAUtil.java

@@ -3,6 +3,7 @@ package com.usai.redant.rautils.utils;
 import android.app.Activity;
 import android.app.Application;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.SharedPreferences;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
@@ -11,9 +12,12 @@ import android.os.Bundle;
 import android.provider.Settings;
 import android.support.v4.app.ActivityCompat;
 import android.support.v4.content.PermissionChecker;
+import android.support.v7.app.AlertDialog;
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.usai.redant.rautils.R;
+
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -405,4 +409,32 @@ public class RAUtil {
         }
     }
 
+    public static void alertMessage(Context context, String title, String msg) {
+        if (context == null) {
+            return;
+        }
+        if (title == null && msg == null) {
+            return;
+        }
+
+        AlertDialog.Builder builder = new AlertDialog.Builder(context);
+        if (title != null) {
+            builder.setTitle(title);
+        }
+        if (msg != null) {
+            builder.setMessage(msg);
+        }
+
+        builder.setPositiveButton(context.getString(R.string.ra_btn_ok), new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+
+            }
+        });
+
+        builder.show();
+
+
+    }
+
 }

+ 24 - 0
ApexDrivers/RAUtilsLibrary/src/main/res/layout/actionbar_customtitle.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <TextView
+        android:id="@+id/title"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:layout_centerInParent="true"
+
+        android:ellipsize="end"
+        android:gravity="center"
+        android:singleLine="true"
+        android:textColor="@color/pdf_preview_icon_gray"
+        android:textSize="17sp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.6"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+</android.support.constraint.ConstraintLayout>

+ 14 - 0
ApexDrivers/RAUtilsLibrary/src/main/res/layout/pdf_preview_activity.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="com.usai.redant.rautils.preview.RAPDFPreviewActivity">
+
+    <com.github.barteksc.pdfviewer.PDFView
+        android:id="@+id/pdfView"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"/>
+
+</android.support.constraint.ConstraintLayout>

+ 17 - 0
ApexDrivers/RAUtilsLibrary/src/main/res/menu/pdf_preview_menu.xml

@@ -0,0 +1,17 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+ >
+
+    <item
+        android:id="@+id/pdf_preview_action_open"
+        android:orderInCategory="100"
+        android:title="@string/pdf_preview_open"
+        app:showAsAction="never"/>
+
+    <item
+        android:id="@+id/pdf_preview_action_send"
+        android:orderInCategory="200"
+        android:title="@string/pdf_preview_share"
+        app:showAsAction="never"/>
+
+</menu>

+ 12 - 0
ApexDrivers/RAUtilsLibrary/src/main/res/values-zh/strings.xml

@@ -44,6 +44,18 @@
 
     <!---->
 
+    <string name="ra_btn_ok">好</string>
+    <string name="ra_btn_cancel">取消</string>
+    <string name="ra_title_warning">警告</string>
+    <string name="ra_sorry">对不起,发生未知错误</string>
+
     <string name="ra_allow_camera_and_storage">请检查相机权限和存储权限是否打开</string>
 
+    <string name="ra_map_alert_no_google_map">没有安装谷歌地图</string>
+
+    <string name="ra_email_no_email">没有安装邮件应用</string>
+
+    <string name="pdf_preview_open">打开</string>
+    <string name="pdf_preview_share">分享</string>
+
 </resources>

+ 2 - 0
ApexDrivers/RAUtilsLibrary/src/main/res/values/colors.xml

@@ -15,4 +15,6 @@
     <color name="message_success">#ee00ff00</color>
     <color name="message_fail">#eeff0000</color>
 
+    <color name="pdf_preview_icon_gray">#444445</color>
+
 </resources>

+ 12 - 0
ApexDrivers/RAUtilsLibrary/src/main/res/values/strings.xml

@@ -44,6 +44,18 @@
 
     <!---->
 
+    <string name="ra_btn_ok">Ok</string>
+    <string name="ra_btn_cancel">Cancel</string>
+    <string name="ra_title_warning">Warning</string>
+    <string name="ra_sorry">Sorry,there is something wrong</string>
+
     <string name="ra_allow_camera_and_storage">please allow app use camera and storage</string>
 
+    <string name="ra_map_alert_no_google_map">There is no google map</string>
+
+    <string name="ra_email_no_email">There is no email application</string>
+
+    <string name="pdf_preview_open">Open</string>
+    <string name="pdf_preview_share">Share</string>
+
 </resources>

+ 0 - 0
ApexDrivers/apexdriversi/src/main/res/xml/provider_paths.xml → ApexDrivers/RAUtilsLibrary/src/main/res/xml/ra_provider_paths.xml


+ 1 - 0
ApexDrivers/apexcrm/build.gradle

@@ -34,4 +34,5 @@ dependencies {
     androidTestImplementation 'com.android.support.test:runner:1.0.2'
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
     compile project(path: ':RAUtilsLibrary')
+    implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'
 }

+ 17 - 1
ApexDrivers/apexcrm/src/main/AndroidManifest.xml

@@ -8,7 +8,9 @@
 
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
+
     <application
+        android:name=".application.ApexCRMApp"
         android:allowBackup="true"
         android:icon="@mipmap/ic_launcher"
         android:label="@string/app_name"
@@ -17,13 +19,27 @@
         android:theme="@style/AppTheme"
         tools:replace="android:theme,android:icon,android:roundIcon"
         >
+
+        <provider
+            android:name="android.support.v4.content.FileProvider"
+            android:authorities="com.usai.apex.apex.crm.fileprovider"
+            android:exported="false"
+            android:grantUriPermissions="true">
+            <meta-data
+                android:name="android.support.FILE_PROVIDER_PATHS"
+                android:resource="@xml/apex_crm_provider_paths" />
+        </provider>
+
+
         <activity android:name=".MainActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
+                <action android:name="android.intent.action.VIEW"/>
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
+
         </activity>
+
     </application>
 
 </manifest>

+ 147 - 32
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/MainActivity.java

@@ -5,8 +5,6 @@ import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
 import android.support.v4.content.PermissionChecker;
 import android.support.v7.app.AppCompatActivity;
 
@@ -15,8 +13,12 @@ import android.view.View;
 import android.webkit.ValueCallback;
 import android.widget.Toast;
 
+import com.usai.apex.apexcrm.dataProvider.DataProvider;
 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.map.MapHelper;
+import com.usai.redant.rautils.preview.RAPDFPreviewActivity;
 import com.usai.redant.rautils.utils.FileManager;
 import com.usai.redant.rautils.utils.ImageUtil;
 import com.usai.redant.rautils.utils.RAUtil;
@@ -27,8 +29,13 @@ import org.json.JSONException;
 import org.json.JSONObject;
 
 import java.io.File;
-import java.net.URI;
 import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+
+import static com.usai.apex.apexcrm.RAWebView.RALocalFileScheme;
+import static com.usai.redant.rautils.utils.Network.RESULT_TRUE;
 
 
 public class MainActivity extends AppCompatActivity {
@@ -190,38 +197,69 @@ public class MainActivity extends AppCompatActivity {
      * Private
      * */
 
-    private void evaluateCurrentAction(String value) {
+    private void evaluateCurrentAction(final String value) {
 
-        if (mCurrentActionString != null && value != null) {
-            try {
-                JSONObject json = new JSONObject(mCurrentActionString);
-                String js = mJSInterface.returnToWebPage(json, value);
-                if (js != null) {
+        if (value != null) {
 
-                    saveExcuteJS(js);
-
-                    mWebView.evaluateJavascript(js, new ValueCallback<String>() {
-                        @Override
-                        public void onReceiveValue(String value) {
-                            Log.d(TAG, "onReceiveValue: " + value);
+            runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+
+                    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();
                         }
-                    });
+                    }
+
                 }
+            });
 
-            } catch (JSONException e) {
-                e.printStackTrace();
-            }
+        }
+
+    }
+
+    private void setWebImageWithBase64(String imageWithBase64) {
+
+        if (imageWithBase64 != null) {
+            String base64 = String.format("data:image/jpg;base64,%s",imageWithBase64);
+            evaluateCurrentAction(base64);
         }
     }
 
-    private void setImageForPath(String path) {
+    private void setWebImageForPath(String path) {
         if (path != null) {
-            String imgBase64 = FileManager.base64StringFromFile(path);
+//            String imgBase64 = FileManager.base64StringFromFile(path);
+//            setWebImageWithBase64(imgBase64);
+
+            /**
+             * 加载本地文件需要将文件路径转换以下,然后在WebView中拦截响应替换
+             * 如果直接写file://xxxx 那么webview不会加载
+             * 建议写为http://local/file://
+             * */
+            evaluateCurrentAction(String.format("%s%s",RALocalFileScheme,path));
+        }
+    }
 
-            if (imgBase64 != null) {
-                String base64 = String.format("data:image/jpg;base64,%s",imgBase64);
-                evaluateCurrentAction(base64);
-            }
+    private void setWebImageForUri(Uri uri) {
+        if (uri != null) {
+
+//            String imgBase64 = FileManager.base64StringFromUri(self,uri);
+//            setWebImageWithBase64(imgBase64);
         }
     }
 
@@ -249,7 +287,7 @@ public class MainActivity extends AppCompatActivity {
                 mCameraFile = ImageUtil.compressImageFile(self, mCameraFile);
 
                 if (mCameraFile != null) {
-                    self.setImageForPath(mCameraFile.getAbsolutePath());
+                    self.setWebImageForPath(mCameraFile.getAbsolutePath());
                 }
             }
 
@@ -261,12 +299,13 @@ public class MainActivity extends AppCompatActivity {
 
         if (resultCode == RESULT_OK) {
             Uri uri = CameraHelper.getImageUriFromData(data);
-            if (uri != null) {
-                String path = uri.getPath();
-                if (path != null) {
-                    setImageForPath(path);
-                }
-            }
+            String destDir = FileManager.internalStorageTempDir(self);
+            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmSS").format(new Date());
+            File destF = new File(destDir, timeStamp);
+
+            FileManager.copyFileFromUri(self, uri, destF.getAbsolutePath());
+
+            self.setWebImageForPath(destF.getAbsolutePath());
         }
     }
 
@@ -387,17 +426,93 @@ public class MainActivity extends AppCompatActivity {
         @Override
         public void Email(String msg) {
 
+            if (msg != null) {
+
+                try {
+                    JSONObject json = new JSONObject(msg);
+
+                    String subject = json.getString("subject");
+                    String[] receipt = json.getString("receipt").split(",");
+                    String[] cc = json.getString("cc").split(",");
+                    String content = json.getString("content");
+
+                    EmailHelper.sendEmail(self, receipt, cc, null, subject, content, null);
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+
+            }
 
         }
 
         @Override
         public void Preview(String msg) {
 
+            if (msg != null) {
+
+                try {
+                    JSONObject json = new JSONObject(msg);
+
+                    String urlStr = json.getString("url");
+                    String dir = FileManager.SDApplicationTempFolder(self);
+
+                    urlStr = "http://192.168.0.130/ios.pdf";
+
+                    DataProvider.GET_Download(urlStr, dir, new DataProvider.DataProviderCompletion() {
+                        @Override
+                        public void completion(Object object) {
+
+                            if (object != null && object instanceof  JSONObject) {
+
+                                JSONObject json = (JSONObject) object;
+                                int result = json.optInt("result");
+                                if (result == RESULT_TRUE) {
+
+                                    String path = json.optString("path");
+
+                                    RAPDFPreviewActivity.startPreviewActivity(self, path);
+
+                                } else {
+
+                                    String msg = json.optString("msg");
+                                    RAUtil.alertMessage(self, getString(R.string.ra_title_warning), msg);
+                                }
+                            } else {
+
+                                RAUtil.alertMessage(self, getString(R.string.ra_title_warning), getString(R.string.ra_sorry));
+                            }
+
+                        }
+                    });
+
+
+                } catch (JSONException e) {
+                    e.printStackTrace();
+                }
+            }
         }
 
         @Override
         public void Navigation(String msg) {
 
+            if (msg != null) {
+
+                try {
+                    JSONObject json = new JSONObject(msg);
+
+                    String name = json.getString("name");
+                    String street = json.getString("address");
+
+                    MapHelper.navigate(self, street);
+
+                } catch (JSONException e) {
+                    e.printStackTrace();
+                }
+
+
+            }
+
         }
 
         @Override

+ 1 - 0
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/RAJSInterface.java

@@ -147,6 +147,7 @@ public class RAJSInterface extends Object {
                 value = String.format("'%s'",value);
             }
             String callback = params.optString("callback");
+            callback = "imageCallback(%s,%s)";
             if (callback != null) {
                 String js = String.format(callback,caller,value);
                 return js;

+ 56 - 1
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/RAWebView.java

@@ -3,7 +3,9 @@ package com.usai.apex.apexcrm;
 
 import android.annotation.SuppressLint;
 import android.content.Context;
+import android.net.Uri;
 import android.os.Bundle;
+import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 import android.util.AttributeSet;
 import android.util.Log;
@@ -13,10 +15,18 @@ import android.webkit.JsPromptResult;
 import android.webkit.JsResult;
 import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient;
+import android.webkit.WebResourceRequest;
+import android.webkit.WebResourceResponse;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
+import android.webkit.WebViewClient;
 import android.widget.RelativeLayout;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
 public class RAWebView extends RelativeLayout {
     private final static String TAG = "RAWebView";
 
@@ -24,6 +34,8 @@ public class RAWebView extends RelativeLayout {
     private Context mCtx;
     private RAWebView self = this;
 
+    public static final String RALocalFileScheme = "http://local/file://";
+
     /**
     private RAWebViewDelegate delegate;
     public interface RAWebViewDelegate {
@@ -103,7 +115,12 @@ public class RAWebView extends RelativeLayout {
             //如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
             webSettings.setJavaScriptEnabled(true);
 
+            webSettings.setAllowFileAccess(true);
+            webSettings.setAllowFileAccessFromFileURLs(true);
+            webSettings.setAllowUniversalAccessFromFileURLs(true);
+
             hackWebJSMethod();
+            hackWebURL();
         }
     }
 
@@ -154,6 +171,42 @@ public class RAWebView extends RelativeLayout {
         }
     }
 
+    /**
+     * WebClient
+     * */
+    private void hackWebURL() {
+        if (mWebView != null) {
+            mWebView.setWebViewClient(new WebViewClient(){
+
+                @Nullable
+                @Override
+                public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
+                    WebResourceResponse response = super.shouldInterceptRequest(view, request);
+
+                    Uri uri = request.getUrl();
+                    String url = uri.getPath();
+                    if (url.startsWith("/file://")) {
+
+                        String path = url.replace("/file://","");
+                        File file = new File(path);
+                        try {
+                            InputStream is = new FileInputStream(file);
+                            response = new WebResourceResponse("*/*", "utf-8",is);
+                            return response;
+                        } catch (FileNotFoundException e) {
+                            e.printStackTrace();
+                        }
+
+                    }
+
+                    return response;
+                }
+
+            });
+        }
+    }
+
+
     /**
 
      private boolean canHack(String message) {
@@ -167,7 +220,9 @@ public class RAWebView extends RelativeLayout {
      */
 
     private void hackWebJSMethod() {
-        mWebView.setWebChromeClient(new RAWebChromeClient());
+        if (mWebView != null) {
+            mWebView.setWebChromeClient(new RAWebChromeClient());
+        }
     }
 
 

+ 13 - 0
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/application/ApexCRMApp.java

@@ -0,0 +1,13 @@
+package com.usai.apex.apexcrm.application;
+
+import android.app.Application;
+
+import com.usai.redant.rautils.utils.RAProviderHelper;
+
+public class ApexCRMApp extends Application implements RAProviderHelper.ProviderHelperDelegate {
+
+    @Override
+    public String getProviderAuthorities() {
+        return "com.usai.apex.apex.crm.fileprovider";
+    }
+}

+ 72 - 0
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/dataProvider/DataProvider.java

@@ -0,0 +1,72 @@
+package com.usai.apex.apexcrm.dataProvider;
+
+import com.usai.redant.rautils.operationQueue.OperationQueue;
+import com.usai.redant.rautils.utils.Network;
+
+import org.json.JSONObject;
+
+import java.io.File;
+
+import static com.usai.redant.rautils.utils.Network.RESULT_TRUE;
+
+public class DataProvider {
+
+    public interface DataProviderCompletion {
+        void completion(Object object);
+    }
+
+    public static void GET_Download(final String url, final String destDir, final DataProviderCompletion completion) {
+
+        OperationQueue.sharedQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
+            @Override
+            public Object operationDoInBackground() {
+
+                File file = Network.GET_DownloadFile(url, destDir);
+
+                if (file != null) {
+
+                    try {
+                        JSONObject json = new JSONObject();
+                        json.put("result", RESULT_TRUE);
+                        json.put("path", file.getAbsolutePath());
+                        return json;
+
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+
+                }
+                return null;
+
+            }
+        }, new OperationQueue.OperationCompletionCallBack() {
+            @Override
+            public void operationCompletion(Object object) {
+
+                if (completion != null) {
+                    completion.completion(object);
+                }
+            }
+        }, new OperationQueue.OperationCancelCallBack() {
+            @Override
+            public void operationCancelled() {
+
+                try {
+                    JSONObject json = new JSONObject();
+                    json.put("result", 0);
+                    json.put("msg", "operation canceled");
+
+                    if (completion != null) {
+                        completion.completion(json);
+                    }
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+
+            }
+        });
+
+    }
+
+}

+ 36 - 0
ApexDrivers/apexcrm/src/main/res/xml/apex_crm_provider_paths.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<paths xmlns:android="http://schemas.android.com/apk/res/android">
+
+        <external-path
+            name="external"
+            path="."
+            />
+
+        <files-path
+            name="files"
+            path="."
+            />
+
+        <cache-path
+            name="caches"
+            path="."
+            />
+
+        <external-files-path
+            name="ex_f"
+            path="."
+            />
+
+        <external-cache-path
+            name="ex_c"
+            path="."
+            />
+
+        <!--<files-path path="offline" name="ra_files_offline"/>-->
+        <!--<files-path path="Photo" name="ra_files_photo"/>-->
+        <!--<files-path path="Signature" name="ra_files_signature"/>-->
+
+        <!--<cache-path path="Log" name="ra_cache_log"/>-->
+        <!--<cache-path path="ImageCache" name="ra_cache_images"/>-->
+
+</paths>

+ 1 - 1
ApexDrivers/apexdriverscn/src/main/AndroidManifest.xml

@@ -15,7 +15,7 @@
         <activity android:name=".MainActivityCN">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
+                <action android:name="android.intent.action.VIEW"/>
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>

+ 2 - 2
ApexDrivers/apexdriversi/src/main/AndroidManifest.xml

@@ -21,7 +21,7 @@
             android:grantUriPermissions="true">
             <meta-data
                 android:name="android.support.FILE_PROVIDER_PATHS"
-                android:resource="@xml/provider_paths" />
+                android:resource="@xml/apex_driver_provider_paths" />
         </provider>
 
 
@@ -31,7 +31,7 @@
                   android:windowSoftInputMode="adjustPan">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
+                <action android:name="android.intent.action.VIEW"/>
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>

+ 7 - 1
ApexDrivers/apexdriversi/src/main/java/com/usai/apex/apexdriversi/ApplicationI.java

@@ -1,8 +1,9 @@
 package com.usai.apex.apexdriversi;
 
 import com.usai.redant.apexdrivers.ApexDriverApplication;
+import com.usai.redant.rautils.utils.RAProviderHelper;
 
-public class ApplicationI extends ApexDriverApplication {
+public class ApplicationI extends ApexDriverApplication implements RAProviderHelper.ProviderHelperDelegate {
 
     @Override
     public void onCreate()
@@ -21,4 +22,9 @@ public class ApplicationI extends ApexDriverApplication {
     public boolean isbUseSystemLocation() {
         return false;
     }
+
+    @Override
+    public String getProviderAuthorities() {
+        return "com.usai.apex.apexdriversi.fileprovider";
+    }
 }

+ 36 - 0
ApexDrivers/apexdriversi/src/main/res/xml/apex_driver_provider_paths.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<paths xmlns:android="http://schemas.android.com/apk/res/android">
+
+        <external-path
+            name="external"
+            path="."
+            />
+
+        <files-path
+            name="files"
+            path="."
+            />
+
+        <cache-path
+            name="caches"
+            path="."
+            />
+
+        <external-files-path
+            name="ex_f"
+            path="."
+            />
+
+        <external-cache-path
+            name="ex_c"
+            path="."
+            />
+
+        <!--<files-path path="offline" name="ra_files_offline"/>-->
+        <!--<files-path path="Photo" name="ra_files_photo"/>-->
+        <!--<files-path path="Signature" name="ra_files_signature"/>-->
+
+        <!--<cache-path path="Log" name="ra_cache_log"/>-->
+        <!--<cache-path path="ImageCache" name="ra_cache_images"/>-->
+
+</paths>

+ 1 - 1
ApexDrivers/build.gradle

@@ -7,7 +7,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.1.1'
+        classpath 'com.android.tools.build:gradle:3.2.1'
         
 
         // NOTE: Do not place your application dependencies here; they belong