CardView responding to click events even when hidden - android

I have a form with a clickeable cardview. Depending on some of the options, I hide the CardView setting its visibility to GONE.
Other form controls below the card come up to occupy the space the cardview was taking. However when clicking in the area the Cardview used to be, the onclick event is fired for the cardview.
I even put a check to verify the visibility before the click action, but the cardview repots VISIBLE (even though its not being shown). I use Butterknife for the onClick event:
#OnClick(R.id.logo_cardview)
public void onLogoClick(){
if (mLogoCardView.getVisibility() == VISIBLE) {
Snackbar.make(this, "Logo clicked", Snackbar.LENGTH_SHORT).show();
showSettingsDialog();
}
}
I hide the Cardview using an animation:
mAlphaAnimation = new AlphaAnimation(1.0f, 0.0f);
mAlphaAnimation.setDuration(200);
mAlphaAnimation.setFillAfter(true);
mHideListener = new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
mMatchInfo.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
};

Related

How to clear Animation Listeners set by NineOldAndroids?

I am trying to have a view animated in my app and am using NineOldAndroid for animations.
The desired effect is to fade the view out and then set it's visibility to gone so that it doesn't get clicked while invisible. Here is How I do it.
ViewPropertyAnimator.animate(view).alpha(0).setListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
}
#Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(View.GONE);
}
#Override
public void onAnimationCancel(Animator animation) {
}
#Override
public void onAnimationRepeat(Animator animation) {
}
});
The problem here is that the listener above sticks with the view and when I try to fade it in again the listener gets called again resulting the view to be GONE upon appearing.
ViewPropertyAnimator.animate(enterGallery).alpha(1);
How can I clear the listener after the view visibility is set to GONE in the first piece of code?
I found the solution and it would be to pass null as listener when making the view VISIBLE.
ViewPropertyAnimator.animate(view).alpha(1).setListener(null);

Disable list item while animating

So when I click a list item in my ListView it gets animated. The problem is that when it's animating I can still click it and this is undesirable. I'm using nineOldAndroids and to disable the ListItem I do:
set.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animator) {
v.setClickable(false);
v.setEnabled(false);
}
#Override
public void onAnimationEnd(Animator animator) {
v.setClickable(true);
v.setEnabled(true);
}
#Override
public void onAnimationCancel(Animator animator) {
}
#Override
public void onAnimationRepeat(Animator animator) {
}
});
setClickable behaves strangely: it does let me click the list item for a brief time after the animation starts and after the animation ends it won't let me click it anymore (even though I set it to true). And setEnabled doesn't work at all.
How can I disable a list Item while an animation is running?
make the adapter isEnabled(int position) method return false while the animation on that item is going on.
add this to your adapter
Set<Integer> disabledItems;
private void setRowEnabled(int position,boolean enabled){
if(enabled){
disabledItems.remove(position);
}else{
disabledItems.add(position);
}
}
#Override
public boolean isEnabled(int position) {
return !disabledItems.contains(position);
}
And call the setRowEnabled from the onAnimationStart onAnimationEnd of your Animation

how to clear aftereffects of animation

I have 2 views that are being animated by sliding in and out of the screen simultaniously
this is the code for it: How to animate a slide in notification view that pushes the content view down
However, when the animation slides in, i must clear the animation, in order for the click events to work properly, otherwise they are also translated (which is not what i want)
What do i need to put in onAnimationEnd in the listener in order to clear the animation and have the view remain the way it looks after it has been animated
this is my current code:
greenViewSlideIn(1500, 0, new AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
greenView.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animator animation) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(blueView.getWidth(), blueView.getHeight());
layoutParams.setMargins(blueView.getLeft(), blueView.getTop() - greenViewHeight, blueView.getRight(), blueView.getBottom());
blueView.setLayoutParams(layoutParams);
greenView.clearAnimation();
// blueView.clearAnimation();
}
#Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
Two things you can do:
Make sure the setFillAfter flag on the animation is set to false. Then there's no need to an AnimationListener
Once the animation ends, call view.setAnimation(null);
Hope this helps :)

Wait for animation end

I've an activity that loads the resources and shows the message "Please wait, loading", and when all resources are loader, the textview changes to "Ready" and change the views of the activity. The problem is that I want to wait for the animation end, but the views are removed even before they start. How can I wait for that?
tview1.startAnimation(desvanecer); tview2.startAnimation(desvanecer);
tview1.setText(R.string.ready);
tview2.setText(R.string.launcher_continue);
tview1.startAnimation(aparecer);
tview2.startAnimation(aparecer);
layout = (RelativeLayout) findViewById(R.id.launcher_layout);
screen = new Screen(context);
thread = new Thread(screen);
layout.removeAllViews();
layout.addView(screen);
thread.start();
You can perform your removals at the end of the animation by using an animation listener and doing them onAnimationEnd
desvanecer.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
//REMOVAL OR OTHER CODE HERE
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
What you need is an AnimationListener and implement the onAnimationEnd method. But have a look at my comment and the doubts I have about your code.

Doing animation on "hidden" Activity

I have been working on trying to get an Activity to not show until data has been selected and is ready for display: Prevent screen display until after fetching data
Finally got it to work with the aid of themes.
Now I have another problem.
I need to animate the transition from one Activity to the next.
I know how to use overridePendingTransition but this won't work here since I am already in the target Activity when I want to do the animation.
The only reason I can see the other one is because the current one is transparent.
I have no problem sliding in the new one:
View view = getLayoutInflater().inflate(R.layout.content_screen, null);
view.startAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_right));
setContentView(view);
However, I can't think of any way to get the old one to slide out.
Any ideas anyone?
Create a "slide out left" animation. Then adjust your animation for the new view, so when the animation starts, you apply and start the other animation to the other view. E.g.,
Animation animation = AnimationUtils.loadAnimation(context,
R.anim.slide_in_right);
animation.setDuration(TIME);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO - Set and start other animation here
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
}
});
view.startAnimation(animation);
[Edit]
// First, define and infalte the view that will be incoming
View upcomingView = inflater.inflate(...);
// Next, we'll set the animation up
Animation animation = AnimationUtils.loadAnimation(context,
R.anim.slide_in_right);
animation.setDuration(TIME);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
Animation outAnimation = AnimationUtils.loadAnimation(context,
R.anim.slide_out_left);
upcomingView.startAnimation(outAnimation);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
}
});
currentView.startAnimation(animation); // This will start the animation defined above, which will also set and start the animation for the incoming object

Categories

Resources