XML Animation executing synced - android

I've made some simple animations which I called breath because the object slowly get bigger and smaller in a loop.
Then I associated this animation to 3 imagebuttons and everything works ok, but when I interact with a button, which do another "vibrate" animation, all of them restart the animation together, while the expected behaviour was that only the pressed button would have restarted the animation.
I would like to understand that a bit better, and maybe how to achieve that every button's animation have its own lifecycle.
That's the code:
breath.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator" >
<scale
android:duration="1500"
android:startOffset="0"
android:fromXScale="0.9"
android:fromYScale="0.9"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0"
android:repeatMode="reverse"
android:repeatCount="infinite" />
</set>
and that's the java code:
package com.anesoft.android.citmania;
import com.anesoft.android.citmania.models.Defines;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MenuActivity extends Activity implements OnClickListener, AnimationListener {
ImageButton opzioni;
ImageButton play;
ImageButton espansioni;
ImageView logo;
TextView title,title2;
Animation breath,rotate_r,rotate_l,vibrate;
int flag = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
logo = (ImageView)findViewById(R.id.logo);
title = (TextView)findViewById(R.id.title);
title2 = (TextView)findViewById(R.id.title2);
opzioni = (ImageButton)findViewById(R.id.options);
play = (ImageButton)findViewById(R.id.play);
espansioni = (ImageButton)findViewById(R.id.expansions);
breath = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.breath);
rotate_r = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_right);
rotate_l = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_left);
vibrate = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.vibrate);
vibrate.setAnimationListener(this);
Typeface tf = Typeface.createFromAsset(getAssets(), "font/Canter_Light.otf");
Typeface tf2 = Typeface.createFromAsset(getAssets(), "font/Canter Bold.otf");
title.setTypeface(tf);
title2.setTypeface(tf2);
title.setText("CIT");
title.setTextSize(Defines.TITLE_SIZE);
title2.setText(".MANIA");
title2.setTextSize(Defines.TITLE_SIZE);
opzioni.startAnimation(breath);
play.startAnimation(breath);
espansioni.startAnimation(breath);
logo.setOnClickListener(this);
opzioni.setOnClickListener(this);
play.setOnClickListener(this);
espansioni.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
#Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.options) {
Intent i = new Intent(this, OptionsActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
} else if (id == R.id.play) {
Intent i = new Intent(this, LevelPickerActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
} else if(id == R.id.expansions){
espansioni.startAnimation(vibrate);
Toast.makeText(this, "Implementando", Toast.LENGTH_SHORT).show();
//espansioni.startAnimation(bounce);
}else if(id == R.id.logo){
if(flag==0){
logo.startAnimation(rotate_r);
flag=1;
}else{
logo.startAnimation(rotate_l);
flag=0;
}
}
}
#Override
public void onAnimationEnd(Animation arg0) {
if (arg0 == vibrate) {
espansioni.startAnimation(breath);
}
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
You can see how I start the vibrate animation and then when IT finishes I restart the breath one only in the button being tapped, but all of them restart the animation in a synced way.
Thanks in advance

If you want the animation to work independently on all 3 buttons, you'll need to create 3 instances of the animation.
Once the animation is halted, it gives its views a new state. If you gave 3 views the same animation, they will all receive the new state.

Related

Remove View after animation

I have a view that does an animation and then should be removed or at least sent to the back so i can reuse it. I'm having trouble attaching a listener to it.
I've been stuck on this for about 2 weeks so any help at all is really appreciated.
I'm just trying to get the card to fling off the screen, disappear and then be deleted.
package com.example.trevorwood.biggles.study;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.example.trevorwood.biggles.R;
public class StudyActivity extends AppCompatActivity {
LinearLayout mFlipCardLinearLayout;
LinearLayout mCardFlippedButtons;
FrameLayout mCardFrame;
View mCurrentAnimCardContainer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_study);
Intent intent = getIntent();
// String value = intent.getStringExtra("key");
Toolbar toolbar = (Toolbar) findViewById(R.id.study_toolbar);
toolbar.setTitleTextColor(Color.WHITE);//0xAARRGGBB
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mFlipCardLinearLayout = (LinearLayout) findViewById(R.id.flip_card_linear_layout);
mCardFlippedButtons = (LinearLayout) findViewById(R.id.card_flipped_buttons);
mCardFrame = (FrameLayout) findViewById(R.id.card_frame);
final Drawable upArrow = getResources().getDrawable(R.drawable.ic_back_arrow);
upArrow.setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
makeNewCard();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/HomeFragment button
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
public void onCardClick(View view) {
flipCard();
}
public void onCardFlippedButtonsClick(View view) {
Integer numberPressed;
switch (view.getId()){
case R.id.color_button_1:numberPressed = 1;break;
case R.id.color_button_2:numberPressed = 2;break;
case R.id.color_button_3:numberPressed = 3;break;
case R.id.color_button_4:numberPressed = 4;break;
case R.id.color_button_5:numberPressed = 5;break;
default:numberPressed = 0;
}
saveCardStats(numberPressed);
flingCardAway();
resetForNewCard();
makeNewCard();
}
private void flipCard() {
FrameLayout cardFrame = (FrameLayout) findViewById(R.id.card_frame);
Integer childCount = cardFrame.getChildCount();
Log.d("Simple","childCount: "+childCount);
View cardContainer = findViewById(R.id.card_container);
View cardFace = findViewById(R.id.card_front);
View cardBack = findViewById(R.id.card_back);
FlipAnimation flipAnimation = new FlipAnimation(cardFace, cardBack);
if (cardFace.getVisibility() == View.GONE) {
mFlipCardLinearLayout.setVisibility(View.VISIBLE);
mCardFlippedButtons.setVisibility(View.GONE);
flipAnimation.reverse();
}else{
mFlipCardLinearLayout.setVisibility(View.GONE);
mCardFlippedButtons.setVisibility(View.VISIBLE);
}
cardContainer.startAnimation(flipAnimation);
}
private void saveCardStats(Integer numberPressed){
}
private void flingCardAway(){
mCurrentAnimCardContainer = findViewById(R.id.card_container);
ViewCompat.setTranslationZ(mCurrentAnimCardContainer, 1.0f);
AnimationSet anim = new AnimationSet(true);
RotateAnimation rotate1 = new RotateAnimation(0,-45, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
rotate1.setStartOffset(100);
rotate1.setDuration(500);
anim.addAnimation(rotate1);
TranslateAnimation trans1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
trans1.setDuration(600);
anim.addAnimation(trans1);
AlphaAnimation opacity1 = new AlphaAnimation(1.0f, 0.0f);
opacity1.setDuration(400);
opacity1.setStartOffset(200);
anim.addAnimation(opacity1);
mCurrentAnimCardContainer.setAnimation(anim);
mCurrentAnimCardContainer.setVisibility(View.VISIBLE);
final FrameLayout cardFrame = (FrameLayout) findViewById(R.id.card_frame);
anim.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationStart(Animation arg0) {
}
#Override
public void onAnimationRepeat(Animation arg0) {
}
#Override
public void onAnimationEnd(Animation arg0) {
//The problem area, also this is not always called
// ((ViewGroup)mCurrentAnimCardContainer.getParent()).removeView(mCurrentAnimCardContainer);
// cardFrame.removeAllViews();
}
});
}
private void resetForNewCard(){
mFlipCardLinearLayout.setVisibility(View.VISIBLE);
mCardFlippedButtons.setVisibility(View.GONE);
}
private void makeNewCard(){
Integer childCount = mCardFrame.getChildCount();
Log.d("Simple","childCount: "+childCount);
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.study_card, mCardFrame);
}
}
Is it just me or does making an Android app feel like you're constantly swimming against the current in a river.
Edit: If you want to see real improvement, explain why you think this is a bad question rather than just down voting.
I took out onAnimationEnd and just put the removeAllView method outside of it and it worked. Honestly I have no idea how this works. One would imagine that if you remove a View it cannot have an animation work on it.
private void flingCardAway(){
View currentAnimCardContainer = findViewById(R.id.card_container);
ViewCompat.setTranslationZ(currentAnimCardContainer, 1.0f);
AnimationSet anim = new AnimationSet(true);
RotateAnimation rotate1 = new RotateAnimation(0,-45, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF, 0.5f );
rotate1.setStartOffset(1);
rotate1.setDuration(400);
anim.addAnimation(rotate1);
TranslateAnimation trans1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.0f, Animation.RELATIVE_TO_PARENT, -1.5f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -0.5f);
trans1.setStartOffset(1);
trans1.setDuration(550);
anim.addAnimation(trans1);
AlphaAnimation opacity1 = new AlphaAnimation(1.0f, 0.0f);
opacity1.setStartOffset(300);
opacity1.setDuration(600);
anim.addAnimation(opacity1);
currentAnimCardContainer.startAnimation(anim);
mCardFrame.removeAllViews();
}

Toast Message not working android

I have 2 classes BlockIdActivity.java and ScanWifi.java. I have 2 buttons in BlockIdActivity.java file and i am able to see my toast defined there. However i cant see the toast for the button i defined in ScanWifi.Java class.
Following is the code for BlockIdActivity.java
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
public class BlockIdActivity extends ActionBarActivity {
private ImageButton mUpButton;
private ImageButton mDownButton;
private TextView mBlock_Id_Field;
int counter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_block_id);
mUpButton = (ImageButton)findViewById(R.id.arrow_up);
mDownButton = (ImageButton)findViewById(R.id.arrow_down);
mBlock_Id_Field = (TextView)findViewById(R.id.BlockIdField);
mUpButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mBlock_Id_Field.getText().toString().trim().equals(""))
{
counter = 1;
mBlock_Id_Field.setText(String.valueOf(counter));
}
else {
counter = Integer.valueOf(mBlock_Id_Field.getText().toString().trim());
counter++;
mBlock_Id_Field.setText(String.valueOf(counter));
}
}
});
mDownButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int counter = Integer.valueOf(mBlock_Id_Field.getText().toString().trim());
// boolean emptyfield = mBlock_Id_Field.getText().toString().equals("");
if(counter <=1 ){
Toast.makeText(BlockIdActivity.this,
R.string.negative_blockid_toast,
Toast.LENGTH_SHORT).show();
counter = 1;
mBlock_Id_Field.setText(String.valueOf(counter));
}else {
counter--;
mBlock_Id_Field.setText(String.valueOf(counter));
}
}
});
}
}
and code for ScanWifi.java
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class ScanWifi extends ActionBarActivity {
private Button mScanWifiButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_block_id);
mScanWifiButton = (Button)findViewById(R.id.ScanWifiButton);
mScanWifiButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getBaseContext(),
R.string.ScanWifi_toast,
Toast.LENGTH_SHORT).show();
}
});
}
}
This is the strings.xml file :
<resources>
<string name="app_name">SnifferTrain</string>
<string name="BlockId">BlockId</string>
<string name="ScanWifi">ScanWifi</string>
<string name="ScanWifi_toast">ScanWifi Button Pressed</string>
<string name="negative_blockid_toast">Block Id Field Cannot Be Less Than 1 or Empty.Setting BlockID To 1</string>
<string name="action_settings">Settings</string>
</resources>
Can someone please explain why ScanWifi_toast does not show when i press ScanWifi Button. I have tried changing the context of the toast to ScanWifi.this or getApplicationContext() but it doesn't seem to work. I don't get any compilation errors. Please help
I think the problem with your string file. Do like other way:
Toast.makeText(ScanWifi.this,getResource().getString(R.string.string.ScanWifi_toast),Toast.LENGTH_SHORT).show();
Your ScanWifi activity code is not run. Hence the click listener is not registered to a button on screen and therefore the toast is not seen.
Since both your activities are using the same content view layout, you should probably move the findViewById() and setOnClickListener() to the main activity.
To launch other activities, use an Intent, e.g.
startActivity(new Intent(context, ActivityName.class));
It should be :
Toast.makeText(getBaseContext(),getResource().getString(R.string.ScanWifi_toast), Toast.LENGTH_SHORT).show();
Because R.string.ScanWifi_toast dont automatically return the String you put in your XML, it only return the id.
you should use getString(R.string.ScanWifi_toast) in place of directly using R.string.ScanWifi_toast
Use this for Toast message
Toast.makeText(getBaseContext(),
getResource().getString(R.string.ScanWifi_toast),
Toast.LENGTH_SHORT).show();
Try this
Toast.makeText(context, context.getString(R.string.ScanWifi_toast), Toast.LENGTH_LONG).show();
You can use this
Toast.makeText(getBaseContext(),"xyz",Toast.LENGTH_SHORT).show();
or
Toast.makeText(Activity.this,string,Toast.LENGTH_SHORT).show();

