user989501
user989501

Reputation: 1843

Simple animation conflict in android

I've implemented a custom view. This view is really simple, just have 2 states (with and without border), and they switch with ontouch event (with border when press down, without when press up).

This is going without problems. The problem arises when I want to show a sequence to user (so, disabling touchevents, and setting manually changes on view state).

I've 4 views of that type in my layout, and all I want is to switch state of that views in an order to be visible to user.

MyView v1 = (MyView)findViewById(...)
MyView v2 = (MyView)findViewById(...)
MyView v3 = (MyView)findViewById(...)
MyView v4 = (MyView)findViewById(...)

v1.switchMode()
v2.switchMode()
v3.switchMode()
v4.switchMode()

This switch should hold some time (1 second) to be visible for user. Mode is implemented through a boolean var. My implementation is the following:

public void switchMode()
  this.mode = false;
  this.invalidate();
  try {
Thread.sleep(1000);
  } catch (InterruptedException e) {
e.printStackTrace();
  }
  this.mode = true;
  this.invalidate();
}

It seems that my sleep is a whole thread sleep, so my view does not redraw, and I hold 4 seconds without any response and change on view.

Any clue about how to implement this simple switch of states?

Thank you in advance

Upvotes: 1

Views: 328

Answers (1)

user989501
user989501

Reputation: 1843

I found a good method to solve that problem. CountDownTimer acts as I desired: it provides an interface to set a timer on arbitrary actions, and a tick controller to introduce some variability in that actions (for my case, I could set 2 ticks over all time, to change the mode over desired time).

Upvotes: 1

Related Questions