Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timob-15345: Android: ScrollableView does not show after using a 2D matrix transform #4899

Merged
merged 2 commits into from
Nov 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/titanium/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
android.library=true
android.library.reference.1=../runtime/common
# Project target.
target=android-14
target=android-16
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ private AnimationSet buildViewAnimations(int x, int y, int w, int h,
}

anim = new TiMatrixAnimation(tdm, anchorX, anchorY);

addAnimation(as, anim);

}
Expand Down Expand Up @@ -1297,7 +1296,7 @@ private void setAnchor(int width, int height, float thisAnchorX,
* @return true if the map of running animations contains
* the View, false otherwise.
*/
private static boolean isAnimationRunningFor(View v)
public static boolean isAnimationRunningFor(View v)
{
if (sRunningViews.size() == 0) {
return false;
Expand Down Expand Up @@ -1378,4 +1377,9 @@ private void prepareOpacityForAnimation()
}
tiView.setOpacity(1.0f);
}

public boolean isUsingPropertyAnimators()
{
return (tdm == null || tdm.canUsePropertyAnimators());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutParams;
import org.appcelerator.titanium.view.TiGradientDrawable.GradientType;

import android.annotation.TargetApi;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.view.ViewCompat;
Expand All @@ -61,6 +60,8 @@
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.animation.Animation;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
Expand Down Expand Up @@ -451,7 +452,68 @@ protected void applyTransform(Ti2DMatrix matrix)
options.put(TiC.PROPERTY_DURATION, 1);

animBuilder.applyOptions(options);
animBuilder.start(this.proxy, outerView);

// When using Honeycomb+ property Animators, we can only use absolute values to specify the anchor point, eg. "50px".
// Therefore, we must start the transformation after the layout pass when we get the height and width of the view.
if (animBuilder.isUsingPropertyAnimators()) {
startTransformAfterLayout(outerView);
} else {
animBuilder.start(this.proxy, outerView);
}
}

/**
* When using Honeycomb+ property Animators, we start the transformation after the layout pass.
* @param v the view to animate
*/
protected void startTransformAfterLayout(final View v)
{
final TiViewProxy p = this.proxy;
OnGlobalLayoutListener layoutListener = new OnGlobalLayoutListener() {
public void onGlobalLayout()
{
animBuilder.start(p, v);
try {
if (Build.VERSION.SDK_INT < TiC.API_LEVEL_JELLY_BEAN) {
v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
v.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
} catch (IllegalStateException e) {
if (Log.isDebugModeEnabled()) {
Log.w(TAG, "Unable to remove the OnGlobalLayoutListener.", e.getMessage());
}
}
}
};
v.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);

// On Jelly Bean+, the view will visibly transform if the transformation starts after the layout pass,
// so we add OnPreDrawListener to skip the drawing pass before the animation is ended.
// This mechanism only works for Honeycomb+ property Animators. Because if we use pre-Honeycomb view
// animations and skip the drawing pass, the AnimationListener will not be triggered so
// TiAnimationBuilder.isAnimationRunningFor(view) will always return true.
if (Build.VERSION.SDK_INT >= TiC.API_LEVEL_JELLY_BEAN) {
final OnPreDrawListener preDrawListener = new OnPreDrawListener()
{
public boolean onPreDraw()
{
if (TiAnimationBuilder.isAnimationRunningFor(v)) {
// Skip the current drawing pass.
return false;
}
try {
v.getViewTreeObserver().removeOnPreDrawListener(this);
} catch (IllegalStateException e) {
if (Log.isDebugModeEnabled()) {
Log.w(TAG, "Unable to remove the OnPreDrawListener.", e.getMessage());
}
}
return true;
}
};
v.getViewTreeObserver().addOnPreDrawListener(preDrawListener);
}
}

public void forceLayoutNativeView(boolean informParent)
Expand Down