if (!selectedIndices.containsKey(i)) {
// start fading in
// System.out.println("Fade in on index " + i);
if (!fadeCanceled) {
Timeline selectionTimeline = selectionTimelineTracker
.getTimeline(
i,
new TimelineTracker.TimelineCreator() {
@Override
public Timeline create() {
Timeline result = createSingleRowSelectionTimeline(rowIndex);
return result;
}
});
selectionTimeline.play();
initiatedTimelines.put(selectionTimeline,
rowIndex);
if (initiatedTimelines.size() > 25) {
for (Map.Entry<Timeline, Integer> entry : initiatedTimelines
.entrySet()) {
entry.getKey().cancel();
int rIndex = entry.getValue();
selectedIndices.put(rIndex, list
.getModel()
.getElementAt(rIndex));
}
initiatedTimelines.clear();
fadeCanceled = true;
}
} else {
selectedIndices.put(i, list.getModel()
.getElementAt(i));
}
}
} else {
// check if was selected before and still points to the
// same element
Timeline existing = selectionTimelineTracker
.getTimeline(i, null);
if (existing != null) {
if (!fadeCanceled) {
existing.playReverse();
initiatedTimelines.put(existing, rowIndex);
if (initiatedTimelines.size() > 25) {
for (Map.Entry<Timeline, Integer> entry : initiatedTimelines
.entrySet()) {
entry.getKey().cancel();
int rIndex = entry.getValue();
selectedIndices.remove(rIndex);
}
initiatedTimelines.clear();
fadeCanceled = true;
}
} else {
selectedIndices.remove(i);
}
} else {
if (selectedIndices.containsKey(i)) {
if (selectedIndices.get(i) == list.getModel()
.getElementAt(i)) {
// start fading out
// System.out
// .println("Fade out on index " + i);
if (!fadeCanceled) {
Timeline selectionTimeline = selectionTimelineTracker
.getTimeline(
i,
new TimelineTracker.TimelineCreator() {
@Override
public Timeline create() {
Timeline result = createSingleRowSelectionTimeline(rowIndex);
return result;
}
});
selectionTimeline.playReverse();