Example usage for java.util ArrayList clear

List of usage examples for java.util ArrayList clear

Introduction

In this page you can find the example usage for java.util ArrayList clear.

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this list.

Usage

From source file:com.panahit.telegramma.support.widget.DefaultItemAnimator.java

@Override
public void runPendingAnimations() {
    boolean removalsPending = !mPendingRemovals.isEmpty();
    boolean movesPending = !mPendingMoves.isEmpty();
    boolean changesPending = !mPendingChanges.isEmpty();
    boolean additionsPending = !mPendingAdditions.isEmpty();
    if (!removalsPending && !movesPending && !additionsPending && !changesPending) {
        // nothing to animate
        return;/*from  ww  w  .  jav  a  2s .  com*/
    }
    // First, remove stuff
    for (RecyclerView.ViewHolder holder : mPendingRemovals) {
        animateRemoveImpl(holder);
    }
    mPendingRemovals.clear();
    // Next, move stuff
    if (movesPending) {
        final ArrayList<MoveInfo> moves = new ArrayList<MoveInfo>();
        moves.addAll(mPendingMoves);
        mMovesList.add(moves);
        mPendingMoves.clear();
        Runnable mover = new Runnable() {
            @Override
            public void run() {
                for (MoveInfo moveInfo : moves) {
                    animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX,
                            moveInfo.toY);
                }
                moves.clear();
                mMovesList.remove(moves);
            }
        };
        if (removalsPending) {
            View view = moves.get(0).holder.itemView;
            ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
        } else {
            mover.run();
        }
    }
    // Next, change stuff, to run in parallel with move animations
    if (changesPending) {
        final ArrayList<ChangeInfo> changes = new ArrayList<ChangeInfo>();
        changes.addAll(mPendingChanges);
        mChangesList.add(changes);
        mPendingChanges.clear();
        Runnable changer = new Runnable() {
            @Override
            public void run() {
                for (ChangeInfo change : changes) {
                    animateChangeImpl(change);
                }
                changes.clear();
                mChangesList.remove(changes);
            }
        };
        if (removalsPending) {
            RecyclerView.ViewHolder holder = changes.get(0).oldHolder;
            ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
        } else {
            changer.run();
        }
    }
    // Next, add stuff
    if (additionsPending) {
        final ArrayList<RecyclerView.ViewHolder> additions = new ArrayList<RecyclerView.ViewHolder>();
        additions.addAll(mPendingAdditions);
        mAdditionsList.add(additions);
        mPendingAdditions.clear();
        Runnable adder = new Runnable() {
            public void run() {
                for (RecyclerView.ViewHolder holder : additions) {
                    animateAddImpl(holder);
                }
                additions.clear();
                mAdditionsList.remove(additions);
            }
        };
        if (removalsPending || movesPending || changesPending) {
            long removeDuration = removalsPending ? getRemoveDuration() : 0;
            long moveDuration = movesPending ? getMoveDuration() : 0;
            long changeDuration = changesPending ? getChangeDuration() : 0;
            long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
            View view = additions.get(0).itemView;
            ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
        } else {
            adder.run();
        }
    }
}

From source file:net.simonvt.cathode.widget.ScalingItemAnimator.java

