2013.11.18
7123 ワード
:2
,android 。。。
app, url , webview ,
copy, 。
, url 。 , html(url) , ,
。 , , , 。
, , url ,
, , 。 , 。
, ,webview javascript
, webview js , html , img , ,
。
javascript
contentWebView.getSettings().setJavaScriptEnabled(true);
js
contentWebView.addJavascriptInterface(new InJavaScriptLocalObj(), "local_obj");
MyWebViewClient
@Override
public void onPageFinished(WebView view, String url) {
view.getSettings().setJavaScriptEnabled(true);
super.onPageFinished(view, url);
// html , js
addImageClickListner();
view.loadUrl("javascript:(function(){" +
"var objs = document.getElementsByTagName(\"img\"); " +
"var arr=new Array(); " +
"if(objs.length>0){" +
"for(var i=0;i " {" +
" arr[i]=objs[i].src;"
+ " } " +
"var str=arr.join(\",\");" +
"function Image(){window.cache_image.cacheimage(str);}" +
" Image();}" +
"})()");
view.loadUrl("javascript:window.local_obj.showSource(''+" +
"document.getElementsByTagName('html')[0].innerHTML+'');");
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
view.getSettings().setJavaScriptEnabled(true);
super.onPageStarted(view, url, favicon);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String
failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
}
imageview.addUrl()
js:
contentWebView.loadUrl("javascript:(function(){" +
"var objs = document.getElementsByTagName(\"img\"); " +
"for(var i=0;i "{"
+ " objs[i].onclick=function() " +
" { "
+ " window.imagelistner.openImage(this.src); " +
" } " +
"}" +
"})()");
js html 。
、
:
activity , activity 。 OnTouchListener
imgview.setOnTouchListener(this);
imgview.setLongClickable(true);
View setLongClickable(boolean longClickable) , 。
true ,false 。 true MotionEvent.ACTION_UP !
onTouch
2 View v, MotionEvent event
v ,event
switch (event.getActionMasked()) {//
case MotionEvent.ACTION_DOWN://
matrix.set(imgview.getImageMatrix());
savedMatrix.set(matrix);
start.set(event.getX(), event.getY());// (PointF)
start Log.d("Infor", " ...");
mode = DRAG;
break;
case MotionEvent.ACTION_POINTER_DOWN: //
oldDist = this.spacing(event);// 2 , 10f,
if (oldDist > 10f) {
Log.d("Infor", "oldDist" + oldDist);
savedMatrix.set(matrix);
midPoint(mid, event);//
old.set(event.getX(1), event.getY(1));//
old ,
mode = ZOOM;
}
break;
case MotionEvent.ACTION_POINTER_UP://
mode = NONE;
break;
case MotionEvent.ACTION_MOVE:
if (mode == DRAG) { // ...
matrix.set(savedMatrix);
matrix.postTranslate(event.getX() - start.x, event.getY()
- start.y);//postTranslate
} else if (mode == ZOOM) {// ...
now.set(event.getX(1), event.getY(1));
, , now
float newDist = spacing(event);//
if (newDist > 10) {
float angle=degree(mid,event);
matrix.set(savedMatrix);
float scale = newDist / oldDist;
matrix.postScale(scale, scale, mid.x, mid.y);
matrix.postRotate(angle, mid.x, mid.y);
}
}
break;
}
imgview.setImageMatrix(matrix);
,
: , 。——————————》 !!!!
html img , , html 。
private void addImageClickListner() {
// js , img , onclick ,
java url
contentWebView.loadUrl("javascript:(function(){" +
"var objs = document.getElementsByTagName(\"img\"); " +
"for(var i=0;i "{"
+ " objs[i].onclick=function() " +
" { "
+ " window.imagelistner.openImage(this.src); " +
" } " +
"}" +
"})()");
}
MyWebViewClient
addImageClickListner();
contentWebView.addJavascriptInterface(new JavascriptInterface(this), "imagelistner");
url
js
js
android
File myCaptureFile = new File(ALBUM_PATH+nid+".html");
try {
BufferedOutputStream bos = new BufferedOutputStream(new
FileOutputStream(myCaptureFile));
// byte
byte[] bytes = s1.getBytes();
bos.write(bytes);// byte
bos.close();//
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent();
intent.setClass(MainActivity.this, MainLoginActivity.class);
startActivity(intent);
MainActivity.this.finish();
}
}, 3000);