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

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

Issue 2322623002: [Remoting Android] Refactor GlDesktopView (Closed)
Patch Set: Reviewer's Feedback Created 4 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; 5 package org.chromium.chromoting;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.Matrix;
9 import android.graphics.PointF;
10 import android.text.InputType; 8 import android.text.InputType;
9 import android.util.AttributeSet;
11 import android.view.MotionEvent; 10 import android.view.MotionEvent;
12 import android.view.SurfaceView; 11 import android.view.SurfaceView;
13 import android.view.inputmethod.EditorInfo; 12 import android.view.inputmethod.EditorInfo;
14 import android.view.inputmethod.InputConnection; 13 import android.view.inputmethod.InputConnection;
15 import android.view.inputmethod.InputMethodManager; 14 import android.view.inputmethod.InputMethodManager;
16 15
17 import org.chromium.chromoting.jni.Client; 16 import org.chromium.chromoting.jni.Client;
18 17
19 /** 18 /**
20 * The abstract class for viewing and interacting with a specific remote host. H andles logic 19 * The class for viewing and interacting with a specific remote host.
joedow 2016/09/12 19:55:08 IIUC the lifetime for this class is longer than th
Yuwei 2016/09/12 20:57:18 I think it should be roughly the same as the activ
joedow 2016/09/12 21:01:56 It would be good to confirm and document. I had a
Yuwei 2016/09/12 22:17:57 Confirm that it's recreated when the activity is r
21 * for touch input and render data.
22 */ 20 */
23 public abstract class DesktopView extends SurfaceView { 21 public class DesktopView extends SurfaceView {
24
25 protected final TouchInputHandler mInputHandler;
26
27 /**
28 * Subclass should trigger this event when the client view size is changed.
29 */
30 protected final Event.Raisable<SizeChangedEventParameter> mOnClientSizeChang ed =
31 new Event.Raisable<>();
32
33 /**
34 * Subclass should trigger this event when the host (desktop frame) size is changed.
35 */
36 protected final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged =
37 new Event.Raisable<>();
38
39 /**
40 * Subclass should trigger this event when a frame is rendered.
41 */
42 protected final Event.Raisable<Void> mOnCanvasRendered = new Event.Raisable< >();
43
44 /** The parent Desktop activity. */
45 private final Desktop mDesktop;
46 22
47 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa ble<>(); 23 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa ble<>();
48 24
49 public DesktopView(Desktop desktop, Client client) { 25 /** The parent Desktop activity. */
50 super(desktop); 26 private Desktop mDesktop;
51 Preconditions.notNull(desktop); 27
52 Preconditions.notNull(client); 28 private TouchInputHandler mInputHandler;
53 mDesktop = desktop; 29
54 mInputHandler = new TouchInputHandler(this, desktop); 30 public DesktopView(Context context, AttributeSet attributeSet) {
55 mInputHandler.init(desktop, new InputEventSender(client)); 31 super(context, attributeSet);
56 32
57 // Give this view keyboard focus, allowing us to customize the soft keyb oard's settings. 33 // Give this view keyboard focus, allowing us to customize the soft keyb oard's settings.
58 setFocusableInTouchMode(true); 34 setFocusableInTouchMode(true);
59 } 35 }
60 36
37 /**
38 * Initializes the view and attaches listeners to RenderStub's events. The d esktop view can
39 * only be attached once at a time.
40 */
41 public void attach(Client client, Desktop desktop, RenderStub renderStub) {
42 Preconditions.isNull(mDesktop);
43 Preconditions.notNull(desktop);
44 mDesktop = desktop;
45 renderStub.setDesktopView(this);
46 mInputHandler = new TouchInputHandler(this, desktop, renderStub,
47 new InputEventSender(client));
48 }
49
50 /**
51 * Detaches listeners from the RenderStub's events. The desktop view must ha ve been attached
52 * when calling this function.
joedow 2016/09/12 19:55:08 nit: s/when/prior to
Yuwei 2016/09/12 22:17:58 Obsolete.
53 */
54 public void detach() {
55 Preconditions.notNull(mDesktop);
56 mInputHandler.detach();
57 }
58
61 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl ass. 59 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl ass.
62 /** Shows the action bar. */ 60 /** Shows the action bar. */
63 public final void showActionBar() { 61 public final void showActionBar() {
64 mDesktop.showSystemUi(); 62 mDesktop.showSystemUi();
65 } 63 }
66 64
67 /** Shows the software keyboard. */ 65 /** Shows the software keyboard. */
68 public final void showKeyboard() { 66 public final void showKeyboard() {
69 InputMethodManager inputManager = 67 InputMethodManager inputManager =
70 (InputMethodManager) getContext().getSystemService(Context.INPUT _METHOD_SERVICE); 68 (InputMethodManager) getContext().getSystemService(Context.INPUT _METHOD_SERVICE);
71 inputManager.showSoftInput(this, 0); 69 inputManager.showSoftInput(this, 0);
72 } 70 }
73 71
74 /** An {@link Event} which is triggered when user touches the screen. */ 72 /** An {@link Event} which is triggered when user touches the screen. */
75 public final Event<TouchEventParameter> onTouch() { 73 public final Event<TouchEventParameter> onTouch() {
76 return mOnTouch; 74 return mOnTouch;
77 } 75 }
78 76
79 /** An {@link Event} which is triggered when the client size is changed. */
80 public final Event<SizeChangedEventParameter> onClientSizeChanged() {
81 return mOnClientSizeChanged;
82 }
83
84 /** An {@link Event} which is triggered when the host size is changed. */
85 public final Event<SizeChangedEventParameter> onHostSizeChanged() {
86 return mOnHostSizeChanged;
87 }
88
89 /** An {@link Event} which is triggered when a frame is rendered. */
90 public final Event<Void> onCanvasRendered() {
91 return mOnCanvasRendered;
92 }
93
94 // View overrides.
95 /** Called when a software keyboard is requested, and specifies its options. */ 77 /** Called when a software keyboard is requested, and specifies its options. */
96 @Override 78 @Override
97 public final InputConnection onCreateInputConnection(EditorInfo outAttrs) { 79 public final InputConnection onCreateInputConnection(EditorInfo outAttrs) {
98 // Disables rich input support and instead requests simple key events. 80 // Disables rich input support and instead requests simple key events.
99 outAttrs.inputType = InputType.TYPE_NULL; 81 outAttrs.inputType = InputType.TYPE_NULL;
100 82
101 // Prevents most third-party IMEs from ignoring our Activity's adjustRes ize preference. 83 // Prevents most third-party IMEs from ignoring our Activity's adjustRes ize preference.
102 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN; 84 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN;
103 85
104 // Ensures that keyboards will not decide to hide the remote desktop on small displays. 86 // Ensures that keyboards will not decide to hide the remote desktop on small displays.
105 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI; 87 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI;
106 88
107 // Stops software keyboards from closing as soon as the enter key is pre ssed. 89 // Stops software keyboards from closing as soon as the enter key is pre ssed.
108 outAttrs.imeOptions |= EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_ NO_ENTER_ACTION; 90 outAttrs.imeOptions |= EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_ NO_ENTER_ACTION;
109 91
110 return null; 92 return null;
111 } 93 }
112 94
113 /** Called whenever the user attempts to touch the canvas. */ 95 /** Called whenever the user attempts to touch the canvas. */
114 @Override 96 @Override
115 public final boolean onTouchEvent(MotionEvent event) { 97 public final boolean onTouchEvent(MotionEvent event) {
116 TouchEventParameter parameter = new TouchEventParameter(event); 98 TouchEventParameter parameter = new TouchEventParameter(event);
117 mOnTouch.raise(parameter); 99 mOnTouch.raise(parameter);
118 return parameter.handled; 100 return parameter.handled;
119 } 101 }
120
121 /** Triggers a brief animation to indicate the existence and location of an input event. */
122 public abstract void showInputFeedback(RenderStub.InputFeedbackType feedback ToShow, PointF pos);
123
124 /**
125 * Informs the view that its transformation matrix (for rendering the remote desktop bitmap)
126 * has been changed by the TouchInputHandler, which requires repainting.
127 */
128 public abstract void transformationChanged(Matrix matrix);
129
130 /**
131 * Informs the view that the cursor has been moved by the TouchInputHandler, which requires
132 * repainting.
133 */
134 public abstract void cursorMoved(PointF position);
135
136 /**
137 * Informs the view that the cursor visibility has been changed (for differe nt input mode) by
138 * the TouchInputHandler, which requires repainting.
139 */
140 public abstract void cursorVisibilityChanged(boolean visible);
141 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698