2012-03-28 12 views
7

Tanto en el emulador como en mi dispositivo Galaxy Nexus, esta sencilla aplicación demo demora 1000 milisegundos o más para seleccionar o anular la selección de una casilla de verificación. Quería escribir la mayoría de mi aplicación en JavaScript para poder reutilizar el código en ios/android/web, pero esto es un factor decisivo.¿Hay alguna manera de hacer que una vista web ejecute Android 4.0 en un nivel aceptable?

Aquí está mi código:

(la actividad)

package com.mycompanyname; 

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.os.Bundle; 
import android.webkit.ConsoleMessage; 
import android.webkit.WebChromeClient; 
import android.webkit.WebSettings; 
import android.webkit.WebSettings.RenderPriority; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

import com.mycompanyname.R; 

public class JavascriptListViewTestActivity extends Activity { 
    private JavascriptListViewTestActivity parent = this; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main);    

     WebChromeClient chrome = new WebChromeClient() { 
      @Override 
      public boolean onConsoleMessage(ConsoleMessage consoleMessage) { 
       parent.showDialog(consoleMessage.message() + "\n" + consoleMessage.lineNumber()); 
       return true; 
      } 
     }; 

     WebViewClient client = new WebViewClient() { 

     }; 

     WebView webView = (WebView)findViewById(R.id.webView1); 
     webView.setWebChromeClient(chrome); 
     webView.setWebViewClient(client); 

     webView.getSettings().setJavaScriptEnabled(false); 
     webView.getSettings().setAllowFileAccess(false); 
     webView.getSettings().setAppCacheEnabled(false); 
     webView.getSettings().setBuiltInZoomControls(false); 
     webView.getSettings().setDatabaseEnabled(false); 
     webView.getSettings().setDomStorageEnabled(false); 
     webView.getSettings().setGeolocationEnabled(false); 
     webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false); 
     webView.getSettings().setLightTouchEnabled(false); 
     webView.getSettings().setLoadWithOverviewMode(false); 
     webView.getSettings().setNavDump(false); 
     webView.getSettings().setNeedInitialFocus(false); 
     webView.getSettings().setPluginsEnabled(false); 
     webView.getSettings().setRenderPriority(RenderPriority.HIGH); 
     webView.getSettings().setSaveFormData(false); 
     webView.getSettings().setSavePassword(false); 
     webView.getSettings().setSupportMultipleWindows(false); 
     webView.getSettings().setSupportZoom(false); 
     webView.getSettings().setUseDoubleTree(false); 
     webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 

     String html = readText(R.raw.listview); 

     webView.loadData(html, "text/html", "UTF-8"); 

    } 

    private void showDialog(String message) 
    { 
     AlertDialog alert = new AlertDialog.Builder(parent).create(); 
     alert.setMessage(message); 
     alert.show(); 
    } 

    private String readText(int resourceId) 
    { 
     InputStream is = this.getResources().openRawResource(resourceId); 
     BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
     String readLine = null; 
     StringBuffer outputBuffer = new StringBuffer(); 

     try 
     { 
      while ((readLine = br.readLine()) != null) 
      { 
       outputBuffer.append(readLine); 
      } 
      return outputBuffer.toString(); 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
      return ""; 
     } 
     finally 
     { 
      // TODO: might throw - use IOUtils.close() 
      try 
      { 
       is.close(); 
       br.close(); 
      } 
      catch (IOException ex) 
      { 
       showDialog(ex.toString()); 
      } 
     } 
    } 
} 

(El diseño xml)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <WebView 
     android:id="@+id/webView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 

(el código HTML cargado en la vista web)

<html> 
<body> 

<input type="checkbox" /> 

</body> 
</html> 
+0

Me di cuenta de que obtengo el mismo rendimiento terrible en un navegador web normal con el navegador estándar o Chrome para Android. ir a gmail.com, y seleccionar o anular la selección de la casilla cuando se cierra la sesión para alternar "recordarme" aún demora un segundo entero. Esto es una locura... – davidjnelson

Respuesta

2

Me doy cuenta de que esto es más de un año es viejo, pero podría intentar implementar fastclick.js: https://github.com/ftlabs/fastclick

Lo he usado con éxito en bastantes proyectos. A medida que la página se explica:

... navegadores móviles esperarán aproximadamente 300 ms desde el momento en que toca el botón para disparar el evento click. La razón para esto es que el navegador está esperando para ver si realmente está realizando un doble toque .

Igual va para las interacciones dentro de una vista web (hasta donde yo sé).

Cuestiones relacionadas