写了简单
Android环境下基于webview的浏览器,实现划屏切换页面的手势,在一个activity里webview的缓冲内切换的。并测试下调用系统拍照的功能
MVC模式(Model-View-Controller)
1.WebView的设置部分
01 |
private void showViews() { |
03 |
mGestureDetector = new GestureDetector( this ); |
04 |
wv_vm.getSettings().setSupportZoom( true ); |
05 |
wv_vm.getSettings().setBuiltInZoomControls( true ); |
09 |
wv_vm.setOnTouchListener( this ); |
10 |
wv_vm.setClickable( true ); |
11 |
wv_vm.setLongClickable( true ); |
13 |
mGestureDetector.setIsLongpressEnabled( true ); |
15 |
wv_vm.setWebViewClient( new HelloWebViewClient()); |
16 |
wv_vm.setFocusable( true ); |
在WebView加载新开的页面,是重写了Android.webkit.WebViewClient
1 |
private class HelloWebViewClient extends WebViewClient { |
3 |
public boolean shouldOverrideUrlLoading(WebView view, String url) { |
2.划屏手势部分
监听触摸时间传给手势对象
2 |
public boolean onTouch(View v, MotionEvent event) { |
5 |
return mGestureDetector.onTouchEvent(event); |
重写了划动事件
02 |
public boolean onFling(MotionEvent e1, MotionEvent e2, float <SPAN class =wp_keywordlink_affiliate><A title=Velocity href= "http://www.mikel.cn/tag/velocity/" target=_blank>Velocity</A></SPAN>X, |
05 |
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE |
06 |
&& Math.abs(<SPAN class =wp_keywordlink_affiliate><A title=Velocity href= "http://www.mikel.cn/tag/velocity/" target=_blank>Velocity</A></SPAN>X) > SWIPE_THRESHOLD_VELOCITY) { |
08 |
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE |
09 |
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { |
变量、常量的声明
1 |
private GestureDetector mGestureDetector; |
3 |
private static final int SWIPE_MIN_DISTANCE = 120 ; |
4 |
private static final int SWIPE_THRESHOLD_VELOCITY = 200 ; |
3.调用系统拍照功能部分
01 |
private void setListensers() { |
03 |
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
04 |
startActivityForResult(intent, 1 ); |
08 |
private void findViews() { |
10 |
img_pic=(ImageView)findViewById(R.id.img_pic); |
14 |
protected void onActivityResult( int requestCode, int resultCode, Intent data) |
18 |
if (resultCode == Activity.RESULT_OK) |
21 |
Bitmap cameraBitmap = (Bitmap) data.getExtras().get( "data" ); |
23 |
img_pic.setImageBitmap(cameraBitmap); |
26 |
super .onActivityResult(requestCode, resultCode, data); |
小demo的源码本来上传到csdn了,可在我上传的资源就是找不到,可能在审核,等我之后不上下载链接吧
想要demo源码也可以邮件给我