Browse Source

Merge remote-tracking branch 'origin/sheep_develop' into sheep_develop

liujiangyao 7 years ago
parent
commit
4839959b2c

+ 62 - 3
app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java

@@ -4,9 +4,11 @@ import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageInfo;
 import android.graphics.Color;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.GradientDrawable;
+import android.media.MediaMetadataRetriever;
 import android.net.Uri;
 import android.os.Handler;
 import android.os.Message;
@@ -28,6 +30,7 @@ import com.arialyy.aria.core.download.DownloadTarget;
 import com.arialyy.aria.core.download.DownloadTask;
 import com.arialyy.aria.core.inf.IEntity;
 import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
+import com.kfzs.duanduan.utils.ApkUtils;
 import com.mdad.sdk.mdsdk.AdManager;
 import com.mdad.sdk.mdsdk.common.AdData;
 import com.sheep.gamegroup.absBase.BaseActivity;
@@ -65,6 +68,7 @@ import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
+import com.sheep.jiuyan.samllsheep.utils.FileUtil;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
@@ -82,6 +86,7 @@ import org.afinal.simplecache.ApiKey;
 import org.greenrobot.eventbus.EventBus;
 
 import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.Field;
 import java.net.HttpURLConnection;
 import java.net.URL;
@@ -110,6 +115,7 @@ import static com.sheep.gamegroup.util.UMConfigUtils.Event.XIAOMI_GAME_RECEIVE;
 import static com.sheep.gamegroup.util.ViewUtil.mRobTask;
 import static com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp.PUBLIC_TAG_PREFIX_TEXTVIEW_LIST;
 import static com.sheep.gamegroup.view.adapter.WelfareAdapter.TO_REFRESH;
