安卓3.X ONLY的WebView文本选择+ JavaScript的 [英] Android 3.x ONLY WebView Text Selection + JavaScript

查看:155
本文介绍了安卓3.X ONLY的WebView文本选择+ JavaScript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题领域:机器人的WebView基础的ePub格式文件阅读器 -

Problem domain: Android WebView based ePub format reader --

我们需要的文本亮点,它通过JavaScript的方法可访问(即打开EM上,把时间关闭,保存它们给他们发电子邮件等)

We need text highlights which are accessible via JavaScript methods (ie turn em on, turn em off, save them email them, etc)

的任何人都知道,请纠正我,如果我错了: 在上一个的WebView文本选择 -

Anyone in the know, please correct me if I'm wrong: During text selection on a WebView --

基本上,我们都交给一个TextView覆盖(WebTextView),这是在连接到底层的HTML以外的其他视觉(很好的工作,在排队这一切,使之浑然一体,顺便说一句)没办法,上,我们进行了TextSelectionActionMode和ClipboardManager与结果提供...使清楚,用的WebView实际的HTML实际上并没有在此股票的过程,这就是为什么JavaScript不能访问操作的结果选择在任何时间。

Basically we are handed a TextView overlay (WebTextView) which is IN NO WAY attached to the underlying html other than visually (nice job on lining it all up and making it seamless, btw), on which we perform the TextSelectionActionMode and the ClipboardManager is supplied with the results... to make that clear, the actual HTML with the WebView IS NOT actually selected at any time during this stock process, which is why the JavaScript cannot access the results of the action.

因此​​,为了使这种行为的工作3.1+,我有几个可能的计划向前迈进,以实现在web视图我自己的选择 - 这就是我想知道如果我不能看的出来我的角落部分:) -

So in order to make this behavior work in 3.1+, I have a few possible plans going forward to implement my own selection on a WebView -- this is the part where I'm wondering if I cannot see out of my corner :) --

1)捕获的长按它启动选择模式MOTION_DOWN,覆盖内置的TextSelection ActionMode(以provde客户品牌 - 我发现这样做的方式是如此的hackish它伤害)观看拖累,捕捉MOTION_UP位置,映射这些COORDS到 web视图,并让我选择的基础上,COORDS(在比较文字,到ClipboardManager捕获)

1) capture MOTION_DOWN of the long click which initiates selection mode, override the built in TextSelection ActionMode( to provde the clients branding -- the way I found to do so is so hackish it hurts) watch the drag, capture MOTION_UP position, map these coords onto the WebView, and make my selection based on the coords (while comparing the text to that captured by the ClipboardManager)

2)建立自己的WebTextView(整个洛塔工作大声笑)不,所谓hackishly创建自己的ActionMode做上述所有。

2) create my own "WebTextView" (whole lotta work lol) and not-so- hackishly create my own ActionMode and do all of the above.

3)使用的选股过程中产生的MotionEvents并以某种方式覆盖股票TextSelection ActionMode这个引起的。

3) use the MotionEvents generated by the stock selection process and somehow override the stock TextSelection ActionMode triggered by this.

这是我看到的选项,希望我的接近和无奈 这个已经蒙蔽了我一个更简单的(读,由于内置) 溶液或两个。

These are the options I see, hopefully my proximity and frustration with this have blinded me to a simpler (read that as built-in) solution or two.

再次感谢您的时间。

推荐答案

我在2.2得到了这个工作。我使用的JavaScript接口,并通过了所有接触到它。该解决方案似乎工作pretty的很好,我已经把在GitHub上的示例项目。 GitHub的项目包括在资产的文件夹中的必要的JS和加载测试页面,并实现了所有必要的方法来处理选择测试页和Web视图。链接到GitHub的项目是<一个href="https://github.com/btate/BTAndroidWebViewSelection">https://github.com/btate/BTAndroidWebViewSelection.有吧。

I got this working in 2.2 - 4.0.3. I used a javascript interface and passed all touches to it. The solution seems to work pretty well and I've put an example project on github. The github project includes the necessary js in the assets folder as well as a test page and web view that loads the test page and implements all necessary methods to handle the selection. The link to the github project is https://github.com/btate/BTAndroidWebViewSelection. Have at it.

这篇关于安卓3.X ONLY的WebView文本选择+ JavaScript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