public static void setActivity(Activity act) {
    host = act;
    ViewTools.setActivity(act);

    View rootView = host.getWindow().getDecorView().getRootView();
    rootView.setDrawingCacheEnabled(true);
    rootView.buildDrawingCache();
    // host.getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new
    // LayoutObserver());

  }
  //	class EventDispatcher implements Runnable{
  //		private MotionEvent event;
  //		private ArrayList<View> hits;
  //		public EventDispatcher(MotionEvent e){
  //			event=e;
  //			hits = new ArrayList<View>();
  //		}
  //		public ArrayList<View> GetHits(){return hits;}
  //		public boolean isTarget(View view){
  //			android.graphics.Rect outRect = new android.graphics.Rect();
  //			view.getHitRect(outRect);
  //			for(int i=0;i<event.getPointerCount();i++){
  //				android.graphics.Rect pointerRect = new android.graphics.Rect();
  //				PointerCoords coords = new PointerCoords();
  //				event.getPointerCoords(i, coords);
  //				pointerRect.set(left, top, right, bottom);
  //			}
  //		}
  //		public synchronized void run(){
  //			ArrayList<View> touchables = host.getWindow().getDecorView().getTouchables();
  //			for(View view : touchables){
  //				view.getHitRect(outRect)
  //				if(view.onTouchEvent(event)){
  //					view.invalidate();view.gethit
  //					hits.add(view);
  //				}
  //			}
  //
  //			//this.notify();
  //		}
  //	}
  protected void dispatchMotionEvent(RFBClient client, final MotionEvent e) {
    // ViewTools.findViewsForMotionEvent(e);

    final View view = ViewTools.findViewAt((int) e.getX(), (int) e.getY());
    if (view == null) return;
    host.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            view.dispatchTouchEvent(e);
            view.invalidate();
            // target.getViewTreeObserver().addOnPreDrawListener(new
            // PreDrawListener(target,client,4));
          }
        });
  }
  @Override
  public void pointerEvent(final RFBClient client, int buttonMask, int x, int y)
      throws IOException {
    int action = (buttonMask == 1) ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_UP;
    final MotionEvent e =
        MotionEvent.obtain(
            SystemClock.uptimeMillis(),
            SystemClock.uptimeMillis(),
            action,
            x,
            y,
            1.f,
            0.5f,
            0,
            1,
            1,
            0,
            0);
    final View target = ViewTools.findViewAt(x, y);
    if (target == null) return;
    updateAttempts = 3;

    host.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            target.dispatchTouchEvent(e);
            target.invalidate();
            // target.getViewTreeObserver().addOnPreDrawListener(new
            // PreDrawListener(target,client,4));
          }
        });
    //		target.dispatchTouchEvent(e);
    // target.postInvalidate();
    return;
  }