96 lines
3.3 KiB
Java
96 lines
3.3 KiB
Java
package com.tencent.mm.opensdk.modelmsg;
|
|
|
|
import android.graphics.Bitmap;
|
|
import android.os.Bundle;
|
|
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
|
|
import com.tencent.mm.opensdk.utils.Log;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.File;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class WXImageObject implements WXMediaMessage.IMediaObject {
|
|
private static final int CONTENT_LENGTH_LIMIT = 10485760;
|
|
private static final int PATH_LENGTH_LIMIT = 10240;
|
|
private static final String TAG = "MicroMsg.SDK.WXImageObject";
|
|
public byte[] imageData;
|
|
public String imagePath;
|
|
|
|
public WXImageObject() {
|
|
}
|
|
|
|
public WXImageObject(Bitmap bitmap) {
|
|
try {
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, byteArrayOutputStream);
|
|
this.imageData = byteArrayOutputStream.toByteArray();
|
|
byteArrayOutputStream.close();
|
|
} catch (Exception e) {
|
|
Log.e(TAG, "WXImageObject <init>, exception:" + e.getMessage());
|
|
}
|
|
}
|
|
|
|
public WXImageObject(byte[] bArr) {
|
|
this.imageData = bArr;
|
|
}
|
|
|
|
private int getFileSize(String str) {
|
|
if (str == null || str.length() == 0) {
|
|
return 0;
|
|
}
|
|
File file = new File(str);
|
|
if (file.exists()) {
|
|
return (int) file.length();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@Override // com.tencent.mm.opensdk.modelmsg.WXMediaMessage.IMediaObject
|
|
public boolean checkArgs() {
|
|
String str;
|
|
String str2;
|
|
byte[] bArr = this.imageData;
|
|
if ((bArr == null || bArr.length == 0) && ((str = this.imagePath) == null || str.length() == 0)) {
|
|
str2 = "checkArgs fail, all arguments are null";
|
|
} else {
|
|
byte[] bArr2 = this.imageData;
|
|
if (bArr2 == null || bArr2.length <= CONTENT_LENGTH_LIMIT) {
|
|
String str3 = this.imagePath;
|
|
if (str3 == null || str3.length() <= PATH_LENGTH_LIMIT) {
|
|
String str4 = this.imagePath;
|
|
if (str4 == null || getFileSize(str4) <= CONTENT_LENGTH_LIMIT) {
|
|
return true;
|
|
}
|
|
str2 = "checkArgs fail, image content is too large";
|
|
} else {
|
|
str2 = "checkArgs fail, path is invalid";
|
|
}
|
|
} else {
|
|
str2 = "checkArgs fail, content is too large";
|
|
}
|
|
}
|
|
Log.e(TAG, str2);
|
|
return false;
|
|
}
|
|
|
|
@Override // com.tencent.mm.opensdk.modelmsg.WXMediaMessage.IMediaObject
|
|
public void serialize(Bundle bundle) {
|
|
bundle.putByteArray("_wximageobject_imageData", this.imageData);
|
|
bundle.putString("_wximageobject_imagePath", this.imagePath);
|
|
}
|
|
|
|
public void setImagePath(String str) {
|
|
this.imagePath = str;
|
|
}
|
|
|
|
@Override // com.tencent.mm.opensdk.modelmsg.WXMediaMessage.IMediaObject
|
|
public int type() {
|
|
return 2;
|
|
}
|
|
|
|
@Override // com.tencent.mm.opensdk.modelmsg.WXMediaMessage.IMediaObject
|
|
public void unserialize(Bundle bundle) {
|
|
this.imageData = bundle.getByteArray("_wximageobject_imageData");
|
|
this.imagePath = bundle.getString("_wximageobject_imagePath");
|
|
}
|
|
}
|