android browser中长按图片事件
来源:互联网 发布:数据分析的重要性 编辑:程序博客网 时间:2024/05/02 01:30
1. 长按事件
public boolean onLongClick(View v) {
final HitTestResult htr = webview.getHitTestResult();
if (htr.getType() == WebView.HitTestResult.IMAGE_TYPE) {
new AlertDialog.Builder(this)
.setTitle(htr.getExtra())
.setItems(R.array.image_long_click_event,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
if (which == 0) {
// view image
webview.loadUrl(htr.getExtra());
} else if (which == 1) {
// save image
downloadImage(htr.getExtra());
} else if (which == 2) {
// set wallpaper
setWallpaper(htr.getExtra());
}
}
}).show();
}
return false;
}
其中
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="image_long_click_event">
<item>View Image</item>
<item> Save Image</item>
<item>Save as Wallpaper</item>
</string-array>
</resources>
protected void downloadImage(String extra) {
DownloadManager downloadManager = ((DownloadManager) getSystemService(Activity.DOWNLOAD_SERVICE));
Request request = new Request(Uri.parse(extra));
request.setShowRunningNotification(true);
request.setVisibleInDownloadsUi(true);
request.setDescription(extra);
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, "allenSample.png");
downloadManager.enqueue(request);
}
protected void setWallpaper(String extra) {
try {
Bitmap bitmap = loadImageFromUrl(extra);
setWallpaper(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Bitmap loadImageFromUrl(String url) {
InputStream inputStream;
Bitmap b;
try {
inputStream = (InputStream) new URL(url).getContent();
BitmapFactory.Options bpo = new BitmapFactory.Options();
bpo.inSampleSize = 2;
b = BitmapFactory.decodeStream(inputStream, null, bpo);
return b;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
- android browser中长按图片事件
- Android中长按事件操作
- Android中长按事件时短按事件也触发的问题
- Android系统中长按事件的实现机制解析
- Android系统中长按事件的实现机制解析
- Android系统中长按事件的实现机制解析
- Android系统中长按事件的实现机制解析
- Android系统中长按事件的实现机制解析
- listview中长按事件响应
- Android实现在webview中长按图片弹出菜单保存图片
- Listview中长按事件响应处理
- Listview中长按事件响应处理
- Android自定义popupwindow实现ios中UC浏览器中长按图片弹出的PopupWindow效果
- Android中长按ListView实现批量删除
- Android中长按监听的使用
- 关于iOS开发中长按保存图片到相册
- Android中长按弹出选项框View进行操作
- android 自己写的Launcher中长按选择壁纸
- ArcGIS Server 9.3安装流程
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- 解决VSTO EXCEL 设置合并单元格锁定时报错问题
- 关于python 的学习资料
- Builder
- android browser中长按图片事件
- div+CSS设置一行内文字超过宽度不换行且不显示
- Android模仿iPhone ListView旋转刷新数据动画详解
- adb remount bash: /usr/local/bin/adb: Permission denied
- ABAP:区别CALL SCREEN/SET SCREEN/LEAVE TO SCREEN
- tomcat与resin的比较
- android像素单位:dip 、px、dp、sp
- 设计模式之观察者模式
- Groovy:简单的介绍Groovy