@Override
public void runPendingAnimations() {
    boolean removalsPending = !pendingRemovals.isEmpty();
    boolean movesPending = !pendingMoves.isEmpty();
    boolean changesPending = !pendingChanges.isEmpty();
    boolean additionsPending = !pendingAdditions.isEmpty();
    if (!removalsPending && !movesPending && !additionsPending && !changesPending) {
        // nothing to animate
        return;/*from   w  ww. j a  v  a2s  . co m*/
    }
    // First, remove stuff
    for (ViewHolder holder : pendingRemovals) {
        animateRemoveImpl(holder);
    }
    pendingRemovals.clear();
    // Next, move stuff
    if (movesPending) {
        final ArrayList<MoveInfo> moves = new ArrayList<MoveInfo>();
        moves.addAll(pendingMoves);
        movesList.add(moves);
        pendingMoves.clear();
        Runnable mover = new Runnable() {
            @Override
            public void run() {
                for (MoveInfo moveInfo : moves) {
                    animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX,
                            moveInfo.toY);
                }
                moves.clear();
                movesList.remove(moves);
            }
        };
        if (removalsPending) {
            View view = moves.get(0).holder.itemView;
            ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
        } else {
            mover.run();
        }
    }
    // Next, change stuff, to run in parallel with move animations
    if (changesPending) {
        final ArrayList<ChangeInfo> changes = new ArrayList<ChangeInfo>();
        changes.addAll(pendingChanges);
        changesList.add(changes);
        pendingChanges.clear();
        Runnable changer = new Runnable() {
            @Override
            public void run() {
                for (ChangeInfo change : changes) {
                    animateChangeImpl(change);
                }
                changes.clear();
                changesList.remove(changes);
            }
        };
        if (removalsPending) {
            ViewHolder holder = changes.get(0).oldHolder;
            ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
        } else {
            changer.run();
        }
    }
    // Next, add stuff
    if (additionsPending) {
        final ArrayList<ViewHolder> additions = new ArrayList<ViewHolder>();
        additions.addAll(pendingAdditions);
        additionsList.add(additions);
        pendingAdditions.clear();
        Runnable adder = new Runnable() {
            public void run() {
                for (ViewHolder holder : additions) {
                    animateAddImpl(holder);
                }
                additions.clear();
                additionsList.remove(additions);
            }
        };
        if (removalsPending || movesPending || changesPending) {
            long removeDuration = removalsPending ? getRemoveDuration() : 0;
            long moveDuration = movesPending ? getMoveDuration() : 0;
            long changeDuration = changesPending ? getChangeDuration() : 0;
            long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
            View view = additions.get(0).itemView;
            ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
        } else {
            adder.run();
        }
    }
}

From source file:com.eleybourn.bookcatalogue.utils.SimpleTaskQueueProgressFragment.java

/**
 * If we have an Activity, deliver the current queue.
 */// w ww  .j a  v a  2s.com
private void deliverMessages() {
    Activity a = getActivity();
    if (a != null) {
        ArrayList<TaskMessage> toDeliver = new ArrayList<TaskMessage>();
        int count = 0;
        do {
            synchronized (mTaskMessages) {
                toDeliver.addAll(mTaskMessages);
                mTaskMessages.clear();
            }
            count = toDeliver.size();
            for (TaskMessage m : toDeliver) {
                try {
                    m.deliver(a);
                } catch (Exception e) {
                    Logger.logError(e);
                }
            }
            toDeliver.clear();
        } while (count > 0);
    }
}

From source file:gdsc.smlm.ij.plugins.ResultsManager.java

public void run(String arg) {
    if (arg != null && arg.equals("clear")) {
        long memorySize = MemoryPeakResults.estimateMemorySize();
        if (memorySize > 0) {
            String memory = MemoryPeakResults.memorySizeString(memorySize);
            int size = MemoryPeakResults.countMemorySize();

            GenericDialog gd = new GenericDialog(TITLE);
            gd.addMessage(String.format("Do you want to remove all %d result%s from memory (%s)", size,
                    (size > 1) ? "s" : "", memory));
            gd.enableYesNoCancel();/*from w  ww . ja va 2 s.  c om*/
            gd.showDialog();
            if (!gd.wasOKed())
                return;

            IJ.log(String.format("Cleared %d result%s (%s)", size, (size > 1) ? "s" : "", memory));
            MemoryPeakResults.clearMemory();
            SummariseResults.clearSummaryTable();
        }
        return;
    }

    if (!showDialog())
        return;

    MemoryPeakResults results = loadResults(inputOption);

    if (results == null || results.size() == 0) {
        IJ.error(TITLE, "No results could be loaded");
        IJ.showStatus("");
        return;
    }

    results = cropToRoi(results);
    if (results.size() == 0) {
        IJ.error(TITLE, "No results within the crop region");
        return;
    }

    if (resultsSettings.resultsInMemory && fileInput)
        MemoryPeakResults.addResults(results);

    IJ.showStatus("Processing outputs ...");

    Rectangle bounds = results.getBounds(true);
    boolean showDeviations = resultsSettings.showDeviations && canShowDeviations(results);
    boolean showEndFrame = canShowEndFrame(results);
    boolean showId = canShowId(results);

    // Display the configured output
    PeakResultsList output = new PeakResultsList();

    output.copySettings(results);
    //String title = results.getSource();
    //if (title == null || title.length() == 0)
    //   output.setSource(TITLE);

    addTableResults(results, output, showDeviations, showEndFrame);
    addImageResults(output, results.getName(), bounds, results.getNmPerPixel(), results.getGain());
    addFileResults(output, showDeviations, showEndFrame, showId);

    output.begin();

    // Process in batches to provide progress
    int batchSize = 100;
    ArrayList<PeakResult> batch = new ArrayList<PeakResult>(batchSize);
    List<PeakResult> list = results.getResults();
    int size = 0;
    for (; size < list.size(); size += batchSize) {
        IJ.showProgress(size, list.size());
        for (int j = size; j < FastMath.min(list.size(), size + batchSize); j++)
            batch.add(list.get(j));
        output.addAll(batch);
        batch.clear();
        if (isInterrupted())
            break;
    }
    IJ.showProgress(1);
    output.end();

    if (size > results.size())
        size = results.size();

    IJ.showStatus(String.format("Processed %d result%s", size, (size > 1) ? "s" : ""));
}

