Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1992)

Unified Diff: remoting/android/java/src/org/chromium/chromoting/DesktopView.java

Issue 21120005: Add Android Chromoting client keyboard input (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improve related comments Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/android/java/src/org/chromium/chromoting/DesktopView.java
diff --git a/remoting/android/java/src/org/chromium/chromoting/DesktopView.java b/remoting/android/java/src/org/chromium/chromoting/DesktopView.java
index 52151c6e009c3adfde20b6143c2d84709fbf1f6c..f02dd789979cfe49db851ba8f45154ff7faa668a 100644
--- a/remoting/android/java/src/org/chromium/chromoting/DesktopView.java
+++ b/remoting/android/java/src/org/chromium/chromoting/DesktopView.java
@@ -4,7 +4,8 @@
package org.chromium.chromoting;
-import android.content.Context;
+import android.app.ActionBar;
+import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -52,6 +53,8 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
UNDEFINED, WIDTH, HEIGHT
}
+ private ActionBar mActionBar;
+
private GestureDetector mScroller;
private ScaleGestureDetector mZoomer;
@@ -64,6 +67,9 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
/** Specifies the dimension by which the zoom level is being lower-bounded. */
private Constraint mConstraint;
Sergey Ulanov 2013/07/30 19:19:27 Should this be called mZoomConstraint?
solb 2013/07/30 21:30:54 Not really, since it also affects panning behavior
+ /** Whether the dimension of constraint should be reckecked on the next aspect ratio change. */
+ private boolean mRecheckConstraint;
+
/** Whether the right edge of the image was visible on-screen during the last render. */
private boolean mRightUsedToBeOut;
@@ -73,11 +79,10 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
private int mMouseButton;
private boolean mMousePressed;
- /** Whether the canvas needs to be redrawn. The update occurs when its size is next updated. */
- private boolean mCanvasNeedsRedraw;
-
- public DesktopView(Context context) {
+ public DesktopView(Activity context) {
super(context);
+ mActionBar = context.getActionBar();
+
getHolder().addCallback(this);
DesktopListener listener = new DesktopListener();
mScroller = new GestureDetector(context, listener);
@@ -86,15 +91,15 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
mTransform = new Matrix();
mScreenWidth = 0;
mScreenHeight = 0;
+
mConstraint = Constraint.UNDEFINED;
+ mRecheckConstraint = false;
mRightUsedToBeOut = false;
mBottomUsedToBeOut = false;
mMouseButton = BUTTON_UNDEFINED;
mMousePressed = false;
-
- mCanvasNeedsRedraw = false;
}
/**
@@ -127,8 +132,8 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
boolean recenter = false;
if (mConstraint == Constraint.UNDEFINED) {
- mConstraint = image.getWidth()/image.getHeight() > mScreenWidth/mScreenHeight ?
- Constraint.WIDTH : Constraint.HEIGHT;
+ mConstraint = (double)image.getWidth()/image.getHeight() >
Sergey Ulanov 2013/07/30 19:19:27 mConstraint is calculated and used in the same met
solb 2013/07/30 21:30:54 Sometimes we need to keep the old value between re
+ (double)mScreenWidth/mScreenHeight ? Constraint.WIDTH : Constraint.HEIGHT;
recenter = true; // We always rescale and recenter after a rotation.
}
@@ -209,9 +214,15 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
getHolder().unlockCanvasAndPost(canvas);
}
- /** Causes the canvas to be redrawn the next time our surface changes. */
- public void requestCanvasRedraw() {
- mCanvasNeedsRedraw = true;
+ /**
+ * Causes the next canvas redraw to perform a check for which screen dimension more tightly
+ * constrains the view of the image. This should be called between the time that a screen size
+ * change is requested and the time it actually occurs. If it is not called in such a case, the
+ * screen will not be rearranged as aggressively (which is desirable when the software keyboard
+ * appears in order to allow it to cover the image without forcing a resize).
+ */
+ public void requestRecheckConstrainingDimension() {
+ mRecheckConstraint = true;
Sergey Ulanov 2013/07/30 19:19:27 Can we reset mContraint here?
solb 2013/07/30 21:30:54 No, because we won't know the screen size until on
}
/**
@@ -221,15 +232,20 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
@Override
public void surfaceChanged(
SurfaceHolder holder, int format, int width, int height) {
+ mActionBar.hide();
+
synchronized (mTransform) {
mScreenWidth = width;
mScreenHeight = height;
- mConstraint = Constraint.UNDEFINED;
+
+ if (mRecheckConstraint) {
+ mConstraint = Constraint.UNDEFINED;
+ mRecheckConstraint = false;
+ }
}
- if (mCanvasNeedsRedraw) {
- JniInterface.redrawGraphics();
- mCanvasNeedsRedraw = false;
+ if (!JniInterface.redrawGraphics()) {
+ JniInterface.provideRedrawCallback(this);
}
}
@@ -237,7 +253,6 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.i("deskview", "DesktopView.surfaceCreated(...)");
- JniInterface.provideRedrawCallback(this);
}
/**
@@ -247,10 +262,9 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i("deskview", "DesktopView.surfaceDestroyed(...)");
- JniInterface.provideRedrawCallback(null);
- // Redraw the desktop as soon as the user switches back to this window.
- mCanvasNeedsRedraw = true;
+ // Stop this canvas from being redrawn.
+ JniInterface.provideRedrawCallback(null);
}
/** Called when a mouse action is made. */
@@ -270,9 +284,13 @@ public class DesktopView extends SurfaceView implements Runnable, SurfaceHolder.
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
+ if (event.getPointerCount() == 3) {
+ mActionBar.show();
+ }
+
boolean handled = mScroller.onTouchEvent(event) || mZoomer.onTouchEvent(event);
- if (event.getPointerCount()==1) {
+ if (event.getPointerCount() == 1) {
Sergey Ulanov 2013/07/30 19:19:27 Do we still need to handle the event here when han
solb 2013/07/30 21:30:54 Unfortunately, in order to ensure the gesture dete
float[] coordinates = {event.getRawX(), event.getY()};
switch (event.getActionMasked()) {

Powered by Google App Engine
This is Rietveld 408576698