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

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. The lifecy cle of DesktopView
21 * for touch input and render data. 20 * is roughly the same as the Desktop activity.
joedow 2016/09/13 00:08:51 What does 'roughly' mean? What should be document
Yuwei 2016/09/13 01:22:46 Sorry for the vagueness. Here are the details: *
Yuwei 2016/09/13 01:42:26 Removed.
22 */ 21 */
23 public abstract class DesktopView extends SurfaceView { 22 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 23
47 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa ble<>(); 24 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa ble<>();
48 25
49 public DesktopView(Desktop desktop, Client client) { 26 /** The parent Desktop activity. */
50 super(desktop); 27 private Desktop mDesktop;
51 Preconditions.notNull(desktop);
52 Preconditions.notNull(client);
53 mDesktop = desktop;
54 mInputHandler = new TouchInputHandler(this, desktop);
55 mInputHandler.init(desktop, new InputEventSender(client));
56 28
29 private RenderStub mRenderStub;
30
31 private TouchInputHandler mInputHandler;
32
33 private InputEventSender mInputEventSender;
34
35 public DesktopView(Context context, AttributeSet attributeSet) {
36 super(context, attributeSet);
57 // Give this view keyboard focus, allowing us to customize the soft keyb oard's settings. 37 // Give this view keyboard focus, allowing us to customize the soft keyb oard's settings.
58 setFocusableInTouchMode(true); 38 setFocusableInTouchMode(true);
59 } 39 }
60 40
41 /**
42 * Initializes the view.
43 */
44 public void init(Client client, Desktop desktop, RenderStub renderStub) {
45 Preconditions.isNull(mDesktop);
46 Preconditions.isNull(mRenderStub);
47 Preconditions.isNull(mInputEventSender);
48 Preconditions.notNull(desktop);
49 Preconditions.notNull(renderStub);
50 mDesktop = desktop;
51 mRenderStub = renderStub;
52 mInputEventSender = new InputEventSender(client);
53 }
54
55 @Override
56 public void onAttachedToWindow() {
57 Preconditions.isNull(mInputHandler);
58 super.onAttachedToWindow();
59 mRenderStub.setDesktopView(this);
60 mInputHandler = new TouchInputHandler(this, mDesktop, mRenderStub, mInpu tEventSender);
61 }
62
63 @Override
64 public void onDetachedFromWindow() {
65 Preconditions.notNull(mInputHandler);
joedow 2016/09/13 00:08:51 I think the check on line 57 is fine (to prevent m
Yuwei 2016/09/13 01:22:46 detachEventListeners() doesn't check whether it ha
Yuwei 2016/09/13 01:42:26 Removed this check and added emptiness check in de
66 mInputHandler.detachEventListeners();
67 super.onDetachedFromWindow();
68 }
69
61 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl ass. 70 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl ass.
62 /** Shows the action bar. */ 71 /** Shows the action bar. */
63 public final void showActionBar() { 72 public final void showActionBar() {
64 mDesktop.showSystemUi(); 73 mDesktop.showSystemUi();
65 } 74 }
66 75
67 /** Shows the software keyboard. */ 76 /** Shows the software keyboard. */
68 public final void showKeyboard() { 77 public final void showKeyboard() {
69 InputMethodManager inputManager = 78 InputMethodManager inputManager =
70 (InputMethodManager) getContext().getSystemService(Context.INPUT _METHOD_SERVICE); 79 (InputMethodManager) getContext().getSystemService(Context.INPUT _METHOD_SERVICE);
71 inputManager.showSoftInput(this, 0); 80 inputManager.showSoftInput(this, 0);
72 } 81 }
73 82
74 /** An {@link Event} which is triggered when user touches the screen. */ 83 /** An {@link Event} which is triggered when user touches the screen. */
75 public final Event<TouchEventParameter> onTouch() { 84 public final Event<TouchEventParameter> onTouch() {
76 return mOnTouch; 85 return mOnTouch;
77 } 86 }
78 87
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. */ 88 /** Called when a software keyboard is requested, and specifies its options. */
96 @Override 89 @Override
97 public final InputConnection onCreateInputConnection(EditorInfo outAttrs) { 90 public final InputConnection onCreateInputConnection(EditorInfo outAttrs) {
98 // Disables rich input support and instead requests simple key events. 91 // Disables rich input support and instead requests simple key events.
99 outAttrs.inputType = InputType.TYPE_NULL; 92 outAttrs.inputType = InputType.TYPE_NULL;
100 93
101 // Prevents most third-party IMEs from ignoring our Activity's adjustRes ize preference. 94 // Prevents most third-party IMEs from ignoring our Activity's adjustRes ize preference.
102 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN; 95 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN;
103 96
104 // Ensures that keyboards will not decide to hide the remote desktop on small displays. 97 // Ensures that keyboards will not decide to hide the remote desktop on small displays.
105 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI; 98 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI;
106 99
107 // Stops software keyboards from closing as soon as the enter key is pre ssed. 100 // 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; 101 outAttrs.imeOptions |= EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_ NO_ENTER_ACTION;
109 102
110 return null; 103 return null;
111 } 104 }
112 105
113 /** Called whenever the user attempts to touch the canvas. */ 106 /** Called whenever the user attempts to touch the canvas. */
114 @Override 107 @Override
115 public final boolean onTouchEvent(MotionEvent event) { 108 public final boolean onTouchEvent(MotionEvent event) {
116 TouchEventParameter parameter = new TouchEventParameter(event); 109 TouchEventParameter parameter = new TouchEventParameter(event);
117 mOnTouch.raise(parameter); 110 mOnTouch.raise(parameter);
118 return parameter.handled; 111 return parameter.handled;
119 } 112 }
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 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698