Comments (2)
How do I get an image click event?
from markdownview.
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {
private MarkdownView mMarkdownView;
@SuppressLint("JavascriptInterface")
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
mMarkdownView = (MarkdownView )findViewById(R.id.markdown_view);
InternalStyleSheet css = new Github();
//css.addRule("body", "line-height: 1.6", "padding: 0px");
//css.addRule(".scrollup", "width: 40px", "height: 40px", "position: fixed", "bottom: 15px", "right: 15px", "visibility: hidden", "display: flex", "align-items: center", "justify-content: center", "margin: 0 !important", "line-height: 70px", "box-shadow: 0 0 4px rgba(0, 0, 0, 0.14), 0 4px 8px rgba(0, 0, 0, 0.28)", "border-radius: 50%", "color: #fff", "padding: 5px");
//css.removeRule (".scrollup");
mMarkdownView.addStyleSheet(css);
mMarkdownView.loadMarkdown("***********");//
**mMarkdownView.setWebViewClient(new WebViewClient (){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
});
**mMarkdownView.getSettings().setJavaScriptEnabled(true); //支持JS**
mMarkdownView.addJavascriptInterface(new JsInterface(this), "imageClick"); //JS交互
mMarkdownView.setOnTouchListener(this);
}
class JsInterface{
Context context;
public JsInterface(Context context){
this.context = context;
}
//查看图片url
@JavascriptInterface
public void click(String url){
Toast.makeText (context,url,Toast.LENGTH_SHORT).show ();
Log.d ("1111",url);
}
}
float x,y;
@Override
public boolean onTouch(View v, MotionEvent event) {
//通过wenview的touch来响应web上的图片点击事件
float density = getResources().getDisplayMetrics().density; //屏幕密度
float touchX = event.getX() / density; //必须除以屏幕密度
float touchY = event.getY() / density;
if(event.getAction() == MotionEvent.ACTION_DOWN){
x = touchX;
y = touchY;
}
if(event.getAction() == MotionEvent.ACTION_UP){
float dx = Math.abs(touchX-x);
float dy = Math.abs(touchY-y);
if(dx<10.0/density&&dy<10.0/density){
clickImage(touchX,touchY);
}
}
return false;
}
private void clickImage(float touchX, float touchY) {
//通过触控的位置来获取图片URL
String js = "javascript:(function(){" +
"var obj=document.elementFromPoint("+touchX+","+touchY+");"
+"if(obj.src!=null){"+ " window.imageClick.click(obj.src);}" +
"})()";
mMarkdownView.loadUrl(js);
}
}
from markdownview.
Related Issues (20)
- Arrumar o MathJax
- Adicionar botão voltar ao topo HOT 1
- Usar outra fonte de emojis em vez do EmojiOne
- Adicionar quebra de linha em algumas tags
- Atualizar o Highlight.js
- How do I get all the pictures?
- minSdk might be downgraded to 15
- Can i disable the FAB? HOT 2
- Make the scroll up button optional HOT 2
- Proguard rules missing HOT 1
- Can you add a dark mode?
- Load images from assets folder HOT 3
- MathJax support
- Complex mathematical formulas fails to display
- Add request: Listeners load, Finished... HOT 1
- App hangs on loading multiple markdown views
- Remove "app_name" resource
- Support RTL in Paragraphs HOT 1
- Substituir MathJax por Katex
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdownview.