| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.graphics.Matrix; | 7 import android.graphics.Matrix; |
| 8 import android.graphics.PointF; | 8 import android.graphics.PointF; |
| 9 import android.graphics.Rect; | 9 import android.graphics.Rect; |
| 10 import android.graphics.RectF; | 10 import android.graphics.RectF; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 updateCursorPosition( | 105 updateCursorPosition( |
| 106 mDesiredCenter.x + deltaX, mDesiredCenter.y + deltaY, getViewpor
tBounds()); | 106 mDesiredCenter.x + deltaX, mDesiredCenter.y + deltaY, getViewpor
tBounds()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * Handles System UI size and visibility changes. | 110 * Handles System UI size and visibility changes. |
| 111 * | 111 * |
| 112 * @param parameter The set of values defining the current System UI state. | 112 * @param parameter The set of values defining the current System UI state. |
| 113 */ | 113 */ |
| 114 public void onSystemUiVisibilityChanged(SystemUiVisibilityChangedEventParame
ter parameter) { | 114 public void onSystemUiVisibilityChanged(SystemUiVisibilityChangedEventParame
ter parameter) { |
| 115 if (parameter.softInputMethodVisible) { | 115 mSystemUiScreenRect.set(parameter.left, parameter.top, parameter.right,
parameter.bottom); |
| 116 mSystemUiScreenRect.set( | 116 stopOffsetReductionAnimation(); |
| 117 parameter.left, parameter.top, parameter.right, parameter.bo
ttom); | |
| 118 | 117 |
| 119 stopOffsetReductionAnimation(); | 118 PointF targetOffset; |
| 119 if (mSystemUiScreenRect.isEmpty()) { |
| 120 targetOffset = new PointF(0.0f, 0.0f); |
| 120 } else { | 121 } else { |
| 121 mSystemUiScreenRect.setEmpty(); | 122 // If the System UI size has changed such viewport offset is affecte
d, then start an |
| 122 startOffsetReductionAnimation(); | 123 // animation to adjust the amount of offset used. This functionalit
y ensures that we |
| 124 // don't leave content-less areas on the screen when the System UI r
esizes. |
| 125 RectF systemUiOverlap = getSystemUiOverlap(); |
| 126 RectF newBounds = new RectF(-systemUiOverlap.left, -systemUiOverlap.
top, |
| 127 systemUiOverlap.right, systemUiOverlap.bottom); |
| 128 targetOffset = new PointF(mViewportOffset.x, mViewportOffset.y); |
| 129 constrainPointToBounds(targetOffset, newBounds); |
| 123 } | 130 } |
| 131 startOffsetReductionAnimation(targetOffset); |
| 132 |
| 124 | 133 |
| 125 if (mRenderData.initialized()) { | 134 if (mRenderData.initialized()) { |
| 126 // The viewport center may have changed so update the position to re
flect the new value. | 135 // The viewport center may have changed so update the position to re
flect the new value. |
| 127 repositionImage(); | 136 repositionImage(); |
| 128 } | 137 } |
| 129 } | 138 } |
| 130 | 139 |
| 131 public void adjustViewportForSystemUi(boolean adjustViewportForSystemUi) { | 140 public void adjustViewportForSystemUi(boolean adjustViewportForSystemUi) { |
| 132 mAdjustViewportSizeForSystemUi = adjustViewportForSystemUi; | 141 mAdjustViewportSizeForSystemUi = adjustViewportForSystemUi; |
| 133 | 142 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 // viewport offset as a maximum boundary. If we add the offset first, t
he result ends up | 401 // viewport offset as a maximum boundary. If we add the offset first, t
he result ends up |
| 393 // being unbounded. Thus we use a temporary object for the boundary cal
culation. | 402 // being unbounded. Thus we use a temporary object for the boundary cal
culation. |
| 394 PointF requestedOffset = | 403 PointF requestedOffset = |
| 395 new PointF(mViewportOffset.x + offsets[0], mViewportOffset.y + o
ffsets[1]); | 404 new PointF(mViewportOffset.x + offsets[0], mViewportOffset.y + o
ffsets[1]); |
| 396 constrainPointToBounds(requestedOffset, getViewportOffsetBounds()); | 405 constrainPointToBounds(requestedOffset, getViewportOffsetBounds()); |
| 397 mViewportOffset.set(requestedOffset); | 406 mViewportOffset.set(requestedOffset); |
| 398 } | 407 } |
| 399 | 408 |
| 400 /** | 409 /** |
| 401 * Starts an animation to smoothly reduce the viewport offset. Does nothing
if an animation is | 410 * Starts an animation to smoothly reduce the viewport offset. Does nothing
if an animation is |
| 402 * already running or the offset is already 0. | 411 * already running, the offset is already 0, or the offset and target are th
e same. |
| 403 */ | 412 */ |
| 404 private void startOffsetReductionAnimation() { | 413 private void startOffsetReductionAnimation(final PointF targetOffset) { |
| 405 if (mFrameRenderedCallback != null || mViewportOffset.length() < EPSILON
) { | 414 if (mFrameRenderedCallback != null || mViewportOffset.length() < EPSILON |
| 415 || arePointsEqual(mViewportOffset, targetOffset, EPSILON)) { |
| 406 return; | 416 return; |
| 407 } | 417 } |
| 408 | 418 |
| 409 mFrameRenderedCallback = new Event.ParameterCallback<Boolean, Void>() { | 419 mFrameRenderedCallback = new Event.ParameterCallback<Boolean, Void>() { |
| 410 private static final float DURATION_MS = 250.0f; | 420 private static final float DURATION_MS = 250.0f; |
| 411 | 421 |
| 412 private final Interpolator mInterpolator = new DecelerateInterpolato
r(); | 422 private final Interpolator mInterpolator = new DecelerateInterpolato
r(); |
| 413 | 423 |
| 414 private long mStartTime = 0; | 424 private long mStartTime = 0; |
| 415 private float mOriginalX = 0.0f; | 425 private final float mOriginalX = mViewportOffset.x - targetOffset.x; |
| 416 private float mOriginalY = 0.0f; | 426 private final float mOriginalY = mViewportOffset.y - targetOffset.y; |
| 417 | 427 |
| 418 @Override | 428 @Override |
| 419 public Boolean run(Void p) { | 429 public Boolean run(Void p) { |
| 420 if (mFrameRenderedCallback == null) { | 430 if (mFrameRenderedCallback == null) { |
| 421 return false; | 431 return false; |
| 422 } | 432 } |
| 423 | 433 |
| 424 if (mStartTime == 0) { | 434 if (mStartTime == 0) { |
| 425 mStartTime = SystemClock.elapsedRealtime(); | 435 mStartTime = SystemClock.elapsedRealtime(); |
| 426 mOriginalX = mViewportOffset.x; | |
| 427 mOriginalY = mViewportOffset.y; | |
| 428 } | 436 } |
| 429 | 437 |
| 430 float progress = (SystemClock.elapsedRealtime() - mStartTime) /
DURATION_MS; | 438 float progress = (SystemClock.elapsedRealtime() - mStartTime) /
DURATION_MS; |
| 431 if (progress < 1.0f) { | 439 if (progress < 1.0f) { |
| 432 float reductionFactor = 1.0f - mInterpolator.getInterpolatio
n(progress); | 440 float reductionFactor = 1.0f - mInterpolator.getInterpolatio
n(progress); |
| 433 mViewportOffset.set(mOriginalX * reductionFactor, mOriginalY
* reductionFactor); | 441 mViewportOffset.set(mOriginalX * reductionFactor + targetOff
set.x, |
| 442 mOriginalY * reductionFactor + targetOffset.y); |
| 434 } else { | 443 } else { |
| 435 mViewportOffset.set(0.0f, 0.0f); | 444 mViewportOffset.set(targetOffset.x, targetOffset.y); |
| 436 mFrameRenderedCallback = null; | 445 mFrameRenderedCallback = null; |
| 437 } | 446 } |
| 438 | 447 |
| 439 repositionImage(); | 448 repositionImage(); |
| 440 | 449 |
| 441 return mFrameRenderedCallback != null; | 450 return mFrameRenderedCallback != null; |
| 442 } | 451 } |
| 443 }; | 452 }; |
| 444 | 453 |
| 445 mRenderStub.onCanvasRendered().addSelfRemovable(mFrameRenderedCallback); | 454 mRenderStub.onCanvasRendered().addSelfRemovable(mFrameRenderedCallback); |
| 446 } | 455 } |
| 447 | 456 |
| 448 /** | 457 /** |
| 449 * Stops an existing offset reduction animation. | 458 * Stops an existing offset reduction animation. |
| 450 */ | 459 */ |
| 451 private void stopOffsetReductionAnimation() { | 460 private void stopOffsetReductionAnimation() { |
| 452 // Setting this value this null will prevent it from continuing to execu
te. | 461 // Setting this value this null will prevent it from continuing to execu
te. |
| 453 mFrameRenderedCallback = null; | 462 mFrameRenderedCallback = null; |
| 454 } | 463 } |
| 464 |
| 465 private boolean arePointsEqual(PointF a, PointF b, float epsilon) { |
| 466 return Math.abs(a.x - b.x) < epsilon && Math.abs(a.y - b.y) < epsilon; |
| 467 } |
| 455 } | 468 } |
| OLD | NEW |