EnterTransition working while exitTransition() not working - android

Trying to put enter & exit transition to an activity which is opening a fragment. Following are the steps followed.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
TransitionSet enterTransitionSet = new TransitionSet();
enterTransitionSet.addTransition(TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.move));
enterTransitionSet.setDuration(400);
enterTransitionSet.setStartDelay(0);
getWindow().setSharedElementEnterTransition(enterTransitionSet);
Slide enterSlide = new Slide();
enterSlide.setStartDelay(300);
enterSlide.setDuration(300);
getActivity().getWindow().setEnterTransition(enterSlide);
Fade exitFade = new Fade();
exitFade.setStartDelay(300);
exitFade.setDuration(300);
getActivity().getWindow().setExitTransition(exitFade);
}
}
Issue : Enter transition is successfully applied as slide, while the exit transition for window is not reflecting. Activity is exiting with slide effect only without any delay or so.

Related

Application is not responding while using animation on Imageview

I've a imageview and animating the image infinitely with YoYo. I need to start a new activity AnimalIntroducer when this imageview is clicked. I can start new activity AnimalIntroducer clicking this animated button. But when clicking the back button in AnimalIntroducer activity when I come back to my HomeActivity then this animation on imageview stops, and button click becomes unresponsive and shows application is not responding. Do I have to run the animation in background thread? If so how can I do this?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_activity);
hangingMonkeyImageView = findViewById(R.id.monkey_hanging_image_view);
YoYo.with(Techniques.Bounce)
.duration(1000)
.repeat(-1)
.playOn(hangingMonkeyImageView);
hangingMonkeyImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(HomeActivity.this,AnimalIntroducer.class);
startActivity(intent);
}
});
}
I would suggest you to stop the animation on view when the user navigates to the second activity, and restart the animation in onResume() method of HomeActivity.
If you want to learn more about it please see Android Activity Lifecycle

views are invisible after activity transition ends

i recently faced a pretty strange issue with activity transitions. I'm trying to make a slide in transition with exclusions, which are native status bar, native navigation bar and my custom bottom navigation bar. So i created piece of code based on documentation (link here) which in most cases works pretty well, but sometimes all views in the activity have visibility set as View.INVISIBLE (i know that fact from Layout Inspector).
So, i have activity A and activity B. Then i'm navigating from activity A to B via startActivity(). When i click back on activity B sometimes transition works fine, but in some cases all views on activity A (except bottom navigation bar, which was excluded from transition) are set to View.INVISIBLE
My code:
Activity A :
Intent i = new Intent(this, ActivityB.class);
Transition slide = new Slide(Gravity.RIGHT);
slide.excludeTarget(findViewById(R.id.bottom_navigation_bar), true);
slide.excludeTarget(findViewById(android.R.id.navigationBarBackground), true);
slide.excludeTarget(findViewById(android.R.id.statusBarBackground), true);
getWindow().setExitTransition(slide);
startActivity(i,
ActivityOptionsCompat.makeSceneTransitionAnimation(this, createPairs()).toBundle());
private Pair[] createPairs() {
Pair[] pairs = new Pair[2];
pairs[0] = Pair.create(findViewById(android.R.id.statusBarBackground), Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME);
pairs[1] = Pair.create(findViewById(android.R.id.navigationBarBackground), Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME);
return pairs;
}
Activity B:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
setContentView(R.layout.activity);
final View decor = getWindow().getDecorView();
decor.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
#Override
public boolean onPreDraw() {
decor.getViewTreeObserver().removeOnPreDrawListener(this);
Transition fade = new Fade();
fade.excludeTarget(findViewById(R.id.bottom_navigation_bar), true);
fade.excludeTarget(findViewById(android.R.id.navigationBarBackground), true);
fade.excludeTarget(findViewById(android.R.id.statusBarBackground), true);
getWindow().setEnterTransition(fade);
return true;
}
});

Image slide show in Android

I am making an application in android for picture slide show. I have tried the following code:
class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Drawable backgrounds[] = new Drawable[2];
Resources res = getResources();
backgrounds[0] = res.getDrawable(android.R.drawable.btn_star_big_on);
backgrounds[1] = res.getDrawable(android.R.drawable.btn_star_big_off);
TransitionDrawable crossfader = new TransitionDrawable(backgrounds);
ImageView image = (ImageView)findViewById(R.id.image);
image.setImageDrawable(crossfader);
crossfader.startTransition(3000);
}
}
This code successfully bring the new image on top but previous image is not faded out.
Can anyone help me on it?
You need to enable the cross fade on your transition to have both of your images fade. Use the method setCrossFadeEnabled to enable it by setting it tu true.
See documentation here http://developer.android.com/reference/android/graphics/drawable/TransitionDrawable.html#setCrossFadeEnabled(boolean)

