I want to enable animations in my app dynamically as we do manually from Settings>Display>Animation>All Animation.
I have tried appended code but to no avail,
Settings.System.putInt(getContentResolver(), Settings.System.WINDOW_ANIMATION_SCALE, 1);
Settings.System.putInt(getContentResolver(), Settings.System.TRANSITION_ANIMATION_SCALE, 1);
Please help
Imran
i think., you can do it for your app., but if you are taking it for your device means you can read the flags., if it is disabled you can intent the setting panel to open to enable it by the user.
source:
animation enable
// declare animation
Animation animationSlideInLeft, animationSlideOutRight;
// Now we are giveing image view animated
image1 = (ImageView)findViewById(R.id.image1);
image2 = (ImageView)findViewById(R.id.image2);
image3 = (ImageView)findViewById(R.id.image3);
animationSlideInLeft = AnimationUtils.loadAnimation(this,
android.R.anim.slide_in_left);
animationSlideOutRight = AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right);
animationSlideInLeft.setDuration(1000);
animationSlideOutRight.setDuration(1000);
animationSlideInLeft.setAnimationListener(animationSlideInLeftListener);
animationSlideOutRight.setAnimationListener(animationSlideOutRightListener);
curSlidingImage = image1;
image1.startAnimation(animationSlideInLeft);
image1.setVisibility(View.VISIBLE);
// Create animation listener
AnimationListener animationSlideInLeftListener
= new AnimationListener(){
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
if(curSlidingImage == image1){
image1.startAnimation(animationSlideOutRight);
}else if(curSlidingImage == image2){
image2.startAnimation(animationSlideOutRight);
}else if(curSlidingImage == image3){
image3.startAnimation(animationSlideOutRight);
}
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}};
// and paus clear the listener
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
image1.clearAnimation();
image2.clearAnimation();
image3.clearAnimation();
}
Reference from here
2.Same this one you can do with add xml into res/anim/ folder
Related
i create animation, at the start of animation i am changing the styles of some button and then and at the end of the animation i am changing buttons style back to its previous style but that's is not happing it still show the same style that was set at onAnimationStart()
Every thing looks fine the control is also going through the loop in onActionEnd() but still no update in buttons style. Help Please
public void WrongAnim()
{
AlphaAnimation animation = new AlphaAnimation(1, 0.5f);
//animation.setRepeatCount(1);
animation.setDuration(2000);
animation.setAnimationListener(new AnimationListener(){
#Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
Log.v("Wronganim", "end...");
for(int i=0; i<input_boxes.size(); i++)
{
input_boxes.get(i).getBox().setTextAppearance(context, R.style.textstyle);
}
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
Log.v("Wronganim", "start......");
for(int i=0; i<input_boxes.size(); i++)
{
input_boxes.get(i).getBox().setTextAppearance(context, R.style.redtext);
}
}
});
inputbar.startAnimation(animation); //lienar layout inflate from xml
}
A view after an scale animation, have not resize to new position.
I using a android animation (ScaleAnimation) to make a layout(screen size when start) scale to 0.95 times size by itself and the scale reference the screen central point.
final AnimationListener al2 = new AnimationListener() {
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation arg0) {
}
};
public void animScale(){
ScaleAnimation sa = new ScaleAnimation(1,0.95f,1,0.95f, topLayout.getMeasuredWidth()/2, topLayout.getMeasuredHeight()/2);
sa.setDuration(500);
sa.setFillEnabled(true);
sa.setFillAfter(true);
sa.setAnimationListener(al2);
topLayout.startAnimation(sa);
}
public void onCreate(Bundle savedInstanceState) {
scaleButton = (Button) findViewById(R.id.scaleButton);
scaleButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
animScale();
}
});
}
after this animation my layout have been changed to new position, but when i click again the button
the layout always from screen size scale to 0.95 times.
that show me the layout never change the actual size through the animation.
what code i need to add in the animation listener animation end?
i hope to achieve when i click the button it will do that,
screen size -> screen size *0.95 -> screen size *0.95^2 ->........
thanks a lot.
The problem occurs because you are using Animation class. With Animation you only change the visible appearance.
In your case you need to use Animator which also updates positions and dimensions.
The difference between Animation and Animator is explained in this question.
ScaleAnimation doesn't changes layout's parameters. It animates without changing parameters for a smoother animation.
You can create a Boolean instance variable
Boolean animationDone = false;
and set it to true in onAnimationEnd to indicate if the animation is done
public void onAnimationEnd(Animation arg0) {
animationDone=true;
}
and check it in animScale before animating to prevent multiple animations....
public void animScale(){
if ( animationDone ) return;
//..... animation code here...
}
I have a RotateAnimation attached to an ImageButton which upon click rotates it and using OnAnimationEnd starts a new Activity.
Problem is its not working. After I close my application and come back, I am inside the new Activity(..) and when I go back, then the animation executes. I want the animation to happen and then start the new Activity.
For some reason, it was working absolutely fine before using the same code but I don't know, some trivial change may have affected it.
Here's the code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.menu);
ImageButton amazingPicsButton = (ImageButton) findViewById(R.id.amazingPics),
setViewOnClick(amazingPicsButton, new Intent("com.jasfiddle.AmazingInterface.AMAZINGPICS"));
}
/**
* Generic OnClick setter method for giving various View objects a click listener
* #param b
* #param intent
*/
private <B> void setViewOnClick(B b, final Intent intent){
((View) b).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
amazingPicsSound = createRandButSound();
amazingPicsSound.start();
rotateAndNewActivity(v, intent);
}
});
}
/** function that produces rotation animation on the View v.
* Could be applied to button, ImageView, ImageButton, etc.
*/
private void rotateAndNewActivity(View v, final Intent intent){
// Create an animation instance
Animation an = new RotateAnimation(30, 360, v.getWidth()/2, v.getHeight()/2);
an.setDuration(50); // duration in ms
an.setRepeatCount(3); // -1 = infinite repeate
/*we override the Animation an object to include the start of an new Activity
at the end of animation */
an.setAnimationListener(new AnimationListener(){
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
//start the activity onAnimationEnd
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
startActivity(intent);
}
});
// Set the animation's parameters
v.setAnimation(an);
}
setAnimation only sets the next animation to play on the View. To start an animation immediately, use startAnimation
In your case, use v.startAnimation(an);
I am new to android development.
I have on one image in layout.I used scale animation for that image.
and i am able to stop the scaling of image at particular point. now i want to resize that image on another clicklistener.
How to do that? if any idea,help.
Here is my code.
final ImageView img_graph= (ImageView)findViewById(R.id.graph01);
final Animation AnimationScale= AnimationUtils.loadAnimation(this,R.anim.anim_scale);
final Animation AnimationScale_reverse= AnimationUtils.loadAnimation(this,R.anim.anim_scale_reverse);
if(flag ==FLAG_SCALE_IN) {
if(resp==0){
img_graph.setOnClickListener(new ImageView.OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
img_graph.setBackgroundResource(R.drawable.page01_graph);
img_graph.startAnimation(AnimationScale);
}});
}
}
if(flag==FLAG_SCALE_OUT) {
if(resp==1){
img_graph.setOnClickListener(new ImageView.OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
img_graph.setBackgroundResource(R.drawable.page01_graph);
img_graph.startAnimation(AnimationScale_reverse);
}});
}
}
can't we handle this case using if else in same listner ?
img_graph.setOnClickListener(new ImageView.OnClickListener(){
public void onClick(View arg0) {
if(resp==0 && flag ==FLAG_SCALE_IN) {
img_graph.setBackgroundResource(R.drawable.page01_graph);
img_graph.startAnimation(AnimationScale);
}else if( resp==1 &&flag ==FLAG_SCALE_OUT) {
img_graph.setBackgroundResource(R.drawable.page01_graph);
img_graph.startAnimation(AnimationScale_reverse);
}
}
}});
More optimization:
public void imageViewClick(View v)
{
if(flag==FLAG_SCALE_IN && resp==0)
{
}
else if(flag==FLAG_SCALE_OUT && resp==1)
{
}
}
My problem is:
I customized a view as below JPTabBarMainMenu, set it as part of a listview header. in JPTabBarMainMenu there are two buttons, animation will runs when I click one of the two buttons.
the problem is the animation runs very well on android 2.3.3, but won't run on 4.0.3 and 4.0.4, I guess it won't work on 4.x. I don't know the reason.
JPTabBarMainMenu extends FrameLayout{
code as below:
onAnimationStart/onAnimationRepeat/onAnimationEnd won't getting called.
FrameLayout.LayoutParams params = (LayoutParams) mSlider.getLayoutParams();
JPTranslateAnimation slideRightAnimation = new MaringTranslateTranslateAnimation(params.leftMargin, tabItem.getLeft() + offset / 2, 0, 0, mSlider);
slideRightAnimation.setDuration(slideRightAnimation.computeDuration(
JPTranslateAnimation.ANIMATION_STD_DURATION, mTabLayout.getWidth()));
slideRightAnimation.setRepeatCount(0);
slideRightAnimation.setFillAfter(true);
slideRightAnimation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
isRunningAnimation = true;
if(mSelectionChangedListener != null){
mSelectionChangedListener.onSelectionChangedStart(oldIndex, mCurrentTab);
}
if(oldIndex != -1){
TabItem item = mTabItems.get(oldIndex);
item.onTabItemSelected(false);
}
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
isRunningAnimation = false;
if(mSelectionChangedListener != null){
mSelectionChangedListener.onSelectioinChangedEnd(oldIndex, mCurrentTab);
}
TabItem item = mTabItems.get(mCurrentTab);
item.onTabItemSelected(true);
if(mDrawSelectorByDefault == false){
mSlider.setVisibility(View.INVISIBLE);
}
}
});
if(mSlider.getVisibility() != View.VISIBLE){
mSlider.setVisibility(View.VISIBLE);
}
mSlider.startAnimation(slideRightAnimation);