| 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; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 * 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. |
| 42 */ | 42 */ |
| 43 protected final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged
= | 43 protected final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged
= |
| 44 new Event.Raisable<>(); | 44 new Event.Raisable<>(); |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Subclass should trigger this event when a frame is rendered. | 47 * Subclass should trigger this event when a frame is rendered. |
| 48 */ | 48 */ |
| 49 protected final Event.Raisable<Void> mOnCanvasRendered = new Event.Raisable<
>(); | 49 protected final Event.Raisable<Void> mOnCanvasRendered = new Event.Raisable<
>(); |
| 50 | 50 |
| 51 private final int mTinyFeedbackPixelRadius; | |
| 52 private final int mSmallFeedbackPixelRadius; | |
| 53 private final int mLargeFeedbackPixelRadius; | |
| 54 | |
| 55 /** The parent Desktop activity. */ | 51 /** The parent Desktop activity. */ |
| 56 private final Desktop mDesktop; | 52 private final Desktop mDesktop; |
| 57 | 53 |
| 58 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa
ble<>(); | 54 private final Event.Raisable<TouchEventParameter> mOnTouch = new Event.Raisa
ble<>(); |
| 59 | 55 |
| 60 public DesktopView(Desktop desktop, Client client) { | 56 public DesktopView(Desktop desktop, Client client) { |
| 61 super(desktop); | 57 super(desktop); |
| 62 Preconditions.notNull(desktop); | 58 Preconditions.notNull(desktop); |
| 63 Preconditions.notNull(client); | 59 Preconditions.notNull(client); |
| 64 mDesktop = desktop; | 60 mDesktop = desktop; |
| 65 mInputHandler = new TouchInputHandler(this, desktop); | 61 mInputHandler = new TouchInputHandler(this, desktop); |
| 66 mInputHandler.init(desktop, new InputEventSender(client)); | 62 mInputHandler.init(desktop, new InputEventSender(client)); |
| 67 | |
| 68 // Give this view keyboard focus, allowing us to customize the soft keyb
oard's settings. | |
| 69 setFocusableInTouchMode(true); | |
| 70 | |
| 71 mTinyFeedbackPixelRadius = | |
| 72 getResources().getDimensionPixelSize(R.dimen.feedback_animation_
radius_tiny); | |
| 73 | |
| 74 mSmallFeedbackPixelRadius = | |
| 75 getResources().getDimensionPixelSize(R.dimen.feedback_animation_
radius_small); | |
| 76 | |
| 77 mLargeFeedbackPixelRadius = | |
| 78 getResources().getDimensionPixelSize(R.dimen.feedback_animation_
radius_large); | |
| 79 } | 63 } |
| 80 | 64 |
| 81 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl
ass. | 65 // TODO(yuweih): move showActionBar and showKeyboard out of this abstract cl
ass. |
| 82 /** Shows the action bar. */ | 66 /** Shows the action bar. */ |
| 83 public final void showActionBar() { | 67 public final void showActionBar() { |
| 84 mDesktop.showSystemUi(); | 68 mDesktop.showSystemUi(); |
| 85 } | 69 } |
| 86 | 70 |
| 87 /** Shows the software keyboard. */ | 71 /** Shows the software keyboard. */ |
| 88 public final void showKeyboard() { | 72 public final void showKeyboard() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 115 } |
| 132 | 116 |
| 133 /** Called whenever the user attempts to touch the canvas. */ | 117 /** Called whenever the user attempts to touch the canvas. */ |
| 134 @Override | 118 @Override |
| 135 public final boolean onTouchEvent(MotionEvent event) { | 119 public final boolean onTouchEvent(MotionEvent event) { |
| 136 TouchEventParameter parameter = new TouchEventParameter(event); | 120 TouchEventParameter parameter = new TouchEventParameter(event); |
| 137 mOnTouch.raise(parameter); | 121 mOnTouch.raise(parameter); |
| 138 return parameter.handled; | 122 return parameter.handled; |
| 139 } | 123 } |
| 140 | 124 |
| 141 /** | |
| 142 * Returns the radius of the given feedback type. | |
| 143 * 0.0f will be returned if no feedback should be shown. | |
| 144 */ | |
| 145 protected final float getFeedbackRadius(InputFeedbackType feedbackToShow, fl
oat scaleFactor) { | |
| 146 switch (feedbackToShow) { | |
| 147 case NONE: | |
| 148 return 0.0f; | |
| 149 case SHORT_TOUCH_ANIMATION: | |
| 150 return mSmallFeedbackPixelRadius / scaleFactor; | |
| 151 case LONG_TOUCH_ANIMATION: | |
| 152 return mLargeFeedbackPixelRadius / scaleFactor; | |
| 153 case LONG_TRACKPAD_ANIMATION: | |
| 154 // The size of the longpress trackpad animation is supposed to b
e close to the size | |
| 155 // of the cursor so it doesn't need to be normalized and should
be scaled with the | |
| 156 // canvas. | |
| 157 return mTinyFeedbackPixelRadius; | |
| 158 default: | |
| 159 // Unreachable, but required by Google Java style and findbugs. | |
| 160 assert false : "Unreached"; | |
| 161 return 0.0f; | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 /** Triggers a brief animation to indicate the existence and location of an
input event. */ | 125 /** Triggers a brief animation to indicate the existence and location of an
input event. */ |
| 166 public abstract void showInputFeedback(InputFeedbackType feedbackToShow, Poi
ntF pos); | 126 public abstract void showInputFeedback(InputFeedbackType feedbackToShow, Poi
ntF pos); |
| 167 | 127 |
| 168 /** | 128 /** |
| 169 * Informs the view that its transformation matrix (for rendering the remote
desktop bitmap) | 129 * Informs the view that its transformation matrix (for rendering the remote
desktop bitmap) |
| 170 * has been changed by the TouchInputHandler, which requires repainting. | 130 * has been changed by the TouchInputHandler, which requires repainting. |
| 171 */ | 131 */ |
| 172 public abstract void transformationChanged(Matrix matrix); | 132 public abstract void transformationChanged(Matrix matrix); |
| 173 | 133 |
| 174 /** | 134 /** |
| 175 * Informs the view that the cursor has been moved by the TouchInputHandler,
which requires | 135 * Informs the view that the cursor has been moved by the TouchInputHandler,
which requires |
| 176 * repainting. | 136 * repainting. |
| 177 */ | 137 */ |
| 178 public abstract void cursorMoved(PointF position); | 138 public abstract void cursorMoved(PointF position); |
| 179 | 139 |
| 180 /** | 140 /** |
| 181 * Informs the view that the cursor visibility has been changed (for differe
nt input mode) by | 141 * Informs the view that the cursor visibility has been changed (for differe
nt input mode) by |
| 182 * the TouchInputHandler, which requires repainting. | 142 * the TouchInputHandler, which requires repainting. |
| 183 */ | 143 */ |
| 184 public abstract void cursorVisibilityChanged(boolean visible); | 144 public abstract void cursorVisibilityChanged(boolean visible); |
| 185 } | 145 } |
| OLD | NEW |