fix(android): as inspect code

This commit is contained in:
maxli
2021-03-16 15:42:38 +08:00
committed by siguangli
parent 488e88622d
commit 650d226c0a
38 changed files with 367 additions and 480 deletions
@@ -38,13 +38,8 @@ import com.tencent.mtt.hippy.adapter.soloader.DefaultSoLoaderAdapter;
import com.tencent.mtt.hippy.adapter.soloader.HippySoLoaderAdapter;
import com.tencent.mtt.hippy.adapter.storage.DefaultStorageAdapter;
import com.tencent.mtt.hippy.adapter.storage.HippyStorageAdapter;
import com.tencent.mtt.hippy.utils.LogUtils;
/**
* FileName: HippyGlobalConfigs
* Description:
* History:
* 1.0 xiandongluo on 2017/11/13
*/
public class HippyGlobalConfigs
{
/**
@@ -163,7 +158,7 @@ public class HippyGlobalConfigs
}
catch (Throwable e)
{
LogUtils.d("HippyGlobalConfigs", "destroyIfNeed: " + e.getMessage());
}
}
@@ -18,15 +18,9 @@ package com.tencent.mtt.hippy.adapter.sharedpreferences;
import android.content.Context;
import android.content.SharedPreferences;
/**
* FileName: DefaultSharedPreferencesAdapter
* Description:
* History:
* 1.0 xiandongluo on 2017/11/13
*/
public class DefaultSharedPreferencesAdapter implements HippySharedPreferencesAdapter {
private Context mContext;
private final Context mContext;
public DefaultSharedPreferencesAdapter(Context context){
this.mContext = context;
}
@@ -27,18 +27,13 @@ import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* FileName: DefaultStorageAdapter
* Description:
* History:
*/
public class DefaultStorageAdapter implements HippyStorageAdapter
{
static final int MAX_SQL_KEYS = 999;
private IHippySQLiteHelper mSQLiteHelper;
private Executor mExecutor;
private ExecutorService mExecutorService;
static final int MAX_SQL_KEYS = 999;
private final IHippySQLiteHelper mSQLiteHelper;
private Executor mExecutor;
private ExecutorService mExecutorService;
public DefaultStorageAdapter(Context context)
{
@@ -271,9 +271,8 @@ public class HippyBridgeImpl implements HippyBridge, DevRemoteDebugProxy.OnRecei
if (mCodeCacheThreadExecutor != null) {
mCodeCacheThreadExecutor.shutdownNow();
}
}
catch (Throwable e) {
} catch (Throwable e) {
LogUtils.d("HippyBridgeImpl", "onDestroy: " + e.getMessage());
}
mCodeCacheThreadExecutor = null;
}
@@ -447,21 +446,15 @@ public class HippyBridgeImpl implements HippyBridge, DevRemoteDebugProxy.OnRecei
}
}
public void postCodeCacheRunnable(String codeCacheFile, long nativeRunnableId)
{
try
{
synchronized (sBridgeSyncLock)
{
if (mCodeCacheThreadExecutor != null)
{
public void postCodeCacheRunnable(String codeCacheFile, long nativeRunnableId) {
try {
synchronized (sBridgeSyncLock) {
if (mCodeCacheThreadExecutor != null) {
mCodeCacheThreadExecutor.execute(new CodeCacheRunnable(codeCacheFile, nativeRunnableId));
}
}
}
catch (Throwable e)
{
} catch (Throwable e) {
LogUtils.d("HippyBridgeImpl", "postCodeCacheRunnable: " + e.getMessage());
}
}
@@ -37,6 +37,7 @@ import com.tencent.mtt.hippy.modules.HippyModuleManager;
import com.tencent.mtt.hippy.utils.ArgumentUtils;
import com.tencent.mtt.hippy.utils.DimensionsUtil;
import com.tencent.mtt.hippy.utils.GrowByteBuffer;
import com.tencent.mtt.hippy.utils.LogUtils;
import com.tencent.mtt.hippy.utils.UIThreadUtils;
import java.util.ArrayList;
@@ -327,6 +328,7 @@ public class HippyBridgeManagerImpl implements HippyBridgeManager, HippyBridge.B
}
catch (Throwable e)
{
LogUtils.d("HippyBridgeManagerImpl", "handleMessage: " + e.getMessage());
}
return false;
}
@@ -460,7 +462,7 @@ public class HippyBridgeManagerImpl implements HippyBridgeManager, HippyBridge.B
@Override
public void destroyBridge(Callback<Boolean> callback) {
mHandler = new Handler(mContext.getThreadExecutor().getJsThread().getLooper(), this);
assert (mHandler != null);
Message message = mHandler.obtainMessage(MSG_CODE_DESTROY_BRIDGE, callback);
mHandler.sendMessage(message);
}
@@ -52,7 +52,7 @@ public class ThreadExecutorManager implements ThreadExecutor.UncaughtExceptionHa
LogUtils.e("Hippy", "add same engine twice");
}
} catch (Exception e) {
LogUtils.d("ThreadExecutorManager", "add: " + e.getMessage());
}
}
@@ -93,7 +93,7 @@ public class ThreadExecutorManager implements ThreadExecutor.UncaughtExceptionHa
destroyThreadExecutor(groupId);
}
} catch (Exception e) {
LogUtils.d("ThreadExecutorManager", "remove: " + e.getMessage());
}
}
@@ -22,6 +22,7 @@ import com.tencent.mtt.hippy.adapter.http.HippyHttpRequest;
import com.tencent.mtt.hippy.adapter.http.HippyHttpResponse;
import com.tencent.mtt.hippy.modules.nativemodules.HippySettableFuture;
import com.tencent.mtt.hippy.utils.LogUtils;
import java.io.*;
import java.util.Locale;
@@ -147,7 +148,7 @@ public class DevServerHelper
}
catch (Throwable e)
{
e.printStackTrace();
LogUtils.d("DevServerHelper", "fetchBundleFromURL: " + e.getMessage());
}
finally
{
@@ -159,6 +160,7 @@ public class DevServerHelper
}
catch (IOException e)
{
LogUtils.d("DevServerHelper", "fetchBundleFromURL: " + e.getMessage());
}
}
}
@@ -28,7 +28,7 @@ import java.util.Map;
public class ChoreographerCompat
{
private static boolean IS_JELLY_BEAN = Build.VERSION.SDK_INT >= 16;
private final static boolean IS_JELLY_BEAN = Build.VERSION.SDK_INT >= 16;
private static ChoreographerCompat sInstance;
private ChoreographerCompat()
@@ -45,7 +45,7 @@ public class ChoreographerCompat
return sInstance;
}
private Map<HippyChoreographer.FrameCallback, Choreographer.FrameCallback> mMapper = new HashMap<>();
private final Map<HippyChoreographer.FrameCallback, Choreographer.FrameCallback> mMapper = new HashMap<>();
public void postFrameCallback(final HippyChoreographer.FrameCallback callback)
{
@@ -17,6 +17,7 @@
package com.tencent.mtt.hippy.dom;
import com.tencent.mtt.hippy.utils.LogUtils;
import java.util.ArrayDeque;
/**
@@ -74,7 +75,7 @@ public class HippyChoreographer
}
catch (Exception e)
{
LogUtils.d("HippyChoreographer", "postFrameCallback: " + e.getMessage());
}
}
}
@@ -36,236 +36,228 @@ import com.tencent.mtt.hippy.utils.UrlUtils;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
public class HippyImageSpan extends ImageSpan
{
public final static int STATE_UNLOAD = 0;
public final static int STATE_LOADING = 1;
public final static int STATE_LOADED = 2;
private int mLeft;
private int mTop;
private int mWidth;
private int mHeight;
private String mUrl;
private WeakReference<ImageNode> mImageNodeWeakRefrence;
private int mImageLoadState = 0;
private int mVerticalAlignment;
private HippyImageLoader mImageAdapter;
private Movie mGifMovie = null;
private int mRepeatCount = -1;
private int mShowCount = 0;
private int mGifStartX = 0;
private int mGifStartY = 0;
private float mGifScaleX = 1;
private float mGifScaleY = 1;
private boolean mGifMatrixComputed = false;
private int mGifProgress = 0;
private long mGifLastPlayTime = -1;
public HippyImageSpan(Drawable d, String source, ImageNode node, HippyImageLoader imageAdapter) {
super(d, source, node.getVerticalAlignment());
public class HippyImageSpan extends ImageSpan {
mImageNodeWeakRefrence = new WeakReference<ImageNode> (node);
mImageAdapter = imageAdapter;
setUrl(source);
}
private void updateBoundsAttribute() {
if (mImageNodeWeakRefrence != null) {
ImageNode node = mImageNodeWeakRefrence.get();
if (node != null) {
int width = Math.round(node.getStyleWidth());
int height = Math.round(node.getStyleHeight());
float y = node.getPosition(FlexSpacing.TOP);
float x = node.getPosition(FlexSpacing.LEFT);
int left = (x == Float.NaN) ? 0 : Math.round(x);
int top = (y == Float.NaN) ? 0 : Math.round(y);
mLeft = left;
mTop = top;
mWidth = width;
mHeight = height;
mVerticalAlignment = node.getVerticalAlignment();
}
public final static int STATE_UNLOAD = 0;
public final static int STATE_LOADING = 1;
public final static int STATE_LOADED = 2;
private int mLeft;
private int mTop;
private int mWidth;
private int mHeight;
private String mUrl;
private WeakReference<ImageNode> mImageNodeWeakRefrence;
private int mImageLoadState = 0;
private int mVerticalAlignment;
private HippyImageLoader mImageAdapter;
private Movie mGifMovie = null;
private int mRepeatCount = -1;
private int mShowCount = 0;
private int mGifStartX = 0;
private int mGifStartY = 0;
private float mGifScaleX = 1;
private float mGifScaleY = 1;
private boolean mGifMatrixComputed = false;
private int mGifProgress = 0;
private long mGifLastPlayTime = -1;
public HippyImageSpan(Drawable d, String source, ImageNode node,
HippyImageLoader imageAdapter) {
super(d, source, node.getVerticalAlignment());
mImageNodeWeakRefrence = new WeakReference<ImageNode>(node);
mImageAdapter = imageAdapter;
setUrl(source);
}
}
protected boolean shouldUseFetchImageMode(String url)
{
return UrlUtils.isWebUrl(url) || UrlUtils.isFileUrl(url);
}
private void loadImageWithUrl(String url) {
if (TextUtils.isEmpty(mUrl) || !mUrl.equals(url)) {
mUrl = url;
mImageLoadState = STATE_UNLOAD;
updateBoundsAttribute();
if (mImageAdapter != null) {
if (shouldUseFetchImageMode(mUrl)) {
final HippyMap props = new HippyMap();
props.pushBoolean(NodeProps.CUSTOM_PROP_ISGIF, false);
props.pushInt(NodeProps.WIDTH, mWidth);
props.pushInt(NodeProps.HEIGHT, mHeight);
doFetchImage(mUrl, props, mImageAdapter);
private void updateBoundsAttribute() {
if (mImageNodeWeakRefrence != null) {
ImageNode node = mImageNodeWeakRefrence.get();
if (node != null) {
int width = Math.round(node.getStyleWidth());
int height = Math.round(node.getStyleHeight());
float y = node.getPosition(FlexSpacing.TOP);
float x = node.getPosition(FlexSpacing.LEFT);
int left = (x == Float.NaN) ? 0 : Math.round(x);
int top = (y == Float.NaN) ? 0 : Math.round(y);
mLeft = left;
mTop = top;
mWidth = width;
mHeight = height;
mVerticalAlignment = node.getVerticalAlignment();
}
}
}
protected boolean shouldUseFetchImageMode(String url) {
return UrlUtils.isWebUrl(url) || UrlUtils.isFileUrl(url);
}
private void loadImageWithUrl(String url) {
if (TextUtils.isEmpty(mUrl) || !mUrl.equals(url)) {
mUrl = url;
mImageLoadState = STATE_UNLOAD;
updateBoundsAttribute();
if (mImageAdapter != null) {
if (shouldUseFetchImageMode(mUrl)) {
final HippyMap props = new HippyMap();
props.pushBoolean(NodeProps.CUSTOM_PROP_ISGIF, false);
props.pushInt(NodeProps.WIDTH, mWidth);
props.pushInt(NodeProps.HEIGHT, mHeight);
doFetchImage(mUrl, props, mImageAdapter);
} else {
HippyDrawable hippyDrawable = mImageAdapter.getImage(mUrl, null);
shouldReplaceDrawable(hippyDrawable);
}
}
}
}
public void setUrl(final String url) {
if (UIThreadUtils.isOnUiThread()) {
loadImageWithUrl(url);
} else {
HippyDrawable hippyDrawable = mImageAdapter.getImage(mUrl, null);
shouldReplaceDrawable(hippyDrawable);
UIThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
loadImageWithUrl(url);
}
});
}
}
}
}
public void setUrl(final String url) {
if (UIThreadUtils.isOnUiThread()) {
loadImageWithUrl(url);
} else {
UIThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
loadImageWithUrl(url);
}
});
}
}
private boolean drawGIF(Canvas canvas, float left, float top, int width, int height) {
if (mGifMovie == null)
return false;
int duration = mGifMovie.duration();
if (duration == 0) {
duration = 1000;
}
long now = System.currentTimeMillis();
if (mGifLastPlayTime != -1)
{
mGifProgress += now - mGifLastPlayTime;
if (mGifProgress > duration)
{
mGifProgress = 0;
}
mGifLastPlayTime = now;
}
else
{
mGifLastPlayTime = now;
}
mGifScaleX = width / (float) mGifMovie.width();
mGifScaleY = height / (float) mGifMovie.height();
float x = (mGifScaleX != 0) ? left/mGifScaleX : left;
float y = (mGifScaleY != 0) ? top/mGifScaleY : top;
mGifMovie.setTime(mGifProgress);
canvas.save();
canvas.scale(mGifScaleX, mGifScaleY);
mGifMovie.draw(canvas, x, y);
canvas.restore();
postInvalidateDelayed(40);
return false;
}
@Override
public void draw(Canvas canvas, CharSequence text,
int start, int end, float x,
int top, int y, int bottom, Paint paint) {
int transY = top;
Paint.FontMetricsInt fm = paint.getFontMetricsInt();
if (mGifMovie != null) {
int width = (mWidth == 0) ? mGifMovie.width() : mWidth;
int height = (mHeight == 0) ? mGifMovie.height() : mHeight;
transY = (y + fm.descent + y + fm.ascent) / 2 - height / 2;
drawGIF(canvas, x + mLeft, transY + mTop, width, height);
} else if (mVerticalAlignment == ImageSpan.ALIGN_BASELINE) {
Drawable b = getDrawable();
transY = (y + fm.descent + y + fm.ascent) / 2
- b.getBounds().bottom / 2;
canvas.save();
canvas.translate(x + mLeft, transY + mTop);
b.draw(canvas);
canvas.restore();
} else {
super.draw(canvas, text, start, end, x, top, y, bottom, paint);
}
}
private void postInvalidateDelayed(long delayMilliseconds) {
if (mImageNodeWeakRefrence != null) {
ImageNode node = mImageNodeWeakRefrence.get();
if (node != null) {
DomNode parent = node.getParent();
if (parent != null && parent instanceof TextNode) {
((TextNode)parent).postInvalidateDelayed(delayMilliseconds);
private void drawGIF(Canvas canvas, float left, float top, int width, int height) {
if (mGifMovie == null) {
return;
}
}
}
}
private void shouldReplaceDrawable(HippyDrawable hippyDrawable) {
if (hippyDrawable != null) {
Bitmap bitmap = hippyDrawable.getBitmap();
if (bitmap != null) {
BitmapDrawable drawable = new BitmapDrawable(bitmap);
int w = (mWidth == 0) ? drawable.getIntrinsicWidth() : mWidth;
int h = (mHeight == 0) ? drawable.getIntrinsicHeight() : mHeight;
drawable.setBounds(0, 0, w, h);
try {
Field mDrawableField;
Field mDrawableRefField;
mDrawableField = ImageSpan.class.getDeclaredField("mDrawable");
mDrawableField.setAccessible(true);
mDrawableField.set(HippyImageSpan.this, drawable);
mDrawableRefField = DynamicDrawableSpan.class.getDeclaredField("mDrawableRef");
mDrawableRefField.setAccessible(true);
mDrawableRefField.set(HippyImageSpan.this, null);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
int duration = mGifMovie.duration();
if (duration == 0) {
duration = 1000;
}
} else if(hippyDrawable.isAnimated()) {
mGifMovie = hippyDrawable.getGIF();
}
postInvalidateDelayed(0);
mImageLoadState = STATE_LOADED;
long now = System.currentTimeMillis();
if (mGifLastPlayTime != -1) {
mGifProgress += now - mGifLastPlayTime;
if (mGifProgress > duration) {
mGifProgress = 0;
}
mGifLastPlayTime = now;
} else {
mGifLastPlayTime = now;
}
mGifScaleX = width / (float) mGifMovie.width();
mGifScaleY = height / (float) mGifMovie.height();
float x = (mGifScaleX != 0) ? left / mGifScaleX : left;
float y = (mGifScaleY != 0) ? top / mGifScaleY : top;
mGifMovie.setTime(mGifProgress);
canvas.save();
canvas.scale(mGifScaleX, mGifScaleY);
mGifMovie.draw(canvas, x, y);
canvas.restore();
postInvalidateDelayed(40);
}
@Override
public void draw(Canvas canvas, CharSequence text,
int start, int end, float x,
int top, int y, int bottom, Paint paint) {
int transY = top;
Paint.FontMetricsInt fm = paint.getFontMetricsInt();
if (mGifMovie != null) {
int width = (mWidth == 0) ? mGifMovie.width() : mWidth;
int height = (mHeight == 0) ? mGifMovie.height() : mHeight;
transY = (y + fm.descent + y + fm.ascent) / 2 - height / 2;
drawGIF(canvas, x + mLeft, transY + mTop, width, height);
} else if (mVerticalAlignment == ImageSpan.ALIGN_BASELINE) {
Drawable b = getDrawable();
transY = (y + fm.descent + y + fm.ascent) / 2
- b.getBounds().bottom / 2;
canvas.save();
canvas.translate(x + mLeft, transY + mTop);
b.draw(canvas);
canvas.restore();
} else {
super.draw(canvas, text, start, end, x, top, y, bottom, paint);
}
}
private void postInvalidateDelayed(long delayMilliseconds) {
if (mImageNodeWeakRefrence != null) {
ImageNode node = mImageNodeWeakRefrence.get();
if (node != null) {
DomNode parent = node.getParent();
if (parent != null && parent instanceof TextNode) {
((TextNode) parent).postInvalidateDelayed(delayMilliseconds);
}
}
}
}
private void shouldReplaceDrawable(HippyDrawable hippyDrawable) {
if (hippyDrawable != null) {
Bitmap bitmap = hippyDrawable.getBitmap();
if (bitmap != null) {
BitmapDrawable drawable = new BitmapDrawable(bitmap);
int w = (mWidth == 0) ? drawable.getIntrinsicWidth() : mWidth;
int h = (mHeight == 0) ? drawable.getIntrinsicHeight() : mHeight;
drawable.setBounds(0, 0, w, h);
try {
Field mDrawableField;
Field mDrawableRefField;
mDrawableField = ImageSpan.class.getDeclaredField("mDrawable");
mDrawableField.setAccessible(true);
mDrawableField.set(HippyImageSpan.this, drawable);
mDrawableRefField = DynamicDrawableSpan.class.getDeclaredField("mDrawableRef");
mDrawableRefField.setAccessible(true);
mDrawableRefField.set(HippyImageSpan.this, null);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
} else if (hippyDrawable.isAnimated()) {
mGifMovie = hippyDrawable.getGIF();
}
postInvalidateDelayed(0);
mImageLoadState = STATE_LOADED;
}
}
private void doFetchImage(String url, HippyMap props, HippyImageLoader imageAdapter) {
mImageLoadState = STATE_LOADING;
imageAdapter.fetchImage(url, new HippyImageLoader.Callback() {
@Override
public void onRequestStart(HippyDrawable hippyDrawable) {
}
@Override
public void onRequestSuccess(HippyDrawable hippyDrawable) {
shouldReplaceDrawable(hippyDrawable);
}
@Override
public void onRequestFail(Throwable throwable, String source) {
mImageLoadState = STATE_UNLOAD;
}
}, props);
}
}
private void doFetchImage(String url, HippyMap props, HippyImageLoader imageAdapter) {
mImageLoadState = STATE_LOADING;
imageAdapter.fetchImage(url, new HippyImageLoader.Callback()
{
@Override
public void onRequestStart(HippyDrawable hippyDrawable)
{
}
@Override
public void onRequestSuccess(HippyDrawable hippyDrawable) {
shouldReplaceDrawable(hippyDrawable);
}
@Override
public void onRequestFail(Throwable throwable, String source)
{
mImageLoadState = STATE_UNLOAD;
}
}, props);
}
}
@@ -109,23 +109,13 @@ public class LayoutHelper
return maxWidth;
}
private boolean warmUpLayout(Layout layout)
{
boolean result;
try
{
private void warmUpLayout(Layout layout) {
try {
Canvas canvas = mPicture.beginRecording(getWidth(layout), getHeight(layout));
layout.draw(canvas);
mPicture.endRecording();
result = true;
}
catch (Exception e)
{
} catch (Exception e) {
LogUtils.e("TextNode", "warmUpTextLayoutCache error", e);
result = false;
}
return result;
}
}
@@ -688,7 +688,7 @@ public class TextNode extends StyleNode
}
catch (Throwable e)
{
LogUtils.d("TextNode", "createLayout: " + e.getMessage());
}
float desiredWidth = boring == null ? Layout.getDesiredWidth(text, textPaint) : Float.NaN;
@@ -171,16 +171,15 @@ public class TypeFaceUtil
paint.setTypeface(Typeface.defaultFromStyle(want));
}
}
private static boolean deleteFontFile(String path) {
private static void deleteFontFile(String path) {
if (TextUtils.isEmpty(path)) {
return false;
return;
}
File file = new File(path);
boolean exists = file.exists();
if (exists) {
return file.delete();
file.delete();
}
return false;
}
private static void saveFontFile(String path, byte[] data) {
File file = new File(path);
@@ -18,6 +18,7 @@ package com.tencent.mtt.hippy.modules;
import android.os.SystemClock;
import com.tencent.mtt.hippy.HippyEngineContext;
import com.tencent.mtt.hippy.adapter.monitor.HippyEngineMonitorAdapter;
import com.tencent.mtt.hippy.utils.LogUtils;
import com.tencent.mtt.supportui.utils.struct.Pools;
import java.util.Map;
@@ -152,7 +153,7 @@ public class HippyModuleANRMonitor
}
catch (Throwable e)
{
LogUtils.d("MonitorMessage", "onDispose: " + e.getMessage());
}
}
}
@@ -30,6 +30,7 @@ import com.tencent.mtt.hippy.modules.javascriptmodules.HippyJavaScriptModuleInvo
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase;
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleInfo;
import com.tencent.mtt.hippy.utils.LogUtils;
import java.lang.reflect.Proxy;
import java.util.*;
@@ -344,6 +345,7 @@ public class HippyModuleManagerImpl implements HippyModuleManager, Handler.Callb
}
catch (Throwable e)
{
LogUtils.d("HippyModuleManagerImpl", "handleMessage: " + e.getMessage());
}
finally
{
@@ -367,7 +369,7 @@ public class HippyModuleManagerImpl implements HippyModuleManager, Handler.Callb
}
catch (Throwable e)
{
LogUtils.d("HippyModuleManagerImpl", "handleMessage: " + e.getMessage());
}
return true;
}
@@ -15,7 +15,6 @@
*/
package com.tencent.mtt.hippy.modules.nativemodules.animation;
import android.os.Build;
import com.tencent.mtt.hippy.HippyEngineContext;
import com.tencent.mtt.hippy.annotation.HippyMethod;
import com.tencent.mtt.hippy.annotation.HippyNativeModule;
@@ -24,18 +23,9 @@ import com.tencent.mtt.hippy.dom.ICSChoreographer;
import com.tencent.mtt.hippy.modules.Promise;
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase;
/**
* @author: edsheng
* @date: 2018/1/3 19:42
* @version: V1.0
*/
@HippyNativeModule(name = "AnimationFrameModule", thread = HippyNativeModule.Thread.MAIN)
public class AnimationFrameModule extends HippyNativeModuleBase
{
private static boolean IS_JELLY_BEAN = Build.VERSION.SDK_INT >= 16;
public AnimationFrameModule(HippyEngineContext context)
{
super(context);
@@ -52,5 +42,4 @@ public class AnimationFrameModule extends HippyNativeModuleBase
}
});
}
}
@@ -36,11 +36,6 @@ import com.tencent.mtt.hippy.utils.LogUtils;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* FileName: AnimationModule
* Description:
* History:
*/
@HippyNativeModule(name = "AnimationModule", thread = HippyNativeModule.Thread.DOM)
public class AnimationModule extends HippyNativeModuleBase implements DomActionInterceptor, Animation.AnimationListener, Handler.Callback,
HippyEngineLifecycleEventListener
@@ -285,7 +280,7 @@ public class AnimationModule extends HippyNativeModuleBase implements DomActionI
}
catch (Throwable e)
{
LogUtils.d("AnimationModule", "createAnimationSet: " + e.getMessage());
}
mAnimations.append(animationId, animatorSet);
}
@@ -673,23 +668,18 @@ public class AnimationModule extends HippyNativeModuleBase implements DomActionI
}
}
private void updateAnimationNodeProps(AnimationNode node)
{
if (node == null)
{
private void updateAnimationNodeProps(AnimationNode node) {
if (node == null) {
return;
}
try
{
try {
HippyMap newProps = new HippyMap();
copyAndDealPropertys(node.getId(), node.getProps(), newProps, null);
newProps.pushBoolean(HANDLE_MESSAGE_BY_ANIMATION, true);
mContext.getDomManager().updateNode(node.getId(), newProps, node.getRootView());
}
catch (Throwable e)
{
} catch (Throwable e) {
LogUtils.d("AnimationModule", "updateAnimationNodeProps: " + e.getMessage());
}
}
@@ -20,25 +20,16 @@ import com.tencent.mtt.hippy.common.HippyMap;
import java.util.ArrayList;
/**
* FileName: AnimationNode
* Description:
* History:
*/
public class AnimationNode
{
private int mTagId;
private final int mTagId;
private final HippyRootView mRootView;
private final ArrayList<Animation> mAnimations;
private HippyMap mProps;
private HippyRootView mRootView;
private HippyMap mProps;
private ArrayList<Animation> mAnimations;
public AnimationNode(int tagId, HippyRootView rootView)
{
this.mTagId = tagId;
this.mRootView = rootView;
public AnimationNode(int tagId, HippyRootView rootView) {
mTagId = tagId;
mRootView = rootView;
mAnimations = new ArrayList<>();
}
@@ -34,7 +34,7 @@ public class AnimationSet extends Animation implements Animator.AnimatorListener
private static final int ANIMATION_SET_STATUS_REPEATING = 1;
private static final int ANIMATION_SET_STATUS_END = 2;
private AnimatorSet mAnimatorSet;
private final AnimatorSet mAnimatorSet;
private AnimatorSet.Builder mLastBuilder;
@@ -51,7 +51,7 @@ public class AnimationSet extends Animation implements Animator.AnimatorListener
private int mCurrAnimationStatus = ANIMATION_SET_STATUS_NONE;
private Animation.AnimationListener mChildAnimationListener = new AnimationListener()
private final Animation.AnimationListener mChildAnimationListener = new AnimationListener()
{
@Override
public void onAnimationStart(Animation animation)
@@ -22,7 +22,7 @@ public class AudioPlayerModule extends HippyNativeModuleBase
private static final String PLAYING = "PLAYING";
private static final String STOPPED = "STOPPED";
private HippyEngineContext mHippyEngineContext;
private final HippyEngineContext mHippyEngineContext;
private MediaPlayerStateWrapper mMediaPlayer;
private int mDuration = 0;
@@ -28,12 +28,8 @@ import com.tencent.mtt.hippy.common.HippyMap;
import com.tencent.mtt.hippy.modules.Promise;
import com.tencent.mtt.hippy.modules.javascriptmodules.EventDispatcher;
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase;
import com.tencent.mtt.hippy.utils.LogUtils;
/**
* FileName: NetInfoModule
* Description:
* History:
*/
@HippyNativeModule(name = "NetInfo")
public class NetInfoModule extends HippyNativeModuleBase
{
@@ -125,6 +121,7 @@ public class NetInfoModule extends HippyNativeModuleBase
}
catch (Throwable e)
{
LogUtils.d("NetInfoModule", "registerReceiver: " + e.getMessage());
}
}
}
@@ -142,6 +139,7 @@ public class NetInfoModule extends HippyNativeModuleBase
}
catch (Throwable e)
{
LogUtils.d("NetInfoModule", "unregisterReceiver: " + e.getMessage());
}
}
@@ -183,7 +181,7 @@ public class NetInfoModule extends HippyNativeModuleBase
}
catch (Throwable e)
{
LogUtils.d("ConnectivityReceiver", "onReceive: " + e.getMessage());
}
}
}
@@ -23,12 +23,8 @@ import com.tencent.mtt.hippy.annotation.HippyMethod;
import com.tencent.mtt.hippy.annotation.HippyNativeModule;
import com.tencent.mtt.hippy.common.HippyArray;
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase;
import com.tencent.mtt.hippy.utils.LogUtils;
/**
* FileName: UtilsModule
* Description:harryguo 现在只有一个vibrate 震动
* History:
*/
@HippyNativeModule(name = "UtilsModule")
public class UtilsModule extends HippyNativeModuleBase
{
@@ -52,7 +48,9 @@ public class UtilsModule extends HippyNativeModuleBase
{
pattern[i] = (Integer) patternHippy.get(i);
}
} catch (Exception e) {}
} catch (Exception e) {
LogUtils.d("UtilsModule", "vibrate: " + e.getMessage());
}
}
// 默认一秒
if (pattern == null || pattern.length == 0)
@@ -22,6 +22,7 @@ import com.tencent.mtt.hippy.common.HippyArray;
import com.tencent.mtt.hippy.common.HippyMap;
import com.tencent.mtt.hippy.dom.node.NodeProps;
import com.tencent.mtt.hippy.utils.LogUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -48,7 +49,7 @@ public class DiffUtils
}
catch (Throwable e)
{
LogUtils.d("DiffUtils", "diff: " + e.getMessage());
}
return patchTypes;
@@ -87,7 +87,7 @@ public class ArgumentUtils
}
catch (Throwable e)
{
LogUtils.d("ArgumentUtils", "fromJavaArgs: " + e.getMessage());
}
return array;
}
@@ -22,12 +22,6 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
/**
* @Description: TODO
* @author: edsheng
* @date: 2017/11/18 17:23
* @version: V1.0
*/
public class FileUtils
{
@@ -115,7 +109,7 @@ public class FileUtils
}
catch (Throwable e)
{
LogUtils.d("FileUtils", "readFileToByteArray: " + e.getMessage());
}
fileReader.close();
@@ -28,17 +28,15 @@ public class LogUtils
DEBUG_ENABLE = debuggable;
}
public static int d(String tag, String msg) {
public static void d(String tag, String msg) {
if (DEBUG_ENABLE) {
return Log.d(tag, msg);
} else {
return 0;
Log.d(tag, msg);
}
}
public static int l(String tag, String msg) {
public static void l(String tag, String msg) {
if (!DEBUG_ENABLE) {
return 0;
return;
}
int index = 0; // 当前位置
@@ -55,46 +53,37 @@ public class LogUtils
index = max;
max += 3800;
}
return 0;
}
public static int d(String tag,String msg,Throwable throwable) {
public static void d(String tag,String msg,Throwable throwable) {
if (DEBUG_ENABLE) {
return Log.d(tag, msg,throwable);
} else {
return 0;
Log.d(tag, msg,throwable);
}
}
public static int w(String tag, String msg) {
public static void w(String tag, String msg) {
if (DEBUG_ENABLE) {
return Log.w(tag, msg);
} else {
return 0;
Log.w(tag, msg);
}
}
public static int i(String tag, String msg) {
public static void i(String tag, String msg) {
if (DEBUG_ENABLE) {
return Log.i(tag, msg);
} else {
return 0;
Log.i(tag, msg);
}
}
public static int v(String tag, String msg) {
public static void v(String tag, String msg) {
if (DEBUG_ENABLE) {
return Log.v(tag, msg);
} else {
return 0;
Log.v(tag, msg);
}
}
public static int e(String tag, String msg) {
return Log.e(tag, msg);
public static void e(String tag, String msg) {
Log.e(tag, msg);
}
public static int e(String tag, String msg, Throwable e) {
return Log.e(tag, msg,e);
public static void e(String tag, String msg, Throwable e) {
Log.e(tag, msg,e);
}
}
@@ -15,9 +15,6 @@
*/
package com.tencent.mtt.hippy.utils;
/**
* 1.0 xiandongluo on 2018/2/6
*/
public class MD5Utils
{
public static String getMD5(String string)
@@ -36,6 +33,7 @@ public class MD5Utils
}
catch (Exception e)
{
LogUtils.d("MD5Utils", "getMD5: " + e.getMessage());
}
return s;
}
@@ -50,6 +48,7 @@ public class MD5Utils
}
catch (Exception e)
{
LogUtils.d("MD5Utils", "getMD5: " + e.getMessage());
}
return null;
}
@@ -31,28 +31,22 @@ import android.view.SurfaceHolder;
import java.lang.ref.WeakReference;
/**
* @Description: TODO
* @author: robinsli
* @date: 2019/6/11 11:18
* @version: V1.0
*/
public class AudioPlayManager
{
private static final String TAG = "AudioPlayManager";
private MediaPlayer mSysMediaPlayer; //系统播放器
private String mCurrentPlayUrl; //当前播放音频的url
private int mCurrentPlayID; //当前播放的ID
private SparseArray<AudioManagerListener> mPlayCallbackListener = new SparseArray(); //支持多个audio播放,但是如何释放
private SparseArray<String> mAudioPlayUrlList = new SparseArray();
private SparseArray<Integer> mAudioPlayPositionList = new SparseArray();
private HandlerThread mHandlerThread = new HandlerThread("HippyAudioPlayThread");
private Handler mHandler;
private Runnable mRunnable;
public static final long PROGRESS_UPDATE_TIME = 1000L; //更新播放进度的时间间隔
public static final int AUDIO_STREAM_TYPE = 3;
public static final int PALY_START_POS = 0;
public static int gUniqPlayId = 0;
private static final String TAG = "AudioPlayManager";
private MediaPlayer mSysMediaPlayer; //系统播放器
private String mCurrentPlayUrl; //当前播放音频的url
private int mCurrentPlayID; //当前播放的ID
private final SparseArray<AudioManagerListener> mPlayCallbackListener = new SparseArray(); //支持多个audio播放,但是如何释放
private final SparseArray<String> mAudioPlayUrlList = new SparseArray();
private final SparseArray<Integer> mAudioPlayPositionList = new SparseArray();
private final HandlerThread mHandlerThread = new HandlerThread("HippyAudioPlayThread");
private final Handler mHandler;
private final Runnable mRunnable;
public static final long PROGRESS_UPDATE_TIME = 1000L; //更新播放进度的时间间隔
public static final int AUDIO_STREAM_TYPE = 3;
public static final int PALY_START_POS = 0;
public static int gUniqPlayId = 0;
public static int globalUiqPlayId()
{
@@ -384,8 +378,8 @@ public class AudioPlayManager
}
private static Object afChangeListener;
private static AudioManager audioManager = (AudioManager) ContextHolder.getAppContext().getSystemService(Context.AUDIO_SERVICE);
private static int AUDIOFOCUS_LOSS_TRANSIENT = -2;
private final static AudioManager audioManager = (AudioManager) ContextHolder.getAppContext().getSystemService(Context.AUDIO_SERVICE);
private final static int AUDIOFOCUS_LOSS_TRANSIENT = -2;
public static int requestAudioFocus(OnAudioStateChange onAudioStateChange)
{
@@ -442,17 +436,13 @@ public class AudioPlayManager
* 释放声音播放焦点
*
*/
public static void abandonAudioFocus()
{
try
{
if (audioManager != null)
{
public static void abandonAudioFocus() {
try {
if (audioManager != null) {
audioManager.abandonAudioFocus((AudioManager.OnAudioFocusChangeListener) afChangeListener);
}
}
catch (Throwable e)
{
} catch (Throwable e) {
LogUtils.d("AudioPlayManager", "abandonAudioFocus: " + e.getMessage());
}
}
@@ -215,8 +215,8 @@ public class HippyImageView extends AsyncImageView implements CommonBorder, Hipp
try {
((Map)param).put(IMAGE_PROPS, initProps);
} catch (Exception ignore) {
LogUtils.d("HippyImageView", ignore.getMessage());
} catch (Exception e) {
LogUtils.d("HippyImageView", "doFetchImage: " + e.getMessage());
}
}
@@ -512,9 +512,10 @@ public class HippyImageView extends AsyncImageView implements CommonBorder, Hipp
* @param canvas canvas of the image view
* @return 播放完成返回true,未完成返回false。
*/
protected boolean drawGIF(Canvas canvas) {
if (mGifMovie == null)
return false;
protected void drawGIF(Canvas canvas) {
if (mGifMovie == null) {
return;
}
int duration = mGifMovie.duration();
if (duration == 0) {
@@ -523,21 +524,15 @@ public class HippyImageView extends AsyncImageView implements CommonBorder, Hipp
long now = System.currentTimeMillis();
if (!isGifPaused)
{
if (mGifLastPlayTime != -1)
{
if (!isGifPaused) {
if (mGifLastPlayTime != -1) {
mGifProgress += now - mGifLastPlayTime;
if (mGifProgress > duration)
{
if (mGifProgress > duration) {
mGifProgress = 0;
}
mGifLastPlayTime = now;
}
else
{
} else {
mGifLastPlayTime = now;
}
}
@@ -549,12 +544,9 @@ public class HippyImageView extends AsyncImageView implements CommonBorder, Hipp
mGifMovie.draw(canvas, mGifStartX, mGifStartY);
canvas.restore(); // 恢复变换矩阵
if (!isGifPaused)
{
if (!isGifPaused) {
postInvalidateDelayed(40);
}
return false;
}
protected boolean shouldFetchImage() {
@@ -131,9 +131,9 @@ public class HippyListAdapter extends RecyclerAdapter implements IRecycleItemTyp
{
toNode = mHippyContext.getRenderManager().getRenderNode(mParentRecyclerView.getId()).getChildAt(position);
}
catch (Throwable error)
catch (Throwable e)
{
LogUtils.d("HippyListAdapter", "onBindContentView: " + e.getMessage());
}
//保护下
if (toNode == null)
@@ -41,6 +41,7 @@ import com.tencent.mtt.hippy.HippyEngineContext;
import com.tencent.mtt.hippy.HippyInstanceContext;
import com.tencent.mtt.hippy.HippyInstanceLifecycleEventListener;
import com.tencent.mtt.hippy.utils.ContextHolder;
import com.tencent.mtt.hippy.utils.LogUtils;
import com.tencent.mtt.hippy.views.view.HippyViewGroup;
import java.lang.reflect.Field;
@@ -450,21 +451,17 @@ public class HippyModalHostView extends HippyViewGroup implements HippyInstanceL
}
}
private int getScreenHeight()
{
try
{
private int getScreenHeight() {
try {
Context context = ContextHolder.getAppContext();
android.view.WindowManager manager = (android.view.WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
if (display != null)
{
if (display != null) {
int height = manager.getDefaultDisplay().getHeight();
return height;
}
}
catch (SecurityException e)
{
} catch (SecurityException e) {
LogUtils.d("HippyModalHostView", "getScreenHeight: " + e.getMessage());
}
return -1;
}
@@ -51,12 +51,6 @@ import android.widget.EditText;
import android.widget.TextView;
import java.lang.reflect.Field;
/**
* @Description: TODO
* @author: edsheng
* @date: 2017/12/19 20:05
* @version: V1.0
*/
public class HippyTextInput extends EditText implements HippyViewBase, CommonBorder, TextView.OnEditorActionListener, View.OnFocusChangeListener
{
@@ -288,7 +282,7 @@ public class HippyTextInput extends EditText implements HippyViewBase, CommonBor
}
catch (SecurityException e)
{
LogUtils.d("HippyTextInput", "getScreenHeight: " + e.getMessage());
}
return -1;
}
@@ -749,16 +743,16 @@ public class HippyTextInput extends EditText implements HippyViewBase, CommonBor
break;
}
}
catch (Throwable ignored)
catch (Throwable e)
{
LogUtils.d("robinsli", ignored.getMessage());
LogUtils.d("HippyTextInput", "setCursorColor: " + e.getMessage());
}
editorClass = editorClass.getSuperclass(); //继续往上反射父亲
}
}
catch (Throwable ignored)
catch (Throwable e)
{
LogUtils.d("robinsli", ignored.getMessage());
LogUtils.d("HippyTextInput", "setCursorColor: " + e.getMessage());
}
}
}
@@ -1,5 +1,6 @@
package com.tencent.mtt.hippy.views.videoview;
import com.tencent.mtt.hippy.utils.LogUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
@@ -907,6 +908,7 @@ public class VideoHippyView extends ScalableVideoView
}
catch (Exception e)
{
LogUtils.d("VideoHippyView", "selectTimedMetadataTrack: " + e.getMessage());
}
}
}
@@ -46,13 +46,13 @@ public class BackgroundDrawable extends BaseDrawable
private DashPathEffect mDashPathEffect = null;
private DashPathEffect mDotPathEffect = new DashPathEffect(new float[] { 2, 2}, 0);
private Path mPathWithBorder;
private Paint mPaint;
private final Paint mPaint;
private int mBackgroundColor;
private RectF mTempRectForBorderRadius;
private Path mPathForBorderRadius;
private boolean mNeedUpdateBorderPath = false;
private Paint mShadowPaint;
private final Paint mShadowPaint;
protected float mShadowOpacity = 0.8f;
protected int mShadowColor = Color.GRAY;
protected RectF mShadowRect;
@@ -67,7 +67,7 @@ public class MyActivityDeprecated extends Activity implements HippyEngine.Engine
@Override
public void onBackPressed() {
if (!mEngineManager.onBackPress(this))
super.onBackPressed();;
super.onBackPressed();
}
@Override
@@ -27,7 +27,7 @@ import java.util.List;
@Deprecated
public class MyHippyEngineHost extends HippyEngineHost
{
private Application mApplication;
final private Application mApplication;
public MyHippyEngineHost(Application application)
{
@@ -4,13 +4,14 @@ import android.view.View;
import com.tencent.mtt.hippy.annotation.HippyController;
import com.tencent.mtt.hippy.annotation.HippyControllerProps;
import com.tencent.mtt.hippy.dom.node.NodeProps;
import com.tencent.mtt.hippy.utils.LogUtils;
import com.tencent.mtt.hippy.views.custom.HippyCustomPropsController;
@HippyController(name = HippyCustomPropsController.CLASS_NAME)
public class MyCustomViewController extends HippyCustomPropsController
{
@HippyControllerProps(name = "customString", defaultType = HippyControllerProps.STRING, defaultString = "")
@HippyControllerProps(name = "customString", defaultType = HippyControllerProps.STRING)
public void setCustomString(View view, String text) {
LogUtils.d("MyCustomViewController", "setCustomString: text=" + text);
}
}
@@ -11,13 +11,6 @@ import com.tencent.mtt.hippy.modules.Promise;
import com.tencent.mtt.hippy.uimanager.HippyViewController;
import com.tencent.mtt.hippy.utils.LogUtils;
/**
* @Description: TODO
* @author: edsheng
* @date: 2018/3/22 11:12
* @version: V1.0
*/
@HippyController(name = "MyView")
public class MyViewController extends HippyViewController<MyView>
{
@@ -32,7 +25,7 @@ public class MyViewController extends HippyViewController<MyView>
LogUtils.d("MyViewController", "onManageChildComplete");
}
@HippyControllerProps(name = "text", defaultType = HippyControllerProps.STRING, defaultString = "")
@HippyControllerProps(name = "text", defaultType = HippyControllerProps.STRING)
public void setText(MyView textView, String text)
{
textView.setText(text);
@@ -50,15 +43,18 @@ public class MyViewController extends HippyViewController<MyView>
//this is show receive js call
@Override
public void dispatchFunction(MyView view, String functionName, HippyArray params)
{
public void dispatchFunction(MyView view, String functionName, HippyArray params) {
super.dispatchFunction(view, functionName, params);
switch (functionName)
{
case "changeColor":
String color = params.getString(0);
view.setColor(Color.parseColor(color));
break;
}
switch (functionName) {
case "changeColor":
String color = params.getString(0);
view.setColor(Color.parseColor(color));
break;
case "changeText":
String text = params.getString(0);
view.setText(text);
break;
}
}
}