From source file:cn.ismartv.tvrecyclerview.widget.DefaultItemAnimator.java

@Override
public void runPendingAnimations() {
    boolean removalsPending = !mPendingRemovals.isEmpty();
    boolean movesPending = !mPendingMoves.isEmpty();
    boolean changesPending = !mPendingChanges.isEmpty();
    boolean additionsPending = !mPendingAdditions.isEmpty();
    if (!removalsPending && !movesPending && !additionsPending && !changesPending) {
        // nothing to animate
        return;/*from   w w  w  . j av  a 2s.  com*/
    }
    // First, remove stuff
    for (ViewHolder holder : mPendingRemovals) {
        animateRemoveImpl(holder);
    }
    mPendingRemovals.clear();
    // Next, move stuff
    if (movesPending) {
        final ArrayList<MoveInfo> moves = new ArrayList<>();
        moves.addAll(mPendingMoves);
        mMovesList.add(moves);
        mPendingMoves.clear();
        Runnable mover = new Runnable() {
            @Override
            public void run() {
                for (MoveInfo moveInfo : moves) {
                    animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX,
                            moveInfo.toY);
                }
                moves.clear();
                mMovesList.remove(moves);
            }
        };
        if (removalsPending) {
            View view = moves.get(0).holder.itemView;
            ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
        } else {
            mover.run();
        }
    }
    // Next, change stuff, to run in parallel with move animations
    if (changesPending) {
        final ArrayList<ChangeInfo> changes = new ArrayList<>();
        changes.addAll(mPendingChanges);
        mChangesList.add(changes);
        mPendingChanges.clear();
        Runnable changer = new Runnable() {
            @Override
            public void run() {
                for (ChangeInfo change : changes) {
                    animateChangeImpl(change);
                }
                changes.clear();
                mChangesList.remove(changes);
            }
        };
        if (removalsPending) {
            ViewHolder holder = changes.get(0).oldHolder;
            ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
        } else {
            changer.run();
        }
    }
    // Next, add stuff
    if (additionsPending) {
        final ArrayList<ViewHolder> additions = new ArrayList<>();
        additions.addAll(mPendingAdditions);
        mAdditionsList.add(additions);
        mPendingAdditions.clear();
        Runnable adder = new Runnable() {
            @Override
            public void run() {
                for (ViewHolder holder : additions) {
                    animateAddImpl(holder);
                }
                additions.clear();
                mAdditionsList.remove(additions);
            }
        };
        if (removalsPending || movesPending || changesPending) {
            long removeDuration = removalsPending ? getRemoveDuration() : 0;
            long moveDuration = movesPending ? getMoveDuration() : 0;
            long changeDuration = changesPending ? getChangeDuration() : 0;
            long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
            View view = additions.get(0).itemView;
            ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
        } else {
            adder.run();
        }
    }
}

From source file:com.farmerbb.notepad.fragment.NoteListFragment.java

private void listNotes() {
    // Get array of file names
    String[] listOfFiles = getActivity().getFilesDir().list();
    ArrayList<String> listOfNotes = new ArrayList<>();

    // Get number of files
    int numOfNotes = listOfFiles.length;

    // Remove any files from the list that aren't notes
    for (String listOfFile : listOfFiles) {
        if (NumberUtils.isCreatable(listOfFile))
            listOfNotes.add(listOfFile);
        else//  w ww.  ja  va  2s .co  m
            numOfNotes--;
    }

    // Create arrays of note lists
    String[] listOfNotesByDate = new String[numOfNotes];
    String[] listOfNotesByName = new String[numOfNotes];

    NoteListItem[] listOfTitlesByDate = new NoteListItem[numOfNotes];
    NoteListItem[] listOfTitlesByName = new NoteListItem[numOfNotes];

    ArrayList<NoteListItem> list = new ArrayList<>(numOfNotes);

    for (int i = 0; i < numOfNotes; i++) {
        listOfNotesByDate[i] = listOfNotes.get(i);
    }

    // If sort-by is "by date", sort in reverse order
    if (sortBy.startsWith("date")) {
        Arrays.sort(listOfNotesByDate, Collections.reverseOrder());
        if (sortBy.endsWith("reversed"))
            ArrayUtils.reverse(listOfNotesByDate);
    }

    // Get array of first lines of each note
    for (int i = 0; i < numOfNotes; i++) {
        try {
            String title = listener.loadNoteTitle(listOfNotesByDate[i]);
            String date = listener.loadNoteDate(listOfNotesByDate[i]);
            listOfTitlesByDate[i] = new NoteListItem(title, date);
        } catch (IOException e) {
            showToast(R.string.error_loading_list);
        }
    }

    // If sort-by is "by name", sort alphabetically
    if (sortBy.startsWith("name")) {
        // Copy titles array
        System.arraycopy(listOfTitlesByDate, 0, listOfTitlesByName, 0, numOfNotes);

        // Sort titles
        Arrays.sort(listOfTitlesByName, NoteListItem.NoteComparatorTitle);
        if (sortBy.endsWith("reversed"))
            ArrayUtils.reverse(listOfTitlesByName);

        // Initialize notes array
        for (int i = 0; i < numOfNotes; i++)
            listOfNotesByName[i] = "new";

        // Copy filenames array with new sort order of titles and nullify date arrays
        for (int i = 0; i < numOfNotes; i++) {
            for (int j = 0; j < numOfNotes; j++) {
                if (listOfTitlesByName[i].getNote().equals(listOfTitlesByDate[j].getNote())
                        && listOfNotesByName[i].equals("new")) {
                    listOfNotesByName[i] = listOfNotesByDate[j];
                    listOfNotesByDate[j] = "";
                    listOfTitlesByDate[j] = new NoteListItem("", "");
                }
            }
        }

        // Populate ArrayList with notes, showing name as first line of the notes
        list.addAll(Arrays.asList(listOfTitlesByName));
    } else if (sortBy.startsWith("date"))
        list.addAll(Arrays.asList(listOfTitlesByDate));

    // Create the custom adapters to bind the array to the ListView
    final NoteListDateAdapter dateAdapter = new NoteListDateAdapter(getActivity(), list);
    final NoteListAdapter adapter = new NoteListAdapter(getActivity(), list);

    // Display the ListView
    if (showDate)
        listView.setAdapter(dateAdapter);
    else
        listView.setAdapter(adapter);

    listView.setSelection(ScrollPositions.getInstance().getPosition());

    // Finalize arrays to prepare for handling clicked items
    final String[] finalListByDate = listOfNotesByDate;
    final String[] finalListByName = listOfNotesByName;

    // Make ListView handle clicked items
    listView.setClickable(true);
    listView.setOnItemClickListener((arg0, arg1, position, arg3) -> {
        ScrollPositions.getInstance().setPosition(listView.getFirstVisiblePosition());

        if (sortBy.startsWith("date")) {
            if (directEdit)
                listener.editNote(finalListByDate[position]);
            else
                listener.viewNote(finalListByDate[position]);
        } else if (sortBy.startsWith("name")) {
            if (directEdit)
                listener.editNote(finalListByName[position]);
            else
                listener.viewNote(finalListByName[position]);
        }
    });

    // Make ListView handle contextual action bar
    final ArrayList<String> cab = listener.getCabArray();

    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            // Respond to clicks on the actions in the CAB
            switch (item.getItemId()) {
            case R.id.action_select_all:
                cab.clear();

                for (int i = 0; i < listView.getAdapter().getCount(); i++) {
                    listView.setItemChecked(i, true);
                }
                return false;
            case R.id.action_export:
                if (cab.size() > 0) {
                    mode.finish(); // Action picked, so close the CAB
                    listener.exportNotes();
                    return true;
                } else {
                    showToast(R.string.no_notes_to_export);
                    return false;
                }
            case R.id.action_delete:
                if (cab.size() > 0) {
                    mode.finish(); // Action picked, so close the CAB
                    listener.deleteNotes();
                    return true;
                } else {
                    showToast(R.string.no_notes_to_delete);
                    return false;
                }
            default:
                return false;
            }
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            listener.hideFab();

            // Inflate the menu for the CAB
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.context_menu, menu);

            // Clear any old values from cab array
            cab.clear();

            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            listener.showFab();
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (position > -1) {
                // Add/remove filenames to cab array as they are checked/unchecked
                if (checked) {
                    if (sortBy.startsWith("date"))
                        cab.add(finalListByDate[position]);
                    if (sortBy.startsWith("name"))
                        cab.add(finalListByName[position]);
                } else {
                    if (sortBy.startsWith("date"))
                        cab.remove(finalListByDate[position]);
                    if (sortBy.startsWith("name"))
                        cab.remove(finalListByName[position]);
                }

                listView.setItemChecked(-1, false);
            }

            // Update the title in CAB
            mode.setTitle(cab.size() + " " + listener.getCabString(cab.size()));
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }
    });

    if (cab.size() > 0) {
        List<String> cabClone = new ArrayList<>(cab);
        cab.clear();

        String[] array = null;
        if (sortBy.startsWith("date"))
            array = finalListByDate;
        if (sortBy.startsWith("name"))
            array = finalListByName;

        if (array != null) {
            for (String filename : cabClone) {
                for (int i = 0; i < array.length; i++) {
                    if (filename.equals(array[i]))
                        listView.setItemChecked(i, true);
                }
            }
        }
    }

    // If there are no saved notes, then display the empty view
    if (numOfNotes == 0) {
        TextView empty = getActivity().findViewById(R.id.empty);
        listView.setEmptyView(empty);
    }
}