How to call onclicklistner of animated image android

i am working on android app
in which i have an animated image.
my code is
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth()/2;
left = new TranslateAnimation(0, hight, width, hight);
left1= new TranslateAnimation( 480, 10, 0, 10);
left.setDuration(2000);
left.setAnimationListener(this);
b1 =(ImageView)findViewById( R.id.balloon);
b1.setOnClickListener(this);
b1.startAnimation(left);
#Override
public void onClick(View v) {
Toast.makeText(this, "Clicked", 27).show();
}
using this code i am able to animate ballon or my picture but i the onclick lisnter only works when animation is completed i want onclicklistner should work during animation how to do this.
sorry for bad english
Override onAnimationStart and onAnimationEnd functions in your AnimationListener. Keep a variable to check whether animation is playing when the image clicked.
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity {
private ImageView imageView;
private boolean animationPlaying;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TranslateAnimation animation = new TranslateAnimation( 480, 10, 0, 10);
animation.setDuration(2000);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
animationPlaying = true;
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
animationPlaying = false;
}
});
imageView = (ImageView) findViewById(R.id.imageView1);
imageView.startAnimation(animation);
imageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(animationPlaying) {
Toast.makeText(getBaseContext(), "Click", Toast.LENGTH_SHORT).show();
} else {
Log.d("ANIMATION", "click missed because animation was not playing");
}
}
});
}
}

