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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java

Issue 23532072: Draw the mouse cursor in Chromoting Android client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting.jni; 5 package org.chromium.chromoting.jni;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.AlertDialog; 8 import android.app.AlertDialog;
9 import android.app.ProgressDialog; 9 import android.app.ProgressDialog;
10 import android.content.Context; 10 import android.content.Context;
11 import android.content.DialogInterface; 11 import android.content.DialogInterface;
12 import android.content.SharedPreferences; 12 import android.content.SharedPreferences;
13 import android.graphics.Bitmap; 13 import android.graphics.Bitmap;
14 import android.graphics.Point;
14 import android.os.Looper; 15 import android.os.Looper;
15 import android.text.InputType; 16 import android.text.InputType;
16 import android.util.Log; 17 import android.util.Log;
17 import android.view.KeyEvent; 18 import android.view.KeyEvent;
18 import android.view.View; 19 import android.view.View;
19 import android.view.inputmethod.EditorInfo; 20 import android.view.inputmethod.EditorInfo;
20 import android.widget.CheckBox; 21 import android.widget.CheckBox;
21 import android.widget.TextView; 22 import android.widget.TextView;
22 import android.widget.Toast; 23 import android.widget.Toast;
23 24
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 sConnected = false; 117 sConnected = false;
117 } 118 }
118 119
119 /** Performs the native portion of the connection. */ 120 /** Performs the native portion of the connection. */
120 private static native void connectNative(String username, String authToken, String hostJid, 121 private static native void connectNative(String username, String authToken, String hostJid,
121 String hostId, String hostPubkey, String pairId, String pairSecret); 122 String hostId, String hostPubkey, String pairId, String pairSecret);
122 123
123 /** Performs the native portion of the cleanup. */ 124 /** Performs the native portion of the cleanup. */
124 private static native void disconnectNative(); 125 private static native void disconnectNative();
125 126
127 /** Position of cursor hotspot within cursor image. */
128 public static Point getCursorHotspot() { return sCursorHotspot; }
129
130 /** Returns the current cursor shape. */
131 public static Bitmap getCursorBitmap() { return sCursorBitmap; }
132
126 /* 133 /*
127 * Entry points *from* the native code. 134 * Entry points *from* the native code.
128 */ 135 */
129 /** Callback to signal whenever we need to redraw. */ 136 /** Callback to signal whenever we need to redraw. */
130 private static Runnable sRedrawCallback = null; 137 private static Runnable sRedrawCallback = null;
131 138
132 /** Screen width of the video feed. */ 139 /** Screen width of the video feed. */
133 private static int sWidth = 0; 140 private static int sWidth = 0;
134 141
135 /** Screen height of the video feed. */ 142 /** Screen height of the video feed. */
136 private static int sHeight = 0; 143 private static int sHeight = 0;
137 144
138 /** Buffer holding the video feed. */ 145 /** Buffer holding the video feed. */
139 private static ByteBuffer sBuffer = null; 146 private static ByteBuffer sBuffer = null;
140 147
148 /** Position of cursor hot-spot. */
149 private static Point sCursorHotspot = new Point();
150
151 /** Bitmap holding the cursor shape. */
152 private static Bitmap sCursorBitmap = null;
153
141 /** Reports whenever the connection status changes. */ 154 /** Reports whenever the connection status changes. */
142 private static void reportConnectionStatus(int state, int error) { 155 private static void reportConnectionStatus(int state, int error) {
143 if (state < SUCCESSFUL_CONNECTION && error == 0) { 156 if (state < SUCCESSFUL_CONNECTION && error == 0) {
144 // The connection is still being established, so we'll report the cu rrent progress. 157 // The connection is still being established, so we'll report the cu rrent progress.
145 synchronized (JniInterface.class) { 158 synchronized (JniInterface.class) {
146 if (sProgressIndicator == null) { 159 if (sProgressIndicator == null) {
147 sProgressIndicator = ProgressDialog.show(sContext, sContext. 160 sProgressIndicator = ProgressDialog.show(sContext, sContext.
148 getString(R.string.progress_title), sContext.getReso urces(). 161 getString(R.string.progress_title), sContext.getReso urces().
149 getStringArray(R.array.protoc_states)[state], true, true, 162 getStringArray(R.array.protoc_states)[state], true, true,
150 new DialogInterface.OnCancelListener() { 163 new DialogInterface.OnCancelListener() {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 311 }
299 312
300 int[] frame = new int[sWidth * sHeight]; 313 int[] frame = new int[sWidth * sHeight];
301 314
302 sBuffer.order(ByteOrder.LITTLE_ENDIAN); 315 sBuffer.order(ByteOrder.LITTLE_ENDIAN);
303 sBuffer.asIntBuffer().get(frame, 0, frame.length); 316 sBuffer.asIntBuffer().get(frame, 0, frame.length);
304 317
305 return Bitmap.createBitmap(frame, 0, sWidth, sWidth, sHeight, Bitmap.Con fig.ARGB_8888); 318 return Bitmap.createBitmap(frame, 0, sWidth, sWidth, sHeight, Bitmap.Con fig.ARGB_8888);
306 } 319 }
307 320
321 /**
322 * Updates the cursor shape. This is called from native code on the graphics thread when
323 * receiving a new cursor shape from the host.
324 */
325 public static void updateCursorShape(int width, int height, int hotspotX, in t hotspotY,
326 ByteBuffer buffer) {
327 sCursorHotspot.x = hotspotX;
328 sCursorHotspot.y = hotspotY;
329
330 int[] data = new int[width * height];
331 buffer.order(ByteOrder.LITTLE_ENDIAN);
332 buffer.asIntBuffer().get(data, 0, data.length);
333 sCursorBitmap = Bitmap.createBitmap(data, width, height, Bitmap.Config.A RGB_8888);
334 }
335
308 /** Moves the mouse cursor, possibly while clicking the specified (nonnegati ve) button. */ 336 /** Moves the mouse cursor, possibly while clicking the specified (nonnegati ve) button. */
309 public static void mouseAction(int x, int y, int whichButton, boolean button Down) { 337 public static void mouseAction(int x, int y, int whichButton, boolean button Down) {
310 if (!sConnected) { 338 if (!sConnected) {
311 return; 339 return;
312 } 340 }
313 341
314 mouseActionNative(x, y, whichButton, buttonDown); 342 mouseActionNative(x, y, whichButton, buttonDown);
315 } 343 }
316 344
317 /** Presses and releases the specified (nonnegative) key. */ 345 /** Presses and releases the specified (nonnegative) key. */
(...skipping 10 matching lines...) Expand all
328 356
329 /** Schedules a redraw on the native graphics thread. */ 357 /** Schedules a redraw on the native graphics thread. */
330 private static native void scheduleRedrawNative(); 358 private static native void scheduleRedrawNative();
331 359
332 /** Passes mouse information to the native handling code. */ 360 /** Passes mouse information to the native handling code. */
333 private static native void mouseActionNative(int x, int y, int whichButton, boolean buttonDown); 361 private static native void mouseActionNative(int x, int y, int whichButton, boolean buttonDown);
334 362
335 /** Passes key press information to the native handling code. */ 363 /** Passes key press information to the native handling code. */
336 private static native void keyboardActionNative(int keyCode, boolean keyDown ); 364 private static native void keyboardActionNative(int keyCode, boolean keyDown );
337 } 365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698