├── .gitignore
├── AsynImageWebView
├── AndroidManifest.xml
├── libs
│ └── jsoup-1.7.2.jar
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── activity_main.xml
│ ├── menu
│ │ └── main.xml
│ ├── values-sw600dp
│ │ └── dimens.xml
│ ├── values-sw720dp-land
│ │ └── dimens.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── com
│ └── dpt
│ └── asynimagewebview
│ ├── helper
│ ├── Parser.java
│ └── WebViewHelper.java
│ └── widget
│ └── TouchImageView.java
├── AsynImageWebViewDemo
├── AndroidManifest.xml
├── assets
│ └── web_logo.png
├── ic_launcher-web.png
├── libs
│ └── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── activity_main.xml
│ ├── menu
│ │ └── main.xml
│ ├── values-sw600dp
│ │ └── dimens.xml
│ ├── values-sw720dp-land
│ │ └── dimens.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── com
│ └── dpt
│ └── asynimagewebviewdeno
│ └── MainActivity.java
├── README.md
└── example_image.jpg
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Intellij project files
26 | *.iml
27 | *.ipr
28 | *.iws
29 | .idea/
30 |
--------------------------------------------------------------------------------
/AsynImageWebView/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/AsynImageWebView/libs/jsoup-1.7.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebView/libs/jsoup-1.7.2.jar
--------------------------------------------------------------------------------
/AsynImageWebView/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/AsynImageWebView/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-15
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/AsynImageWebView/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebView/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AsynImageWebView/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebView/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AsynImageWebView/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebView/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AsynImageWebView/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/AsynImageWebView/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/AsynImageWebView/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/AsynImageWebView/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/AsynImageWebView/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/AsynImageWebView/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/AsynImageWebView/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/AsynImageWebView/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | AsynImageWebView
5 | Settings
6 | Hello world!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/AsynImageWebView/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
24 |
25 |
--------------------------------------------------------------------------------
/AsynImageWebView/src/com/dpt/asynimagewebview/helper/Parser.java:
--------------------------------------------------------------------------------
1 | package com.dpt.asynimagewebview.helper;
2 |
3 | import java.io.File;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import org.jsoup.Jsoup;
8 | import org.jsoup.nodes.Document;
9 | import org.jsoup.nodes.Element;
10 | import org.jsoup.select.Elements;
11 |
12 | import android.os.Environment;
13 | import android.webkit.WebView;
14 | /**
15 | *
16 | * @author pengtao.du@downjoy.com
17 | *
18 | */
19 | public abstract class Parser {
20 |
21 | private WebView webView;
22 | public static String Js2JavaInterfaceName = "JsUseJava";
23 | public List imgUrls = new ArrayList();
24 |
25 | public Parser(String mUrl, WebView webView) {
26 | this.webView = webView;
27 | }
28 |
29 | public List getImgUrls(){
30 | return imgUrls;
31 | }
32 |
33 | public void loadData(){
34 | String html=downloadHtml();
35 | Document doc = Jsoup.parse(html);
36 | imgUrls.clear();
37 | Elements es = doc.getElementsByTag("img");
38 | for (Element e : es) {
39 | String imgUrl = e.attr("src");
40 | imgUrls.add(imgUrl);
41 | String imgName;
42 | File file = new File(imgUrl);
43 | imgName = file.getName();
44 | if(imgName.endsWith(".gif")){
45 | e.remove();
46 | }else{
47 | File dir = new File(Environment.getExternalStorageDirectory() + "/test/"+imgName);
48 | String filePath = "file:///mnt/sdcard/test/" + imgName;
49 | e.attr("src","file:///android_asset/web_logo.png");
50 | e.attr("src_link", filePath);
51 | e.attr("ori_link",imgUrl);
52 | String str = "window." + Js2JavaInterfaceName + ".setImgSrc('"
53 | + dir.getPath() + "')";
54 | e.attr("onclick", str);
55 | }
56 | }
57 | webView.loadDataWithBaseURL(null, doc.html(),"text/html", "utf-8", null);
58 | }
59 |
60 | public abstract String downloadHtml();
61 | }
62 |
--------------------------------------------------------------------------------
/AsynImageWebView/src/com/dpt/asynimagewebview/helper/WebViewHelper.java:
--------------------------------------------------------------------------------
1 | package com.dpt.asynimagewebview.helper;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileNotFoundException;
6 | import java.io.FileOutputStream;
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.OutputStream;
10 | import java.net.HttpURLConnection;
11 | import java.net.MalformedURLException;
12 | import java.net.URL;
13 | import java.util.List;
14 |
15 | import android.annotation.SuppressLint;
16 | import android.app.Dialog;
17 | import android.content.Context;
18 | import android.graphics.BitmapFactory;
19 | import android.os.AsyncTask;
20 | import android.os.Environment;
21 | import android.util.Log;
22 | import android.webkit.WebSettings.LayoutAlgorithm;
23 | import android.webkit.WebView;
24 | import android.webkit.WebViewClient;
25 |
26 | import com.dpt.asynimagewebview.R;
27 | import com.dpt.asynimagewebview.widget.TouchImageView;
28 | /**
29 | *
30 | * @author pengtao.du@downjoy.com
31 | *
32 | */
33 | public class WebViewHelper {
34 |
35 | private WebView mWebView;
36 | private Context mContext;
37 | private String TAG = "WebViewHelper";
38 | public WebViewHelper(Context context) {
39 | mContext = context;
40 | }
41 |
42 | public void execute(WebView webView, final Parser parser) {
43 | mWebView = webView;
44 | setupWebView();
45 | parser.loadData();
46 | webView.setWebViewClient(new WebViewClient() {
47 |
48 | public void onPageFinished(WebView view, String url) {
49 |
50 | DownloadWebImgTask downloadTask = new DownloadWebImgTask();
51 | List urlStrs = parser.getImgUrls();
52 | String urlStrArray[] = new String[urlStrs.size() + 1];
53 | urlStrs.toArray(urlStrArray);
54 | downloadTask.execute(urlStrArray);
55 | }
56 |
57 | @Override
58 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
59 | return true;
60 | }
61 | });
62 | }
63 |
64 | @SuppressLint("JavascriptInterface")
65 | private void setupWebView() {
66 | mWebView.addJavascriptInterface(new Js2JavaInterface(),
67 | Parser.Js2JavaInterfaceName);
68 | mWebView.getSettings()
69 | .setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
70 | mWebView.getSettings().setJavaScriptEnabled(true);
71 | mWebView.getSettings().setBlockNetworkImage(true);
72 | }
73 |
74 | public class Js2JavaInterface {
75 | public void setImgSrc(String imgSrc) {
76 | Log.e(TAG, "setImgSrc : " + imgSrc);
77 | Dialog dialog = new Dialog(mContext, R.style.Dialog_Fullscreen);
78 | TouchImageView touch = new TouchImageView(mContext);
79 | try {
80 | touch.setImageBitmap(BitmapFactory
81 | .decodeStream(new FileInputStream(imgSrc)));
82 | } catch (FileNotFoundException e) {
83 | e.printStackTrace();
84 | }
85 | touch.setMaxZoom(4f);
86 | dialog.setContentView(touch);
87 | dialog.show();
88 | }
89 | }
90 |
91 | public class DownloadWebImgTask extends AsyncTask {
92 |
93 | public static final String TAG = "DownloadWebImgTask";
94 |
95 | @Override
96 | protected void onProgressUpdate(String... values) {
97 | super.onProgressUpdate(values);
98 |
99 | mWebView.loadUrl("javascript:(function(){"
100 | + "var objs = document.getElementsByTagName(\"img\"); "
101 | + "for(var i=0;i 0) {
170 | outputStream.write(buffer, 0, bufferLength);
171 | }
172 | outputStream.flush();
173 | publishProgress(urlStr);
174 | } catch (MalformedURLException e) {
175 | e.printStackTrace();
176 | } catch (IOException e) {
177 | e.printStackTrace();
178 | } finally {
179 |
180 | try {
181 | if (inputStream != null) {
182 | inputStream.close();
183 | }
184 | } catch (IOException e1) {
185 | e1.printStackTrace();
186 | }
187 | try {
188 | if (outputStream != null) {
189 | outputStream.close();
190 | }
191 | } catch (IOException e) {
192 | e.printStackTrace();
193 | }
194 | }
195 | }
196 | return null;
197 | }
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/AsynImageWebView/src/com/dpt/asynimagewebview/widget/TouchImageView.java:
--------------------------------------------------------------------------------
1 | package com.dpt.asynimagewebview.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Matrix;
6 | import android.graphics.PointF;
7 | import android.view.MotionEvent;
8 | import android.view.ScaleGestureDetector;
9 | import android.view.View;
10 | import android.widget.ImageView;
11 |
12 | public class TouchImageView extends ImageView {
13 |
14 | Matrix matrix = new Matrix();
15 |
16 | // We can be in one of these 3 states
17 | static final int NONE = 0;
18 | static final int DRAG = 1;
19 | static final int ZOOM = 2;
20 | int mode = NONE;
21 |
22 | // Remember some things for zooming
23 | PointF last = new PointF();
24 | PointF start = new PointF();
25 | float minScale = 1f;
26 | float maxScale = 3f;
27 | float[] m;
28 |
29 | float redundantXSpace, redundantYSpace;
30 |
31 | float width, height;
32 | static final int CLICK = 3;
33 | float saveScale = 1f;
34 | float right, bottom, origWidth, origHeight, bmWidth, bmHeight;
35 |
36 | ScaleGestureDetector mScaleDetector;
37 |
38 | Context context;
39 |
40 |
41 | public TouchImageView(Context context) {
42 | super(context);
43 | super.setClickable(true);
44 | this.context = context;
45 | mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
46 | matrix.setTranslate(1f, 1f);
47 | m = new float[9];
48 | setImageMatrix(matrix);
49 | setScaleType(ScaleType.MATRIX);
50 |
51 | setOnTouchListener(new OnTouchListener() {
52 |
53 | @Override
54 | public boolean onTouch(View v, MotionEvent event) {
55 | mScaleDetector.onTouchEvent(event);
56 |
57 | matrix.getValues(m);
58 | float x = m[Matrix.MTRANS_X];
59 | float y = m[Matrix.MTRANS_Y];
60 | PointF curr = new PointF(event.getX(), event.getY());
61 |
62 | switch (event.getAction()) {
63 | case MotionEvent.ACTION_DOWN:
64 | last.set(event.getX(), event.getY());
65 | start.set(last);
66 | mode = DRAG;
67 | break;
68 | case MotionEvent.ACTION_MOVE:
69 | if (mode == DRAG) {
70 | float deltaX = curr.x - last.x;
71 | float deltaY = curr.y - last.y;
72 | float scaleWidth = Math.round(origWidth * saveScale);
73 | float scaleHeight = Math.round(origHeight * saveScale);
74 | if (scaleWidth < width) {
75 | deltaX = 0;
76 | if (y + deltaY > 0)
77 | deltaY = -y;
78 | else if (y + deltaY < -bottom)
79 | deltaY = -(y + bottom);
80 | } else if (scaleHeight < height) {
81 | deltaY = 0;
82 | if (x + deltaX > 0)
83 | deltaX = -x;
84 | else if (x + deltaX < -right)
85 | deltaX = -(x + right);
86 | } else {
87 | if (x + deltaX > 0)
88 | deltaX = -x;
89 | else if (x + deltaX < -right)
90 | deltaX = -(x + right);
91 |
92 | if (y + deltaY > 0)
93 | deltaY = -y;
94 | else if (y + deltaY < -bottom)
95 | deltaY = -(y + bottom);
96 | }
97 | matrix.postTranslate(deltaX, deltaY);
98 | last.set(curr.x, curr.y);
99 | }
100 | break;
101 |
102 | case MotionEvent.ACTION_UP:
103 | mode = NONE;
104 | int xDiff = (int) Math.abs(curr.x - start.x);
105 | int yDiff = (int) Math.abs(curr.y - start.y);
106 | if (xDiff < CLICK && yDiff < CLICK)
107 | performClick();
108 | break;
109 |
110 | case MotionEvent.ACTION_POINTER_UP:
111 | mode = NONE;
112 | break;
113 | }
114 | setImageMatrix(matrix);
115 | invalidate();
116 | return true; // indicate event was handled
117 | }
118 |
119 | });
120 | }
121 |
122 | @Override
123 | public void setImageBitmap(Bitmap bm) {
124 | super.setImageBitmap(bm);
125 | bmWidth = bm.getWidth();
126 | bmHeight = bm.getHeight();
127 | }
128 |
129 | public void setMaxZoom(float x)
130 | {
131 | maxScale = x;
132 | }
133 |
134 | private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
135 | @Override
136 | public boolean onScaleBegin(ScaleGestureDetector detector) {
137 | mode = ZOOM;
138 | return true;
139 | }
140 |
141 | @Override
142 | public boolean onScale(ScaleGestureDetector detector) {
143 | float mScaleFactor = (float)Math.min(Math.max(.95f, detector.getScaleFactor()), 1.05);
144 | float origScale = saveScale;
145 | saveScale *= mScaleFactor;
146 | if (saveScale > maxScale) {
147 | saveScale = maxScale;
148 | mScaleFactor = maxScale / origScale;
149 | } else if (saveScale < minScale) {
150 | saveScale = minScale;
151 | mScaleFactor = minScale / origScale;
152 | }
153 | right = width * saveScale - width - (2 * redundantXSpace * saveScale);
154 | bottom = height * saveScale - height - (2 * redundantYSpace * saveScale);
155 | if (origWidth * saveScale <= width || origHeight * saveScale <= height) {
156 | matrix.postScale(mScaleFactor, mScaleFactor, width / 2, height / 2);
157 | if (mScaleFactor < 1) {
158 | matrix.getValues(m);
159 | float x = m[Matrix.MTRANS_X];
160 | float y = m[Matrix.MTRANS_Y];
161 | if (mScaleFactor < 1) {
162 | if (Math.round(origWidth * saveScale) < width) {
163 | if (y < -bottom)
164 | matrix.postTranslate(0, -(y + bottom));
165 | else if (y > 0)
166 | matrix.postTranslate(0, -y);
167 | } else {
168 | if (x < -right)
169 | matrix.postTranslate(-(x + right), 0);
170 | else if (x > 0)
171 | matrix.postTranslate(-x, 0);
172 | }
173 | }
174 | }
175 | } else {
176 | matrix.postScale(mScaleFactor, mScaleFactor, detector.getFocusX(), detector.getFocusY());
177 | matrix.getValues(m);
178 | float x = m[Matrix.MTRANS_X];
179 | float y = m[Matrix.MTRANS_Y];
180 | if (mScaleFactor < 1) {
181 | if (x < -right)
182 | matrix.postTranslate(-(x + right), 0);
183 | else if (x > 0)
184 | matrix.postTranslate(-x, 0);
185 | if (y < -bottom)
186 | matrix.postTranslate(0, -(y + bottom));
187 | else if (y > 0)
188 | matrix.postTranslate(0, -y);
189 | }
190 | }
191 | return true;
192 |
193 | }
194 | }
195 |
196 | @Override
197 | protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
198 | {
199 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
200 | width = MeasureSpec.getSize(widthMeasureSpec);
201 | height = MeasureSpec.getSize(heightMeasureSpec);
202 | //Fit to screen.
203 | float scale;
204 | float scaleX = (float)width / (float)bmWidth;
205 | float scaleY = (float)height / (float)bmHeight;
206 | scale = Math.min(scaleX, scaleY);
207 | matrix.setScale(scale, scale);
208 | setImageMatrix(matrix);
209 | saveScale = 1f;
210 |
211 | // Center the image
212 | redundantYSpace = (float)height - (scale * (float)bmHeight) ;
213 | redundantXSpace = (float)width - (scale * (float)bmWidth);
214 | redundantYSpace /= (float)2;
215 | redundantXSpace /= (float)2;
216 |
217 | matrix.postTranslate(redundantXSpace, redundantYSpace);
218 |
219 | origWidth = width - 2 * redundantXSpace;
220 | origHeight = height - 2 * redundantYSpace;
221 | right = width * saveScale - width - (2 * redundantXSpace * saveScale);
222 | bottom = height * saveScale - height - (2 * redundantYSpace * saveScale);
223 | setImageMatrix(matrix);
224 | }
225 |
226 | }
227 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/assets/web_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebViewDemo/assets/web_logo.png
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebViewDemo/ic_launcher-web.png
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebViewDemo/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-15
15 | android.library.reference.1=../AsynImageWebView
16 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebViewDemo/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebViewDemo/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebViewDemo/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/AsynImageWebViewDemo/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | AsynImageWebViewDemo
5 | Settings
6 | Hello world!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/AsynImageWebViewDemo/src/com/dpt/asynimagewebviewdeno/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dpt.asynimagewebviewdeno;
2 |
3 | import java.io.IOException;
4 |
5 | import org.apache.http.client.ClientProtocolException;
6 | import org.apache.http.client.HttpClient;
7 | import org.apache.http.client.methods.HttpGet;
8 | import org.apache.http.impl.client.BasicResponseHandler;
9 | import org.apache.http.impl.client.DefaultHttpClient;
10 |
11 | import android.os.Bundle;
12 | import android.app.Activity;
13 | import android.text.Html;
14 | import android.view.Menu;
15 | import android.webkit.WebView;
16 | import com.dpt.asynimagewebview.helper.*;
17 |
18 | public class MainActivity extends Activity {
19 |
20 | private WebView mWebView;
21 | private Parser mParser;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 | mWebView=(WebView)findViewById(R.id.webview);
28 | }
29 |
30 | @Override
31 | protected void onResume() {
32 | super.onResume();
33 | // only a demo
34 | new Thread(){
35 | public void run() {
36 | mParser = new Parser(null, mWebView) {
37 | @Override
38 | public String downloadHtml() {
39 | String html="";
40 | new Thread(){
41 | @Override
42 | public void run() {
43 | }
44 |
45 | }.start();
46 | DefaultHttpClient httpClient = new DefaultHttpClient();
47 | HttpGet httpGet = new HttpGet("http://wcf.open.cnblogs.com/news/item/183201");
48 | try {
49 | html = httpClient.execute(httpGet, new BasicResponseHandler());
50 | } catch (ClientProtocolException e) {
51 | e.printStackTrace();
52 | } catch (IOException e) {
53 | e.printStackTrace();
54 | }
55 | html=Html.fromHtml(html).toString();
56 | return html;
57 | }
58 | };
59 | new WebViewHelper(MainActivity.this).execute(mWebView, mParser);
60 | };
61 | }.start();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AsynImageWebView
2 | ================
3 |
4 | webview asynchronously load images refresh
5 |
6 | 实现了webview 加载网页,图片的异步加载和下载
7 |
8 | ###Demo截图
9 | 
10 |
--------------------------------------------------------------------------------
/example_image.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/AsynImageWebView/cd96bcaf02dafbc5ca1cbce1544abf4adfdebf9a/example_image.jpg
--------------------------------------------------------------------------------