Skip to content

Commit

Permalink
feat(android): add tdk feature step 1
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and xuqingkuang committed Jun 30, 2020
1 parent f886e0b commit dbc60c4
Show file tree
Hide file tree
Showing 23 changed files with 1,068 additions and 60 deletions.
1 change: 1 addition & 0 deletions android/sdk/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public void forceUpdateNode(int);
-keep class * extends com.tencent.mtt.hippy.dom.node.DomNode {*;}

-keep class com.tencent.mtt.hippy.views.** {*;}
-keep class com.tencent.mtt.tkd.views.** {*;}
-keep interface com.tencent.mtt.hippy.bridge.HippyBridge {*;}

-keep class com.tencent.mtt.supportui.views.** {*;}
Expand Down
12 changes: 8 additions & 4 deletions android/sdk/src/main/java/com/tencent/mtt/hippy/HippyEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.tencent.mtt.hippy.adapter.storage.HippyStorageAdapter;
import com.tencent.mtt.hippy.bridge.HippyCoreAPI;
import com.tencent.mtt.hippy.bridge.bundleloader.HippyBundleLoader;
import com.tencent.mtt.hippy.common.HippyJsException;
import com.tencent.mtt.hippy.common.HippyMap;
import com.tencent.mtt.hippy.utils.ContextHolder;
import com.tencent.mtt.hippy.utils.LogUtils;
Expand Down Expand Up @@ -425,8 +426,11 @@ public interface EngineListener
*/
public void onInitialized(int statusCode, String msg);
}
public interface ModuleListener
{
public void onInitialized(int statusCode, String msg,HippyRootView hippyRootView);
}

public interface ModuleListener
{
public void onInitialized(int statusCode, String msg,HippyRootView hippyRootView);

boolean onJsException(HippyJsException exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ public void handleException(Throwable throwable)
if (throwable instanceof HippyJsException)
{
mGlobalConfigs.getExceptionHandler().handleJsException((HippyJsException) throwable);
mEngineContext.getBridgeManager().notifyModuleJsException((HippyJsException) throwable);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.tencent.mtt.hippy.HippyRootView;
import com.tencent.mtt.hippy.bridge.bundleloader.HippyBundleLoader;
import com.tencent.mtt.hippy.common.Callback;
import com.tencent.mtt.hippy.common.HippyJsException;
import com.tencent.mtt.hippy.common.HippyMap;


Expand All @@ -33,6 +34,8 @@ public interface HippyBridgeManager

void runBundle(int id, HippyBundleLoader loader, HippyEngine.ModuleListener listener, HippyRootView hippyRootView);

void notifyModuleJsException(final HippyJsException exception);

void loadInstance(String name, int id, HippyMap params);

void resumeInstance(int id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
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.UIThreadUtils;
import com.tencent.mtt.hippy.adapter.thirdparty.HippyThirdPartyAdapter;
import com.tencent.mtt.hippy.utils.LogUtils;
import com.tencent.mtt.hippy.utils.UIThreadUtils;

import android.os.Build;
import android.os.Handler;
Expand Down Expand Up @@ -332,35 +332,51 @@ public void runBundle(int id, HippyBundleLoader loader, HippyEngine.ModuleListen
Message message = mHandler.obtainMessage(MSG_CODE_RUN_BUNDLE, 0, id, loader);
mHandler.sendMessage(message);
}
private void notifyModuleLoaded(final int statusCode, final String msg,final HippyRootView hippyRootView)
{
if (mLoadModuleListener != null)
{
if (UIThreadUtils.isOnUiThread())
{
if(mLoadModuleListener != null)
{
mLoadModuleListener.onInitialized(statusCode, msg,hippyRootView);
mLoadModuleListener = null;
}
}
else
{
UIThreadUtils.runOnUiThread(new Runnable()
{
@Override
public void run()
{
if(mLoadModuleListener != null) {
mLoadModuleListener.onInitialized(statusCode, msg, hippyRootView);
mLoadModuleListener = null;
}
}
});
}
}
}

public void notifyModuleJsException(final HippyJsException exception)
{
if (UIThreadUtils.isOnUiThread()) {
if(mLoadModuleListener != null && mLoadModuleListener.onJsException(exception)) {
mLoadModuleListener = null;
}
}
else
{
UIThreadUtils.runOnUiThread(new Runnable()
{
@Override
public void run()
{
if(mLoadModuleListener != null && mLoadModuleListener.onJsException(exception)) {
mLoadModuleListener = null;
}
}
});
}
}

private void notifyModuleLoaded(final int statusCode, final String msg,final HippyRootView hippyRootView)
{
if (UIThreadUtils.isOnUiThread()) {
if(mLoadModuleListener != null) {
mLoadModuleListener.onInitialized(statusCode, msg,hippyRootView);
//mLoadModuleListener = null;
}
}
else
{
UIThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if(mLoadModuleListener != null) {
mLoadModuleListener.onInitialized(statusCode, msg, hippyRootView);
//mLoadModuleListener = null;
}
}
});
}
}

@Override
public void loadInstance(String name, int id, HippyMap params)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
import com.tencent.mtt.hippy.views.viewpager.HippyViewPagerController;
import com.tencent.mtt.hippy.views.viewpager.HippyViewPagerItemController;
import com.tencent.mtt.hippy.views.webview.HippyWebViewController;
import com.tencent.mtt.tkd.views.scroll.TkdScrollViewController;
import com.tencent.mtt.tkd.views.list.TkdListItemViewController;
import com.tencent.mtt.tkd.views.list.TkdListViewController;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -224,6 +227,9 @@ public List<Class<? extends HippyViewController>> getControllers()
components.add(HippyWebViewController.class);
components.add(AudioViewController.class);
components.add(VideoHippyViewController.class);
components.add(TkdScrollViewController.class);
components.add(TkdListItemViewController.class);
components.add(TkdListViewController.class);
return components;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,15 @@ public void fetch(final HippyMap request, final Promise promise)
HippyMap headers = request.getMap("headers");
if (headers != null)
{
HippyArray requestCookies = headers.getArray("Cookie");
saveCookie2Manager(url, requestCookies);
hippyMapToRequestHeaders(httpRequest, headers);
}
String body = request.getString("body");
httpRequest.setBody(body);
String cookie = getCookieManager().getCookie(url);
if (!TextUtils.isEmpty(cookie))
httpRequest.addHeader(HttpHeader.REQ.COOKIE, cookie);

HippyGlobalConfigs configs = mContext.getGlobalConfigs();
HippyHttpAdapter adapter = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.tencent.mtt.hippy.views.image;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
Expand All @@ -30,6 +31,7 @@
import com.tencent.mtt.hippy.HippyInstanceContext;
import com.tencent.mtt.hippy.adapter.image.HippyDrawable;
import com.tencent.mtt.hippy.adapter.image.HippyImageLoader;
import com.tencent.mtt.hippy.common.HippyMap;
import com.tencent.mtt.hippy.uimanager.HippyViewBase;
import com.tencent.mtt.hippy.uimanager.HippyViewController;
import com.tencent.mtt.hippy.uimanager.HippyViewEvent;
Expand Down Expand Up @@ -358,7 +360,18 @@ protected void handleGetImageSuccess()
// send onLoadEnd event
if (mShouldSendImageEvent[ImageEvent.ONLOAD_END.ordinal()])
{
getOnLoadEndEvent().send(this, null);
HippyMap map = new HippyMap();
map.pushInt("success", 1);
if (mSourceDrawable != null) {
Bitmap bitmap = mSourceDrawable.getBitmap();
if (bitmap != null) {
HippyMap imageSize = new HippyMap();
imageSize.pushInt("width", bitmap.getWidth());
imageSize.pushInt("height", bitmap.getHeight());
map.pushMap("image", imageSize);
}
}
getOnLoadEndEvent().send(this, map);
}
}

