Select images from Galley and add animation - android

I am creating an app where user selects images from gallery and selects a song of his/her choice and on click of a button 'Run Movie'. Animation is played along with the song.
I am stuck at the animation playing part it plays only music and does not show any pictures.
I was successful playing animation with sound when I had images picked from drawables and specified in the animation.xml. Kindly guide me where I am making a mistake.
Update: I am able to get all image and song paths which user has selected.The only problem is with playing frameanimation.
Here is the code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation_sound);
m_imageView = (ImageView)findViewById(R.id.imageView1);
Bundle bundle = getIntent().getExtras();
imgPathArr = bundle.getStringArray("picsPath");
songPath = bundle.getString("songPath");
m_imageView.setBackgroundResource(R.drawable.animation);
frameAnimation = (AnimationDrawable)m_imageView.getBackground();
if(imgPathArr == null || imgPathArr.length == 0){
Toast.makeText(this, "Please selct images first", Toast.LENGTH_LONG).show();
}else{
for(int i =0 ; i< imgPathArr.length; i++){
Log.d("Activity", imgPathArr[i]);
**frameAnimation.addFrame(
Drawable.createFromPath(imgPathArr[i]), 5000);**
}
}
animation.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="4000"
android:fromAlpha="0.0"
android:toAlpha="0.9" >
</animation-list>
My code for Animation with sound when I am picking images from drawables
m_imageView.setBackgroundResource(R.anim.anim);
frameAnimation = (AnimationDrawable)m_imageView.getBackground();
anim.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/pic1"
android:fromAlpha="0.0"
android:toAlpha="0.9"
android:duration="5000"/>
<item
android:drawable="#drawable/pic2"
android:fromAlpha="0.0"
android:toAlpha="0.9"
android:duration="5000"/>
<item
android:drawable="#drawable/pic3"
android:fromAlpha="0.0"
android:toAlpha="0.9"
android:duration="5000"/>
</animation-list>

"I was successful playing animation with sound when I had images picked from drawables."
If that worked for you then you can convert your images into BitmapDrawables by using these methods
BitmapDrawable(Resources res, String filepath)
BitmapDrawable(Resources res, Bitmap bitmap)
from the documentation
"A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object."
Use it like this
Drawable d =new BitmapDrawable(getResources(),filepath);
Hope it workes for you. Cheers :)

Related

Android dimsiss ImageView on swipe gesture

In a RelativeLayout I have a TextView and a Button under the TextView and an ImageView covering both of the other objects. As the user opens the activity, the ImageView should cover the other items.
As the user swipes on the image (left or right), it should dismiss so the user can operate the button and read the textfield.
Whith an onClick listener I could dismiss the Image when clicked but I would like an animation, exactly like in a RecicleView when swiping to delete an element.
You could add the desired animation to the onClick event.
1) create(or add if existing) the anim folder inside the res directory and put slide_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
2) Add this code to the onclick action of the image view :
// Refer the ImageView like this
imageView = (ImageView) findViewById(R.id.imageView);
// Load the animation like this
animSlide = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.slide_animation);
// Start the animation like this
imageView.startAnimation(animSlide);
You can modify the animation specs in the xml so you can get the desired effect.
And then just implement AnimatorListener so you can dismiss the image view at animation end.
animSlide.setListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
//remove image view from the layout
}
});

How to create Animated Splash Screen such this

I need to make such animated splash screen. Can you help me?
One way is to use Tween Animation like the following. In your case needs more than one anim file
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation);
Say like if you have to animate white circle image then do the following
ImageView image = (ImageView)findViewById(R.id.imageView);
Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
image.startAnimation(animation1);
Now you need to create anim file in res/anim/move.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
This is an example. You need to find ways to modify these basic animations for your requirement . For more refer this link
To use a gif for your splash screen.
In your build.gradle file:
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
In your activities layout:
<pl.droidsonroids.gif.GifImageView
android:id="#+id/gifView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/gif"
/>
And finally in your class file:
private static int SPLASH_TIME_OUT = 1500;
private boolean isInFront;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_gif);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
// This method will be executed once the timer is over
if(isInFront)
{
// Start your app main activity
Intent i = new Intent(SplashScreen_Gif.this, MainMenuActivity.class);
startActivity(i);
}
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
You can use a gif image like this and use it on your splash screen instead of a normal jpg or png image

