Commit ebb7dca2 authored by silver47gin's avatar silver47gin
Browse files

增加Taro-RN代码

parent fc039aac
package com.tencent.wework.api.model;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.util.Log;
/**
* Created by hu on 16/8/1.
* 消息合并转发
*/
public class WWMediaMergedConvs extends WWMediaMessage.WWMediaObject {
private static final String TAG = "WWAPI.WWMediaConv";
/**
* 消息列表 可以是 这里定义的各种消息和集合
*/
public List<WWMediaConversation> messages = new ArrayList<WWMediaConversation>();
public boolean addItem(WWMediaConversation wc){
if(wc != null && wc.checkArgs()){
messages.add(wc);
return true;
}
return false;
}
@Override
public int getType() {
return WWMediaMessage.WWMediaObject.TYPE_MERGED_CONVERSATION;
}
@Override
public boolean checkArgs() {
if (!super.checkArgs()) {
return false;
}
if (this.messages == null || this.messages.size() == 0) {
Log.d(TAG, "checkArgs fail, all arguments are null");
return false;
}
boolean ret = true;
for (BaseMessage msg : messages) {
if (!msg.checkArgs()) {
ret = false;
break;
}
}
return ret;
}
public void toBundle(Bundle var1) {
var1.putInt("_wwmergedconvobject_messageslen", messages.size());
for (int i = 0; i < messages.size(); i++) {
var1.putBundle("_wwmergedconvobject_messages" + i, BaseMessage.pack(messages.get(i)));
}
super.toBundle(var1);
}
public void fromBundle(Bundle var1) {
int len = var1.getInt("_wwmergedconvobject_messageslen");
for (int i = 0; i < len; i++) {
BaseMessage msg = BaseMessage.parse(var1.getBundle("_wwmergedconvobject_messages" + i));
if (msg != null && msg instanceof WWMediaConversation) {
messages.add((WWMediaConversation) msg);
} else {
Log.d(TAG, "fromBundle " + (msg==null?"null":msg));
}
}
super.fromBundle(var1);
}
}
package com.tencent.wework.api.model;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.File;
/**
* Created by hu on 16/5/30.
*/
public class WWMediaMessage extends WWBaseMessage {
private static final String TAG = "WWAPI.WWMediaMessage";
public static final int THUMB_LENGTH_LIMIT = 32768;
private static final int TITLE_LENGTH_LIMIT = 512;
private static final int DESCRIPTION_LENGTH_LIMIT = 1024;
private static final int MEDIA_TAG_NAME_LENGTH_LIMIT = 64;
private static final int MESSAGE_ACTION_LENGTH_LIMIT = 2048;
private static final int MESSAGE_EXT_LENGTH_LIMIT = 2048;
public String title;
public String description;
public byte[] thumbData;
@Override
public int getType() {
return BaseMessage.TYPE_SHARE_MESSAGE;
}
public void toBundle(Bundle var1) {
super.toBundle(var1);
var1.putString("_wwobject_title", title);
var1.putString("_wwobject_description", description);
var1.putByteArray("_wwobject_thumbdata", thumbData);
}
public void fromBundle(Bundle var1) {
super.fromBundle(var1);
title = var1.getString("_wwobject_title");
description = var1.getString("_wwobject_description");
var1.putByteArray("_wwobject_thumbdata", thumbData);
}
public final void setThumbImage(Bitmap var1) {
try {
ByteArrayOutputStream var2 = new ByteArrayOutputStream();
var1.compress(Bitmap.CompressFormat.JPEG, 85, var2);
this.thumbData = var2.toByteArray();
var2.close();
} catch (Exception var3) {
var3.printStackTrace();
Log.d(TAG, "put thumb failed");
}
}
public boolean checkArgs() {
if(this.thumbData != null && this.thumbData.length > THUMB_LENGTH_LIMIT) {
Log.d(TAG, "checkArgs fail, thumbData is invalid");
return false;
} else if(this.title != null && this.title.length() > TITLE_LENGTH_LIMIT) {
Log.d(TAG, "checkArgs fail, title is invalid");
return false;
} else if(this.description != null && this.description.length() > DESCRIPTION_LENGTH_LIMIT) {
Log.d(TAG, "checkArgs fail, description is invalid");
return false;
}else {
return true;
}
}
public static abstract class WWMediaObject extends WWMediaMessage {
public static final int TYPE_UNKNOWN = 0;
public static final int TYPE_TEXT = 1;
public static final int TYPE_IMAGE = 2;
public static final int TYPE_URL = 5;
public static final int TYPE_FILE = 6;
public static final int TYPE_VIDEO = 7;
public static final int TYPE_CONVERSATION = 8;
public static final int TYPE_MERGED_CONVERSATION = 9;
public static final int TYPE_LOC = 10;
protected int getFileSize(String var1) {
File var2;
return var1 != null && var1.length() != 0 ? (!(var2 = new File(var1)).exists() ? 0 : (int) var2.length()) : 0;
}
}
}
package com.tencent.wework.api.model;
import android.os.Bundle;
import android.util.Log;
/**
* Created by hu on 16/5/30.
* ı
*/
public class WWMediaText extends WWMediaMessage.WWMediaObject {
private static final String TAG = "WWAPI.WWMediaText";
private static final int LENGTH_LIMIT = 10240;
/**
* ı
*/
public String text;
public WWMediaText(){
}
public WWMediaText(String txt){
text = txt;
}
@Override
public int getType() {
return WWMediaMessage.WWMediaObject.TYPE_TEXT;
}
@Override
public boolean checkArgs() {
if(!super.checkArgs()){
return false;
}
if (this.text != null && this.text.length() != 0 && this.text.length() <= LENGTH_LIMIT) {
return true;
} else {
Log.d(TAG, "checkArgs fail, text is invalid");
return false;
}
}
public void toBundle(Bundle var1) {
var1.putString("_wwtextobject_text", text);
super.toBundle(var1);
}
public void fromBundle(Bundle var1) {
text = var1.getString("_wwtextobject_text");
super.fromBundle(var1);
}
}
package com.tencent.wework.api.model;
/**
* Created by hu on 16/5/30.
* Ƶ
*/
public class WWMediaVideo extends WWMediaFile {
private static final String TAG = "WWAPI.WWMediaVideo";
@Override
public int getType() {
return WWMediaMessage.WWMediaObject.TYPE_VIDEO;
}
}
package com.tencent.wework.api.util;
import android.util.Log;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* 类的字段方法获取工具类,为了提高效率,采用了状态机的工作方式
*
* @author boyliang
*/
public final class ReflecterHelper {
private static final String LOG_TAG = "ReflecterHelper";
public static Class<?> mCurrentClass;
/**
* 设置
*
* @param name
* 类的完整路径
* @return 是否设置成功
*/
public final static boolean setClass(String name) {
Class<?> tmpClass = null;
try {
tmpClass = Class.forName(name);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
mCurrentClass = tmpClass;
return mCurrentClass != null;
}
public final static int getStaticIntValue(String name, int defvalue) {
int result = defvalue;
Field field = getField(name);
if (field != null) {
try {
result = field.getInt(null);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return result;
}
public final static int getIntValue(Object owner, String name, int defvalue) {
int result = defvalue;
setClass(owner.getClass().getName());
Field field = getField(name);
if (field != null) {
try {
result = field.getInt(owner);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return result;
}
private final static Field getField(String name) {
Field field = null;
try {
field = mCurrentClass.getDeclaredField(name);
field.setAccessible(true);
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
return field;
}
/**
* 得到某个类的静态属性
*
* @param className
* @param fieldName
* @return
* @throws Exception
*/
public static Object getStaticProperty(String className, String fieldName) {
setClass(className);
Field field = getField(fieldName);
Object result = null;
if (field != null) {
try {
result = field.get(null);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return result;
}
public static void setStaticProperty(String className, String fieldName, Object value) {
setClass(className);
Field field = getField(fieldName);
if (field != null) {
try {
field.set(null, value);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 实例化对象;; 只支持 没有null对象和 只有String对象是null的情况
*
* @param className
* @param args
* @return
* @throws Exception
*/
static public Object newInstance(String className, Object[] args) throws Exception {
Class<?> newoneClass = Class.forName(className);
Constructor<?> cons = newoneClass.getDeclaredConstructor(getArgsClasses(args));
cons.setAccessible(true);
return cons.newInstance(args);
}
/**
* 实例化对象
*
* @param className
* @param args
* @return
* @throws Exception
*/
static public Object newInstance(String className) throws Exception {
return newInstance(className, (Object[]) null);
}
/**
* 执行某对象的方法; 只支持 没有null对象和 只有String对象是null的情况
*
* @param owner
* @param methodName
* @param args
* @return
* @throws Exception
*/
static public Object invokeMethod(Object owner, String methodName, Object[] args)
throws Exception {
return invokeMethod(owner, methodName, getArgsClasses(args), args);
}
/**
* 执行某对象的无参方法
*
* @param owner
* @param methodName
* @param args
* @return
* @throws Exception
*/
static public Object invokeMethod(Object owner, String methodName) throws Exception {
return invokeMethod(owner, methodName, null);
}
/**
* 执行某对象的方法
*
* @param owner
* @param methodName
* @param args
* @return
* @throws Exception
*/
static public Object invokeMethod(Object owner, String methodName, Class<?> argsClass[],
Object[] args) throws Exception {
Class<?> ownerClass = owner.getClass();
Method method = null;
try {
method = ownerClass.getDeclaredMethod(methodName, argsClass);
} catch (Exception e) {
if (method == null && ownerClass.getSuperclass() != null) {
method = ownerClass.getSuperclass().getDeclaredMethod(methodName, argsClass);
}
if (method == null) {
throw e;
}
}
method.setAccessible(true);
return method.invoke(owner, args);
}
/**
* 获取某对象的属性
*
* @param owner
* @param fieldName
* @return
* @throws Exception
*/
public static Object getProperty(Object owner, String fieldName) throws Exception {
Field field = getFieldInternal(owner, fieldName);
field.setAccessible(true);
Object property = field.get(owner);
return property;
}
public static boolean setPropertyNoThrowable(Object owner, String fieldName, Object value) {
try {
setPropertyInternal(owner, fieldName, value);
return true;
} catch (Exception e) {
return false;
}
}
public static void setProperty(Object owner, String fieldName, Object value) throws Exception {
setPropertyInternal(owner, fieldName, value);
}
private static void setPropertyInternal(Object owner, String fieldName, Object value)
throws Exception {
if (null == owner) {
throw new NullPointerException("setProperty null owner");
}
Field field = getFieldInternal(owner, fieldName);
try {
field.setAccessible(true);
field.set(owner, value);
} catch (Exception e) {
// protect
throw e;
}
}
private static Field getFieldInternal(Object owner, String fieldName)
throws NoSuchFieldException {
Class<?> cls = null;
Field field = null;
for (cls = owner.getClass(); null != cls; cls = cls.getSuperclass()) {
try {
field = cls.getDeclaredField(fieldName);
break;
} catch (NoSuchFieldException e) {
field = null;
}
}
if (null == field) {
throw new NoSuchFieldException("setProperty field " + fieldName + " not found");
}
return field;
}
public static Object newInstance(String className, Object args[], Class<?> argsClass[])
throws Exception {
Class<?> newoneClass = Class.forName(className);
Constructor<?> cons = newoneClass.getDeclaredConstructor(argsClass);
cons.setAccessible(true);
return cons.newInstance(args);
}
public static void dump(Class<?> cls) {
Log.v(LOG_TAG, cls.getCanonicalName());
Method[] methods = cls.getMethods();
for (Method method : methods) {
Class<?>[] params = method.getParameterTypes();
StringBuilder sb = new StringBuilder();
sb.append(" - ");
sb.append(method.getReturnType());
sb.append(' ');
sb.append(method.getName());
sb.append('(');
final int length = params.length;
for (int i = 0; i != length; ++i) {
sb.append(params[i].getName());
if (i != length - 1) {
sb.append(", ");
}
}
sb.append(')');
Log.v(LOG_TAG, sb.toString());
}
}
public static Method reflectStaticMethod(String className, String methodName,
Class<?> argsClass[]) throws Exception {
Class<?> cls = Class.forName(className);
return reflectStaticMethod(cls, methodName, argsClass);
}
public static Method reflectStaticMethod(Class<?> cls, String methodName, Class<?> argsClass[])
throws Exception {
Method staticMethod = null;
try {
staticMethod = cls.getDeclaredMethod(methodName, argsClass);
} catch (Exception e) {
if (staticMethod == null && cls.getSuperclass() != null) {
staticMethod = cls.getSuperclass().getDeclaredMethod(methodName, argsClass);
}
if (staticMethod == null) {
throw e;
}
}
staticMethod.setAccessible(true);
return staticMethod;
}
public static Object invokeStaticMethod(String className, String methodName, Object args[],
Class<?> argsClass[]) throws Exception {
Class<?> cls = Class.forName(className);
Method staticMethod = null;
Object ret = null;
try {
staticMethod = cls.getDeclaredMethod(methodName, argsClass);
} catch (Exception e) {
if (staticMethod == null && cls.getSuperclass() != null) {
staticMethod = cls.getSuperclass().getDeclaredMethod(methodName, argsClass);
}
if (staticMethod == null) {
throw e;
}
}
staticMethod.setAccessible(true);
ret = staticMethod.invoke(cls, args);
return ret;
}
/**
* 只支持 没有null对象和 只有String对象是null的情况
*
* @param className
* @param methodName
* @param args
* @return
* @throws Exception
*
* @author yuanhanhu in 2013-5-10
*/
public static Object invokeStaticMethod(String className, String methodName, Object args[])
throws Exception {
return invokeStaticMethod(className, methodName, args, getArgsClasses(args));
}
public static Object invokeStaticMethod(String className, String methodName) throws Exception {
return invokeStaticMethod(className, methodName, (Object[]) null);
}
private static Class<?>[] getArgsClasses(Object[] args) {
Class<?>[] argsClass = (Class<?>[]) null;
if (args != null) {
argsClass = new Class<?>[args.length];
for (int i = 0, j = args.length; i < j; i++) {
if (args[i] != null) {
argsClass[i] = args[i].getClass();
} else {
argsClass[i] = String.class;
}
if (argsClass[i] == Integer.class) {
argsClass[i] = int.class;
} else if (argsClass[i] == Boolean.class) {
argsClass[i] = boolean.class;
} else if (argsClass[i] == Long.class) {
argsClass[i] = long.class;
}
}
}
return argsClass;
}
public static Field[] getDeclaredFields(Object clsObj) {
Field[] fieldList = null;
if (clsObj != null) {
try {
Class<?> ownerClass = clsObj.getClass();
if (ownerClass != null) {
fieldList = ownerClass.getDeclaredFields();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return fieldList;
}
public static Method[] getDeclaredMethods(Object clsObj) {
Method[] methodList = null;
if (clsObj != null) {
try {
Class<?> ownerClass = clsObj.getClass();
if (ownerClass != null) {
methodList = ownerClass.getDeclaredMethods();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return methodList;
}
public static Class<?> getClass(String name) {
try {
return Class.forName(name);
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
}
<resources>
<!-- <string name="app_name">taroDemo</string> -->
<string moduleConfig="true" name="CodePushDeploymentKey">x_8Lkp25JM0jYK8RzQ6GwxF-4QqmiwvBVr-GY</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
</style>
</resources>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
}
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
maven {
// expo-camera bundles a custom com.google.android:cameraview
url "$rootDir/../node_modules/expo-camera/android/maven"
}
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://www.jitpack.io' }
google()
jcenter()
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment