Merge "Properly notify magnification listener" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
286c5b7741
@@ -131,11 +131,11 @@ public class MagnificationSpec implements Parcelable {
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("<scale:");
|
||||
builder.append(scale);
|
||||
builder.append(Float.toString(scale));
|
||||
builder.append(",offsetX:");
|
||||
builder.append(offsetX);
|
||||
builder.append(Float.toString(offsetX));
|
||||
builder.append(",offsetY:");
|
||||
builder.append(offsetY);
|
||||
builder.append(Float.toString(offsetY));
|
||||
builder.append(">");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -144,27 +144,35 @@ class MagnificationController {
|
||||
* @param updateSpec {@code true} to update the scale and center based on
|
||||
* the region bounds, {@code false} to leave them as-is
|
||||
*/
|
||||
public void setMagnifiedRegion(Region magnified, Region available, boolean updateSpec) {
|
||||
private void setMagnifiedRegion(Region magnified, Region available, boolean updateSpec) {
|
||||
synchronized (mLock) {
|
||||
mMagnifiedRegion.set(magnified);
|
||||
mMagnifiedRegion.getBounds(mMagnifiedBounds);
|
||||
boolean magnificationChanged = false;
|
||||
boolean boundsChanged = false;
|
||||
|
||||
if (!mMagnifiedRegion.equals(magnified)) {
|
||||
mMagnifiedRegion.set(magnified);
|
||||
mMagnifiedRegion.getBounds(mMagnifiedBounds);
|
||||
boundsChanged = true;
|
||||
}
|
||||
mAvailableRegion.set(available);
|
||||
|
||||
final MagnificationSpec sentSpec = mSpecAnimationBridge.mSentMagnificationSpec;
|
||||
final float scale = sentSpec.scale;
|
||||
final float offsetX = sentSpec.offsetX;
|
||||
final float offsetY = sentSpec.offsetY;
|
||||
|
||||
// Compute the new center and update spec as needed.
|
||||
final float centerX = (mMagnifiedBounds.width() / 2.0f
|
||||
+ mMagnifiedBounds.left - offsetX) / scale;
|
||||
final float centerY = (mMagnifiedBounds.height() / 2.0f
|
||||
+ mMagnifiedBounds.top - offsetY) / scale;
|
||||
if (updateSpec) {
|
||||
setScaleAndCenter(scale, centerX, centerY, false);
|
||||
} else {
|
||||
mAms.onMagnificationStateChanged();
|
||||
mAms.notifyMagnificationChanged(mMagnifiedRegion, scale, centerX, centerY);
|
||||
final MagnificationSpec sentSpec = mSpecAnimationBridge.mSentMagnificationSpec;
|
||||
final float scale = sentSpec.scale;
|
||||
final float offsetX = sentSpec.offsetX;
|
||||
final float offsetY = sentSpec.offsetY;
|
||||
|
||||
// Compute the new center and update spec as needed.
|
||||
final float centerX = (mMagnifiedBounds.width() / 2.0f
|
||||
+ mMagnifiedBounds.left - offsetX) / scale;
|
||||
final float centerY = (mMagnifiedBounds.height() / 2.0f
|
||||
+ mMagnifiedBounds.top - offsetY) / scale;
|
||||
magnificationChanged = setScaleAndCenterLocked(
|
||||
scale, centerX, centerY, false);
|
||||
}
|
||||
|
||||
// If magnification changed we already notified for the change.
|
||||
if (boundsChanged && updateSpec && !magnificationChanged) {
|
||||
onMagnificationChangedLocked();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -327,21 +335,17 @@ class MagnificationController {
|
||||
*/
|
||||
public boolean reset(boolean animate) {
|
||||
synchronized (mLock) {
|
||||
return resetLocked(animate);
|
||||
final MagnificationSpec spec = mCurrentMagnificationSpec;
|
||||
final boolean changed = !spec.isNop();
|
||||
if (changed) {
|
||||
spec.clear();
|
||||
onMagnificationChangedLocked();
|
||||
}
|
||||
mSpecAnimationBridge.updateSentSpec(spec, animate);
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean resetLocked(boolean animate) {
|
||||
final MagnificationSpec spec = mCurrentMagnificationSpec;
|
||||
final boolean changed = !spec.isNop();
|
||||
if (changed) {
|
||||
spec.clear();
|
||||
}
|
||||
|
||||
mSpecAnimationBridge.updateSentSpec(spec, animate);
|
||||
return changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales the magnified region around the specified pivot point,
|
||||
* optionally animating the transition. If animation is disabled, the
|
||||
@@ -416,8 +420,8 @@ class MagnificationController {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setScaleAndCenterLocked(
|
||||
float scale, float centerX, float centerY, boolean animate) {
|
||||
private boolean setScaleAndCenterLocked(float scale, float centerX, float centerY,
|
||||
boolean animate) {
|
||||
final boolean changed = updateMagnificationSpecLocked(scale, centerX, centerY);
|
||||
mSpecAnimationBridge.updateSentSpec(mCurrentMagnificationSpec, animate);
|
||||
return changed;
|
||||
@@ -440,6 +444,12 @@ class MagnificationController {
|
||||
}
|
||||
}
|
||||
|
||||
private void onMagnificationChangedLocked() {
|
||||
mAms.onMagnificationStateChanged();
|
||||
mAms.notifyMagnificationChanged(mMagnifiedRegion,
|
||||
getScale(), getCenterX(), getCenterY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists the current magnification scale to the current user's settings.
|
||||
*/
|
||||
@@ -524,6 +534,10 @@ class MagnificationController {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
onMagnificationChangedLocked();
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user