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