Expand All @@ -373,7 +386,9 @@ protected void handleGetImageFail(Throwable throwable)
// send onLoadEnd event
if (mShouldSendImageEvent[ImageEvent.ONLOAD_END.ordinal()])
{
getOnLoadEndEvent().send(this, null);
HippyMap map = new HippyMap();
map.pushInt("success", 0);
getOnLoadEndEvent().send(this, map);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class HippyHorizontalScrollView extends HorizontalScrollView implements H
protected int mScrollEventThrottle = 400; // 400ms最多回调一次
private long mLastScrollEventTimeStamp = -1;

protected int mScrollMinOffset = 0;
private int mLastX = 0;

public HippyHorizontalScrollView(Context context)
{
super(context);
Expand Down Expand Up @@ -201,12 +204,15 @@ protected void onScrollChanged(int x, int y, int oldX, int oldY)
if (mScrollEventEnable)
{
long currTime = System.currentTimeMillis();
if (currTime - mLastScrollEventTimeStamp < mScrollEventThrottle)
{
return;
}
int offsetX = Math.abs(x - mLastX);
if (mScrollMinOffset > 0 && offsetX >= mScrollMinOffset) {
mLastX = x;
} else if ((mScrollMinOffset == 0) && (currTime - mLastScrollEventTimeStamp >= mScrollEventThrottle)) {
mLastScrollEventTimeStamp = currTime;
} else {
return;
}

mLastScrollEventTimeStamp = currTime;
HippyScrollViewEventHelper.emitScrollEvent(this);
}
mDoneFlinging = false;
Expand Down Expand Up @@ -376,4 +382,11 @@ public boolean horizontalCanScroll(int i)
{
return true;
}

@Override
public void setScrollMinOffset(int scrollMinOffset)
{
scrollMinOffset = Math.max(5, scrollMinOffset);
mScrollMinOffset = (int)PixelUtil.dp2px(scrollMinOffset);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ public interface HippyScrollView

void callSmoothScrollTo(int x,int y,int duration);

void setScrollMinOffset(int scrollMinOffset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public void setScrollEventThrottle(HippyScrollView view, int scrollEventThrottle
view.setScrollEventThrottle(scrollEventThrottle);
}

@HippyControllerProps(name = "scrollMinOffset", defaultType = HippyControllerProps.NUMBER, defaultNumber = 5)
public void setScrollMinOffset(HippyScrollView view, int scrollMinOffset)
{
view.setScrollMinOffset(scrollMinOffset);
}

@Override
public void dispatchFunction(View view, String functionName, HippyArray args) {
super.dispatchFunction(view, functionName, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void emitScrollAnimationEndEvent(ViewGroup view)
emitScrollEvent(view, EVENT_TYPE_ANIMATION_END);
}

private static void emitScrollEvent(ViewGroup view, String scrollEventType)
protected static void emitScrollEvent(ViewGroup view, String scrollEventType)
{
if(view == null)
{
Expand Down
Loading

0 comments on commit dbc60c4

Please sign in to comment.