Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. |
| 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. | |
| 39 */ | |
| 40 public void attach(Client client, Desktop desktop, RenderStub renderStub) { | |
| 41 Preconditions.notNull(client); | |
| 42 Preconditions.notNull(desktop); | |
| 43 Preconditions.notNull(renderStub); | |
|
Hzj_jie
2016/09/10 02:06:32
You do not need to notNull renderStub, as the it w
Yuwei
2016/09/10 05:29:14
You mean checking whether mDesktop is null so that
Yuwei
2016/09/12 18:56:13
Done.
Hzj_jie
2016/09/12 21:28:04
Yes, I think so. Is my understanding correct?
Yuwei
2016/09/12 21:50:04
Asserting mDesktop is null? Yes.
| |
| 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. | |
| 52 */ | |
| 53 public void detach() { | |
| 54 mInputHandler.detach(); | |
| 55 } | |
| 56 | |
| 61 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl ass. | 57 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl ass. |
| 62 /** Shows the action bar. */ | 58 /** Shows the action bar. */ |
| 63 public final void showActionBar() { | 59 public final void showActionBar() { |
| 64 mDesktop.showSystemUi(); | 60 mDesktop.showSystemUi(); |
| 65 } | 61 } |
| 66 | 62 |
| 67 /** Shows the software keyboard. */ | 63 /** Shows the software keyboard. */ |
| 68 public final void showKeyboard() { | 64 public final void showKeyboard() { |
| 69 InputMethodManager inputManager = | 65 InputMethodManager inputManager = |
| 70 (InputMethodManager) getContext().getSystemService(Context.INPUT _METHOD_SERVICE); | 66 (InputMethodManager) getContext().getSystemService(Context.INPUT _METHOD_SERVICE); |
| 71 inputManager.showSoftInput(this, 0); | 67 inputManager.showSoftInput(this, 0); |
| 72 } | 68 } |
| 73 | 69 |
| 74 /** An {@link Event} which is triggered when user touches the screen. */ | 70 /** An {@link Event} which is triggered when user touches the screen. */ |
| 75 public final Event<TouchEventParameter> onTouch() { | 71 public final Event<TouchEventParameter> onTouch() { |
| 76 return mOnTouch; | 72 return mOnTouch; |
| 77 } | 73 } |
| 78 | 74 |
| 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. */ | 75 /** Called when a software keyboard is requested, and specifies its options. */ |
| 96 @Override | 76 @Override |
| 97 public final InputConnection onCreateInputConnection(EditorInfo outAttrs) { | 77 public final InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 98 // Disables rich input support and instead requests simple key events. | 78 // Disables rich input support and instead requests simple key events. |
| 99 outAttrs.inputType = InputType.TYPE_NULL; | 79 outAttrs.inputType = InputType.TYPE_NULL; |
| 100 | 80 |
| 101 // Prevents most third-party IMEs from ignoring our Activity's adjustRes ize preference. | 81 // Prevents most third-party IMEs from ignoring our Activity's adjustRes ize preference. |
| 102 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN; | 82 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN; |
| 103 | 83 |
| 104 // Ensures that keyboards will not decide to hide the remote desktop on small displays. | 84 // Ensures that keyboards will not decide to hide the remote desktop on small displays. |
| 105 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI; | 85 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI; |
| 106 | 86 |
| 107 // Stops software keyboards from closing as soon as the enter key is pre ssed. | 87 // 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; | 88 outAttrs.imeOptions |= EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_ NO_ENTER_ACTION; |
| 109 | 89 |
| 110 return null; | 90 return null; |
| 111 } | 91 } |
| 112 | 92 |
| 113 /** Called whenever the user attempts to touch the canvas. */ | 93 /** Called whenever the user attempts to touch the canvas. */ |
| 114 @Override | 94 @Override |
| 115 public final boolean onTouchEvent(MotionEvent event) { | 95 public final boolean onTouchEvent(MotionEvent event) { |
| 116 TouchEventParameter parameter = new TouchEventParameter(event); | 96 TouchEventParameter parameter = new TouchEventParameter(event); |
| 117 mOnTouch.raise(parameter); | 97 mOnTouch.raise(parameter); |
| 118 return parameter.handled; | 98 return parameter.handled; |
| 119 } | 99 } |
| 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 } | 100 } |
| OLD | NEW |