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