From source file:com.flipkart.phantom.runtime.impl.server.netty.handler.mysql.MysqlChannelHandler.java

/**
 * read complete result set from mysql server all the input bytes
 */// ww w. ja v a  2  s  .co m
private ArrayList<byte[]> readFullResultSet(InputStream in, MessageEvent messageEvent, ArrayList<byte[]> buffer,
        boolean bufferResultSet) throws IOException {
    // Assume we have the start of a result set already

    byte[] packet = buffer.get((buffer.size() - 1));
    long colCount = ColCount.loadFromPacket(packet).colCount;

    // Read the columns and the EOF field
    for (int i = 0; i < (colCount + 1); i++) {
        packet = Packet.read_packet(in);
        if (packet == null) {
            throw new IOException();
        }
        buffer.add(packet);

        if (!bufferResultSet) {
            write(messageEvent.getChannel(), buffer);
            buffer.clear();
        }
    }
    byte[] packedPacket = new byte[PACKED_PACKET_SIZE];
    int position = offset;

    while (true) {
        packet = Packet.read_packet(in);

        if (packet == null) {
            throw new IOException();
        }

        int packetType = Packet.getType(packet);

        if (packetType == Flags.EOF || packetType == Flags.ERR) {
            byte[] newPackedPacket = new byte[position];
            System.arraycopy(packedPacket, offset, newPackedPacket, offset, position);
            buffer.add(newPackedPacket);
            packedPacket = packet;
            break;
        }

        if (position + packet.length > PACKED_PACKET_SIZE) {
            int subsize = PACKED_PACKET_SIZE - position;
            System.arraycopy(packet, offset, packedPacket, position, subsize);
            buffer.add(packedPacket);

            if (!bufferResultSet) {
                write(messageEvent.getChannel(), buffer);
                buffer.clear();
            }

            packedPacket = new byte[PACKED_PACKET_SIZE];
            position = offset;
            System.arraycopy(packet, subsize, packedPacket, position, packet.length - subsize);
            position += packet.length - subsize;
        } else {
            System.arraycopy(packet, offset, packedPacket, position, packet.length);
            position += packet.length;
        }
    }
    buffer.add(packedPacket);

    if (!bufferResultSet) {
        write(messageEvent.getChannel(), buffer);
        buffer.clear();
    }

    if (Packet.getType(packet) == Flags.ERR) {
        return buffer;
    }

    if (EOF.loadFromPacket(packet).hasStatusFlag(Flags.SERVER_MORE_RESULTS_EXISTS)) {
        buffer.add(Packet.read_packet(in));
        buffer = readFullResultSet(in, messageEvent, buffer, bufferResultSet);
    }
    return buffer;
}

