I have translate animation for items on my layout. When first item have animation end start second item and others. It dont work on Sony Ericsson Xperia Arc S LT18i and i dont know why.
This is my code
public class LoginActivity extends FragmentActivity {
private static final String TAG = LoginActivity.class.getSimpleName();
private EditText mUsername;
private EditText mPassword;
private CheckBox mSaveUserNameCheckbox;
private View contentHolder;
private ImageView logoImage;
private LinearLayout logLay, passLay, rememberLay, buttonLay;
private String key_link = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Uri data = getIntent().getData();
Log.i("URI issue", "uri="+data);
if (data != null) {
String scheme = data.getScheme();
List<String> params = data.getPathSegments();
if (params.get(0) != null && params.get(1) != null) {
Log.i("PARSING", "data=" + data + " shame=" + scheme + " host="
+ data.getHost() + " ::: param 0=" + params.get(0)
+ " param 1=" + params.get(1));
if (scheme.equalsIgnoreCase("https")) {
String host = data.getHost();
if (host.equalsIgnoreCase("jira.hiqo-solutions.us")) {
if (params.get(0).equalsIgnoreCase("browse"))
key_link = params.get(1);
} else {
Toast.makeText(this, "Incorrect link!",
Toast.LENGTH_LONG).show();
}
}
}
}
contentHolder = findViewById(R.id.content_holder);
logoImage = (ImageView) findViewById(R.id.imageLogo);
logoImage.setVisibility(View.GONE);
logLay = (LinearLayout) findViewById(R.id.usernameLay);
logLay.setVisibility(View.GONE);
passLay = (LinearLayout) findViewById(R.id.passLay);
passLay.setVisibility(View.GONE);
rememberLay = (LinearLayout) findViewById(R.id.rememberLay);
rememberLay.setVisibility(View.GONE);
buttonLay = (LinearLayout) findViewById(R.id.buttonLay);
buttonLay.setVisibility(View.GONE);
contentHolder.setVisibility(View.GONE);
if (CredentialsPrefs.mRememberMe.get() && checkConnection()) {
setMode();
doLogin(CredentialsPrefs.mLogin.get(),
CredentialsPrefs.mPassword.get());
} else {
if (!checkConnection()) {
Toast.makeText(this, "No Internet Connections!",
Toast.LENGTH_LONG).show();
}
contentHolder.setVisibility(View.VISIBLE);
CredentialsPrefs.mLogined.put(false);
final Animation logoAnim = AnimationUtils.loadAnimation(this,
R.anim.logo_animation);
final Animation loginAnim = AnimationUtils.loadAnimation(this,
R.anim.items_animation);
final Animation passAnim = AnimationUtils.loadAnimation(this,
R.anim.items_animation);
final Animation rememberAnim = AnimationUtils.loadAnimation(this,
R.anim.items_animation);
final Animation buttonAnim = AnimationUtils.loadAnimation(this,
R.anim.items_animation);
loginAnim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
passLay.setVisibility(View.VISIBLE);
passLay.startAnimation(passAnim);
}
});
passAnim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
rememberLay.setVisibility(View.VISIBLE);
rememberLay.startAnimation(rememberAnim);
}
});
rememberAnim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
buttonLay.setVisibility(View.VISIBLE);
buttonLay.startAnimation(buttonAnim);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
}
});
buttonAnim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
initializateControls();
}
});
logoAnim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
logLay.setVisibility(View.VISIBLE);
logLay.startAnimation(loginAnim);
}
});
logoImage.setVisibility(View.VISIBLE);
logoImage.startAnimation(logoAnim);
}
What it can be?
Related
I am animating a loader on start up. How can I work around it so that instead of using ontouch listener to stop the timer, I use a time of say like 3 seconds? Here is my code:
private void showdiag() {
loader = findViewById(R.id.loader);
logo= loader.findViewById(R.id.logo);
logo.setAnimation(AnimationUtils.loadAnimation(this,R.anim.rotate));
loader.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
loader.setVisibility(View.GONE);
}
});
}
You can use View.postDelayed() to run some action after a set delay:
private void showdiag() {
loader = findViewById(R.id.loader);
logo = loader.findViewById(R.id.logo);
logo.setAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate));
loader.postDelayed(new Runnable() {
#Override
public void run() {
loader.setVisibility(View.GONE);
}
}, 3000);
}
logo.getAnimation().setAnimationListener(new Animation.AnimationListener() {
#Override public void onAnimationStart(Animation animation) {
}
#Override public void onAnimationEnd(Animation animation) {
loader.setVisibility(View.GONE);
}
#Override public void onAnimationRepeat(Animation animation) {
}
});
Please try following code.
logo.getAnimation().setAnimationListener(new Animation.AnimationListener() {
#Override public void onAnimationStart(Animation animation) {
}
#Override public void onAnimationEnd(Animation animation) {
loader.postDelayed(new Runnable() {
#Override
public void run() {
loader.setVisibility(View.GONE);
}
}, 3000);
}
#Override public void onAnimationRepeat(Animation animation) {
}
});
i want to make a toss app ..it is spining all time and will not stop to show a head or tail..i want that when i click on the coin then it should spin for 2 3 seconds and then stops to show head or tail at random selection...but it is continuously spinning.
Here is the code...
public class MainActivity extends AppCompatActivity {
ImageView Coin;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Coin=(ImageView) findViewById(R.id.ImgViewcoin);
Coin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Animation animation = new AlphaAnimation(1, 0);
animation.setInterpolator(new DecelerateInterpolator());
animation.setDuration(3000);
Coin.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
final int[] photos = {R.drawable.heads, R.drawable.tails};
final ImageView image = (ImageView) findViewById(R.id.ImgViewcoin);
final Random ran = new Random();
int i = ran.nextInt(photos.length);
image.setImageResource(photos[i]);
image.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int k = ran.nextInt(photos.length);
image.setImageResource(photos[k]);
}
}
);
}
#Override
public void onAnimationEnd(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
Coin.startAnimation(animation);
}
});
}
}
Remove the findviewbyid from onclick and use with Coin instance you have.
I have a custom pager that uses two animations
final Animation fadeOut = AnimationUtils.loadAnimation(mContext, R.anim.fade_out);
final Animation fadeIn = AnimationUtils.loadAnimation(mContext, R.anim.fade_in);
For some reason, the animations are not starting up. For example, I'm logging
Log.v("TAG", "L1 start animation"); //prints "L1 start animation"
But I'm not logging anything in onAnimationEnd
Log.v("TAG", "L1 animation end"); //nothing is printing out
Here is setAnimation() method of CustomPager class
public void setAnimation(){
final Animation fadeOut = AnimationUtils.loadAnimation(mContext, R.anim.fade_out);
final Animation fadeIn = AnimationUtils.loadAnimation(mContext, R.anim.fade_in);
l1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.v("TAG", "L1 clicked");
if (clicked) {
//do nothing
} else {
clicked = true;
fadeOut.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
Log.v("TAG", "L1 animation start");
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
Log.v("TAG", "L1 animation end");
l1.setVisibility(View.GONE);
l2.bringToFront();
clicked = false;
}
});
Log.v("TAG", "L1 start animation");
l1.startAnimation(fadeOut);
l2.setVisibility(View.VISIBLE);
l2.startAnimation(fadeIn);
}
}
});
//etc
}
Here is CustomPager class
public class CustomPager extends PagerAdapter {
private Context mContext;
private View l1;
private View l2;
private LayoutInflater inflater;
private ViewGroup layout;
private Bitmap pic;
private Bitmap pic_blurred;
private boolean clicked = false;
public CustomPager(Context context) {
this.mContext = context;
}
#Override
public Object instantiateItem(ViewGroup collection, int position) {
inflater = LayoutInflater.from(mContext);
layout = (ViewGroup) inflater.inflate(R.layout.pager_play_panel, collection, false);
collection.addView(layout);
l1 = layout.findViewById(R.id.l1);
l2 = layout.findViewById(R.id.l2);
pic = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.pic);
picture_blurred = blur(pic, 1, 100);
BitmapDrawable bkg1 = new BitmapDrawable(pic);
l1.setBackgroundDrawable(bkg1);
BitmapDrawable bkg2 = new BitmapDrawable(picture_blurred);
l2.setBackgroundDrawable(bkg2);
setAnimation();
return layout;
}
public void setAnimation(){
final Animation fadeOut = AnimationUtils.loadAnimation(mContext, R.anim.fade_out);
final Animation fadeIn = AnimationUtils.loadAnimation(mContext, R.anim.fade_in);
l1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.v("TAG", "L1 clicked");
if (clicked) {
//do nothing
} else {
clicked = true;
fadeOut.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
Log.v("TAG", "L1 animation start");
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
Log.v("TAG", "L1 animation end");
l1.setVisibility(View.GONE);
l2.bringToFront();
clicked = false;
}
});
Log.v("TAG", "L1 start animation");
l1.startAnimation(fadeOut);
l2.setVisibility(View.VISIBLE);
l2.startAnimation(fadeIn);
}
}
});
l2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.v("TAG", "L2 clicked");
if (clicked) {
//do nothing
} else {
clicked = true;
fadeOut.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
l2.setVisibility(View.GONE);
l1.bringToFront();
Log.v("TAG", "L2 visibility set to gone");
clicked = false;
}
});
l2.startAnimation(fadeOut);
l1.setVisibility(View.VISIBLE);
l1.startAnimation(fadeIn);
}
}
});
}
//Etc.
}
Looks like the problem was I had to change the scope of my view variables
public void setAnimation(View l1, View l2){
//etc
}
Rather than using them globally
public void setAnimation(){
//etc
}
I want to make three text views fade in one after another. I am trying to do this with start animation after finishing first and so on. But it not works for me. Please help
text_1.setVisibility(View.INVISIBLE);
text_2.setVisibility(View.INVISIBLE);
text_3.setVisibility(View.INVISIBLE);
private void fadingAnimation() {
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
fadeIn.setDuration(2000);
AnimationSet animation1 = new AnimationSet(false); //change to false
final AnimationSet animation2 = new AnimationSet(false); //change to false
final AnimationSet animation3 = new AnimationSet(false); //change to false
animation1.addAnimation(fadeIn);
animation1.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationStart(Animation arg0) {
}
#Override
public void onAnimationRepeat(Animation arg0) {
}
#Override
public void onAnimationEnd(Animation arg0) {
text_1.setVisibility(View.VISIBLE);
text_2.startAnimation(animation2);
}
});
text_1.startAnimation(animation1);
}
Change your menthod to
private void fadingAnimation() {
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
fadeIn.setDuration(2000);
AnimationSet animation1 = new AnimationSet(false); //change to false
final AnimationSet animation2 = new AnimationSet(false); //change to false
final AnimationSet animation3 = new AnimationSet(false); //change to false
animation1.addAnimation(fadeIn);
animation1.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationStart(Animation arg0) {
}
#Override
public void onAnimationRepeat(Animation arg0) {
}
#Override
public void onAnimationEnd(Animation arg0) {
text_1.setVisibility(View.VISIBLE);
text_2.startAnimation(animation2);
}
});
animation2.addAnimation(fadeIn);
animation2.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationStart(Animation arg0) {
}
#Override
public void onAnimationRepeat(Animation arg0) {
}
#Override
public void onAnimationEnd(Animation arg0) {
text_2.setVisibility(View.VISIBLE);
text_3.startAnimation(animation3);
}
});
animation3.addAnimation(fadeIn);
animation3.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationStart(Animation arg0) {
}
#Override
public void onAnimationRepeat(Animation arg0) {
}
#Override
public void onAnimationEnd(Animation arg0) {
text_3.setVisibility(View.VISIBLE);
}
});
text_1.startAnimation(animation1);
}
I am trying to Hide/Show a TableLayout on button click but the animation listener is not working here is the code i am trying
Slide_down = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_down);
Slide_up = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_up);
searchArea = (TableLayout) findViewById(R.id.TableLayout1);
SearchButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (check_tableView == 0) {
Slide_up.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
searchArea.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationEnd(Animation animation) {
searchArea.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
check_tableView = 1;
} else {
Slide_down.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
searchArea.setVisibility(View.GONE);
}
#Override
public void onAnimationEnd(Animation animation) {
searchArea.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
check_tableView = 0;
}
}
});
//just start animation
searchArea = (TableLayout) findViewById(R.id.TableLayout1);
SearchButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (check_tableView == 0) {
searchArea.startAnimation(Slide_up);
}
});
You just set animation listener outside of onClickListener. No need of setting each time View is clicked. Also make sure that you are calling searchArea.startAnimation(Slide_up) and searchArea.startAnimation(Slide_down) method. Call start animation method inside onClickListener.