Animate views before activity finished - android

I use view animations in a predrawlistener to animate the activity start.
Exist a similar listener to animate my views before my activity is finished?
I know the overridependingtransition method for animations in xml but i want to use ViewPropertyAnimations in a programmatically way for specific views.

I suggest you to override finish() method, then add your animation there:
#Override
public void finish (){
// do your animation
super.finish();
}
You can call YourActivity.finsih(); when you want to finish your activity from code.

Related

Catch the end of Return Activity Transition

From Activity A to B , I set enter and return transitions.
I want to put a fadein animation after the return transition ( B to A after a back).
Originally , I thought that in Activity's onStart method will a good place.
It turns out I don't see the fadein animation so I suppose the ending of the Return Transition happens after onStart()
I checked with SharedElementCallback but it doesn't tell when the transition ends.
How to catch the moment when the Return Transition ends ?
For Activity you'll need to call overridePendingTransition() in Activity A after calling startActivity() and provide your own animations. You can also override onEnterAnimationComplete() in Activity A so you know when it has been animated on to the screen.
For Fragments, you can do this by adding your own custom animations for the transitions using setCustomAnimations() on the transaction. These will override the default animations for your Fragment transitions.

Slide right to left transition anim. Fragment -> Activity

I have a fragment with list view on it. When the user clicks on any of the list view's items he/she is transferred in an Activity. The default animation of the activity that is started (startActivity from the fragment -> opens this activity) is from the bottom slide to top of the screen. How I can override this animation and create a slide from right animation when the activity is created.
I have tried to override the overridePendingTransition method in the activity but that did not change anything.
#Override
public void overridePendingTransition(int enterAnim, int exitAnim) {
super.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
}
From the Activity.overridePendingTransition documentation :
Call immediately after one of the flavors of startActivity(Intent) or finish() to specify an explicit transition animation to perform next.
In other words, call the method on the current Activity after starting the new Activity, instead of overriding it.

How to disable supportFinishAfterTransition when backing out from an activity

I have an activity I animate to with a transition animation, like this:
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, transitionStr);
ActivityCompat.startActivity(activity, intent, options.toBundle());
However, when I go back, I don't want the animation to run in inverse. Is that possible? I'm using AppCompatActivity from appcompat-v7:23.1.1.
If you never want to have that transition back to the parent activity, use
finish();
You can wrap it around a condition if you sometimes want to the transition on the way back to the parent activity. An example use case would be to disable the transition when an interstitial ad was displayed:
if (interstitialAdWasDisplayed) {
finish();
} else {
finishAfterTransition();
}
A possible duplicate of Overriding Transition
finish();
Details.this.overridePendingTransition(R.anim.nothing,R.anim.nothing);
With this piece of code, you can override the finish animation of the current activity.
According to the answers to this question you can't run an animation in inverse. Instead I would create another transition which is basically the inverse of the transition you use when you start the activity and add it to the Activity like this (R.anim.inverseTransition is the Transition you created):
finish();
Details.this.overridePendingTransition(R.anim.inverseTransition,R.anim.inverseTransition);
(see this answer for more information)

Blocking UI interaction on a Fragment

I want to be able to block all UI interaction with a fragment until a callback occurs.
I have two buttons: ButtonA and ButtonB.
ButtonA shows a progress bar and kicks-off an asynchronous thread that calls-back to the fragment when it's done. In the meantime, someone can press ButtonB which I don't want to allow.
My solution was to spin up another fragment which is transparent and intercepts all clicks. However there appears to be delay between FragmentManagers commit() and the fragment actually working.
I've tried calling executePendingTransactions() but I still end up with threading issues whereby the fragment isn't in a state to accept onClick events before the user hits ButtonB.
Is there a more elegant solution?
Thanks,
John
Another option is to use a progress dialog fragment and set it to be non cancelable. It will cover the fragment and prevent the underlying fragment from receiving any touch event.
Instead of calling another fragment,u can have another tranparent view with a progress dialog above the present view and make its visibility VIEW or GONE accordingly.Else u can simply show a prgress dialog with cancelable parameter as false.
Call buttonB.setEnabled(false); after clicking buttonA.
CustomButton extends View {
private boolean mIsEnabled = true;
public void setEnabled (boolean enabled) {
this.mIsEnabled = enabled;
}
#Override
public void onClick() {
if (mIsEnabled) {
mOnClickListener.onClick();
} else {
return;
}
}
}
I didnt understood the question perfectly..
hope it may helps you.
when you adding transaprent fragment over it make the transparent layout clickable=true
if a view is mentioned as clickable it does not pass touch events to below views.
sorry if i understtod your question wrong.
Can't button A put its containing activity in a given state (with a boolean flag raised in its listener) and button B read that flag before doing any stuff ?
I think it's not only a UI issue here but also some presentation logic and mini-state machine that you should implement. This mechanism plus the fragment you already have should be enough to prevent gaps in the sequence of executions of UI Thread events.

Change activity transition when inside a TabHost

I have successfully changed the transitions between activities using overridePendingTransition().
Unfortunately when I am on a TabActivity and use activities inside each tab. When one of those activities inside the content of the tab, starts another activity, the overridePendingTransition() seems to not work.
I basically have a TabActivity, inside it resides an activity with a ListView. What I'm doing is when the item is clicked, I launch the item details' activity.
This new activity's transition animation is not being overridden with the overridePendingTransition()
I basically do this:
private Activity owner;
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent programActivity = new Intent().setClass(view.getContext(), ProgramActivity.class);
Program program = (Program) parent.getItemAtPosition(position);
programActivity.putExtra("programID", program.getId());
owner.startActivity(programActivity);
owner.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
So, I believe that the pending transition is overridden after I'm trying to override them.
Is there a different place I should do that?
Am I doing some other stupid mistake?
Thanks !
I had a similar problem with calling overridePendingTransition() from within a Fragment, because Fragments do not have overridePendingTransition() method defined.
I solved it using:
getActivity().overridePendingTransition(R.anim.enterAnim, R.anim.exitAnim);
Hope it helps. The Fragment was within a TabHost.
I found out that the problem was because my view was a sub-activity inside a tab.
To correctly override the transitions I've overridden the onPause method on the TabActivity and it now works as expected.
Note: You still have to use the overridePendingTransition() on the listener for your items if your activity is NOT within a tab.

Categories

Resources