| 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; | 8 import android.graphics.Matrix; |
| 9 import android.graphics.PointF; | 9 import android.graphics.PointF; |
| 10 import android.text.InputType; | 10 import android.text.InputType; |
| 11 import android.view.MotionEvent; | 11 import android.view.MotionEvent; |
| 12 import android.view.SurfaceView; | 12 import android.view.SurfaceView; |
| 13 import android.view.inputmethod.EditorInfo; | 13 import android.view.inputmethod.EditorInfo; |
| 14 import android.view.inputmethod.InputConnection; | 14 import android.view.inputmethod.InputConnection; |
| 15 import android.view.inputmethod.InputMethodManager; | 15 import android.view.inputmethod.InputMethodManager; |
| 16 | 16 |
| 17 import org.chromium.chromoting.jni.Client; | 17 import org.chromium.chromoting.jni.Client; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * The abstract class for viewing and interacting with a specific remote host. H
andles logic | 20 * The abstract class for viewing and interacting with a specific remote host. H
andles logic |
| 21 * for touch input and render data. | 21 * for touch input and render data. |
| 22 */ | 22 */ |
| 23 public abstract class DesktopView extends SurfaceView { | 23 public abstract class DesktopView extends SurfaceView { |
| 24 /** Used to define the animation feedback shown when a user touches the scre
en. */ | |
| 25 public enum InputFeedbackType { | |
| 26 NONE, | |
| 27 SHORT_TOUCH_ANIMATION, | |
| 28 LONG_TOUCH_ANIMATION, | |
| 29 LONG_TRACKPAD_ANIMATION | |
| 30 } | |
| 31 | 24 |
| 32 protected final TouchInputHandler mInputHandler; | 25 protected final TouchInputHandler mInputHandler; |
| 33 | 26 |
| 34 /** | 27 /** |
| 35 * Subclass should trigger this event when the client view size is changed. | 28 * Subclass should trigger this event when the client view size is changed. |
| 36 */ | 29 */ |
| 37 protected final Event.Raisable<SizeChangedEventParameter> mOnClientSizeChang
ed = | 30 protected final Event.Raisable<SizeChangedEventParameter> mOnClientSizeChang
ed = |
| 38 new Event.Raisable<>(); | 31 new Event.Raisable<>(); |
| 39 | 32 |
| 40 /** | 33 /** |
| 41 * Subclass should trigger this event when the host (desktop frame) size is
changed. | 34 * Subclass should trigger this event when the host (desktop frame) size is
changed. |
| 42 */ | 35 */ |
| 43 protected final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged
= | 36 protected final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged
= |
| 44 new Event.Raisable<>(); | 37 new Event.Raisable<>(); |
| 45 | 38 |
| 46 private final int mTinyFeedbackPixelRadius; | |
| 47 private final int mSmallFeedbackPixelRadius; | |
| 48 private final int mLargeFeedbackPixelRadius; | |
| 49 | |
| 50 /** The parent Desktop activity. */ | 39 /** The parent Desktop activity. */ |
| 51 private final Desktop mDesktop; | 40 private final Desktop mDesktop; |
| 52 | 41 |
| 53 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa
ble<>(); | 42 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa
ble<>(); |
| 54 | 43 |
| 55 public DesktopView(Desktop desktop, Client client) { | 44 public DesktopView(Desktop desktop, Client client) { |
| 56 super(desktop); | 45 super(desktop); |
| 57 Preconditions.notNull(desktop); | 46 Preconditions.notNull(desktop); |
| 58 Preconditions.notNull(client); | 47 Preconditions.notNull(client); |
| 59 mDesktop = desktop; | 48 mDesktop = desktop; |
| 60 mInputHandler = new TouchInputHandler(this, desktop); | 49 mInputHandler = new TouchInputHandler(this, desktop); |
| 61 mInputHandler.init(desktop, new InputEventSender(client)); | 50 mInputHandler.init(desktop, new InputEventSender(client)); |
| 62 | 51 |
| 63 // Give this view keyboard focus, allowing us to customize the soft keyb
oard's settings. | 52 // Give this view keyboard focus, allowing us to customize the soft keyb
oard's settings. |
| 64 setFocusableInTouchMode(true); | 53 setFocusableInTouchMode(true); |
| 65 | |
| 66 mTinyFeedbackPixelRadius = | |
| 67 getResources().getDimensionPixelSize(R.dimen.feedback_animation_
radius_tiny); | |
| 68 | |
| 69 mSmallFeedbackPixelRadius = | |
| 70 getResources().getDimensionPixelSize(R.dimen.feedback_animation_
radius_small); | |
| 71 | |
| 72 mLargeFeedbackPixelRadius = | |
| 73 getResources().getDimensionPixelSize(R.dimen.feedback_animation_
radius_large); | |
| 74 } | 54 } |
| 75 | 55 |
| 76 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl
ass. | 56 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl
ass. |
| 77 /** Shows the action bar. */ | 57 /** Shows the action bar. */ |
| 78 public final void showActionBar() { | 58 public final void showActionBar() { |
| 79 mDesktop.showSystemUi(); | 59 mDesktop.showSystemUi(); |
| 80 } | 60 } |
| 81 | 61 |
| 82 /** Shows the software keyboard. */ | 62 /** Shows the software keyboard. */ |
| 83 public final void showKeyboard() { | 63 public final void showKeyboard() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 101 } |
| 122 | 102 |
| 123 /** Called whenever the user attempts to touch the canvas. */ | 103 /** Called whenever the user attempts to touch the canvas. */ |
| 124 @Override | 104 @Override |
| 125 public final boolean onTouchEvent(MotionEvent event) { | 105 public final boolean onTouchEvent(MotionEvent event) { |
| 126 TouchEventParameter parameter = new TouchEventParameter(event); | 106 TouchEventParameter parameter = new TouchEventParameter(event); |
| 127 mOnTouch.raise(parameter); | 107 mOnTouch.raise(parameter); |
| 128 return parameter.handled; | 108 return parameter.handled; |
| 129 } | 109 } |
| 130 | 110 |
| 131 /** | |
| 132 * Returns the radius of the given feedback type. | |
| 133 * 0.0f will be returned if no feedback should be shown. | |
| 134 */ | |
| 135 protected final float getFeedbackRadius(InputFeedbackType feedbackToShow, fl
oat scaleFactor) { | |
| 136 switch (feedbackToShow) { | |
| 137 case NONE: | |
| 138 return 0.0f; | |
| 139 case SHORT_TOUCH_ANIMATION: | |
| 140 return mSmallFeedbackPixelRadius / scaleFactor; | |
| 141 case LONG_TOUCH_ANIMATION: | |
| 142 return mLargeFeedbackPixelRadius / scaleFactor; | |
| 143 case LONG_TRACKPAD_ANIMATION: | |
| 144 // The size of the longpress trackpad animation is supposed to b
e close to the size | |
| 145 // of the cursor so it doesn't need to be normalized and should
be scaled with the | |
| 146 // canvas. | |
| 147 return mTinyFeedbackPixelRadius; | |
| 148 default: | |
| 149 // Unreachable, but required by Google Java style and findbugs. | |
| 150 assert false : "Unreached"; | |
| 151 return 0.0f; | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 /** Triggers a brief animation to indicate the existence and location of an
input event. */ | 111 /** Triggers a brief animation to indicate the existence and location of an
input event. */ |
| 156 public abstract void showInputFeedback(InputFeedbackType feedbackToShow, Poi
ntF pos); | 112 public abstract void showInputFeedback(RenderStub.InputFeedbackType feedback
ToShow, PointF pos); |
| 157 | 113 |
| 158 /** | 114 /** |
| 159 * Informs the view that its transformation matrix (for rendering the remote
desktop bitmap) | 115 * Informs the view that its transformation matrix (for rendering the remote
desktop bitmap) |
| 160 * has been changed by the TouchInputHandler, which requires repainting. | 116 * has been changed by the TouchInputHandler, which requires repainting. |
| 161 */ | 117 */ |
| 162 public abstract void transformationChanged(Matrix matrix); | 118 public abstract void transformationChanged(Matrix matrix); |
| 163 | 119 |
| 164 /** | 120 /** |
| 165 * Informs the view that the cursor has been moved by the TouchInputHandler,
which requires | 121 * Informs the view that the cursor has been moved by the TouchInputHandler,
which requires |
| 166 * repainting. | 122 * repainting. |
| 167 */ | 123 */ |
| 168 public abstract void cursorMoved(PointF position); | 124 public abstract void cursorMoved(PointF position); |
| 169 | 125 |
| 170 /** | 126 /** |
| 171 * Informs the view that the cursor visibility has been changed (for differe
nt input mode) by | 127 * Informs the view that the cursor visibility has been changed (for differe
nt input mode) by |
| 172 * the TouchInputHandler, which requires repainting. | 128 * the TouchInputHandler, which requires repainting. |
| 173 */ | 129 */ |
| 174 public abstract void cursorVisibilityChanged(boolean visible); | 130 public abstract void cursorVisibilityChanged(boolean visible); |
| 175 | 131 |
| 176 /** | 132 /** |
| 177 * Starts or stops an animation. Whilst the animation is running, the Deskto
pView will | 133 * Starts or stops an animation. Whilst the animation is running, the Deskto
pView will |
| 178 * periodically call TouchInputHandler.processAnimation() and repaint itself
. | 134 * periodically call TouchInputHandler.processAnimation() and repaint itself
. |
| 179 */ | 135 */ |
| 180 public abstract void setAnimationEnabled(boolean enabled); | 136 public abstract void setAnimationEnabled(boolean enabled); |
| 181 } | 137 } |
| OLD | NEW |