How to start activity on animation end

This is my first app and i need to start new activity when the animation ends. what do I need to do? My code:
package com.lineage.goddess;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
public class LineageSplashActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
startAnimation();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
private void startAnimation() {
// TODO Auto-generated method stub
TextView logo1= (TextView) findViewById(R.id.TextView1);
Animation fade1= AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo1.startAnimation(fade1);
TextView logo2= (TextView) findViewById(R.id.TextView2);
Animation fade2= AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo2.startAnimation(fade2);
TextView logo3= (TextView) findViewById(R.id.TextView3);
Animation fade3= AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo3.startAnimation(fade3);
TextView logo4= (TextView) findViewById(R.id.TextView4);
Animation fade4= AnimationUtils.loadAnimation(this, R.anim.fade_in2);
logo4.startAnimation(fade4);}
public void onAnimationEnd() {
Intent i = new Intent( LineageSplashActivity.this, LineageMenuActivity.class );
LineageSplashActivity.this.startActivity( i );
;
}
}
Set an AnimationListener to the animation you want to use to start your Activity.
myAnimation.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
Intent i = new Intent( LineageSplashActivity.this, LineageMenuActivity.class );
LineageSplashActivity.this.startActivity( i );
}
}
So, your code will be like this:
package com.lineage.goddess;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
public class LineageSplashActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
startAnimation();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
private void startAnimation() {
// TODO Auto-generated method stub
TextView logo1= (TextView) findViewById(R.id.TextView1);
Animation fade1= AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo1.startAnimation(fade1);
TextView logo2= (TextView) findViewById(R.id.TextView2);
Animation fade2= AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo2.startAnimation(fade2);
TextView logo3= (TextView) findViewById(R.id.TextView3);
Animation fade3= AnimationUtils.loadAnimation(this, R.anim.fade_in);
logo3.startAnimation(fade3);
TextView logo4= (TextView) findViewById(R.id.TextView4);
Animation fade4= AnimationUtils.loadAnimation(this, R.anim.fade_in2);
face4.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
Intent i = new Intent( LineageSplashActivity.this, LineageMenuActivity.class );
LineageSplashActivity.this.startActivity( i );
}
}
logo4.startAnimation(fade4);
}
}
Your code made my eye's bleed, so I fixed it as much as I could:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
public class LineageSplashActivity extends Activity implements AnimationListener {
private static final int NUMBER_OF_ANIMATIONS = 4;
private int animationFinishedCount = 0;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
startAnimations();
}
private void startAnimations() {
Animation fade = AnimationUtils.loadAnimation(this, R.anim.fade_in);
fade.setAnimationListener(this);
findViewById(R.id.TextView1).startAnimation(fade);
findViewById(R.id.TextView2).startAnimation(fade);
findViewById(R.id.TextView3).startAnimation(fade);
findViewById(R.id.TextView4).startAnimation(fade);
}
#Override
public void onAnimationEnd(Animation animation) {
// When all animations have finished - start the next activity
if(++animationFinishedCount == NUMBER_OF_ANIMATIONS){
Intent intent = new Intent( this, LineageMenuActivity.class );
startActivity( intent );
}
}
#Override
public void onAnimationStart(Animation animation) {
// Nothing
}
#Override
public void onAnimationRepeat(Animation animation) {
// Nothing
}
}
And if it's not a mis-type and you actually need a different animation for the 4th textview you can remove the count check and just add the animation listener to that individual animation.

