导航菜单

页面标题

页面副标题

Hyouka private v5.8.9 - ShareActivity.java 源代码

正在查看: Hyouka private v5.8.9 应用的 ShareActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.beint.project.screens;

import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import com.beint.project.MainActivity;
import com.beint.project.MainApplication;
import com.beint.project.core.model.contact.Contact;
import com.beint.project.core.model.sms.MessageType;
import com.beint.project.core.model.sms.ZangiFileInfo;
import com.beint.project.core.model.sms.ZangiMessage;
import com.beint.project.core.model.sms.links.ContactMessageInfo;
import com.beint.project.core.services.impl.ContactsManager;
import com.beint.project.core.services.impl.PathManager;
import com.beint.project.core.utils.Constants;
import com.beint.project.core.utils.Log;
import com.beint.project.core.utils.ZangiEngineUtils;
import com.beint.project.core.utils.ZangiFileUtils;
import com.beint.project.core.utils.ZangiPermissionUtils;
import com.beint.project.managers.LoginManager;
import com.beint.project.screens.sms.AppModeNotifierActivity;
import com.beint.project.screens.sms.ForwardMessageActivity;
import com.beint.project.screens.sms.ForwardMessageAndBalanceTransferFragment;
import com.beint.project.utils.ProjectUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Iterator;

public class ShareActivity extends AppModeNotifierActivity {
    public static final String TAG = "com.beint.project.screens.ShareActivity";
    ClipData clipData;
    private String filePath;
    private ZangiMessage newZangiMessage;
    private String fileType = null;
    private String extension = "";

    private class ContactData {
        ArrayList<String> emails;
        String name;
        ArrayList<String> numbers;

        private ContactData() {
            this.numbers = new ArrayList<>();
            this.emails = new ArrayList<>();
        }
    }

