How to create dynamic user face model in android? - android

Hello I want to create the dynamic user face model in android and display to the user.
I have searched and found that I need user different angles face frames (Images) like 14 to 16 images and for displaying purpose need to change images (frame) using opengl (for smoothness) on user finger swipe so it look like 3D Image.
But I want like some editing like(wear earing) in each frame and display to the user as like
https://lh3.googleusercontent.com/WLu3hm0nIhW5Ps9GeMS9PZiuc3n2B8xySKs1LfNTU1drOIqJ-iEvdiz-7Ww0ZX3ZtLk=h900
Please give me some suggestion or example on it.

I expect that your images fit in the memory.
You can add ImageView for every image to a FrameLayout and let just one ImageView be visible.
Then you can even use fade in / fade out animation to improve the effect when switching to next image.
ImageView[] imageViews;
int currentView = 0;
...
// fill imageViews
...
ImageView image1 = imageViews[currentView];
if (moveRight) {
if (++currentView >= imageViews.length) currentView = 0;
} else {
if (--currentView < 0) currentView = imageViews.length - 1;
}
ImageView image2 = imageViews[currentView];
image1.setVisibility(View.INVISIBLE);
image1.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_out));
image2.setVisibility(View.VISIBLE);
image2.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in));
anim/fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<alpha
android:duration="150"
android:fromAlpha="0.0"
android:toAlpha="1.0"/>
</set>
anim/fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<alpha
android:duration="150"
android:fromAlpha="1.0"
android:toAlpha="0.0"/>
</set>
About hardware acceleration, I think in this case Android can handle it for you.
From Android 3.0 you can define it in the manifest for application or activity:
android:hardwareAccelerated="true"
Alternatively you can set it just for specific views.
Using XML:
android:layerType="hardware"
Using Java:
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Here you can find more information about Hardware Acceleration

Related

Android Translation animation

i am trying to animate an image view by ensuring that the object appears in the center of the screen and then translates up.. to its final position. the code i used is as follows.
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:fromYDelta="400"
android:toYDelta="0"
android:duration="800"/>
</set>
This code works when u have a device of 4.7"(galaxy s3) screen size the image will appear at the center of the screen and then move to its set position. But on a screen of 4" (S advance or htc desire x) the image practically appears at the screen bottom.
So is there any way to ensure that the image is at the center of the screen heedless of the device on which the code is running?? Thanks in advance..
Use percentages instead of values to make the Animation uniform across all screen sizes.
The animation should apply its transformation after it ends
android:fillAfter="true"
The animation begins from the vertical center, i.e 50% of Y
android:fromYDelta="50%p"
The animation ends at the top, i.e. 0% of Y
android:toYDelta="0%p"
XML:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="800"
android:fillAfter="true"
android:fromYDelta="50%p"
android:toYDelta="0%p" />
</set>
thanks for ur response..
i tried ur suggestion 's and i found that using 50%p to then in a 4 inch screen the image view is present at around 3\4of the screen. but when i use 25%p then its around the center. in case of s advance its center and in s3 its relatively center.. i guess it depends on the size of the image.(dimention)

Animations to make things go around the screen (Android)

