ViewAnimationUtils fails to work - android

Was trying to implement the snippet below. [from developer documentation here]:
View myView = findViewById(R.id.my_view);
// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;
// get the final radius for the clipping circle
int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
// create the animator for this view (the start radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
// make the view visible and start the animation
myView.setVisibility(View.VISIBLE);
anim.start();
Gettting the error below. Why is it so and how can i fix this.
java.lang.NoClassDefFoundError: android.view.ViewAnimationUtils
at dejavu.appzonegroup.com.dejavuandroid.Fragment.PeopleTabFragment$1.onItemClick(PeopleTabFragment.java:59)
at android.widget.AdapterView.performItemClick(AdapterView.java:299)
at android.widget.AbsListView.performItemClick(AbsListView.java:1152)

ViewAnimationUtils was added in API level 21 (Lollipop 5.0). Are you testing your app on Lollipop? It will not work on older API levels. To use it you need to set min SDK to 21.

One google search brought me this, it gives you 3 ways to solve your problem. I'll quote a few wich I think that might resolve your problem:
1) Class is not available in Java Classpath.
2) You might be running your program using jar command and class was
not defined in manifest file's ClassPath attribute.

Related

nineoldandroids - setDuration doesnt work on AnimatorSet

I have the following code which splits an image in half and animate each part in different direction:
final AnimatorSet mSetAnim = new AnimatorSet();
final Animator topAnim = ObjectAnimator.ofFloat(topImage, "translationY", (bmp.getHeight() / 2) * -1);
final Animator bottomAnim = ObjectAnimator.ofFloat(bottomImage, "translationY", bmp.getHeight() / 2);
mSetAnim.setDuration(duration);
mSetAnim.playTogether(topAnim, bottomAnim);
mSetAnim.start();
I'm using NineOldAndroids in order to support old android versions but for some reason no matter what value i put in 'duration' it doesnt seem to have any affect. The animation duration stays the same - half a second more or less.
When i use android's animation apis i can see that the duration is changing.
Any idea how to workarround this ?
Using mSetAnim.getDuration(), Try printing in a toast to see what value exists at runtime.
Use mSetAnim.setDuration(duration); after playTogether() as is done in nineoldandroids.com.

Method getAlpha() with type int not found on target class class android.graphics.drawable.BitmapDrawable

I am trying to use the example from here with code here, about custom animations into a GridView.
All is working OK until I try to use a BitmapDrawable instead of a ColorDrawable.
mBackground = getResources().getDrawable(R.drawable.activity_background);
topView.setBackgroundDrawable(mBackground);
If using a BitmapDrawable, when swiping from main activity to the PictureDetailsActivity and back, makes the background from the main activity disappear. In logs I keep seeing this error when the background is gone (sometimes background is gone only when swiping the list, with the same error below):
Method getAlpha() with type int not found on target class
class android.graphics.drawable.BitmapDrawable
Searching the error I cannot find anything about it.
EDIT:
I am using alpha for fading in and out the background, as in the example:
// Fade in the background
ObjectAnimator bgAnim = ObjectAnimator.ofInt(mBackground, "alpha", 0, 255);
bgAnim.setDuration(duration * 2);
bgAnim.start();
and
// Fade out background
ObjectAnimator bgAnim = ObjectAnimator.ofInt(mBackground, "alpha", 0);
bgAnim.setDuration(duration * 2);
bgAnim.start();
You are probably testing on a device/emulator which is < API19, while getAlpha() was only added on API19. Hence,
Method getAlpha() with type int not found
Please make sure to test on a target with minimum Android 4.4 (KitKat) installed.

Inverse of AccelerateDecelerateInterpolator on Android

I'm pretty much looking for exactly what the question suggests - a DecelerateAccelerateInterpolator. What I want to do is have an animation decelerate for the first half of the animation, and then accelerate after that. (I'm using it to mimic a gravity-like effect on a Bèzier curve).
EDIT:
Basically, what I'm looking for is something that as the object moves upward on the screen along a Bèzier curve, it decelerates until it gets to the top (at which point it momentarily stops, or has 0 speed or whatever), and then it starts to accelerate as it travels back down the other side.
If you're using Android API 21 or greater you can use PathInterpolator with a cubic Bezier curve:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
TimeInterpolator lInter = new PathInterpolator(0.0f, 0.97f, 1.0f, 0.03f);
animation.setInterpolator(lInter);
}
And here's a great website for calculating your desired bezier curve values:
Try to use my custom Interpolator. And you're welcome :)
mAnimation.setInterpolator(new Interpolator() {
#Override
public float getInterpolation(float pInput) {
System.out.println("input " + pInput);
// (1-(1-(x*2))^3)/2
return (float) (1 - Math.pow(1 - (2 * pInput), 3)) / 2;
}
});
I'm thinking you could actually chain two Interpolators. The first would be a DecelerateInterpolator from time 0 to time 1, then start an AccelerateInterpolator at time 1 to time 2. Basically split the time in half.

android - get pivot point of an ImageView for API < 11

suppose imgv is an ImageView
if I say float x = imgv.getPivotX(); float y = imgv.getPivotY();
this will give me the pivot point, however, this requires your app to target api 11 and above, I want to do the same for api 8, what function should I use?
Pivot is related to animations. To make them compatible with Android 1.0+ you should use NineOldAndroids
Then you can use the helper class: float x = ViewHelper.getPivotX(imgv);

Why does the matrix generated by Android's frustumM differ from the Redbook's?

Something seems funny about the way that Android's frustumM works. If I check the OpenGL red book, the matrix generated looks like this:
(source: glprogramming.com)
Songho.ca seems to agree with this:
(source: songho.ca)
However, one component is multiplied by 2 with Android's frustumM, and not in the other example matrices. Here's what it seems to be doing:
Everything seems to functionally match up, except the first row, third column. Why is that being multiplied by two? Here's the lines of code from android.opengl.Matrix's frustumM method that generate the first three elements of the third column:
final float A = 2.0f * ((right + left) * r_width);
final float B = (top + bottom) * r_height;
final float C = (far + near) * r_depth;
With r_width, r_height, r_depth defined as:
final float r_width = 1.0f / (right - left);
final float r_height = 1.0f / (top - bottom);
final float r_depth = 1.0f / (near - far);
The line starting with "final float A" appears to be mistakenly multiplying by 2.
Is this a mistake in Android's code, or am I just missing something? I know that the term cancels out if the frustum is symmetrical. When running the code with an asymmetrical frustum, the generated matrices actually are different and so are the resulting vectors when the same vector is multiplied with those differing matrices.
It's a bug with Android. Please see http://code.google.com/p/android/issues/detail?id=35646
((I'd preffer just to comment but I'm not allowed.))
Thank you guys for the insight. I just had to add
mMyMatrix[8] /= 2f;
after
Matrix.frustrumM(mMyMatrix, ...)
To solve my aspect ratio problems :)
yes, if you call the function with a (-ratio, ratio, -1, 1, 1, 10) parameters set, it does not cause the probelm, but if you call with (right != -1 * left), it makes thing different.
I find this issue when i check the source code. sigh.

Categories

Resources