Android的 - 网页视图页面需要双击 - 如何处理? [英] Android - Webview page requires double clicking - how to handle?

查看:268
本文介绍了Android的 - 网页视图页面需要双击 - 如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序仅仅是为了显示特定网站的WebView。用户不能简单地使用,因为在Android中固有的编程从而改变窃听功能的Chrome应用。

为了简单起见,假设该网站显示日历和该日历上的盒子。这些盒子既可以单单击要选择或单击双击要打开显示事件的详细信息。

该网站有编码处理的事如果事件是单人或双人点击:

 < D​​IV CLASS =boardpiece点击的onclick =选择(事件,这一点); onfocus此=打开('5657849');

我用长preSS模拟了双击完全没问题。这里是我的混乱开始的地方。如何我告诉我的应用程序,当用户执行关于该项目的SingleTap,它需要激活的onclick的网站呼吁?我还需要告诉应用程序,当用户执行上同一项长期preSS,激活onfocus此事件您在网站上看到有编码?

下面是我的活动code:

 进口android.webkit.WebView;
进口android.webkit.WebViewClient;
进口android.webkit.SslErrorHandler;
进口android.net.http.SslError;
进口android.os.Bundle;
进口android.app.Activity;
进口android.util.Log;
进口android.view.GestureDetector;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.view.GestureDetector.SimpleOnGestureListener;
进口android.view.MotionEvent;公共类MainActivity延伸活动{
    的WebView的WebView;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        网页流量=(的WebView)findViewById(R.id.webview);
        //我们是否想/需要启用Java?
        webview.getSettings()setJavaScriptEnabled(真)。
        //这里我们允许缩放控制 - 捏
        。webview.getSettings()setBuiltInZoomControls(真);
        //这里我们去掉变焦控制按钮 - 要求11 API
        。webview.getSettings()setDisplayZoomControls(假);
        //这里我们清除缓存和SSL preferences
        webview.clearCache(真);
        webview.clearSsl preferences();
        //我们是否需要启用滚动条,让人们左右滚动?
        webview.setHorizo​​ntalScrollBarEnabled(真);
        webview.setVerticalScrollBarEnabled(真);
        webview.setWebViewClient(新WebViewClient());
        webview.loadUrl(https://开头的网站);        最后GestureDetector GD =新GestureDetector(新MyGestureDetector());
        View.OnTouchListener GL =新View.OnTouchListener(){
            公共布尔onTouch(视图V,MotionEvent事件){
                返回gd.onTouchEvent(事件);
            }
        };
        webview.setOnTouchListener(GL);
    }    类MyGestureDetector扩展SimpleOnGestureListener {
        @覆盖
        公共布尔onDoubleTap(MotionEvent五){
            Log.i(,DoubleTap);
            返回true;
        }        公共布尔onSingleTap(MotionEvent五){
            Log.i(,SingleTap);
            返回true;
        }
    }
//忽略SSL证书错误
    公共无效onReceivedSslError(的WebView视图,SslErrorHandler处理器,SslError错误){
        handler.proceed();
    }//想有一个菜单按钮刷新页面 - 或者真的只是带给你到登录页面 - 使用时,会话超时
@覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
    menu.add(1,1,0,刷新);
    //getMenuInflater().inflate(R.menu.activity_main,菜单);
    返回true;
    }@覆盖
公共布尔onOptionsItemSelected(菜单项项){
    开关(item.getItemId()){
    案例R.id.reload:
        webview.loadUrl(简称网站);
        返回true;
    }
    返回super.onOptionsItemSelected(项目);}}


解决方案

我觉得你看这是错误的。相反的检测在Android中双击,并试图将其注入到你的Javascript你可能会被检测在JavaScript中双击。只要保持最后一个阶梯的时候,如果它已经足够最近第二次敲击是双击的一部分。

My app is simply a WebView to display a specific website. Users are not able to simply use the Chrome app because of the inherent programming in Android which alters the functions of tapping.

For simplicity, let's say the website displays a calendar and on that calendar are boxes. The boxes can either be single clicked to be selected or double clicked to be opened to display the event details.

The website has coding that handles what to do if an event is single or double clicked:

<div class="boardpiece clickable" onclick="select(event, this);" ondblclick="open('5657849');"

I'm completely fine with using longpress to simulate the double click. Here's where my confusion begins. How to I tell my app that when the user performs a SingleTap on the item, it needs to activate the "onclick" the website is calling for? I also need to tell the app that when the user performs a longpress on that same item, activate the "ondblclick" event you see there in the website coding?

Here is my activity code:

import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.SslErrorHandler;
import android.net.http.SslError;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;

public class MainActivity extends Activity{
    WebView webview;    

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webview = (WebView) findViewById(R.id.webview);   
        //Do we want/need to enable Java?
        webview.getSettings().setJavaScriptEnabled(true); 
        //Here we allow for zoom controls - pinch
        webview.getSettings().setBuiltInZoomControls(true);
        //Here we remove the zoom control buttons - requires API 11
        webview.getSettings().setDisplayZoomControls(false);
        //Here we clear the Cache and SSL Preferences       
        webview.clearCache(true);
        webview.clearSslPreferences();
        //Do we need to enable scroll bars to allow people to scroll left and right?        
        webview.setHorizontalScrollBarEnabled(true);
        webview.setVerticalScrollBarEnabled(true);
        webview.setWebViewClient(new WebViewClient());
        webview.loadUrl("https://website");

        final GestureDetector gd = new GestureDetector(new MyGestureDetector());
        View.OnTouchListener gl = new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                return gd.onTouchEvent(event);
            }
        };
        webview.setOnTouchListener(gl);
    }

    class MyGestureDetector extends SimpleOnGestureListener {    
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            Log.i("", "DoubleTap");
            return true;
        }   

        public boolean onSingleTap(MotionEvent e) {
            Log.i("", "SingleTap");
            return true;
        }
    }    


// Ignore SSL certificate errors    
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed();
    }

//Would like to have a Menu Button to refresh the page - or really just bring you to the login page - for use when the session times out    
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(1, 1, 0, "Reload");
    //getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
    }

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()){
    case R.id.reload:
        webview.loadUrl("website");
        return true;
    }
    return super.onOptionsItemSelected(item);

}

}

解决方案

I think you're looking at this wrong. Instead of detecting the double tap in Android and trying to inject it into your Javascript you could be detecting the double tap in Javascript. Just keep the time of the last tap and if it's been recently enough the second tap is part of a double tap.

这篇关于Android的 - 网页视图页面需要双击 - 如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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