android animation through button

I am creating a dash board application. This is what it looks like:
Now I will explain to you how it is working. When I am clicking the "UP" button the red hand moves up and stay in the 30. The "DOWN" button is used for down the hand from 30 to 0. The BUTTON5 is used for moving the hand from 0 (starting position) to 5. When I am clicking BUTTON10 it means it will move from 5 to 10. BUTTON-5 is used for down the hand from 10 to 5 and BUTTON0 is used for down the hand from 5 to 0.
This is my code:
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class dash1 extends Activity {
ImageView img, img1;
Animation an, an1, an2, an3, an4, an5;
Button bt, bt2, bt3, bt4, bt5, bt6;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img = (ImageView) findViewById(R.id.ImageView01);
final Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.minute);
final int w = bmp.getWidth();
final int h = bmp.getHeight();
final Matrix mat = new Matrix();
mat.postRotate(245);
Bitmap rtd = Bitmap.createBitmap(bmp, 0, 0, w, h, mat, true);
BitmapDrawable bmd = new BitmapDrawable(rtd);
img.setImageDrawable(bmd);
an = AnimationUtils.loadAnimation(this, R.anim.anim);
an1 = AnimationUtils.loadAnimation(this, R.anim.anim1);
an2 = AnimationUtils.loadAnimation(this, R.anim.anim2);
an3 = AnimationUtils.loadAnimation(this, R.anim.anim3);
an4 = AnimationUtils.loadAnimation(this, R.anim.anim4);
an5 = AnimationUtils.loadAnimation(this, R.anim.anim5);
bt = (Button) findViewById(R.id.Button01);
bt2 = (Button) findViewById(R.id.Button02);
bt3 = (Button) findViewById(R.id.Button03);
bt4 = (Button) findViewById(R.id.Button04);
bt5 = (Button) findViewById(R.id.Button05);
bt6 = (Button) findViewById(R.id.Button06);
bt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
an.setFillAfter(true);
img.startAnimation(an);
}
});
bt2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
img.startAnimation(an1);
}
});
bt3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
an2.setFillAfter(true);
img.startAnimation(an2);
}
});
bt4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
an3.setFillAfter(true);
img.startAnimation(an3);
}
});
bt5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
an2.setFillAfter(true);
img.startAnimation(an4);
}
});
bt6.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
an5.setFillAfter(true);
img.startAnimation(an5);
}
});
}
}
Now I want to add a button "+" instead of button5 and button10 (for increment) and "-" for the button-5 and 0. How can I do the increment by a single button. I don't know how to do this. Here for rotating I am using animation. This is the xml code for rotation. Anybody know how to do this means just tell me.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<rotate android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3599"
android:fromDegrees="0"
android:toDegrees="205">
</rotate>
</set>

Categories

Resources