+import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
 
 /**
  * 一些公用的class
@@ -239,7 +245,7 @@ public class CommonUtil {
         task.setMTotalSize(Double.valueOf(size));
         task.setMGameID(gameId);
         task.setWhereFrom(whereFrom);
-        task.setMApkPath(ClassFileHelper.DIR + File.separator + packageName + ClassFileHelper.FILE_SUFFIX);
+        task.setMApkPath(DIR + File.separator + packageName + ClassFileHelper.FILE_SUFFIX);
         return task;
     }
 
@@ -792,6 +798,28 @@ public class CommonUtil {
             case DialogShare.ALL:
                 ViewUtil.newInstance().showShare(activity, realUrl, description);
                 return;
+            case DialogShare.SYS_SEND:
+                PackageInfo packageInfo = ApkUtils.getPackageInfo(SheepApp.getInstance().getPackageName());
+                if(packageInfo != null && packageInfo.applicationInfo != null && !TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)){
+                    String dir = DIR;
+                    //File dir = SheepApp.getInstance().getDir("apk", Context.MODE_PRIVATE);
+                    File file = new File(dir, String.format(Locale.CHINA, "sheep_release_v%s_%d-%s.apk", packageInfo.versionName, packageInfo.versionCode, DataUtil.getInstance().getInvitationCode()));
+                    if(!file.exists()){
+                        try {
+                            FileUtil.copyFile(new File(packageInfo.applicationInfo.sourceDir), file);
+                            ZipChannelUtil.writeQUA(file, DataUtil.getInstance().getInvitationCode());
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                        }
+                    }
+                    if(file.exists())
+                        shareFile(activity, file);
+                    else
+                        G.showToast("暂不支持,或未打开权限");
+                } else {
+                    G.showToast("暂不支持");
+                }
+                return;
             case DialogShare.FACE_TO_FACE:
                 ViewUtil.showQR(activity, realUrl);
                 return;
@@ -830,7 +858,38 @@ public class CommonUtil {
                 .setCallback(new UMShareListener())
                 .share();
     }
+    // 調用系統方法分享文件
+    public static void shareFile(Context context, File file) {
+        if (null != file && file.exists()) {
+            Intent share = new Intent(Intent.ACTION_SEND);
+            share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
+            share.setType(getMimeType(file.getAbsolutePath()));//此处可发送多种文件
+            share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+            context.startActivity(Intent.createChooser(share, "分享文件"));
+        } else {
+            G.showToast("分享文件不存在");
+        }
+    }
 
+    // 根据文件后缀名获得对应的MIME类型。
+    private static String getMimeType(String filePath) {
+        MediaMetadataRetriever mmr = new MediaMetadataRetriever();
+        String mime = "*/*";
+        if (filePath != null) {
+            try {
+                mmr.setDataSource(filePath);
+                mime = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE);
+            } catch (IllegalStateException e) {
+                return mime;
+            } catch (IllegalArgumentException e) {
+                return mime;
+            } catch (RuntimeException e) {
+                return mime;
+            }
+        }
+        return mime;
+    }
     /**
      * 分享
      *
@@ -1807,7 +1866,7 @@ public class CommonUtil {
                                         new View.OnClickListener() {
                                             @Override
                                             public void onClick(View v) {
-                                                File file = ViewUtil.saveImage((View) v.getParent().getParent(), ClassFileHelper.DIR, System.currentTimeMillis() + ".jpg");
+                                                File file = ViewUtil.saveImage((View) v.getParent().getParent(), DIR, System.currentTimeMillis() + ".jpg");
                                                 if (file != null) {
                                                     Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                                                     Uri uri = Uri.fromFile(file);
@@ -1904,7 +1963,7 @@ public class CommonUtil {
         OkHttpUtils.get()
                 .url(url)
                 .build()
-                .execute(new FileCallBack(ClassFileHelper.DIR, name) {
+                .execute(new FileCallBack(DIR, name) {
                     @Override
                     public void onError(Call call, Exception e, int id) {
                         G.showToast("下载文件失败");

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -1412,7 +1412,7 @@ public class ViewUtil {
 //        ask_share_list.setHasFixedSize(true);
 //        ask_share_list.setNestedScrollingEnabled(false);
         List<String> list = ListUtil.emptyList();
-        list.add(DialogShare.FACE_TO_FACE);
+        list.add(DialogShare.SYS_SEND);
         list.add(DialogShare.WX);
         list.add(DialogShare.QQ);
         list.add(DialogShare.WEIXIN_CIRCLE);
@@ -1424,7 +1424,7 @@ public class ViewUtil {
         imgList.add("share_weixin_circle");
         imgList.add("share_copy_share_link");
         final List<String> nameList = ListUtil.emptyList();
-        nameList.add("面对面");
+        nameList.add("分享app");
         nameList.add("微信");
         nameList.add("QQ好友");
         nameList.add("朋友圈");

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/ActInvitation.java

@@ -290,8 +290,8 @@ public class ActInvitation extends BaseActivity {
                     public void onClick(View view) {
                         File file = null;
                         switch (position){
-                            case 1://qq
-                            case 2://wx
+                            case 2://qq
+                            case 1://wx
                                 PictureInvitationEntity picItem = ListUtil.getItem(mPictureList, curPosition);
                                 if(picItem != null && picItem.isLoaded()) {
                                     try {

+ 2 - 1
app/src/main/java/com/sheep/gamegroup/view/dialog/DialogShare.java

@@ -31,9 +31,10 @@ public class DialogShare {
     public final static String QQ = "qq";
     public final static String WX = "wx";
     public final static String ALL = "all";
+    public final static String SYS_SEND = "sys_send";
     public final static String OTHER = "other";
 
-    @StringDef({FACE_TO_FACE, COPY_SHARE_LINK, WEIXIN_CIRCLE, QQ, WX, OTHER, ALL})
+    @StringDef({FACE_TO_FACE, COPY_SHARE_LINK, WEIXIN_CIRCLE, QQ, WX, OTHER, SYS_SEND, ALL})
     @Retention(RetentionPolicy.SOURCE)
     public @interface SHARE_TYPE {
     }

+ 25 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/FileUtil.java

@@ -38,7 +38,7 @@ public class FileUtil {
         }
     }
 
-    public static void copyFile(@NonNull File fileFrom, @NonNull File dirTo) throws IOException {
+    public static void copyFileToDir(@NonNull File fileFrom, @NonNull File dirTo) throws IOException {
         LogUtil.println("copyFile", fileFrom.getAbsolutePath(), dirTo.getAbsolutePath());
         if(!dirTo.isDirectory()){
             return;
@@ -66,4 +66,28 @@ public class FileUtil {
             if (outputChannel != null) outputChannel.close();
         }
     }
+    public static void copyFile(@NonNull File fileFrom, @NonNull File fileTo) throws IOException {
+        LogUtil.println("copyFile", fileFrom.getAbsolutePath(), fileTo.getAbsolutePath());
+        if(!fileTo.getParentFile().exists())
+            fileTo.getParentFile().mkdirs();
+        if (fileTo.exists()) {
+            if(fileTo.delete()){
+                LogUtil.println("copyFile", "删除文件失败");
+            }
+        }
+        if(!fileTo.createNewFile()){
+            LogUtil.println("copyFile", "创建文件失败");
+        }
+        FileChannel outputChannel = null;
+        FileChannel inputChannel = null;
+        try {
+            inputChannel = new FileInputStream(fileFrom).getChannel();
+            outputChannel = new FileOutputStream(fileTo).getChannel();
+            inputChannel.transferTo(0, inputChannel.size(), outputChannel);
+            inputChannel.close();
+        } finally {
+            if (inputChannel != null) inputChannel.close();
+            if (outputChannel != null) outputChannel.close();
+        }
+    }
 }