Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
wyouflf committed Jul 28, 2020
1 parent d2a96c3 commit 4f3c36f
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions demo/src/main/java/org/xutils/demo/ImageFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
public class ImageFragment extends BaseFragment {

private String[] imgSites = {
"http://m.haopic.me/touxiang",
"http://m.haopic.me/touxiang/page/2",
"http://m.haopic.me"
"http://www.gaoxiaogif.cn",
"https://www.ivsky.com/tupian/ziranfengguang/",
"https://www.ivsky.com/tupian/chengshilvyou/"
};

ImageOptions imageOptions;
Expand All @@ -56,6 +56,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
.setImageScaleType(ImageView.ScaleType.CENTER_CROP)
.setLoadingDrawableId(R.mipmap.ic_launcher)
.setFailureDrawableId(R.mipmap.ic_launcher)
.setIgnoreGif(false)
.build();

imageListAdapter = new ImageListAdapter();
Expand Down Expand Up @@ -217,30 +218,20 @@ public void onFinished() {
*/
public static List<String> getImgSrcList(String htmlStr) {
List<String> pics = new ArrayList<String>();
resolveImgUrl(htmlStr, pics, "<img.*?src=['|\"]http://(.*?)['|\"]");
resolveImgUrl(htmlStr, pics, "<img.*?src=['|\"]//(.*?)['|\"]");
return pics;
}

String regEx_img = "<img.*?src=\"http://(.*?).jpg\""; // 图片链接地址
Pattern p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE);
private static void resolveImgUrl(String htmlStr, List<String> pics, String regEx) {
Pattern p_image = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
Matcher m_image = p_image.matcher(htmlStr);
while (m_image.find()) {
String src = m_image.group(1);
if (src.length() < 100) {
pics.add("http://" + src + ".jpg");
//pics.add("http://f.hiphotos.baidu.com/zhidao/pic/item/2fdda3cc7cd98d104cc21595203fb80e7bec907b.jpg");
if (src.length() < 200) {
pics.add("http://" + src);
}
}

regEx_img = "<img.*?src=\"//(.*?).jpg\""; // 图片链接地址
p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE);
m_image = p_image.matcher(htmlStr);
while (m_image.find()) {
String src = m_image.group(1);
if (src.length() < 100) {
pics.add("http://" + src + ".jpg");
//pics.add("http://f.hiphotos.baidu.com/zhidao/pic/item/2fdda3cc7cd98d104cc21595203fb80e7bec907b.jpg");
}
}

return pics;
}

}

0 comments on commit 4f3c36f

Please sign in to comment.