I'm new to Android developing. I want some animations when clicking on the card and it will move around the screen and stay at its new position forever (its interactive area should change too).
At first the card is located at the center-bottom of the screen (XDelta= 50% YDelta = 70%) then it will move up straight to center of the screen (XDelta =50% and YDelta is 40%). Then it will move to its upper left (10 dp from the left of the screen and 10 dp from the top of the screen) Sorry I can't post images due to my lack of reputation.
And here's my code in res/anim/card1.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="50%"
android:fromYDelta="70%"
android:toYDelta="40%"
android:toXDelta="50%"
android:fillEnabled="true"/>
<translate
android:duration="100"
android:fillEnabled="true"
android:fromXDelta="50%"
android:fromYDelta="40%"
android:startOffset="200"
android:toXDelta="10"
android:toYDelta="10" />
</set>
And code to get it work when clicking on the card
Animation anim = AnimationUtils.loadAnimation(MainActivity.this,
R.anim.card1);
iv_card.startAnimation(anim);
... but it just don't animate the way I want. Please help me!!!!
Check Out this (http://www.tktutorials.com/2013/07/animation-in-android-using-xml-files.html) this may help your need. Alter the translate.xml file as per your need, which is located in Res->anim->translate.xml
And solution for your posting Image. My suggestion is upload your pic in googleDrive, then change the share setting for the particular pic from private to Public on web and use the url Link to your question.

Android - Image animation not working as intended

I have 4 clickable images surounding the center of my screen. Upon clicking one of the images I want the image to slide from it's current position to the center of the screen.
Once the image reaches the center of the screen I would like the image to flip and then have my fragment load.
How do I obtain this full sequence? I have my fragment loading but I am unsure of how to create an animation that slides my image from it's current position to the center. The layout of the page is know and is as follows.
1 2 3
4 5 6
7 8 9
where 2, 4, 6, 8 are my images that I want to slide and 5 is the position that I want them to slide to on click (then flip and show my fragment).
Thanks,
Dman
EDIT :
One thing I cannot get to occur is the events to play in sequence. Currently when i click the image it waits the offset that I have set on the flip_image.xml animation and then plays them all at once in the duration given to the flip_image.xml animation. Any help on this would be much appreciated.
slide_left.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%"
android:toXDelta="-112%"
android:duration="1000"/>
slide_alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.8"
android:toAlpha="1.0"
android:duration="1000" />
flip_image.xml
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.0"
android:toXScale="1.0"
android:pivotX="50%"
android:fromYScale="1.0"
android:toYScale="1.0"
android:startOffset="1000"
android:duration="200" />
Calling Code:
private void loadFragmentAnimation(final ImageView view, final int slideDirection) {
AnimationSet animSet = new AnimationSet(true);
animSet.addAnimation(AnimationUtils.loadAnimation(getActivity(), slideDirection));
animSet.addAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.slide_alpha));
animSet.addAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.flip_image));
animSet.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
// mCallBack.categorySelected(view.getId());
}
});
view.startAnimation(animSet);
}
Use View animation.
Create an AnimationSet having a TranslateAnimation
followed by a ScaleAnimation to simulate a flip (you may need
to mirror the image on the other side of the flip. Perhaps there's
an easier way?).
Then set the animation to the ImageView using
setAnimation().
I guess you should be able to specify the animation in XML too.
Edit:
For the flip animation, you may refer to the following links:
Android Animations 3D flip
Android Animation - Flip

How to rotate a shape around a central axis

I'm surprised to find so few examples when it comes to Android animation. I have found the animation demos but they provide only a small set of what you might want to achieve.
For my particular case I'm just trying to animate a shape around a central point. I can see from the demo that you can use the following to pass in values:
ObjectAnimator.ofObject(
ballHolder
, "name"
, new XYEvaluator()
, position1, position2, position3, position4, positionEtc);
But how can I pass in all the values for a circle? I'm sure you wouldn't achieve it this way (as in, the example above).
Maybe I should be doing it a different way? Any help would be much appreciated.
try this code and adjust it as you need :
To implement the rotation animation, you can define that animation in XML:
create an animation xml file under /res/anim folder called :rotate_around_center_point.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<rotate android:toDegrees="360"
android:duration="700"
android:pivotX="205"
android:pivotY="180"
android:interpolator="#android:anim/linear_interpolator"/>
</set>
apply the animation to View : lets say it for rotate image :
ImageView animationTarget = (ImageView) this.findViewById(R.id.testImage);
Animation animation = AnimationUtils.loadAnimation(this,
R.anim.rotate_around_center_point); animationTarget.startAnimation(animation);
OR
create the animation dynamically in Java code:
Animation newAnimation = new RotateAnimation(0, 360, 205, 180);
newAnimation.setDuration(700);
animationTarget.startAnimation(newAnimation);
HOPE THIS HELP .

Rotate button about X-axis in an Android app

I want to rotate a button about X-axis when clicked and then display a different image so it creates an effect that after button click it's flipping and showing a different image which is at its backside.
I'm using following xml for rotation of button:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<set android:interpolator="#android:anim/decelerate_interpolator">
<rotate
android:fromDegrees="0"
android:toDegrees="-360"
android:pivotX="25%"
android:pivotY="25%"
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="0"
android:duration="400" />
</set>
</set>
But it's rotating the button in 2-D plane about the button's center.
I have a flip example here:
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html
I'm afraid the conventional graphics and animation APIs are 2D. To use that 3rd dimension you'd need to look into OpenGL, which is non-trivial.
You might be able to fake a depth effect by writing a custom animation that uses setPolyToPoly to warp your initial rect into a trapezoid.
It's been a while since this question is posted, but just for the record - there is a way in newer versions of android, and for back compatibility use http://nineoldandroids.com/

Categories

Resources