Skip to content

Commit

Permalink
feat(android): support hpfile use in backgroundImage
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and zoomchan-cxj committed Aug 9, 2021
1 parent a2a9e86 commit c4808c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.tencent.mtt.supportui.views.IGradient;
import com.tencent.mtt.supportui.views.IShadow;

import java.io.File;
import java.util.ArrayList;
import java.util.Map;

Expand Down Expand Up @@ -698,4 +699,22 @@ public View getChildAt(T viewGroup, int i) {
}
return null;
}

protected String getInnerPath(HippyInstanceContext context, String path) {
//hpfile://./assets/file_banner02.jpg
if (path != null && path.startsWith("hpfile://")) {
String relativePath = path.replace("hpfile://./", "");
//hippysdk的图片加载协议
String bundlePath = null;
if (context.getBundleLoader() != null) {
bundlePath = context.getBundleLoader().getPath();
}

path = bundlePath == null ? null
: bundlePath.subSequence(0, bundlePath.lastIndexOf(File.separator) + 1) + relativePath;
//assets://index.android.jsbundle
//file:sdcard/hippy/feeds/index.android.jsbundle
}
return path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,6 @@ public void setUrl(HippyImageView hippyImageView, String url) {
hippyImageView.setUrl(getInnerPath((HippyInstanceContext) hippyImageView.getContext(), url));
}

private static String getInnerPath(HippyInstanceContext context, String path) {
//hpfile://./assets/file_banner02.jpg
if (path != null && path.startsWith("hpfile://")) {
String relativePath = path.replace("hpfile://./", "");
//hippysdk的图片加载协议
String bundlePath = null;
if (context.getBundleLoader() != null) {
bundlePath = context.getBundleLoader().getPath();
}

path = bundlePath == null ? null
: bundlePath.subSequence(0, bundlePath.lastIndexOf(File.separator) + 1) + relativePath;
//assets://index.android.jsbundle
//file:sdcard/hippy/feeds/index.android.jsbundle
}
return path;
}

@SuppressWarnings("unused")
@HippyControllerProps(name = "tintColor", defaultType = HippyControllerProps.NUMBER, defaultNumber = Color.TRANSPARENT)
public void setTintColor(HippyImageView hippyImageView, int tintColor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.content.Context;
import android.view.View;

import com.tencent.mtt.hippy.HippyInstanceContext;
import com.tencent.mtt.hippy.annotation.HippyController;
import com.tencent.mtt.hippy.annotation.HippyControllerProps;
import com.tencent.mtt.hippy.dom.node.NodeProps;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void setOverflow(HippyViewGroup hippyViewGroup, String overflow) {

@HippyControllerProps(name = NodeProps.BACKGROUND_IMAGE, defaultType = HippyControllerProps.STRING)
public void setBackgroundImage(HippyViewGroup hippyViewGroup, String url) {
hippyViewGroup.setUrl(url);
hippyViewGroup.setUrl(getInnerPath((HippyInstanceContext)hippyViewGroup.getContext(), url));
}

@HippyControllerProps(name = NodeProps.BACKGROUND_SIZE, defaultType = HippyControllerProps.STRING, defaultString = "origin")
Expand Down

0 comments on commit c4808c8

Please sign in to comment.