Skip to content

Commit 1ddbaa4

Browse files
committed
2 parents 1505ca4 + 2e775ac commit 1ddbaa4

File tree

6 files changed

+37
-84
lines changed

6 files changed

+37
-84
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/activity/MainActivity.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
110110

111111
}
112112

113+
/**
114+
* java 调取 js 代码
115+
* @param view WebView
116+
*/
113117
private void parseHTML(WebView view) {
118+
//这段 js 代码是解析获取到了 Html 文本文件,然后调用本地定义的 Java 代码返回
119+
//解析出来的 Html 文本文件
114120
view.loadUrl("javascript:window.local_obj.showSource('<head>'+"
115121
+ "document.getElementsByTagName('html')[0].innerHTML+'</head>');");
116122
}
@@ -167,17 +173,14 @@ private void addImageClickListener() {
167173
"})()");
168174
}
169175

170-
// js 通信接口
176+
// js 通信接口,定义供 JavaScript 调用的交互接口
171177
private class MyJavascriptInterface {
172-
173178
private Context context;
174-
175179
public MyJavascriptInterface(Context context) {
176180
this.context = context;
177181
}
178-
179182
/**
180-
* 点击图片启动新的 ShowImageFromWebActivity,并传入点击图片对应的 url 和页面所以图片
183+
* 点击图片启动新的 ShowImageFromWebActivity,并传入点击图片对应的 url 和页面所有图片
181184
* 对应的 url
182185
* @param url 点击图片对应的 url
183186
*/
@@ -194,11 +197,12 @@ public void openImage(String url) {
194197

195198
private class InJavaScriptLocalObj {
196199
/**
197-
* 解析 WebView 加载对应的 Html 文本
200+
* 获取要解析 WebView 加载对应的 Html 文本
198201
* @param html WebView 加载对应的 Html 文本
199202
*/
200203
@android.webkit.JavascriptInterface
201204
public void showSource(String html) {
205+
//从 Html 文件中提取页面所有图片对应的地址对象
202206
getAllImageUrlFromHtml(html);
203207
}
204208
}
@@ -215,14 +219,15 @@ private List<String> getAllImageUrlFromHtml(String html) {
215219
while (matcher.find()) {
216220
listImgUrl.add(matcher.group());
217221
}
222+
//从图片对应的地址对象中解析出 src 标签对应的内容
218223
getAllImageUrlFormSrcObject(listImgUrl);
219224
return listImgUrl;
220225
}
221226

222227
/***
223228
* 从图片对应的地址对象中解析出 src 标签对应的内容
224229
* 即 url,例如 "http://sc1.hao123img.com/data/f44d0aab7bc35b8767de3c48706d429e"
225-
* @param listImageUrl 图片地址对应
230+
* @param listImageUrl 图片地址对象
226231
* 例如 <img src="http://sc1.hao123img.com/data/f44d0aab7bc35b8767de3c48706d429e" />
227232
*/
228233
private List<String> getAllImageUrlFormSrcObject(List<String> listImageUrl) {

app/src/main/java/activity/ShowImageFromWebActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void onClick(View v) {
120120
* 开始下载图片
121121
*/
122122
private void downloadImage() {
123-
downloadAsyn(imgUrls.get(currentIndex), Environment.getExternalStorageDirectory().getAbsolutePath() + "/ImagesFromWebView");
123+
downloadAsync(imgUrls.get(currentIndex), Environment.getExternalStorageDirectory().getAbsolutePath() + "/ImagesFromWebView");
124124
}
125125

126126

@@ -130,10 +130,9 @@ private void downloadImage() {
130130
* @param url
131131
* @param destFileDir 本地文件存储的文件夹
132132
*/
133-
private void downloadAsyn(final String url, final String destFileDir) {
133+
private void downloadAsync(final String url, final String destFileDir) {
134134

135135
OkHttpUtil mOkHttpUtil = OkHttpUtil.getInstance();
136-
137136
OkHttpClient mOkHttpClient = mOkHttpUtil.getOkHttpClient();
138137

139138
final Request request = new Request.Builder()

app/src/main/java/adapter/ImageBrowserAdapter.java

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,14 @@
1919

2020
public class ImageBrowserAdapter extends PagerAdapter {
2121

22-
private static final String TAG =ImageBrowserAdapter.class.getSimpleName() ;
2322
private Activity context;
2423
private List<String> picUrls;
25-
private ArrayList<View> picViews;
26-
private PhotoViewAttacher photoViewAttacher;
2724

2825
public ImageBrowserAdapter(Activity context, ArrayList<String> picUrls) {
2926
this.context = context;
3027
this.picUrls = picUrls;
31-
// this.picUrls= Arrays.asList(images);
32-
// initImgs();
3328
}
3429

35-
private void initImgs() {
36-
picViews = new ArrayList<View>();
37-
38-
for(int i=0; i<picUrls.size(); i++) {
39-
// 填充显示图片的页面布局
40-
View view = View.inflate(context, R.layout.item_image_browser, null);
41-
picViews.add(view);
42-
}
43-
}
4430

4531
@Override
4632
public int getCount() {
@@ -55,20 +41,12 @@ public boolean isViewFromObject(View view, Object object) {
5541

5642
@Override
5743
public View instantiateItem(ViewGroup container, int position) {
58-
// View view = picViews.get(position);
5944
View view = View.inflate(context, R.layout.item_image_browser, null);
60-
// View view = View.inflate(context, R.layout.fragment_picture_slide, null);
6145
ImageView iv_image_browser = (ImageView) view.findViewById(R.id.show_webimage_imageview);
62-
// ImageView iv_image_browser = (ImageView) view.findViewById(R.id.iv_main_pic);
6346
String picUrl = picUrls.get(position);
64-
photoViewAttacher=new PhotoViewAttacher(iv_image_browser);
65-
// photoViewAttacher.canZoom();
47+
final PhotoViewAttacher photoViewAttacher=new PhotoViewAttacher(iv_image_browser);
6648
photoViewAttacher.setScaleType(ImageView.ScaleType.FIT_CENTER);
67-
// photoViewAttacher.setZoomable(true);
68-
// 启用图片缩放功能
69-
// iv_image_browser.setEnabled(true);
70-
//显示图片
71-
// ImageLoaderUtils.displayWhole(context, iv_image_browser, picUrl,photoViewAttacher);
49+
photoViewAttacher.setZoomable(false);
7250
Glide.with(context).
7351
load(picUrl)
7452
.crossFade()
@@ -78,9 +56,8 @@ public View instantiateItem(ViewGroup container, int position) {
7856
@Override
7957
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
8058
super.onResourceReady(resource, animation);
81-
if (photoViewAttacher!=null){
8259
photoViewAttacher.update();
83-
}
60+
photoViewAttacher.setZoomable(true);
8461
}
8562
});
8663

@@ -93,19 +70,6 @@ public void destroyItem(ViewGroup container, int position, Object object) {
9370
container.removeView((View) object);
9471
}
9572

96-
private String[] images= images= new String[] {
97-
"http://img.my.csdn.net/uploads/201407/26/1406383299_1976.jpg",
98-
"http://img.my.csdn.net/uploads/201407/26/1406383291_6518.jpg",
99-
"http://img.my.csdn.net/uploads/201407/26/1406383291_8239.jpg",
100-
"http://img.my.csdn.net/uploads/201407/26/1406383290_9329.jpg",
101-
"http://img.my.csdn.net/uploads/201407/26/1406383290_1042.jpg",
102-
"http://img.my.csdn.net/uploads/201407/26/1406383275_3977.jpg",
103-
"http://img.my.csdn.net/uploads/201407/26/1406383265_8550.jpg",
104-
"http://img.my.csdn.net/uploads/201407/26/1406383264_3954.jpg",
105-
"http://img.my.csdn.net/uploads/201407/26/1406383264_4787.jpg",
106-
"http://img.my.csdn.net/uploads/201407/26/1406383264_8243.jpg",
107-
"http://img.my.csdn.net/uploads/201407/26/1406383248_3693.jpg",
108-
};
10973

11074

11175

app/src/main/res/layout/item_image_browser.xml

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,6 @@
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
5-
<<<<<<< HEAD
6-
android:gravity="center"
7-
android:orientation="vertical">
8-
9-
<ScrollView
10-
android:scrollbars="none"
11-
android:fillViewport="true"
12-
android:layout_width="match_parent"
13-
android:layout_height="match_parent"
14-
android:orientation="vertical">
15-
16-
<RelativeLayout
17-
android:gravity="center"
18-
android:layout_width="match_parent"
19-
android:layout_height="wrap_content"
20-
android:layout_gravity="center"
21-
android:orientation="vertical">
22-
23-
<ImageView
24-
android:id="@+id/show_webimage_imageview"
25-
android:layout_width="match_parent"
26-
android:layout_height="match_parent"
27-
android:layout_centerInParent="true"
28-
android:background="@android:color/white"
29-
android:src="@drawable/avatar_default" />
30-
</RelativeLayout>
31-
32-
</ScrollView>
33-
34-
</RelativeLayout>
35-
=======
365
android:gravity="center">
376
<ScrollView
387
android:fillViewport="true"
@@ -46,12 +15,11 @@
4615
android:layout_width="match_parent"
4716
android:layout_height="match_parent"
4817
android:gravity="center_vertical">
49-
50-
<com.bm.library.PhotoView
18+
<uk.co.senab.photoview.PhotoView
5119
android:layout_centerVertical="true"
5220
android:id="@+id/show_webimage_imageview"
5321
android:layout_width="match_parent"
54-
android:layout_height="wrap_content"
22+
android:layout_height="match_parent"
5523
android:layout_centerInParent="true"
5624
android:layout_gravity="center"
5725
android:adjustViewBounds="true"
@@ -62,4 +30,4 @@
6230
</ScrollView>
6331

6432
</RelativeLayout>
65-
>>>>>>> 0831dd24e7b54faf66ebc17009a3bdac575b3baa
33+

0 commit comments

Comments
 (0)