From source file:com.kbot2.scriptable.methods.data.Walking.java

private WalkerNode[] findPath(WalkerNode startNode, WalkerNode endNode) {
    try {//from  w  w  w .j  av  a2s  .  c o  m
        if (!loadNodes || !loadLisks)
            load();
        ArrayList<WalkerNode> l = new ArrayList<WalkerNode>();
        for (int i = 0; i < nodes.size(); i++) {
            WalkerNode thisNode = nodes.get(i);
            thisNode.distance = 999999;
            thisNode.previous = null;
            l.add(thisNode);
        }
        startNode.distance = 0;
        while (l.isEmpty() == false) {
            WalkerNode nearestNode = l.get(0);
            for (int i = 0; i < l.size(); i++) {
                WalkerNode thisNode = l.get(i);
                if (thisNode.distance <= nearestNode.distance)
                    nearestNode = thisNode;

            }
            l.remove(l.indexOf(nearestNode));
            if (nearestNode == endNode)
                l.clear();
            else
                for (int i = 0; i < nearestNode.neighbours.size(); i++) {
                    WalkerNode neighbourNode = nearestNode.neighbours.get(i);
                    int alt = nearestNode.distance + nearestNode.distance(neighbourNode);
                    if (alt < neighbourNode.distance) {
                        neighbourNode.distance = alt;
                        neighbourNode.previous = nearestNode;
                    }
                }
        }
        ArrayList<WalkerNode> nodePath = new ArrayList<WalkerNode>();
        nodePath.add(endNode);
        WalkerNode previousNode = endNode.previous;
        while (previousNode != null) {
            nodePath.add(previousNode);
            previousNode = previousNode.previous;
        }
        if (nodePath.size() == 1)
            return null;
        WalkerNode[] nodeArray = new WalkerNode[nodePath.size()];
        for (int i = nodePath.size() - 1; i >= 0; i--)
            nodeArray[nodePath.size() - i - 1] = nodePath.get(i);
        return nodeArray;
    } catch (Exception e) {
    }
    return null;
}

From source file:acr.browser.lightning.browser.fragment.anim.HorizontalItemAnimator.java

@Override
public void runPendingAnimations() {
    boolean removalsPending = !mPendingRemovals.isEmpty();
    boolean movesPending = !mPendingMoves.isEmpty();
    boolean changesPending = !mPendingChanges.isEmpty();
    boolean additionsPending = !mPendingAdditions.isEmpty();
    if (!removalsPending && !movesPending && !additionsPending && !changesPending) {
        // nothing to animate
        return;//w w w  . ja  va  2s  . co m
    }
    // First, remove stuff
    for (ViewHolder holder : mPendingRemovals) {
        animateRemoveImpl(holder);
    }
    mPendingRemovals.clear();
    // Next, move stuff
    if (movesPending) {
        final ArrayList<MoveInfo> moves = new ArrayList<>();
        moves.addAll(mPendingMoves);
        mMovesList.add(moves);
        mPendingMoves.clear();
        Runnable mover = new Runnable() {
            @Override
            public void run() {
                for (MoveInfo moveInfo : moves) {
                    animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX,
                            moveInfo.toY);
                }
                moves.clear();
                mMovesList.remove(moves);
            }
        };
        if (removalsPending) {
            View view = moves.get(0).holder.itemView;
            ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
        } else {
            mover.run();
        }
    }
    // Next, change stuff, to run in parallel with move animations
    if (changesPending) {
        final ArrayList<ChangeInfo> changes = new ArrayList<>();
        changes.addAll(mPendingChanges);
        mChangesList.add(changes);
        mPendingChanges.clear();
        Runnable changer = new Runnable() {
            @Override
            public void run() {
                for (ChangeInfo change : changes) {
                    animateChangeImpl(change);
                }
                changes.clear();
                mChangesList.remove(changes);
            }
        };
        if (removalsPending) {
            ViewHolder holder = changes.get(0).oldHolder;
            ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
        } else {
            changer.run();
        }
    }
    // Next, add stuff
    if (additionsPending) {
        final ArrayList<ViewHolder> additions = new ArrayList<>();
        additions.addAll(mPendingAdditions);
        mAdditionsList.add(additions);
        mPendingAdditions.clear();
        Runnable adder = new Runnable() {
            public void run() {
                for (ViewHolder holder : additions) {
                    animateAddImpl(holder);
                }
                additions.clear();
                mAdditionsList.remove(additions);
            }
        };
        if (removalsPending || movesPending || changesPending) {
            long removeDuration = removalsPending ? getRemoveDuration() : 0;
            long moveDuration = movesPending ? getMoveDuration() : 0;
            long changeDuration = changesPending ? getChangeDuration() : 0;
            long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
            View view = additions.get(0).itemView;
            ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
        } else {
            adder.run();
        }
    }
}