Is possible to make an animation with the android native ProgressBar image and use as a drawable?

I'm using Universal Image Loader to load a previous image before the official one in my catalog.
But as a request from my boss, I have to insert a native ProgressBar before the loading of all official images in the app.
Universal Image Loader provides in the displayImage() method, a way using a SimpleImageLoadingListener to do that. That's ok and works fine. But I had to call it all over my app.
Is there a way I can draw(copy) the native ProgressBar image and make it rotate as an animation? If this is possible as a 'drawable', I could just change one line in my UIL coonfigs:
IMAGE_OPTIONS = new DisplayImageOptions.Builder() //
.showImageOnLoading(R.drawable.mynativeandanimatedprogressbar)
ETC ETC ETC
Thanks in advance, I really appreciate any help.
bye
//you can do like this
imageLoader.displayImage(IMAGE_DOWNLOAD_URL, holder.image, options,new SimpleImageLoadingListener() {
#Override
public void onLoadingStarted(String imageUri, View view) {
((ImageView) view).setBackgroundResource(R.drawable.my_image_progress);
AnimationDrawable frameAnimation = (AnimationDrawable)((ImageView) view).getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();
}
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
((ImageView) view).setImageBitmap(loadedImage);
}
});
// my_image_progress.xml put in
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item android:drawable="#drawable/logo_n" android:duration="500" />
<item android:drawable="#drawable/logo_l" android:duration="500" />
<item android:drawable="#drawable/logo_d" android:duration="500" />
</animation-list>

How to apply a animation to an imageview in android?

what i am trying to do here is,i have downloaded some images in my application and i want to show these images one by one to the user in full screen after some times say every 30 seconds.I also applied an animation to the imageview when image changes here is my code:-
protected Bitmap doInBackground(String... params) {
// TODO Auto-generated method stub
if (!isCancelled())
{
filename=params[0];
if(ShowImages.vn>d2)
{
ShowImages.vn=0;
}
bmp = BitmapFactory.decodeFile(filename);
}
return bmp;
}
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
ShowImages.tt1.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
r1 = AnimationUtils.loadAnimation(ShowImages.context, R.anim.lefttoright);
ShowImages.tt1.setImageBitmap(result);
ShowImages.tt1.startAnimation(r1);
}
}
this is my code for my animation file:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
i have no problem with this code it is executing fine,but when the image change takes place the whole imageview goes blank for some time and then the next image comes.I do not want this,i want the previous image to be there untill the next image change has taken place,can someone suggest me a method for this.
In your case it would be good to use frame-by-frame animation as well define on developer site Frame- by- frame: An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.
Check below tutorial even you will get more example, just try to Google:
Displaying a frame-by-frame animation in Android

Using FrameAnimations and AnimationDrawable to display images not working

I have a simple .xml layout file that has a simple ImageView, that I want to switch images on. I decided to go ahead and do it with FrameAnimations, using the AnimationDrawable API.
I have managed to create my animation file in "drawable/file.xml", here is the code:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/image_010_1" android:duration="1000" />
<item android:drawable="#drawable/image_010_2" android:duration="1000" />
</animation-list>
Now, Here is the code that should start my animation:
Image1.setBackgroundResource(R.drawable.image_010);
AnimationDrawable animation = (AnimationDrawable) Image1.getBackground();
animation.start();
For some reason, When i run the app I just see the first frame, and the next image does not come after 1000 milis, or at all! What am I doing wrong? Thanks!
so I managed to solve this problem by adding a Runnable to my ImageView:
image.post(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
animation.start();
}
});

Categories

Resources