不能让退格在codeMIRROR工作,下的PhoneGap在Android 4.x的? [英] Can't get backspace to work in codemirror, under Phonegap on Android 4.x?

查看:204
本文介绍了不能让退格在codeMIRROR工作,下的PhoneGap在Android 4.x的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要表现良好,为我的应用程序基于Web的文/ code编辑器。

I need a web-based text/code editor that behaves well, for my App.

我想使用PhoneGap的下codeMIRROR,目前我有收到退格问题工作previously输入的文本。这是我的用例一个巨大的问题。现在我一看四周,看起来它不是一个直接的codeMIRROR问题,而是Android和虚拟键盘说大话,看到了这个问题:<一href="http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection/">Android:退格在web视图/ BaseInputConnection

I'm trying to use codemirror under Phonegap and currently I'm having problems getting backspace to work for previously entered text. This is a huge problem for my use case. Now I've had a look around and it seems like it's not a direct codemirror problem, but rather the android and virtual keyboard malarkey, see this question: Android: Backspace in WebView/BaseInputConnection

我使用PhoneGap的2.6.0版本,最新的codeMIRROR版本(截至昨晚)和测试的Andr​​oid 4.2.2。这似乎是具体的WebView在Android上,任何人都可以证实这不是在iOS上的问题?

I'm using Phonegap version 2.6.0, latest codemirror version (as of last night) and testing on Android 4.2.2. This seems to be specific to WebView on Android, could anyone verify that's not an issue on iOS?

我不反对做一些Java code纠正这个问题,但我不知道如何'钩子'到科尔多瓦的实现的WebView的,因为所有的code,它的裸给我包括:

I'm not averse to doing some Java code to rectify the problem, but I'm not sure how to 'hook' into the cordova's implementation of WebView, as all the code that's exposed to me consists of:

package com.mycompany.MyAppName;

import android.os.Bundle;
import org.apache.cordova.*;

public class MyAppName extends DroidGap{
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html")
    }
}

除非我应该寻找到Cordovas源代码树。基本上我想知道的是我如何可以实现的解决方案,在上面我的情况的链接。任何帮助是极大AP preciated!

unless I'm supposed to look into Cordovas source tree. Essentially what I want to know is how I can implement the solution at the link above in my case. Any help is greatly appreciated!

推荐答案

覆盖初始化活动方式:

public class ProjectName extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        init(); // Don't forget this, you'll get runtime error otherwise!

        // The following does the trick:
        super.appView.getSettings().setUseWideViewPort(true);
        super.appView.getSettings().setLoadWithOverviewMode(true);

        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html")
        super.setIntegerProperty("loadUrlTimeoutValue", 10000); 
    }

    /**
     * Create and initialize web container with default web view objects.
     */
    @Override
    public void init() {
        CordovaWebView webView = new CustomWebView(ProjectName.this);
        CordovaWebViewClient webViewClient;
        if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
        {
            webViewClient = new CordovaWebViewClient(this, webView);
        }
        else
        {
            webViewClient = new IceCreamCordovaWebViewClient(this, webView);
        }
        this.init(webView, webViewClient, new CordovaChromeClient(this, webView));
    }

}

创建于CustomWebView延伸CordovaWebView

Create on CustomWebView which extends CordovaWebView

public class CustomWebView extends CordovaWebView{

    public CustomWebView(Context context) {
        super(context);
    }

    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        MyCustomInputConnection connection = new MyCustomInputConnection(this, false);

        return connection;
    }

}

创建自定义InputConnection:

Create your custom InputConnection :

public class MyCustomInputConnection extends BaseInputConnection{

    public MyCustomInputConnection(View targetView, boolean fullEditor) {
        super(targetView, fullEditor);
    }

    @Override
    public boolean deleteSurroundingText(int beforeLength, int afterLength) {       
        // magic: in latest Android, deleteSurroundingText(1, 0) will be called for backspace
        if (beforeLength == 1 && afterLength == 0) {
            // backspace
            return super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
                && super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
        }

        return super.deleteSurroundingText(beforeLength, afterLength);
    }
}

这篇关于不能让退格在codeMIRROR工作,下的PhoneGap在Android 4.x的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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