Slide transition in new Android L API

I am trying new Android L API in particular transitions. The best experience I have with "Fade" but "Slide.RIGHT" behaves really weird… When screen fly in it brings firstly screen title at the bottom, then title jump to the top of the screen and rest of the screen is appear…
I did not use custom transition, just basic one. Screen I use for testing has just couple of TextView, EditText and button. But even if I change Google ActivitySceneTransitionBasicSample from custom transition to basic Slide.RIGHT it behave the same strange way…
Is somebody managed to implement nice Slide transition? In my case I need to Slide completely different screens. There are no elements I can share.
My code is:
First Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Slide transitionEnter = new Slide();
transitionEnter.setSlideEdge(Gravity.RIGHT);
transitionEnter.setDuration(1000);
Window currentW = getWindow();
currentW.setEnterTransition(transitionEnter);
currentW.setExitTransition(transitionEnter);
getWindow().setAllowEnterTransitionOverlap(true);
getWindow().setAllowExitTransitionOverlap(true);
setContentView(R.layout.slide_test_view);
}
public void buttonLAction(View view){
Utils.startActivity(this, SecondSlideTestActivity.class);
}
Second Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Slide transitionEnter = new Slide();
transitionEnter.setSlideEdge(Gravity.RIGHT);
transitionEnter.setDuration(1000);
Window currentW = getWindow();
currentW.setEnterTransition(transitionEnter);
currentW.setExitTransition(transitionEnter);
getWindow().setAllowEnterTransitionOverlap(true);
getWindow().setAllowExitTransitionOverlap(true);
setContentView(R.layout.second_slide_test_view);
}
Just a small suggestion, doesn't make it perfect but looks better in my opinion:
Use different edges for enter and exit transition, e.g.:
transitionEnter.setSlideEdge(Gravity.RIGHT);
transitionExit.setSlideEdge(Gravity.LEFT);
I did that and for me it looks kinda okay then. Hope this helps!

Why does my animation freeze when returning to activity containing it?

I'm still sort of new with Android, so forgive me if it's an obvious mistake. In this activity I'm using ViewPager to horizontally scroll through three layouts containing an ImageButton that has an animated background depending on its current state. When the button is pressed, it starts a new activity. However, when I hit the back button to go back to the activity containing the animation from the new activity, sometimes the animation freezes or plays back faster than it should. I wrote a method for starting up the animation that I use in onWindowFocusChanged(), and onRestart(). I'm working in Android 2.1 (API 7).
This is my code:
public class CopyOfWorld extends Activity{
MediaPlayer muzak;
Boolean mSwitch = false;
ImageButton holmes;
AnimationDrawable holmesAnimation;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.world);
Preferencer pp = (Preferencer)getApplicationContext();
ViewPagerAdapter adapter = new ViewPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.viewpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(1);
if(pp.getMuzak()){
mSwitch = true;
muzak = MediaPlayer.create(CopyOfWorld.this, R.raw.level1);
muzak.setLooping(true);
muzak.start();
}
}
public void clicker(View v){
Intent myIntent = new Intent(CopyOfWorld.this , Subworld.class);
startActivityForResult(myIntent, 0);
}
#Override
public void onWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
beginRender();
}
#Override
protected void onPause(){
super.onPause();
if(mSwitch){
muzak.release();
}
}
#Override
protected void onRestart(){
super.onRestart();
Preferencer pp = (Preferencer)getApplicationContext();
if(pp.getMuzak()){
muzak = MediaPlayer.create(CopyOfWorld.this, R.raw.level1);
muzak.setLooping(true);
muzak.start();
}
beginRender();
}
public void beginRender(){
ImageButton holmes = (ImageButton) findViewById(R.id.subworlder);
StateListDrawable background = (StateListDrawable) holmes.getBackground();
Drawable current = background.getCurrent();
if(current instanceof AnimationDrawable){
holmesAnimation = (AnimationDrawable) current;
holmesAnimation.start();
}
}
}
I've tried calling the method beginRender() under ()onResume, but then the app simply crashes.
Could anyone point me in the right direction?
EDIT:
I've been tweaking the code here and there, unfortunately to no avail. But I did notice a pattern in the behavior of the animation. When I press down on the ImageButton or hold it so that it goes from its default animation to its pressed or focused animation then move my finger away from the button so that it doesn't start up the new activity, it sometimes behaves very much as I described at the beginning of this post (i.e. it's supposed to return to its default animation, but instead plays back at twice the rate, chokes up, or doesn't play at all.)
Currently the xml that contains these ImageButtons defines their backgrounds as the animations and have no source (src). But when I change the background to transparent and the src to the animations, the app crashes.
Any clues?

Categories

Resources