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.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.graphics.Canvas; | 9 import android.graphics.Canvas; |
10 import android.graphics.Color; | 10 import android.graphics.Color; |
11 import android.graphics.Paint; | 11 import android.graphics.Paint; |
12 import android.graphics.Point; | 12 import android.graphics.Point; |
13 import android.graphics.Rect; | |
14 import android.os.Looper; | 13 import android.os.Looper; |
15 import android.os.SystemClock; | 14 import android.os.SystemClock; |
16 import android.text.InputType; | 15 import android.text.InputType; |
17 import android.util.AttributeSet; | 16 import android.util.AttributeSet; |
18 import android.view.MotionEvent; | 17 import android.view.MotionEvent; |
19 import android.view.SurfaceHolder; | 18 import android.view.SurfaceHolder; |
20 import android.view.SurfaceView; | 19 import android.view.SurfaceView; |
21 import android.view.inputmethod.EditorInfo; | 20 import android.view.inputmethod.EditorInfo; |
22 import android.view.inputmethod.InputConnection; | 21 import android.view.inputmethod.InputConnection; |
23 import android.view.inputmethod.InputMethodManager; | 22 import android.view.inputmethod.InputMethodManager; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 setFocusableInTouchMode(true); | 74 setFocusableInTouchMode(true); |
76 | 75 |
77 mRenderData = new RenderData(); | 76 mRenderData = new RenderData(); |
78 mInputHandler = new TouchInputHandler(this, context, mRenderData); | 77 mInputHandler = new TouchInputHandler(this, context, mRenderData); |
79 | 78 |
80 mRepaintPending = false; | 79 mRepaintPending = false; |
81 | 80 |
82 getHolder().addCallback(this); | 81 getHolder().addCallback(this); |
83 } | 82 } |
84 | 83 |
| 84 @Override |
| 85 public void init(Desktop desktop, Client client) { |
| 86 Preconditions.isNull(mDesktop); |
| 87 Preconditions.isNull(mClient); |
| 88 Preconditions.notNull(desktop); |
| 89 Preconditions.notNull(client); |
| 90 mDesktop = desktop; |
| 91 mClient = client; |
| 92 mInputHandler.init(desktop, client); |
| 93 } |
| 94 |
85 public Event<PaintEventParameter> onPaint() { | 95 public Event<PaintEventParameter> onPaint() { |
86 return mOnPaint; | 96 return mOnPaint; |
87 } | 97 } |
88 | 98 |
89 public void setDesktop(Desktop desktop) { | |
90 mDesktop = desktop; | |
91 } | |
92 | |
93 public void setClient(Client client) { | |
94 mClient = client; | |
95 } | |
96 | |
97 /** See {@link TouchInputHandler#onSoftInputMethodVisibilityChanged} for API
details. */ | |
98 public void onSoftInputMethodVisibilityChanged(boolean inputMethodVisible, R
ect bounds) { | |
99 mInputHandler.onSoftInputMethodVisibilityChanged(inputMethodVisible, bou
nds); | |
100 } | |
101 | |
102 /** Request repainting of the desktop view. */ | 99 /** Request repainting of the desktop view. */ |
103 void requestRepaint() { | 100 void requestRepaint() { |
104 synchronized (mRenderData) { | 101 synchronized (mRenderData) { |
105 if (mRepaintPending) { | 102 if (mRepaintPending) { |
106 return; | 103 return; |
107 } | 104 } |
108 mRepaintPending = true; | 105 mRepaintPending = true; |
109 } | 106 } |
110 mClient.getDisplay().redrawGraphics(); | 107 mClient.getDisplay().redrawGraphics(); |
111 } | 108 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 306 |
310 @Override | 307 @Override |
311 public void setAnimationEnabled(boolean enabled) { | 308 public void setAnimationEnabled(boolean enabled) { |
312 synchronized (mAnimationLock) { | 309 synchronized (mAnimationLock) { |
313 if (enabled && !mInputAnimationRunning) { | 310 if (enabled && !mInputAnimationRunning) { |
314 requestRepaint(); | 311 requestRepaint(); |
315 } | 312 } |
316 mInputAnimationRunning = enabled; | 313 mInputAnimationRunning = enabled; |
317 } | 314 } |
318 } | 315 } |
319 | |
320 /** Updates the current InputStrategy used by the TouchInputHandler. */ | |
321 public void changeInputMode( | |
322 Desktop.InputMode inputMode, CapabilityManager.HostCapability hostTo
uchCapability) { | |
323 // We need both input mode and host input capabilities to select the inp
ut strategy. | |
324 if (!inputMode.isSet() || !hostTouchCapability.isSet()) { | |
325 return; | |
326 } | |
327 | |
328 switch (inputMode) { | |
329 case TRACKPAD: | |
330 mInputHandler.setInputStrategy(new TrackpadInputStrategy(mRender
Data, mClient)); | |
331 break; | |
332 | |
333 case TOUCH: | |
334 if (hostTouchCapability.isSupported()) { | |
335 mInputHandler.setInputStrategy(new TouchInputStrategy(mRende
rData, mClient)); | |
336 } else { | |
337 mInputHandler.setInputStrategy( | |
338 new SimulatedTouchInputStrategy(mRenderData, mClient
, getContext())); | |
339 } | |
340 break; | |
341 | |
342 default: | |
343 // Unreachable, but required by Google Java style and findbugs. | |
344 assert false : "Unreached"; | |
345 } | |
346 | |
347 // Ensure the cursor state is updated appropriately. | |
348 requestRepaint(); | |
349 } | |
350 } | 316 } |
OLD | NEW |