    private String checkGif(String str, String str2) {
        Bitmap thumbnail;
        Bitmap thumbnail2;
        if (str2.substring(0, 9).equals("image/gif")) {
            String stringExtra = getIntent().getStringExtra("id");
            if (stringExtra != null) {
                this.newZangiMessage.setExt("gif");
                this.newZangiMessage.setFileRemotePath(stringExtra);
                this.newZangiMessage.setExtra(stringExtra);
            } else {
                PathManager pathManager = PathManager.INSTANCE;
                if (str.contains(pathManager.getINCOMING_DIR())) {
                    File file = new File(str);
                    if (file.exists()) {
                        String substring = file.getName().substring(0, file.getName().length() - 4);
                        this.newZangiMessage.setExt("gif");
                        this.newZangiMessage.setFileRemotePath(substring);
                        this.newZangiMessage.setExtra(substring);
                        if (!new File(pathManager.getTEMP_DIR() + substring + ".jpg").exists() && (thumbnail = this.newZangiMessage.getThumbnail(MainApplication.Companion.getMainContext())) != null) {
                            try {
                                ZangiFileUtils.writeBitmapToFile(pathManager.getTEMP_DIR(), thumbnail);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                } else {
                    copyFileInOtherDirectory(str, pathManager.getINCOMING_DIR());
                    File file2 = new File(pathManager.getINCOMING_DIR() + new File(str).getName());
                    if (file2.exists()) {
                        str = file2.getAbsolutePath();
                        String substring2 = file2.getName().substring(0, file2.getName().length() - 4);
                        this.newZangiMessage.setExt("gif");
                        this.newZangiMessage.setFileRemotePath(substring2);
                        this.newZangiMessage.setExtra(substring2);
                        if (!new File(pathManager.getTEMP_DIR() + substring2 + ".jpg").exists() && (thumbnail2 = this.newZangiMessage.getThumbnail(MainApplication.Companion.getMainContext())) != null) {
                            try {
                                ZangiFileUtils.writeBitmapToFile(pathManager.getTEMP_DIR(), thumbnail2);
                            } catch (IOException e7) {
                                e7.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
        return str;
    }

    public static boolean containsEndsWidthUri(String str) {
        return str.endsWith(".jpg") || str.endsWith(".png") || str.endsWith(".jpeg") || str.endsWith(".bmp") || str.endsWith(".gif");
    }

    private void copyFile(File file, File file2) throws IOException {
        FileChannel fileChannel;
        FileChannel channel;
        if (!file2.getParentFile().exists()) {
            file2.getParentFile().mkdirs();
        }
        if (!file2.exists()) {
            file2.createNewFile();
        }
        FileChannel fileChannel2 = null;
        try {
            channel = new FileInputStream(file).getChannel();
        } catch (Throwable th) {
            th = th;
            fileChannel = null;
        }
        try {
            fileChannel2 = new FileOutputStream(file2).getChannel();
            fileChannel2.transferFrom(channel, 0L, channel.size());
            channel.close();
            fileChannel2.close();
        } catch (Throwable th2) {
            th = th2;
            FileChannel fileChannel3 = fileChannel2;
            fileChannel2 = channel;
            fileChannel = fileChannel3;
            if (fileChannel2 != null) {
                fileChannel2.close();
            }
            if (fileChannel != null) {
                fileChannel.close();
            }
            throw th;
        }
    }

    private void copyFileInOtherDirectory(String str, String str2) {
        try {
            File file = new File(str);
            File file2 = new File(str2, file.getName());
            if (file2.exists()) {
                return;
            }
            copyFile(file, file2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void copyInputStreamToOutputStream(android.net.Uri r6) {
        throw new UnsupportedOperationException("Method not decompiled: com.beint.project.screens.ShareActivity.copyInputStreamToOutputStream(android.net.Uri):void");
    }

    public static String getFileExt(String str) {
        return str == null ? "" : str.substring(str.lastIndexOf(".") + 1, str.length());
    }

    private ArrayList<Uri> getUriListFromIntent(Intent intent) {
        ArrayList<Uri> arrayList = new ArrayList<>();
        try {
            try {
                arrayList.add((Uri) intent.getExtras().get("android.intent.extra.STREAM"));
                return arrayList;
            } catch (Exception unused) {
                return arrayList;
            }
        } catch (Exception unused2) {
            Iterator it = intent.getParcelableArrayListExtra("android.intent.extra.STREAM").iterator();
            while (it.hasNext()) {
                Object obj = (Parcelable) it.next();
                if (!(obj instanceof Uri)) {
                    obj = Uri.parse(obj.toString());
                }
                arrayList.add((Uri) obj);
            }
            return arrayList;
        }
    }

    private void handleIntent() {
        String str;
        ArrayList arrayList;
        String str2;
        String str3;
        String str4;
        Intent intent = getIntent();
        if (intent == null || intent.getAction() == null) {
            return;
        }
        String type = intent.getType();
        String str5 = "text/x-vcard";
        String str6 = "video/";
        String str7 = "image/";
        int i = 0;
        if (intent.getAction().equals("android.intent.action.SEND_MULTIPLE")) {
            ArrayList arrayList2 = new ArrayList();
            try {
                ArrayList parcelableArrayListExtra = intent.getParcelableArrayListExtra("android.intent.extra.STREAM");
                if (parcelableArrayListExtra != null && !parcelableArrayListExtra.isEmpty()) {
                    while (i < parcelableArrayListExtra.size()) {
                        Object obj = (Parcelable) parcelableArrayListExtra.get(i);
                        if (!(obj instanceof Uri)) {
                            obj = Uri.parse(obj.toString());
                        }
                        Uri uri = (Uri) obj;
                        String copyFileInAppStorageIfNeededAndReturnPath = ZangiFileUtils.copyFileInAppStorageIfNeededAndReturnPath(uri);
                        if (copyFileInAppStorageIfNeededAndReturnPath == null) {
                            str3 = str5;
                            str4 = str6;
                            str2 = str7;
                            arrayList = parcelableArrayListExtra;
                        } else {
                            ZangiMessage zangiMessage = new ZangiMessage();
                            arrayList = parcelableArrayListExtra;
                            String type2 = getContentResolver().getType(uri);
                            if (type2 == null) {
                                type2 = "";
                            }
                            if (type != null && type.startsWith(str7)) {
                                str3 = str5;
                                str4 = str6;
                                str2 = str7;
                                zangiMessage.setMessageType(MessageType.image);
                                zangiMessage.setFilePath(copyFileInAppStorageIfNeededAndReturnPath);
                                arrayList2.add(zangiMessage);
                            }
                            str2 = str7;
                            if (!uri.toString().contains("image") && !type2.contains("image") && !containsEndsWidthUri(uri.toString())) {
                                if (type != null) {
                                    if (!type.startsWith(str6)) {
                                    }
                                    str3 = str5;
                                    str4 = str6;
                                    zangiMessage.setMessageType(MessageType.video);
                                    zangiMessage.setFilePath(copyFileInAppStorageIfNeededAndReturnPath);
                                    arrayList2.add(zangiMessage);
                                }
                                if (!uri.toString().contains("video") && !type2.contains("video")) {
                                    if (type.startsWith(str5)) {
                                        shareVcard(intent);
                                        return;
                                    }
                                    if (TextUtils.isEmpty(copyFileInAppStorageIfNeededAndReturnPath)) {
                                        str3 = str5;
                                        str4 = str6;
                                    } else {
                                        zangiMessage.setMessageType(MessageType.file);
                                        ZangiFileInfo generateZangiFileInfo = ZangiFileUtils.generateZangiFileInfo(new File(copyFileInAppStorageIfNeededAndReturnPath));
                                        try {
                                            String writeValueAsString = new ObjectMapper().writeValueAsString(generateZangiFileInfo);
                                            zangiMessage.setMsg(generateZangiFileInfo.getFileName());
                                            zangiMessage.setExt(generateZangiFileInfo.getFileType());
                                            str3 = str5;
                                            str4 = str6;
                                            zangiMessage.setFileSize(generateZangiFileInfo.getFileSize().longValue());
                                            zangiMessage.setMsgInfo(writeValueAsString);
                                            zangiMessage.setZangiFileInfo(generateZangiFileInfo);
                                        } catch (JsonProcessingException e) {
                                            Log.e(TAG, "cant serialize fileInfo !!!!");
                                            e.printStackTrace();
                                            return;
                                        }
                                    }
                                    zangiMessage.setFilePath(copyFileInAppStorageIfNeededAndReturnPath);
                                    arrayList2.add(zangiMessage);
                                }
                                str3 = str5;
                                str4 = str6;
                                zangiMessage.setMessageType(MessageType.video);
                                zangiMessage.setFilePath(copyFileInAppStorageIfNeededAndReturnPath);
                                arrayList2.add(zangiMessage);
                            }
                            str3 = str5;
                            str4 = str6;
                            zangiMessage.setMessageType(MessageType.image);
                            zangiMessage.setFilePath(copyFileInAppStorageIfNeededAndReturnPath);
                            arrayList2.add(zangiMessage);
                        }
                        i++;
                        parcelableArrayListExtra = arrayList;
                        str7 = str2;
                        str5 = str3;
                        str6 = str4;
                    }
                }
                sendFileMessagesListAfterShare(arrayList2);
                return;
            } catch (Exception e7) {
                Log.e(TAG, e7.getMessage());
                MainApplication.Companion.getMainHandler().postDelayed(new Runnable() {
                    @Override
                    public final void run() {
                        ShareActivity.this.lambda$handleIntent$1();
                    }
                }, 2000L);
                return;
            }
        }
        if (intent.getAction().equals("android.intent.action.SEND")) {
            Uri uri2 = (Uri) intent.getParcelableExtra("android.intent.extra.STREAM");
            if (type == null || TextUtils.isEmpty(type)) {
                return;
            }
            if (getContentResolver() != null && uri2 != null) {
                this.fileType = getContentResolver().getType(uri2);
            }
            if (this.fileType == null) {
                this.fileType = "";
            }
            String str8 = null;
            if (uri2 != null) {
                str = ZangiFileUtils.copyFileInAppStorageIfNeededAndReturnPath(uri2);
                if (str == null || str.isEmpty()) {
                    String[] split = uri2.getPath().split("/");
                    if (split.length > 0) {
                        str = ZangiFileUtils.saveFile(uri2, PathManager.INSTANCE.getTEMP_DIR(), split[split.length - 1]);
                    }
                }
                this.extension = getFileExt(str);
            } else {
                str = null;
            }
            if (type.startsWith("image/") || this.fileType.contains("image")) {
                ZangiMessage zangiMessage2 = new ZangiMessage();
                this.newZangiMessage = zangiMessage2;
                zangiMessage2.setMessageType(MessageType.image);
                this.filePath = str;
                if (type.length() >= 9 && type.substring(0, 9).equals("image/gif")) {
                    this.filePath = checkGif(this.filePath, type);
                } else if (this.fileType.length() >= 9 && this.fileType.substring(0, 9).equals("image/gif")) {
                    this.filePath = checkGif(this.filePath, this.fileType);
                }
                this.newZangiMessage.setFilePath(this.filePath);
                share(uri2, this.newZangiMessage, this.clipData);
                return;
            }
            if ((type.startsWith("audio/") || this.fileType.contains("audio")) && this.extension.contains("m4a")) {
                ZangiMessage zangiMessage3 = new ZangiMessage();
                this.newZangiMessage = zangiMessage3;
                zangiMessage3.setMessageType(MessageType.voice);
                String copyFileInAppStorageIfNeededAndReturnPath2 = ZangiFileUtils.copyFileInAppStorageIfNeededAndReturnPath(uri2);
                this.filePath = copyFileInAppStorageIfNeededAndReturnPath2;
                this.newZangiMessage.setFilePath(copyFileInAppStorageIfNeededAndReturnPath2);
                MediaPlayer mediaPlayer = new MediaPlayer();
                long j = 0;
                try {
                    mediaPlayer.setDataSource(this.filePath);
                    mediaPlayer.prepare();
                    j = mediaPlayer.getDuration();
                    mediaPlayer.release();
                } catch (Exception e8) {
                    Log.d(TAG, e8.getMessage());
                }
                this.newZangiMessage.setMsg(String.valueOf(ProjectUtils.roundDuration(j)));
                share(uri2, this.newZangiMessage, this.clipData);
                return;
            }
            if (type.startsWith("video/") || this.fileType.contains("video")) {
                ZangiMessage zangiMessage4 = new ZangiMessage();
                this.newZangiMessage = zangiMessage4;
                zangiMessage4.setMessageType(MessageType.video);
                String copyFileInAppStorageIfNeededAndReturnPath3 = ZangiFileUtils.copyFileInAppStorageIfNeededAndReturnPath(uri2);
                this.filePath = copyFileInAppStorageIfNeededAndReturnPath3;
                if (!TextUtils.isEmpty(copyFileInAppStorageIfNeededAndReturnPath3) && !new File(this.filePath).exists() && uri2 != null && uri2.getPath() != null && new File(uri2.getPath()).exists()) {
                    this.filePath = uri2.getPath();
                }
                if (this.filePath == null) {
                    copyInputStreamToOutputStream(uri2);
                }
                this.newZangiMessage.setFilePath(this.filePath);
                share(uri2, this.newZangiMessage, this.clipData);
                return;
            }
            if (type.startsWith("text/x-vcard")) {
                shareVcard(intent);
                return;
            }
            if (uri2 != null || !type.startsWith("text/plain")) {
                if (uri2 != null) {
                    ZangiMessage zangiMessage5 = new ZangiMessage();
                    this.newZangiMessage = zangiMessage5;
                    zangiMessage5.setMessageType(MessageType.file);
                    if (str == null || TextUtils.isEmpty(str)) {
                        return;
                    }
                    ZangiFileInfo generateZangiFileInfo2 = ZangiFileUtils.generateZangiFileInfo(new File(str));
                    this.newZangiMessage.setFilePath(str);
                    try {
                        String writeValueAsString2 = new ObjectMapper().writeValueAsString(generateZangiFileInfo2);
                        this.newZangiMessage.setFileSize(generateZangiFileInfo2.getFileSize().longValue());
                        this.newZangiMessage.setMsg(generateZangiFileInfo2.getFileName());
                        this.newZangiMessage.setExt(generateZangiFileInfo2.getFileType());
                        this.newZangiMessage.setMsgInfo(writeValueAsString2);
                        this.newZangiMessage.setZangiFileInfo(generateZangiFileInfo2);
                        share(uri2, this.newZangiMessage, this.clipData);
                        return;
                    } catch (JsonProcessingException e9) {
                        Log.e(TAG, "cant serialize fileInfo !!!!");
                        e9.printStackTrace();
                        MainApplication.Companion.getMainHandler().postDelayed(new Runnable() {
                            @Override
                            public final void run() {
                                ShareActivity.this.lambda$handleIntent$2();
                            }
                        }, 2000L);
                        return;
                    }
                }
                return;
            }
            String stringExtra = intent.getStringExtra("android.intent.extra.TEXT");
            ZangiMessage zangiMessage6 = new ZangiMessage();
            this.newZangiMessage = zangiMessage6;
            if (stringExtra == null) {
                zangiMessage6.setMessageType(MessageType.file);
            } else if (stringExtra.contains("Mobile:")) {
                String str9 = null;
                for (String str10 : stringExtra.split("\n")) {
                    if (str10.contains("Name:")) {
                        str8 = str10.replace("Name:", "");
                    } else if (str10.contains("Mobile:")) {
                        str9 = str10.replace("Mobile:", "");
                    }
                }
                this.newZangiMessage.setMessageType(MessageType.contact);
                if (str8 != null) {
                    this.newZangiMessage.setMsg(str8);
                } else {
                    this.newZangiMessage.setMsg("");
                }
                String e164WithoutPlus = ZangiEngineUtils.getE164WithoutPlus(str9, ZangiEngineUtils.getZipCode(), false);
                Contact contactByNumber = ContactsManager.INSTANCE.getContactByNumber(e164WithoutPlus);
                Boolean bool = Boolean.FALSE;
                if (contactByNumber != null) {
                    bool = Boolean.valueOf(contactByNumber.isInternal());
                }
                ContactMessageInfo contactMessageInfo = new ContactMessageInfo(e164WithoutPlus, str9, "", "mobile", bool.booleanValue());
                ObjectMapper objectMapper = new ObjectMapper();
                ArrayList arrayList3 = new ArrayList();
                arrayList3.add(contactMessageInfo);
                try {
                    this.newZangiMessage.setMsgInfo(objectMapper.writeValueAsString(arrayList3));
                } catch (JsonProcessingException unused) {
                    ZangiMessage zangiMessage7 = new ZangiMessage();
                    this.newZangiMessage = zangiMessage7;
                    zangiMessage7.setMessageType(MessageType.text);
                    this.newZangiMessage.setMsg(stringExtra);
                }
            } else {
                ZangiMessage zangiMessage8 = new ZangiMessage();
                this.newZangiMessage = zangiMessage8;
                zangiMessage8.setMessageType(MessageType.text);
                this.newZangiMessage.setMsg(stringExtra);
            }
            share(uri2, this.newZangiMessage, this.clipData);
        }
    }

    public void lambda$handleIntent$1() {
        finish();
    }

    public void lambda$handleIntent$2() {
        finish();
    }

    public void lambda$onCreate$0(ArrayList arrayList, boolean z) {
        if (z) {
            handleIntent();
        } else {
            finish();
        }
    }

    public void lambda$shareVcard$3() {
        finish();
    }

    public void lambda$shareVcard$4() {
        finish();
    }

    private void sendFileMessageAfterShare() {
        ConversationManager.INSTANCE.setFromShareActivity(true);
        if (!LoginManager.INSTANCE.getAutoLogin()) {
            Intent intent = new Intent((Context) this, (Class<?>) MainActivity.class);
            intent.addFlags(268435456);
            startActivity(intent);
        } else {
            ArrayList<ZangiMessage> arrayList = new ArrayList<>();
            arrayList.add(this.newZangiMessage);
            Intent intent2 = new Intent((Context) this, (Class<?>) ForwardMessageActivity.class);
            ForwardMessageAndBalanceTransferFragment.Companion.setMessageList(arrayList);
            intent2.putExtra(Constants.FORWARD_MESSAGE_TITLE, 2131886588);
            startActivity(intent2);
        }
    }

    private void sendFileMessagesListAfterShare(ArrayList<ZangiMessage> arrayList) {
        ConversationManager.INSTANCE.setFromShareActivity(true);
        Intent intent = new Intent((Context) this, (Class<?>) ForwardMessageActivity.class);
        intent.putExtra(Constants.FORWARD_MESSAGE_TITLE, 2131886587);
        ForwardMessageAndBalanceTransferFragment.Companion.setMessageList(arrayList);
        startActivity(intent);
    }

    private void sendTextMessageAfterShare(ArrayList<ZangiMessage> arrayList) {
        ConversationManager.INSTANCE.setFromShareActivity(true);
        if (!LoginManager.INSTANCE.getAutoLogin()) {
            Intent intent = new Intent((Context) this, (Class<?>) MainActivity.class);
            intent.addFlags(268435456);
            startActivity(intent);
        } else {
            Intent intent2 = new Intent((Context) this, (Class<?>) ForwardMessageActivity.class);
            intent2.putExtra(Constants.FORWARD_MESSAGE_TITLE, 2131886588);
            ForwardMessageAndBalanceTransferFragment.Companion.setMessageList(arrayList);
            startActivity(intent2);
        }
    }

    private void share(Uri uri, ZangiMessage zangiMessage, ClipData clipData) {
        if (uri != null) {
            sendFileMessageAfterShare();
        } else if (clipData != null) {
            ArrayList<ZangiMessage> arrayList = new ArrayList<>();
            arrayList.add(zangiMessage);
            sendTextMessageAfterShare(arrayList);
        }
    }

    private void shareVcard(android.content.Intent r18) {
        throw new UnsupportedOperationException("Method not decompiled: com.beint.project.screens.ShareActivity.shareVcard(android.content.Intent):void");
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.clipData = getIntent().getClipData();
        if (ZangiPermissionUtils.hasPermission(this, 1007, true, new ZangiPermissionUtils.OnPermissionResult() {
            public final void onResult(ArrayList arrayList, boolean z) {
                ShareActivity.this.lambda$onCreate$0(arrayList, z);
            }
        })) {
            handleIntent();
        }
    }
}