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; | |
| 18 | |
| 19 /** | 16 /** |
| 20 * The abstract class for viewing and interacting with a specific remote host. H andles logic | 17 * The abstract class for viewing and interacting with a specific remote host. H andles logic |
|
joedow
2016/09/08 18:32:47
Change the comment here too since it is no longer
Yuwei
2016/09/08 23:09:14
Done.
| |
| 21 * for touch input and render data. | 18 * for touch input and render data. |
| 22 */ | 19 */ |
| 23 public abstract class DesktopView extends SurfaceView { | 20 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 | 21 |
| 47 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa ble<>(); | 22 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa ble<>(); |
| 48 | 23 |
| 49 public DesktopView(Desktop desktop, Client client) { | 24 /** The parent Desktop activity. */ |
| 50 super(desktop); | 25 private Desktop mDesktop; |
| 51 Preconditions.notNull(desktop); | 26 |
| 52 Preconditions.notNull(client); | 27 public DesktopView(Context context, AttributeSet attributeSet) { |
| 53 mDesktop = desktop; | 28 super(context, attributeSet); |
| 54 mInputHandler = new TouchInputHandler(this, desktop); | |
| 55 mInputHandler.init(desktop, new InputEventSender(client)); | |
| 56 | 29 |
| 57 // Give this view keyboard focus, allowing us to customize the soft keyb oard's settings. | 30 // Give this view keyboard focus, allowing us to customize the soft keyb oard's settings. |
| 58 setFocusableInTouchMode(true); | 31 setFocusableInTouchMode(true); |
| 59 } | 32 } |
| 60 | 33 |
| 34 public void init(Desktop desktop) { | |
|
Yuwei
2016/09/07 20:45:40
Maybe we can get rid of this function by casting t
joedow
2016/09/08 18:32:47
Some good reasons to separate c'tor and init is if
Yuwei
2016/09/08 19:12:16
So maybe just keep the init function? Looks like t
Hzj_jie
2016/09/08 21:37:33
If you need to use Desktop instead of Context, you
Yuwei
2016/09/08 23:09:14
Acknowledged.
| |
| 35 Preconditions.notNull(desktop); | |
| 36 mDesktop = desktop; | |
| 37 } | |
| 38 | |
| 61 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl ass. | 39 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl ass. |
| 62 /** Shows the action bar. */ | 40 /** Shows the action bar. */ |
| 63 public final void showActionBar() { | 41 public final void showActionBar() { |
| 64 mDesktop.showSystemUi(); | 42 mDesktop.showSystemUi(); |
| 65 } | 43 } |
| 66 | 44 |
| 67 /** Shows the software keyboard. */ | 45 /** Shows the software keyboard. */ |
| 68 public final void showKeyboard() { | 46 public final void showKeyboard() { |
| 69 InputMethodManager inputManager = | 47 InputMethodManager inputManager = |
| 70 (InputMethodManager) getContext().getSystemService(Context.INPUT _METHOD_SERVICE); | 48 (InputMethodManager) getContext().getSystemService(Context.INPUT _METHOD_SERVICE); |
| 71 inputManager.showSoftInput(this, 0); | 49 inputManager.showSoftInput(this, 0); |
| 72 } | 50 } |
| 73 | 51 |
| 74 /** An {@link Event} which is triggered when user touches the screen. */ | 52 /** An {@link Event} which is triggered when user touches the screen. */ |
| 75 public final Event<TouchEventParameter> onTouch() { | 53 public final Event<TouchEventParameter> onTouch() { |
| 76 return mOnTouch; | 54 return mOnTouch; |
| 77 } | 55 } |
| 78 | 56 |
| 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. */ | 57 /** Called when a software keyboard is requested, and specifies its options. */ |
| 96 @Override | 58 @Override |
| 97 public final InputConnection onCreateInputConnection(EditorInfo outAttrs) { | 59 public final InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 98 // Disables rich input support and instead requests simple key events. | 60 // Disables rich input support and instead requests simple key events. |
| 99 outAttrs.inputType = InputType.TYPE_NULL; | 61 outAttrs.inputType = InputType.TYPE_NULL; |
| 100 | 62 |
| 101 // Prevents most third-party IMEs from ignoring our Activity's adjustRes ize preference. | 63 // Prevents most third-party IMEs from ignoring our Activity's adjustRes ize preference. |
| 102 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN; | 64 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN; |
| 103 | 65 |
| 104 // Ensures that keyboards will not decide to hide the remote desktop on small displays. | 66 // Ensures that keyboards will not decide to hide the remote desktop on small displays. |
| 105 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI; | 67 outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI; |
| 106 | 68 |
| 107 // Stops software keyboards from closing as soon as the enter key is pre ssed. | 69 // 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; | 70 outAttrs.imeOptions |= EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_ NO_ENTER_ACTION; |
| 109 | 71 |
| 110 return null; | 72 return null; |
| 111 } | 73 } |
| 112 | 74 |
| 113 /** Called whenever the user attempts to touch the canvas. */ | 75 /** Called whenever the user attempts to touch the canvas. */ |
| 114 @Override | 76 @Override |
| 115 public final boolean onTouchEvent(MotionEvent event) { | 77 public final boolean onTouchEvent(MotionEvent event) { |
| 116 TouchEventParameter parameter = new TouchEventParameter(event); | 78 TouchEventParameter parameter = new TouchEventParameter(event); |
| 117 mOnTouch.raise(parameter); | 79 mOnTouch.raise(parameter); |
| 118 return parameter.handled; | 80 return parameter.handled; |
| 119 } | 81 } |
| 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 } | 82 } |
| OLD | NEW |