Skip to content

Commit

Permalink
fix: getSize
Browse files Browse the repository at this point in the history
  • Loading branch information
niuniuyang committed Sep 7, 2021
1 parent 5f184c1 commit 26f76f3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 41 deletions.
2 changes: 1 addition & 1 deletion android/sdk/maven_for_qb.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ publishing {
myPub(MavenPublication) {
groupId 'com.tencent.qqbrowser.hippyforqb'
artifactId 'hippysdk'
version 'qb-androidx-11.9.6.1'
version 'qb-androidx-11.9.6.2'
artifact(androidSourcesJar)
artifact("$buildDir/outputs/aar/android-sdk.aar")
pom.withXml {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
package com.tencent.mtt.hippy.adapter.image;

import android.graphics.Bitmap;
import android.util.SparseArray;
import com.tencent.mtt.hippy.common.HippyMap;
import com.tencent.mtt.hippy.modules.Promise;
import com.tencent.mtt.supportui.adapters.image.IImageLoaderAdapter;
import com.tencent.mtt.supportui.adapters.image.IImageRequestListener;

Expand Down Expand Up @@ -56,6 +59,33 @@ public HippyDrawable getImage(String source, Object param)
return drawable;
}

public void getSize(final String url, final Promise promise) {
fetchImage(url, new HippyImageLoader.Callback() {
@Override
public void onRequestStart(HippyDrawable hippyDrawable) {
}

@Override
public void onRequestSuccess(HippyDrawable hippyDrawable) {
if (hippyDrawable != null) {
Bitmap bitmap = hippyDrawable.getBitmap();
HippyMap resultMap = new HippyMap();
resultMap.pushInt("width", bitmap != null ? bitmap.getWidth() : hippyDrawable.getWidth());
resultMap.pushInt("height", bitmap != null ? bitmap.getHeight() : hippyDrawable.getHeight());
promise.resolve(resultMap);
hippyDrawable.onDrawableDetached();
} else {
promise.reject("fetch image fail " + url);
}
}

@Override
public void onRequestFail(Throwable throwable, String source) {
promise.reject("fetch image fail " + source);
}
}, null);
}

public void destroyIfNeed(){
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
*/
package com.tencent.mtt.hippy.modules.nativemodules.image;

import android.graphics.Bitmap;

import com.tencent.mtt.hippy.HippyEngineContext;
import com.tencent.mtt.hippy.adapter.image.HippyDrawable;
import com.tencent.mtt.hippy.adapter.image.HippyImageLoader;
import com.tencent.mtt.hippy.annotation.HippyMethod;
import com.tencent.mtt.hippy.annotation.HippyNativeModule;
import com.tencent.mtt.hippy.common.HippyMap;
import com.tencent.mtt.hippy.modules.Promise;
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase;

Expand All @@ -42,43 +39,9 @@ public ImageLoaderModule(HippyEngineContext context)
}

@HippyMethod(name = "getSize")
public void getSize(final String url, final Promise promise)
{
if (mImageAdapter != null)
{
mImageAdapter.fetchImage(url, new HippyImageLoader.Callback()
{
@Override
public void onRequestStart(HippyDrawable hippyDrawable)
{
}

@Override
public void onRequestSuccess(HippyDrawable hippyDrawable)
{
if (hippyDrawable != null)
{
Bitmap bitmap = hippyDrawable.getBitmap();
int width = bitmap != null ? bitmap.getWidth() : hippyDrawable.getWidth();
int height = bitmap != null ? bitmap.getHeight() : hippyDrawable.getHeight();
HippyMap resultMap = new HippyMap();
resultMap.pushInt("width", width);
resultMap.pushInt("height", height);
promise.resolve(resultMap);
hippyDrawable.onDrawableDetached();
}
else
{
promise.reject("fetch image fail " + url);
}
}

@Override
public void onRequestFail(Throwable throwable, String source)
{
promise.reject("fetch image fail " + source);
}
}, null);
public void getSize(final String url, final Promise promise) {
if (mImageAdapter != null) {
mImageAdapter.getSize(url, promise);
}
}

Expand Down

0 comments on commit 26f76f3

Please sign in to comment.