From source file:com.jash.expandablerecycler.MyItemAnimator.java

@Override
public void runPendingAnimations() {
    boolean removalsPending = !mPendingRemovals.isEmpty();
    boolean movesPending = !mPendingMoves.isEmpty();
    boolean changesPending = !mPendingChanges.isEmpty();
    boolean additionsPending = !mPendingAdditions.isEmpty();
    if (!removalsPending && !movesPending && !additionsPending && !changesPending) {
        // nothing to animate
        return;/*from   w  ww  .  j a v a 2s .  c  o  m*/
    }
    Collections.sort(mPendingRemovals, new Comparator<ViewHolder>() {
        @Override
        public int compare(ViewHolder lhs, ViewHolder rhs) {
            return ((TreeAdapter.TreeViewHolder) lhs).getMyPosition()
                    - ((TreeAdapter.TreeViewHolder) rhs).getMyPosition();
        }
    });
    // First, remove stuff
    for (int i = 0; i < mPendingRemovals.size(); i++) {
        animateRemoveImpl(mPendingRemovals.get(i), i);
    }
    //        for (ViewHolder holder : mPendingRemovals) {
    //            animateRemoveImpl(holder);
    //        }
    long delayMillis = getRemoveDuration() + (mPendingRemovals.size() - 1) * 100;
    mPendingRemovals.clear();
    // Next, move stuff
    if (movesPending) {
        final ArrayList<MoveInfo> moves = new ArrayList<>();
        moves.addAll(mPendingMoves);
        mMovesList.add(moves);
        mPendingMoves.clear();
        Runnable mover = new Runnable() {
            @Override
            public void run() {
                for (MoveInfo moveInfo : moves) {
                    animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX,
                            moveInfo.toY);
                }
                moves.clear();
                mMovesList.remove(moves);
            }
        };
        if (removalsPending) {
            View view = moves.get(0).holder.itemView;
            ViewCompat.postOnAnimationDelayed(view, mover, delayMillis);
        } else {
            mover.run();
        }
    }
    // Next, change stuff, to run in parallel with move animations
    if (changesPending) {
        final ArrayList<ChangeInfo> changes = new ArrayList<>();
        changes.addAll(mPendingChanges);
        mChangesList.add(changes);
        mPendingChanges.clear();
        Runnable changer = new Runnable() {
            @Override
            public void run() {
                for (ChangeInfo change : changes) {
                    animateChangeImpl(change);
                }
                changes.clear();
                mChangesList.remove(changes);
            }
        };
        if (removalsPending) {
            ViewHolder holder = changes.get(0).oldHolder;
            ViewCompat.postOnAnimationDelayed(holder.itemView, changer, delayMillis);
        } else {
            changer.run();
        }
    }
    // Next, add stuff
    if (additionsPending) {
        final ArrayList<ViewHolder> additions = new ArrayList<>();
        additions.addAll(mPendingAdditions);
        mAdditionsList.add(additions);
        mPendingAdditions.clear();
        Runnable adder = new Runnable() {
            public void run() {
                Collections.sort(additions, new Comparator<ViewHolder>() {
                    @Override
                    public int compare(ViewHolder lhs, ViewHolder rhs) {
                        return lhs.getAdapterPosition() - rhs.getAdapterPosition();
                    }
                });
                for (int i = 0; i < additions.size(); i++) {
                    animateAddImpl(additions.get(i), i);
                }
                //                    for (ViewHolder holder : additions) {
                //                        animateAddImpl(holder);
                //                    }
                additions.clear();
                mAdditionsList.remove(additions);
            }
        };
        if (removalsPending || movesPending || changesPending) {
            long removeDuration = removalsPending ? delayMillis : 0;
            long moveDuration = movesPending ? getMoveDuration() : 0;
            long changeDuration = changesPending ? getChangeDuration() : 0;
            long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
            View view = additions.get(0).itemView;
            ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
        } else {
            adder.run();
        }
    }
}