Overriding pending transition with animation object instead of resource id - android

Is there any way to override the pending transition by passing it actual Animation object instead of an ID to an animation resource?
From
startActivity(intent);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
To
startActivity(intent);
overridePendingTransition(new MyFadeInAnimation(), new MyFadeOutAnimation());
If not, is there a way for me to manually register an animation resource (and attain an ID) programatically?
I really do not want to define the activity transition animations as XML for other reasons.

So one way to do this is to use Fragments. Set overridePendingTransition(0,0); for the Activity. and then in the Fragment, override onCreateAnimator() or if using the old animations, use android.support.v4.app.Fragment and override onCreateAnimation().

Related

Transition Animation From Fragment To Activity Android

In my application, I want to transit from Fragment to Activity.
For this purpose I am using following code for Animation,
Bundle bndlanimation =ActivityOptions.makeCustomAnimation(getActivity(), R.anim.slideinleft,R.anim.slideinright).toBundle();
startActivity(intentonboard,bndlanimation);
This works fine.
But What I want to do is that, I am moving from Fragment To Activity.
So I just want to apply the exit animation for Fragment only. Next Activity should be added behind the scene without animation.
So What Should I write in place of enter animation ?
I tried with 0 instead of R.anim.slideinright. But It effects on Exit animation.
Thanks
if you in fragment Layout and wanna to get intent to same activity you must use this...
Intent intent = new Intent(getActivity(),MainActivty.class);
startActivity(intent);
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
getActivity().overridePendingTransition(R.animator.slide_in_from_left, R.animator.slide_in_from_right);
Use getActivity() After startActivity(intent);
May this help you.

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)

Animate views before activity finished

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.

Create new "screens" dynamically

I have an application that gets information from a database and it creates ImageButtons dynamically. What I want is, when I click a dynamically created ImageButton, I want it to make a search in my database (which I know how to do) and then create a new activity (or screen) with new ImageButtons created dynamically, too.
How can I do this?
You cannot create activities without declaring them in the manifest file. You can either call setContentView after creating the new layout(I do not recomend this.).
Or use the viewflipper and add the the different layouts as childs to it. So you can use the viewflipper to switch between layouts.
Best option is to read the android developer documentation on how Intents can be used to launch a New Activity
An Intent object is passed to Context.startActivity() or
Activity.startActivityForResult() to launch an activity or
get an existing activity to do something new.
(It can also be passed to Activity.setResult() to return
information to the activity that called startActivityForResult().)
ImageButton imagebutton=new ImageButton(this);
imagebutton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
getDataFromDataBase();//In this method you get data from database
Intent intent=new Intent(currentactivity.this,newactivity.class);//start new screen.. in this you can create imagebutton dynamically
startActivity(intent);
finish();
}
});
just execute the code that you have inside your onCreate (wrap it in an init(Params param) method), and call that inside your onClickListener. of course exclude the setContentView and findViewById's.

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