示例#1
0
  private static void updateForView(final RFBClient client, View view) {
    view.setDrawingCacheEnabled(true);
    // view.destroyDrawingCache();
    //		view.buildLayer();

    //		Bitmap bm = Bitmap.createBitmap( view.getMeasuredWidth(), view.getMeasuredHeight(),
    // Bitmap.Config.ARGB_8888);
    //		Canvas c = new Canvas(bm);
    //		view.invalidate();
    //		view.forceLayout();
    //		view.layout(0, 0, view.getLayoutParams().width, view.getLayoutParams().height);
    //		view.draw(c);
    //
    // view.getDrawingCache();
    Bitmap cache = view.getDrawingCache();
    //		Canvas renderC = new Canvas(cache);
    // view.destroyDrawingCache();
    //		view.layout(0, 0, cache.getWidth(), cache.getHeight());
    //		view.draw(renderC);
    // view.buildDrawingCache(false);

    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int[] pixels = new int[cache.getWidth() * cache.getHeight()];
    cache.getPixels(
        pixels,
        0,
        cache.getWidth(),
        view.getLeft(),
        view.getTop(),
        cache.getWidth(),
        cache.getHeight());
    Rect rect =
        Rect.encode(
            client.getPreferredEncoding(),
            pixels,
            client.getPixelFormat(),
            cache.getWidth(),
            view.getLeft(),
            view.getTop(),
            cache.getWidth(),
            cache.getHeight());
    rect.transform(location[0], location[1]);
    Rect[] rects = {rect};

    try {
      client.writeFrameBufferUpdate(rects);
    } catch (IOException e) {
      Log.e("RemoteDisplay", "error while sending update rect", e);
    }
  }
 @Override
 public void frameBufferUpdateRequest(
     RFBClient client, boolean incremental, int x, int y, int w, int h) throws IOException {
   client.writeFrameBufferUpdate(buffer.getRects(client, incremental));
 }
示例#3
0
  private void sendWholeScreen(final RFBClient client) throws IOException {
    //		if( updateAttempts < 0  )
    //			return;
    //		if(!getLock() )
    //			return;

    View rootView = host.getWindow().getDecorView().getRootView();
    //		View rootView = host.findViewById(R.id.scroller);

    rootView.setDrawingCacheEnabled(true);
    // rootView.buildDrawingCache();

    //		rootView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
    //	            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    //		rootView.layout(0, 0, rootView.getMeasuredWidth(), rootView.getMeasuredHeight());
    // rootView.layout(0, 0, rootView.getLayoutParams().width, rootView.getLayoutParams().height);

    // rootView.buildDrawingCache(false);
    Bitmap cache = rootView.getDrawingCache();

    //		host.runOnUiThread(null);

    int[] pixels = new int[cache.getWidth() * cache.getHeight()];
    cache.getPixels(pixels, 0, cache.getWidth(), 0, 0, cache.getWidth(), cache.getHeight());
    Rect rect =
        Rect.encode(
            client.getPreferredEncoding(),
            pixels,
            client.getPixelFormat(),
            cache.getWidth(),
            0,
            0,
            cache.getWidth(),
            cache.getHeight());

    Rect[] rects = {rect};
    rootView.setDrawingCacheEnabled(false);
    try {
      client.writeFrameBufferUpdate(rects);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    //		ObjThread t = 	new ObjThread(){
    //			public void run(){
    //				final Bitmap cache = rootView.getDrawingCache();
    //				new Thread(){@Override
    //					public void run(){
    //						int[] pixels = new int[cache.getWidth()* cache.getHeight()];
    //						cache.getPixels(pixels, 0, cache.getWidth(), 0, 0, cache.getWidth(), cache.getHeight());
    //						Rect rect = Rect.encode(
    //								client.getPreferredEncoding(),
    //								pixels,
    //								client.getPixelFormat(),
    //								cache.getWidth(),
    //								0,
    //								0,
    //								cache.getWidth(),
    //								cache.getHeight());
    //						Rect[] rects = {rect};
    //
    //						try {
    //							client.writeFrameBufferUpdate(rects);
    //						} catch (IOException e) {
    //							// TODO Auto-generated catch block
    //							e.printStackTrace();
    //						}
    //
    ////				updateAttempts--;
    ////				releaseLock();
    //				}}.start();

    //			}
    //		};
    //		t.setName("building cache");
    //		host.runOnUiThread(t);
    //		try {
    //			while(t.getState() == Thread.State.NEW)
    //				this.wait(1);
    //			t.join();
    //		} catch (InterruptedException e) {
    //			e.printStackTrace();
    //		}
    //		cache = (Bitmap)t.parameter;
    //		t.stop();

  }