コード例 #1
0
 @Override
 public boolean sendKeyEvent(KeyEvent event) {
   // BaseInputConnection.sendKeyEvent() dispatches the key event to the main thread.
   // In order to ensure events are processed in the proper order, we must block the
   // IC thread until the main thread finishes processing the key event
   super.sendKeyEvent(event);
   final View v = getView();
   if (v == null) {
     return false;
   }
   final Handler icHandler = mEditableClient.getInputConnectionHandler();
   final Handler mainHandler = v.getRootView().getHandler();
   if (icHandler.getLooper() != mainHandler.getLooper()) {
     // We are on separate IC thread but the event is queued on the main thread;
     // wait on IC thread until the main thread processes our posted Runnable. At
     // that point the key event has already been processed.
     mainHandler.post(
         new Runnable() {
           @Override
           public void run() {
             InputThreadUtils.sInstance.endWaitForUiThread();
           }
         });
     InputThreadUtils.sInstance.waitForUiThread(icHandler);
   }
   return false; // seems to always return false
 }
コード例 #2
0
 public void testViaBackButtonOnLayout() {
   testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
   sleep();
   String url = mUiThread.getUrl();
   assertTrue(url.endsWith("sample2.html"));
   testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
   sleep();
   url = mUiThread.getUrl();
   assertTrue(url.endsWith("sample3.html"));
   BaseInputConnection viewConnection = new BaseInputConnection(containerView, true);
   KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
   KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
   viewConnection.sendKeyEvent(backDown);
   viewConnection.sendKeyEvent(backUp);
   sleep();
   url = mUiThread.getUrl();
   assertTrue(url.endsWith("sample2.html"));
   viewConnection.sendKeyEvent(backDown);
   viewConnection.sendKeyEvent(backUp);
   sleep();
   url = mUiThread.getUrl();
   assertTrue(url.endsWith("index.html"));
 }