Example usage for android.util SparseArray keyAt

List of usage examples for android.util SparseArray keyAt

Introduction

In this page you can find the example usage for android.util SparseArray keyAt.

Prototype

public int keyAt(int index) 

Source Link

Document

Given an index in the range 0...size()-1, returns the key from the indexth key-value mapping that this SparseArray stores.

Usage

From source file:org.telegraph.messenger.NotificationsController.java

public void processReadMessages(SparseArray<Long> inbox, long dialog_id, int max_date, int max_id,
        boolean isPopup) {
    int oldCount = popupMessages.size();
    if (inbox != null) {
        for (int b = 0; b < inbox.size(); b++) {
            int key = inbox.keyAt(b);
            long messageId = inbox.get(key);
            for (int a = 0; a < pushMessages.size(); a++) {
                MessageObject messageObject = pushMessages.get(a);
                if (messageObject.getDialogId() == key && messageObject.getId() <= (int) messageId) {
                    if (isPersonalMessage(messageObject)) {
                        personal_count--;
                    }//from  w ww.j av a2 s. c  om
                    popupMessages.remove(messageObject);
                    pushMessagesDict.remove(messageObject.getId());
                    delayedPushMessages.remove(messageObject);
                    pushMessages.remove(a);
                    a--;
                }
            }
        }
        if (pushMessages.isEmpty() && !popupMessages.isEmpty()) {
            popupMessages.clear();
        }
    }
    if (dialog_id != 0 && (max_id != 0 || max_date != 0)) {
        for (int a = 0; a < pushMessages.size(); a++) {
            MessageObject messageObject = pushMessages.get(a);
            if (messageObject.getDialogId() == dialog_id) {
                boolean remove = false;
                if (max_date != 0) {
                    if (messageObject.messageOwner.date <= max_date) {
                        remove = true;
                    }
                } else {
                    if (!isPopup) {
                        if (messageObject.getId() <= max_id || max_id < 0) {
                            remove = true;
                        }
                    } else {
                        if (messageObject.getId() == max_id || max_id < 0) {
                            remove = true;
                        }
                    }
                }
                if (remove) {
                    if (isPersonalMessage(messageObject)) {
                        personal_count--;
                    }
                    pushMessages.remove(a);
                    delayedPushMessages.remove(messageObject);
                    popupMessages.remove(messageObject);
                    pushMessagesDict.remove(messageObject.getId());
                    a--;
                }
            }
        }
        if (pushMessages.isEmpty() && !popupMessages.isEmpty()) {
            popupMessages.clear();
        }
    }
    if (oldCount != popupMessages.size()) {
        NotificationCenter.getInstance().postNotificationName(NotificationCenter.pushMessagesUpdated);
    }
}

From source file:com.oakesville.mythling.MediaActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (v == getListView()) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        Listable listable = (Listable) getListView().getItemAtPosition(info.position);
        if (listable instanceof Item) {
            Item item = (Item) listable;
            menu.setHeaderTitle(item.getDialogTitle());
            if (isSplitView()) {
                getListView().performItemClick(getListView().getChildAt(info.position), info.position,
                        getListView().getAdapter().getItemId(info.position));
            } else {
                getListView().setItemChecked(info.position, true);
            }/*  w ww  .jav  a  2s.  co  m*/
            SparseArray<String> menuItems = getLongClickMenuItems(item);
            for (int i = 0; i < menuItems.size(); i++) {
                int id = menuItems.keyAt(i);
                menu.add(MEDIA_ACTIVITY_CONTEXT_MENU_GROUP_ID, id, id, menuItems.get(id));
            }
        }
    }
}

From source file:android.transitions.everywhere.Transition.java

/**
 * Match start/end values by Adapter view ID. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd, using
 * startIds and endIds as a guide for which Views have unique IDs.
 *//*w  w w .j ava  2  s .c  o m*/
private void matchIds(ArrayMap<View, TransitionValues> unmatchedStart,
        ArrayMap<View, TransitionValues> unmatchedEnd, SparseArray<View> startIds, SparseArray<View> endIds) {
    int numStartIds = startIds.size();
    for (int i = 0; i < numStartIds; i++) {
        View startView = startIds.valueAt(i);
        if (startView != null && isValidTarget(startView)) {
            View endView = endIds.get(startIds.keyAt(i));
            if (endView != null && isValidTarget(endView)) {
                TransitionValues startValues = unmatchedStart.get(startView);
                TransitionValues endValues = unmatchedEnd.get(endView);
                if (startValues != null && endValues != null) {
                    mStartValuesList.add(startValues);
                    mEndValuesList.add(endValues);
                    unmatchedStart.remove(startView);
                    unmatchedEnd.remove(endView);
                }
            }
        }
    }
}

From source file:edu.umich.flowfence.sandbox.ResolvedQM.java

@Override
public void call(int flags, IQMCallback callback, List<CallParam> params) throws RemoteException {
    try {// w ww  . j a va2 s.co  m
        if (localLOGD) {
            Log.d(TAG, String.format("Incoming sandbox call for %s, %d parameters:", mOriginalDescriptor,
                    params.size()));
            for (CallParam param : params) {
                Log.d(TAG, param.toString(mContext.getClassLoader()));
            }
        }
        if (localLOGV) {
            Log.v(TAG, String.format("Callback %s, flags %d", callback, flags));
        }
        // Sanity check.
        final int numParams = params.size();
        if (numParams != mMemberData.countParameters()) {
            throw new IllegalArgumentException("Wrong number of arguments supplied");
        }

        boolean hasReturn = (flags & CallFlags.NO_RETURN_VALUE) == 0;

        final ArrayList<Object> args = new ArrayList<>();
        final SparseArray<IBinder> outs = new SparseArray<>();

        mContext.beginQM();
        try {
            if (hasReturn) {
                outs.append(CallResult.RETURN_VALUE, null);
            }

            for (int i = 0; i < numParams; i++) {
                CallParam param = params.get(i);
                int paramHeader = param.getHeader();
                if (param.getType() == CallParam.TYPE_HANDLE
                        && (paramHeader & CallParam.HANDLE_SYNC_ONLY) != 0) {
                    Log.w(TAG, "HANDLE_SYNC_ONLY in sandbox for " + mOriginalDescriptor);
                    continue;
                }
                // Deserialize argument, marshaling as necessary.
                Object arg = unpack(param);
                // TODO: FLAG_BY_REF
                args.add(arg);
                // Put together the out parameter for inout params.
                if ((paramHeader & CallParam.FLAG_RETURN) != 0) {
                    if (localLOGV) {
                        Log.v(TAG, String.format("Adding out param %d", i));
                    }
                    outs.append(i, SandboxObject.binderForObject(this, arg));
                }
            }

            // Actually do the call.
            Object[] argArray = args.toArray();
            if (localLOGD) {
                Log.d(TAG, "Preparing to call " + mOriginalDescriptor.printCall(argArray));
            }

            Object retval = mMemberData.call(argArray);

            if (localLOGD) {
                Log.d(TAG, "Call returned: " + Objects.toString(retval));
            }

            // Bundle up handle for return value.
            if (hasReturn) {
                IBinder retvalObj = SandboxObject.binderForObject(this, retval);
                outs.put(CallResult.RETURN_VALUE, retvalObj);
            }

            // DEBUG: print out params
            if (localLOGV) {
                for (int i = 0; i < outs.size(); i++) {
                    Log.v(TAG, String.format("out[%d] = %s", outs.keyAt(i), outs.valueAt(i)));
                }
            }
            // Post results to caller.
            if (localLOGD) {
                Log.d(TAG, "Posting results to caller");
            }
            callback.onResult(new CallResult(outs));
        } catch (InvocationTargetException ioe) {
            Throwable t = ioe.getTargetException();
            if (t instanceof Exception) {
                throw ((Exception) t);
            }
            throw ioe;
        } finally {
            // Clear our ambient context.
            if (localLOGD) {
                Log.d(TAG, "Clearing call token");
            }
            mContext.endQM();
        }
    } catch (Exception e) {
        //Log.e(TAG, String.format("Error invoking %s", mOriginalDescriptor), e);
        callback.onResult(new CallResult(e));
    }
}

From source file:edu.umich.oasis.sandbox.ResolvedSoda.java

@Override
public void call(int flags, ISodaCallback callback, List<CallParam> params) throws RemoteException {
    try {//from   w  w w  . ja v a 2  s  . c  om
        if (localLOGD) {
            Log.d(TAG, String.format("Incoming sandbox call for %s, %d parameters:", mOriginalDescriptor,
                    params.size()));
            for (CallParam param : params) {
                Log.d(TAG, param.toString(mContext.getClassLoader()));
            }
        }
        if (localLOGV) {
            Log.v(TAG, String.format("Callback %s, flags %d", callback, flags));
        }
        // Sanity check.
        final int numParams = params.size();
        if (numParams != mMemberData.countParameters()) {
            throw new IllegalArgumentException("Wrong number of arguments supplied");
        }

        boolean hasReturn = (flags & CallFlags.NO_RETURN_VALUE) == 0;

        final ArrayList<Object> args = new ArrayList<>();
        final SparseArray<IBinder> outs = new SparseArray<>();

        mContext.beginSoda();
        try {
            if (hasReturn) {
                outs.append(CallResult.RETURN_VALUE, null);
            }

            for (int i = 0; i < numParams; i++) {
                CallParam param = params.get(i);
                int paramHeader = param.getHeader();
                if (param.getType() == CallParam.TYPE_HANDLE
                        && (paramHeader & CallParam.HANDLE_SYNC_ONLY) != 0) {
                    Log.w(TAG, "HANDLE_SYNC_ONLY in sandbox for " + mOriginalDescriptor);
                    continue;
                }
                // Deserialize argument, marshaling as necessary.
                Object arg = unpack(param);
                // TODO: FLAG_BY_REF
                args.add(arg);
                // Put together the out parameter for inout params.
                if ((paramHeader & CallParam.FLAG_RETURN) != 0) {
                    if (localLOGV) {
                        Log.v(TAG, String.format("Adding out param %d", i));
                    }
                    outs.append(i, SandboxObject.binderForObject(this, arg));
                }
            }

            // Actually do the call.
            Object[] argArray = args.toArray();
            if (localLOGD) {
                Log.d(TAG, "Preparing to call " + mOriginalDescriptor.printCall(argArray));
            }

            Object retval = mMemberData.call(argArray);

            if (localLOGD) {
                Log.d(TAG, "Call returned: " + Objects.toString(retval));
            }

            // Bundle up handle for return value.
            if (hasReturn) {
                IBinder retvalObj = SandboxObject.binderForObject(this, retval);
                outs.put(CallResult.RETURN_VALUE, retvalObj);
            }

            // DEBUG: print out params
            if (localLOGV) {
                for (int i = 0; i < outs.size(); i++) {
                    Log.v(TAG, String.format("out[%d] = %s", outs.keyAt(i), outs.valueAt(i)));
                }
            }
            // Post results to caller.
            if (localLOGD) {
                Log.d(TAG, "Posting results to caller");
            }
            callback.onResult(new CallResult(outs));
        } catch (InvocationTargetException ioe) {
            Throwable t = ioe.getTargetException();
            if (t instanceof Exception) {
                throw ((Exception) t);
            }
            throw ioe;
        } finally {
            // Clear our ambient context.
            if (localLOGD) {
                Log.d(TAG, "Clearing call token");
            }
            mContext.endSoda();
        }
    } catch (Exception e) {
        //Log.e(TAG, String.format("Error invoking %s", mOriginalDescriptor), e);
        callback.onResult(new CallResult(e));
    }
}

From source file:com.ferdi2005.secondgram.NotificationsController.java

public void processReadMessages(final SparseArray<Long> inbox, final long dialog_id, final int max_date,
        final int max_id, final boolean isPopup) {
    final ArrayList<MessageObject> popupArray = popupMessages.isEmpty() ? null : new ArrayList<>(popupMessages);
    notificationsQueue.postRunnable(new Runnable() {
        @Override/*w w w  .  jav a2 s .  com*/
        public void run() {
            int oldCount = popupArray != null ? popupArray.size() : 0;
            if (inbox != null) {
                for (int b = 0; b < inbox.size(); b++) {
                    int key = inbox.keyAt(b);
                    long messageId = inbox.get(key);
                    for (int a = 0; a < pushMessages.size(); a++) {
                        MessageObject messageObject = pushMessages.get(a);
                        if (messageObject.getDialogId() == key && messageObject.getId() <= (int) messageId) {
                            if (isPersonalMessage(messageObject)) {
                                personal_count--;
                            }
                            if (popupArray != null) {
                                popupArray.remove(messageObject);
                            }
                            long mid = messageObject.messageOwner.id;
                            if (messageObject.messageOwner.to_id.channel_id != 0) {
                                mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
                            }
                            pushMessagesDict.remove(mid);
                            delayedPushMessages.remove(messageObject);
                            pushMessages.remove(a);
                            a--;
                        }
                    }
                }
                if (popupArray != null && pushMessages.isEmpty() && !popupArray.isEmpty()) {
                    popupArray.clear();
                }
            }
            if (dialog_id != 0 && (max_id != 0 || max_date != 0)) {
                for (int a = 0; a < pushMessages.size(); a++) {
                    MessageObject messageObject = pushMessages.get(a);
                    if (messageObject.getDialogId() == dialog_id) {
                        boolean remove = false;
                        if (max_date != 0) {
                            if (messageObject.messageOwner.date <= max_date) {
                                remove = true;
                            }
                        } else {
                            if (!isPopup) {
                                if (messageObject.getId() <= max_id || max_id < 0) {
                                    remove = true;
                                }
                            } else {
                                if (messageObject.getId() == max_id || max_id < 0) {
                                    remove = true;
                                }
                            }
                        }
                        if (remove) {
                            if (isPersonalMessage(messageObject)) {
                                personal_count--;
                            }
                            pushMessages.remove(a);
                            delayedPushMessages.remove(messageObject);
                            if (popupArray != null) {
                                popupArray.remove(messageObject);
                            }
                            long mid = messageObject.messageOwner.id;
                            if (messageObject.messageOwner.to_id.channel_id != 0) {
                                mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
                            }
                            pushMessagesDict.remove(mid);
                            a--;
                        }
                    }
                }
                if (popupArray != null && pushMessages.isEmpty() && !popupArray.isEmpty()) {
                    popupArray.clear();
                }
            }
            if (popupArray != null && oldCount != popupArray.size()) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        popupMessages = popupArray;
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.pushMessagesUpdated);
                    }
                });
            }
        }
    });
}

From source file:com.ferdi2005.secondgram.NotificationsController.java

public void removeDeletedMessagesFromNotifications(final SparseArray<ArrayList<Integer>> deletedMessages) {
    final ArrayList<MessageObject> popupArray = popupMessages.isEmpty() ? null : new ArrayList<>(popupMessages);
    notificationsQueue.postRunnable(new Runnable() {
        @Override//from w w  w  .j  a v a2s .co m
        public void run() {
            int old_unread_count = total_unread_count;
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            for (int a = 0; a < deletedMessages.size(); a++) {
                int key = deletedMessages.keyAt(a);
                long dialog_id = -key;
                ArrayList<Integer> mids = deletedMessages.get(key);
                Integer currentCount = pushDialogs.get(dialog_id);
                if (currentCount == null) {
                    currentCount = 0;
                }
                Integer newCount = currentCount;
                for (int b = 0; b < mids.size(); b++) {
                    long mid = mids.get(b);
                    mid |= ((long) key) << 32;
                    MessageObject messageObject = pushMessagesDict.get(mid);
                    if (messageObject != null) {
                        pushMessagesDict.remove(mid);
                        delayedPushMessages.remove(messageObject);
                        pushMessages.remove(messageObject);
                        if (isPersonalMessage(messageObject)) {
                            personal_count--;
                        }
                        if (popupArray != null) {
                            popupArray.remove(messageObject);
                        }
                        newCount--;
                    }
                }
                if (newCount <= 0) {
                    newCount = 0;
                    smartNotificationsDialogs.remove(dialog_id);
                }
                if (!newCount.equals(currentCount)) {
                    total_unread_count -= currentCount;
                    total_unread_count += newCount;
                    pushDialogs.put(dialog_id, newCount);
                }
                if (newCount == 0) {
                    pushDialogs.remove(dialog_id);
                    pushDialogsOverrideMention.remove(dialog_id);
                    if (popupArray != null && pushMessages.isEmpty() && !popupArray.isEmpty()) {
                        popupArray.clear();
                    }
                }
            }
            if (popupArray != null) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        popupMessages = popupArray;
                    }
                });
            }
            if (old_unread_count != total_unread_count) {
                if (!notifyCheck) {
                    delayedPushMessages.clear();
                    showOrUpdateNotification(notifyCheck);
                } else {
                    scheduleNotificationDelay(
                            lastOnlineFromOtherDevice > ConnectionsManager.getInstance().getCurrentTime());
                }
            }
            notifyCheck = false;
            if (preferences.getBoolean("badgeNumber", true)) {
                setBadge(total_unread_count);
            }
        }
    });
}

From source file:org.telepatch.ui.ChatActivity.java

@SuppressWarnings("unchecked")
@Override//  ww w . j  a  va 2 s  . co m
public void didReceivedNotification(int id, final Object... args) {
    if (id == NotificationCenter.messagesDidLoaded) {
        long did = (Long) args[0];
        if (did == dialog_id) {
            loadsCount++;
            int count = (Integer) args[1];
            boolean isCache = (Boolean) args[3];
            int fnid = (Integer) args[4];
            int last_unread_date = (Integer) args[7];
            boolean forwardLoad = (Boolean) args[8];
            boolean wasUnread = false;
            boolean positionToUnread = false;
            if (fnid != 0) {
                first_unread_id = fnid;
                last_unread_id = (Integer) args[5];
                unread_to_load = (Integer) args[6];
                positionToUnread = true;
            }
            ArrayList<MessageObject> messArr = (ArrayList<MessageObject>) args[2];

            int newRowsCount = 0;
            unread_end_reached = last_unread_id == 0;

            if (loadsCount == 1 && messArr.size() > 20) {
                loadsCount++;
            }

            if (firstLoading) {
                if (!unread_end_reached) {
                    messages.clear();
                    messagesByDays.clear();
                    messagesDict.clear();
                    if (currentEncryptedChat == null) {
                        maxMessageId = Integer.MAX_VALUE;
                        minMessageId = Integer.MIN_VALUE;
                    } else {
                        maxMessageId = Integer.MIN_VALUE;
                        minMessageId = Integer.MAX_VALUE;
                    }
                    maxDate = Integer.MIN_VALUE;
                    minDate = 0;
                }
                firstLoading = false;
            }

            for (int a = 0; a < messArr.size(); a++) {
                MessageObject obj = messArr.get(a);
                if (messagesDict.containsKey(obj.messageOwner.id)) {
                    continue;
                }

                if (obj.messageOwner.id > 0) {
                    maxMessageId = Math.min(obj.messageOwner.id, maxMessageId);
                    minMessageId = Math.max(obj.messageOwner.id, minMessageId);
                } else if (currentEncryptedChat != null) {
                    maxMessageId = Math.max(obj.messageOwner.id, maxMessageId);
                    minMessageId = Math.min(obj.messageOwner.id, minMessageId);
                }
                maxDate = Math.max(maxDate, obj.messageOwner.date);
                if (minDate == 0 || obj.messageOwner.date < minDate) {
                    minDate = obj.messageOwner.date;
                }

                if (obj.type < 0) {
                    continue;
                }

                if (!obj.isOut() && obj.isUnread()) {
                    wasUnread = true;
                }
                messagesDict.put(obj.messageOwner.id, obj);
                ArrayList<MessageObject> dayArray = messagesByDays.get(obj.dateKey);

                if (dayArray == null) {
                    dayArray = new ArrayList<MessageObject>();
                    messagesByDays.put(obj.dateKey, dayArray);

                    TLRPC.Message dateMsg = new TLRPC.Message();
                    dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
                    dateMsg.id = 0;
                    MessageObject dateObj = new MessageObject(dateMsg, null);
                    dateObj.type = 10;
                    dateObj.contentType = 4;
                    if (forwardLoad) {
                        messages.add(0, dateObj);
                    } else {
                        messages.add(dateObj);
                    }
                    newRowsCount++;
                }

                newRowsCount++;
                dayArray.add(obj);
                if (forwardLoad) {
                    messages.add(0, obj);
                } else {
                    messages.add(messages.size() - 1, obj);
                }

                if (!forwardLoad) {
                    if (obj.messageOwner.id == first_unread_id) {
                        TLRPC.Message dateMsg = new TLRPC.Message();
                        dateMsg.message = "";
                        dateMsg.id = 0;
                        MessageObject dateObj = new MessageObject(dateMsg, null);
                        dateObj.contentType = dateObj.type = 6;
                        boolean dateAdded = true;
                        if (a != messArr.size() - 1) {
                            MessageObject next = messArr.get(a + 1);
                            dateAdded = !next.dateKey.equals(obj.dateKey);
                        }
                        messages.add(messages.size() - (dateAdded ? 0 : 1), dateObj);
                        unreadMessageObject = dateObj;
                        newRowsCount++;
                    }
                    if (obj.messageOwner.id == last_unread_id) {
                        unread_end_reached = true;
                    }
                }

            }

            if (unread_end_reached) {
                first_unread_id = 0;
                last_unread_id = 0;
            }

            if (forwardLoad) {
                if (messArr.size() != count) {
                    unread_end_reached = true;
                    first_unread_id = 0;
                    last_unread_id = 0;
                }

                chatAdapter.notifyDataSetChanged();
                loadingForward = false;
            } else {
                if (messArr.size() != count) {
                    if (isCache) {
                        cacheEndReaced = true;
                        if (currentEncryptedChat != null || isBroadcast) {
                            endReached = true;
                        }
                    } else {
                        cacheEndReaced = true;
                        endReached = true;
                    }
                }
                loading = false;

                if (chatListView != null) {
                    if (first || scrollToTopOnResume) {
                        chatAdapter.notifyDataSetChanged();
                        if (positionToUnread && unreadMessageObject != null) {
                            if (messages.get(messages.size() - 1) == unreadMessageObject) {
                                chatListView.setSelectionFromTop(0, AndroidUtilities.dp(-11));
                            } else {
                                chatListView.setSelectionFromTop(
                                        messages.size() - messages.indexOf(unreadMessageObject),
                                        AndroidUtilities.dp(-11));
                            }
                            ViewTreeObserver obs = chatListView.getViewTreeObserver();
                            obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                                @Override
                                public boolean onPreDraw() {
                                    if (!messages.isEmpty()) {
                                        if (messages.get(messages.size() - 1) == unreadMessageObject) {
                                            chatListView.setSelectionFromTop(0, AndroidUtilities.dp(-11));
                                        } else {
                                            chatListView.setSelectionFromTop(
                                                    messages.size() - messages.indexOf(unreadMessageObject),
                                                    AndroidUtilities.dp(-11));
                                        }
                                    }
                                    chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
                                    return false;
                                }
                            });
                            chatListView.invalidate();
                            showPagedownButton(true, true);
                        } else {
                            chatListView.post(new Runnable() {
                                @Override
                                public void run() {
                                    chatListView.setSelectionFromTop(messages.size() - 1,
                                            -100000 - chatListView.getPaddingTop());
                                }
                            });
                        }
                    } else {
                        int firstVisPos = chatListView.getLastVisiblePosition();
                        View firstVisView = chatListView.getChildAt(chatListView.getChildCount() - 1);
                        int top = ((firstVisView == null) ? 0 : firstVisView.getTop())
                                - chatListView.getPaddingTop();
                        chatAdapter.notifyDataSetChanged();
                        chatListView.setSelectionFromTop(firstVisPos + newRowsCount - (endReached ? 1 : 0),
                                top);
                    }

                    if (paused) {
                        scrollToTopOnResume = true;
                        if (positionToUnread && unreadMessageObject != null) {
                            scrollToTopUnReadOnResume = true;
                        }
                    }

                    if (first) {
                        if (chatListView.getEmptyView() == null) {
                            chatListView.setEmptyView(emptyViewContainer);
                        }
                    }
                } else {
                    scrollToTopOnResume = true;
                    if (positionToUnread && unreadMessageObject != null) {
                        scrollToTopUnReadOnResume = true;
                    }
                }
            }

            if (first && messages.size() > 0) {
                if (last_unread_id != 0) {
                    MessagesController.getInstance().markDialogAsRead(dialog_id,
                            messages.get(0).messageOwner.id, last_unread_id, 0, last_unread_date, wasUnread,
                            false);
                } else {
                    MessagesController.getInstance().markDialogAsRead(dialog_id,
                            messages.get(0).messageOwner.id, minMessageId, 0, maxDate, wasUnread, false);
                }
                first = false;
            }

            if (progressView != null) {
                progressView.setVisibility(View.GONE);
            }
        }
    } else if (id == NotificationCenter.emojiDidLoaded) {
        if (chatListView != null) {
            chatListView.invalidateViews();
        }
    } else if (id == NotificationCenter.updateInterfaces) {
        int updateMask = (Integer) args[0];
        if ((updateMask & MessagesController.UPDATE_MASK_NAME) != 0
                || (updateMask & MessagesController.UPDATE_MASK_STATUS) != 0
                || (updateMask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0
                || (updateMask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0) {
            //TODO non aggiorno niente se sto effettuando una ricerca
            if (!searching) {
                updateSubtitle();
                updateOnlineCount();
            }
        }
        if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0
                || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0
                || (updateMask & MessagesController.UPDATE_MASK_NAME) != 0) {
            checkAndUpdateAvatar();
            updateVisibleRows();
        }
        if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
            CharSequence printString = MessagesController.getInstance().printingStrings.get(dialog_id);
            if (lastPrintString != null && printString == null || lastPrintString == null && printString != null
                    || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
                //TODO non aggiorno niente se sto effettuando una ricerca
                if (!searching) {
                    updateSubtitle();
                }
            }
        }
        if ((updateMask & MessagesController.UPDATE_MASK_USER_PHONE) != 0) {
            updateContactStatus();
        }
    } else if (id == NotificationCenter.didReceivedNewMessages) {
        long did = (Long) args[0];
        if (did == dialog_id) {

            boolean updateChat = false;
            boolean hasFromMe = false;
            ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[1];

            if (currentEncryptedChat != null && arr.size() == 1) {
                MessageObject obj = arr.get(0);

                if (currentEncryptedChat != null && obj.isOut() && obj.messageOwner.action != null
                        && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction
                        && obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL
                        && getParentActivity() != null) {
                    TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) obj.messageOwner.action.encryptedAction;
                    if (AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 17
                            && currentEncryptedChat.ttl > 0 && currentEncryptedChat.ttl <= 60) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                        builder.setPositiveButton(R.string.OK, null);
                        builder.setMessage(LocaleController.formatString("CompatibilityChat",
                                R.string.CompatibilityChat, currentUser.first_name, currentUser.first_name));
                        showAlertDialog(builder);
                    }
                }
            }

            if (!unread_end_reached) {
                int currentMaxDate = Integer.MIN_VALUE;
                int currentMinMsgId = Integer.MIN_VALUE;
                if (currentEncryptedChat != null) {
                    currentMinMsgId = Integer.MAX_VALUE;
                }
                boolean currentMarkAsRead = false;

                for (MessageObject obj : arr) {
                    if (currentEncryptedChat != null && obj.messageOwner.action != null
                            && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction
                            && obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL
                            && timerButton != null) {
                        TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) obj.messageOwner.action.encryptedAction;
                        timerButton.setTime(action.ttl_seconds);
                    }
                    if (obj.isOut() && obj.isSending()) {
                        scrollToLastMessage();
                        return;
                    }
                    if (messagesDict.containsKey(obj.messageOwner.id)) {
                        continue;
                    }
                    currentMaxDate = Math.max(currentMaxDate, obj.messageOwner.date);
                    if (obj.messageOwner.id > 0) {
                        currentMinMsgId = Math.max(obj.messageOwner.id, currentMinMsgId);
                    } else if (currentEncryptedChat != null) {
                        currentMinMsgId = Math.min(obj.messageOwner.id, currentMinMsgId);
                    }

                    if (!obj.isOut() && obj.isUnread()) {
                        unread_to_load++;
                        currentMarkAsRead = true;
                    }
                    if (obj.type == 10 || obj.type == 11) {
                        updateChat = true;
                    }
                }

                if (currentMarkAsRead) {
                    if (paused) {
                        readWhenResume = true;
                        readWithDate = currentMaxDate;
                        readWithMid = currentMinMsgId;
                    } else {
                        if (messages.size() > 0) {
                            MessagesController.getInstance().markDialogAsRead(dialog_id,
                                    messages.get(0).messageOwner.id, currentMinMsgId, 0, currentMaxDate, true,
                                    false);
                        }
                    }
                }
                updateVisibleRows();
            } else {
                boolean markAsRead = false;
                int oldCount = messages.size();
                for (MessageObject obj : arr) {
                    if (currentEncryptedChat != null && obj.messageOwner.action != null
                            && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction
                            && obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL
                            && timerButton != null) {
                        TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) obj.messageOwner.action.encryptedAction;
                        timerButton.setTime(action.ttl_seconds);
                    }
                    if (messagesDict.containsKey(obj.messageOwner.id)) {
                        continue;
                    }
                    if (minDate == 0 || obj.messageOwner.date < minDate) {
                        minDate = obj.messageOwner.date;
                    }

                    if (obj.isOut()) {
                        removeUnreadPlane(false);
                        hasFromMe = true;
                    }

                    if (!obj.isOut() && unreadMessageObject != null) {
                        unread_to_load++;
                    }

                    if (obj.messageOwner.id > 0) {
                        maxMessageId = Math.min(obj.messageOwner.id, maxMessageId);
                        minMessageId = Math.max(obj.messageOwner.id, minMessageId);
                    } else if (currentEncryptedChat != null) {
                        maxMessageId = Math.max(obj.messageOwner.id, maxMessageId);
                        minMessageId = Math.min(obj.messageOwner.id, minMessageId);
                    }
                    maxDate = Math.max(maxDate, obj.messageOwner.date);
                    messagesDict.put(obj.messageOwner.id, obj);
                    ArrayList<MessageObject> dayArray = messagesByDays.get(obj.dateKey);
                    if (dayArray == null) {
                        dayArray = new ArrayList<MessageObject>();
                        messagesByDays.put(obj.dateKey, dayArray);

                        TLRPC.Message dateMsg = new TLRPC.Message();
                        dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
                        dateMsg.id = 0;
                        MessageObject dateObj = new MessageObject(dateMsg, null);
                        dateObj.type = 10;
                        dateObj.contentType = 4;
                        messages.add(0, dateObj);
                    }
                    if (!obj.isOut() && obj.isUnread()) {
                        if (!paused) {
                            obj.setIsRead();
                        }
                        markAsRead = true;
                    }
                    dayArray.add(0, obj);
                    messages.add(0, obj);
                    if (obj.type == 10 || obj.type == 11) {
                        updateChat = true;
                    }
                }
                if (progressView != null) {
                    progressView.setVisibility(View.GONE);
                }
                if (chatAdapter != null) {
                    chatAdapter.notifyDataSetChanged();
                } else {
                    scrollToTopOnResume = true;
                }

                if (chatListView != null && chatAdapter != null) {
                    int lastVisible = chatListView.getLastVisiblePosition();
                    if (endReached) {
                        lastVisible++;
                    }
                    if (lastVisible == oldCount || hasFromMe) {
                        if (!firstLoading) {
                            if (paused) {
                                scrollToTopOnResume = true;
                            } else {
                                chatListView.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        chatListView.setSelectionFromTop(messages.size() - 1,
                                                -100000 - chatListView.getPaddingTop());
                                    }
                                });
                            }
                        }
                    } else {
                        showPagedownButton(true, true);
                    }
                } else {
                    scrollToTopOnResume = true;
                }

                if (markAsRead) {
                    if (paused) {
                        readWhenResume = true;
                        readWithDate = maxDate;
                        readWithMid = minMessageId;
                    } else {
                        MessagesController.getInstance().markDialogAsRead(dialog_id,
                                messages.get(0).messageOwner.id, minMessageId, 0, maxDate, true, false);
                    }
                }
            }
            //TODO non aggiorno niente se sto effettuando una ricerca
            if (updateChat && !searching) {
                updateSubtitle();
                checkAndUpdateAvatar();
            }
        }
    } else if (id == NotificationCenter.closeChats) {
        if (args != null && args.length > 0) {
            long did = (Long) args[0];
            if (did == dialog_id) {
                finishFragment();
            }
        } else {
            removeSelfFromStack();
        }
    } else if (id == NotificationCenter.messagesRead) {
        ArrayList<Integer> markAsReadMessages = (ArrayList<Integer>) args[0];
        boolean updated = false;
        for (Integer ids : markAsReadMessages) {
            MessageObject obj = messagesDict.get(ids);
            if (obj != null) {
                obj.setIsRead();
                updated = true;
            }
        }
        if (updated) {
            updateVisibleRows();
        }
    } else if (id == NotificationCenter.messagesDeleted) {
        ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>) args[0];
        boolean updated = false;
        for (Integer ids : markAsDeletedMessages) {
            MessageObject obj = messagesDict.get(ids);
            if (obj != null) {
                int index = messages.indexOf(obj);
                if (index != -1) {
                    messages.remove(index);
                    messagesDict.remove(ids);
                    ArrayList<MessageObject> dayArr = messagesByDays.get(obj.dateKey);
                    dayArr.remove(obj);
                    if (dayArr.isEmpty()) {
                        messagesByDays.remove(obj.dateKey);
                        messages.remove(index);
                    }
                    updated = true;
                }
            }
        }
        if (messages.isEmpty()) {
            if (!endReached && !loading) {
                progressView.setVisibility(View.GONE);
                chatListView.setEmptyView(null);
                if (currentEncryptedChat == null) {
                    maxMessageId = Integer.MAX_VALUE;
                    minMessageId = Integer.MIN_VALUE;
                } else {
                    maxMessageId = Integer.MIN_VALUE;
                    minMessageId = Integer.MAX_VALUE;
                }
                maxDate = Integer.MIN_VALUE;
                minDate = 0;
                MessagesController.getInstance().loadMessages(dialog_id, 30, 0, !cacheEndReaced, minDate,
                        classGuid, false, false, null);
                loading = true;
            }
        }
        if (updated && chatAdapter != null) {
            removeUnreadPlane(false);
            chatAdapter.notifyDataSetChanged();
        }
    } else if (id == NotificationCenter.messageReceivedByServer) {
        Integer msgId = (Integer) args[0];
        MessageObject obj = messagesDict.get(msgId);
        if (obj != null) {
            Integer newMsgId = (Integer) args[1];
            TLRPC.Message newMsgObj = (TLRPC.Message) args[2];
            if (newMsgObj != null) {
                obj.messageOwner.media = newMsgObj.media;
                obj.generateThumbs(true, 1);
            }
            messagesDict.remove(msgId);
            messagesDict.put(newMsgId, obj);
            obj.messageOwner.id = newMsgId;
            obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
            updateVisibleRows();
        }
    } else if (id == NotificationCenter.messageReceivedByAck) {
        Integer msgId = (Integer) args[0];
        MessageObject obj = messagesDict.get(msgId);
        if (obj != null) {
            obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
            updateVisibleRows();
        }
    } else if (id == NotificationCenter.messageSendError) {
        Integer msgId = (Integer) args[0];
        MessageObject obj = messagesDict.get(msgId);
        if (obj != null) {
            obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
            updateVisibleRows();
        }
    } else if (id == NotificationCenter.chatInfoDidLoaded) {
        int chatId = (Integer) args[0];
        if (currentChat != null && chatId == currentChat.id) {
            info = (TLRPC.ChatParticipants) args[1];
            updateOnlineCount();
            if (isBroadcast) {
                SendMessagesHelper.getInstance().setCurrentChatInfo(info);
            }
        }
    } else if (id == NotificationCenter.contactsDidLoaded) {
        updateContactStatus();
        updateSubtitle();
    } else if (id == NotificationCenter.encryptedChatUpdated) {
        TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat) args[0];
        if (currentEncryptedChat != null && chat.id == currentEncryptedChat.id) {
            currentEncryptedChat = chat;
            updateContactStatus();
            updateSecretStatus();
        }
    } else if (id == NotificationCenter.messagesReadedEncrypted) {
        int encId = (Integer) args[0];
        if (currentEncryptedChat != null && currentEncryptedChat.id == encId) {
            int date = (Integer) args[1];
            boolean started = false;
            for (MessageObject obj : messages) {
                if (!obj.isOut()) {
                    continue;
                } else if (obj.isOut() && !obj.isUnread()) {
                    break;
                }
                if (obj.messageOwner.date <= date) {
                    obj.setIsRead();
                }
            }
            updateVisibleRows();
        }
    } else if (id == NotificationCenter.audioDidReset) {
        Integer mid = (Integer) args[0];
        if (chatListView != null) {
            int count = chatListView.getChildCount();
            for (int a = 0; a < count; a++) {
                View view = chatListView.getChildAt(a);
                if (view instanceof ChatAudioCell) {
                    ChatAudioCell cell = (ChatAudioCell) view;
                    if (cell.getMessageObject() != null && cell.getMessageObject().messageOwner.id == mid) {
                        cell.updateButtonState();
                        break;
                    }
                }
            }
        }
    } else if (id == NotificationCenter.audioProgressDidChanged) {
        Integer mid = (Integer) args[0];
        if (chatListView != null) {
            int count = chatListView.getChildCount();
            for (int a = 0; a < count; a++) {
                View view = chatListView.getChildAt(a);
                if (view instanceof ChatAudioCell) {
                    ChatAudioCell cell = (ChatAudioCell) view;
                    if (cell.getMessageObject() != null && cell.getMessageObject().messageOwner.id == mid) {
                        cell.updateProgress();
                        break;
                    }
                }
            }
        }
    } else if (id == NotificationCenter.removeAllMessagesFromDialog) {
        long did = (Long) args[0];
        if (dialog_id == did) {
            messages.clear();
            messagesByDays.clear();
            messagesDict.clear();
            progressView.setVisibility(View.GONE);
            chatListView.setEmptyView(emptyViewContainer);
            if (currentEncryptedChat == null) {
                maxMessageId = Integer.MAX_VALUE;
                minMessageId = Integer.MIN_VALUE;
            } else {
                maxMessageId = Integer.MIN_VALUE;
                minMessageId = Integer.MAX_VALUE;
            }
            maxDate = Integer.MIN_VALUE;
            minDate = 0;
            selectedMessagesIds.clear();
            selectedMessagesCanCopyIds.clear();
            actionBarLayer.hideActionMode();
            chatAdapter.notifyDataSetChanged();
        }
    } else if (id == NotificationCenter.screenshotTook) {
        updateInformationForScreenshotDetector();
    } else if (id == NotificationCenter.blockedUsersDidLoaded) {
        if (currentUser != null) {
            boolean oldValue = userBlocked;
            userBlocked = MessagesController.getInstance().blockedUsers.contains(currentUser.id);
            if (oldValue != userBlocked) {
                updateBottomOverlay();
            }
        }
    } else if (id == NotificationCenter.FileNewChunkAvailable) {
        MessageObject messageObject = (MessageObject) args[0];
        long finalSize = (Long) args[2];
        if (finalSize != 0 && dialog_id == messageObject.getDialogId()) {
            MessageObject currentObject = messagesDict.get(messageObject.messageOwner.id);
            if (currentObject != null) {
                currentObject.messageOwner.media.video.size = (int) finalSize;
                updateVisibleRows();
            }
        }
    } else if (id == NotificationCenter.didCreatedNewDeleteTask) {
        SparseArray<ArrayList<Integer>> mids = (SparseArray<ArrayList<Integer>>) args[0];
        boolean changed = false;
        for (int i = 0; i < mids.size(); i++) {
            int key = mids.keyAt(i);
            ArrayList<Integer> arr = mids.get(key);
            for (Integer mid : arr) {
                MessageObject messageObject = messagesDict.get(mid);
                if (messageObject != null) {
                    messageObject.messageOwner.destroyTime = key;
                    changed = true;
                }
            }
        }
        if (changed) {
            updateVisibleRows();
        }
    } else if (id == NotificationCenter.audioDidStarted) {
        MessageObject messageObject = (MessageObject) args[0];
        sendSecretMessageRead(messageObject);
    }
}

From source file:android.support.transition.TransitionPort.java

/**
 * This method, essentially a wrapper around all calls to createAnimator for all
 * possible target views, is called with the entire set of start/end
 * values. The implementation in Transition iterates through these lists
 * and calls {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}
 * with each set of start/end values on this transition. The
 * TransitionSet subclass overrides this method and delegates it to
 * each of its children in succession./*from   w  w w  .  j a va  2  s  . com*/
 *
 * @hide
 */
@RestrictTo(GROUP_ID)
protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues,
        TransitionValuesMaps endValues) {
    if (DBG) {
        Log.d(LOG_TAG, "createAnimators() for " + this);
    }
    ArrayMap<View, TransitionValues> endCopy = new ArrayMap<>(endValues.viewValues);
    SparseArray<TransitionValues> endIdCopy = new SparseArray<>(endValues.idValues.size());
    for (int i = 0; i < endValues.idValues.size(); ++i) {
        int id = endValues.idValues.keyAt(i);
        endIdCopy.put(id, endValues.idValues.valueAt(i));
    }
    LongSparseArray<TransitionValues> endItemIdCopy = new LongSparseArray<>(endValues.itemIdValues.size());
    for (int i = 0; i < endValues.itemIdValues.size(); ++i) {
        long id = endValues.itemIdValues.keyAt(i);
        endItemIdCopy.put(id, endValues.itemIdValues.valueAt(i));
    }
    // Walk through the start values, playing everything we find
    // Remove from the end set as we go
    ArrayList<TransitionValues> startValuesList = new ArrayList<>();
    ArrayList<TransitionValues> endValuesList = new ArrayList<>();
    for (View view : startValues.viewValues.keySet()) {
        TransitionValues start;
        TransitionValues end = null;
        boolean isInListView = false;
        if (view.getParent() instanceof ListView) {
            isInListView = true;
        }
        if (!isInListView) {
            int id = view.getId();
            start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view)
                    : startValues.idValues.get(id);
            if (endValues.viewValues.get(view) != null) {
                end = endValues.viewValues.get(view);
                endCopy.remove(view);
            } else if (id != View.NO_ID) {
                end = endValues.idValues.get(id);
                View removeView = null;
                for (View viewToRemove : endCopy.keySet()) {
                    if (viewToRemove.getId() == id) {
                        removeView = viewToRemove;
                    }
                }
                if (removeView != null) {
                    endCopy.remove(removeView);
                }
            }
            endIdCopy.remove(id);
            if (isValidTarget(view, id)) {
                startValuesList.add(start);
                endValuesList.add(end);
            }
        } else {
            ListView parent = (ListView) view.getParent();
            if (parent.getAdapter().hasStableIds()) {
                int position = parent.getPositionForView(view);
                long itemId = parent.getItemIdAtPosition(position);
                start = startValues.itemIdValues.get(itemId);
                endItemIdCopy.remove(itemId);
                // TODO: deal with targetIDs for itemIDs for ListView items
                startValuesList.add(start);
                endValuesList.add(end);
            }
        }
    }
    int startItemIdCopySize = startValues.itemIdValues.size();
    for (int i = 0; i < startItemIdCopySize; ++i) {
        long id = startValues.itemIdValues.keyAt(i);
        if (isValidTarget(null, id)) {
            TransitionValues start = startValues.itemIdValues.get(id);
            TransitionValues end = endValues.itemIdValues.get(id);
            endItemIdCopy.remove(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    // Now walk through the remains of the end set
    for (View view : endCopy.keySet()) {
        int id = view.getId();
        if (isValidTarget(view, id)) {
            TransitionValues start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view)
                    : startValues.idValues.get(id);
            TransitionValues end = endCopy.get(view);
            endIdCopy.remove(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    int endIdCopySize = endIdCopy.size();
    for (int i = 0; i < endIdCopySize; ++i) {
        int id = endIdCopy.keyAt(i);
        if (isValidTarget(null, id)) {
            TransitionValues start = startValues.idValues.get(id);
            TransitionValues end = endIdCopy.get(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    int endItemIdCopySize = endItemIdCopy.size();
    for (int i = 0; i < endItemIdCopySize; ++i) {
        long id = endItemIdCopy.keyAt(i);
        // TODO: Deal with targetIDs and itemIDs
        TransitionValues start = startValues.itemIdValues.get(id);
        TransitionValues end = endItemIdCopy.get(id);
        startValuesList.add(start);
        endValuesList.add(end);
    }
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    for (int i = 0; i < startValuesList.size(); ++i) {
        TransitionValues start = startValuesList.get(i);
        TransitionValues end = endValuesList.get(i);
        // Only bother trying to animate with values that differ between start/end
        if (start != null || end != null) {
            if (start == null || !start.equals(end)) {
                if (DBG) {
                    View view = (end != null) ? end.view : start.view;
                    Log.d(LOG_TAG, "  differing start/end values for view " + view);
                    if (start == null || end == null) {
                        Log.d(LOG_TAG, "    "
                                + ((start == null) ? "start null, end non-null" : "start non-null, end null"));
                    } else {
                        for (String key : start.values.keySet()) {
                            Object startValue = start.values.get(key);
                            Object endValue = end.values.get(key);
                            if (startValue != endValue && !startValue.equals(endValue)) {
                                Log.d(LOG_TAG,
                                        "    " + key + ": start(" + startValue + "), end(" + endValue + ")");
                            }
                        }
                    }
                }
                // TODO: what to do about targetIds and itemIds?
                Animator animator = createAnimator(sceneRoot, start, end);
                if (animator != null) {
                    // Save animation info for future cancellation purposes
                    View view;
                    TransitionValues infoValues = null;
                    if (end != null) {
                        view = end.view;
                        String[] properties = getTransitionProperties();
                        if (view != null && properties != null && properties.length > 0) {
                            infoValues = new TransitionValues();
                            infoValues.view = view;
                            TransitionValues newValues = endValues.viewValues.get(view);
                            if (newValues != null) {
                                for (int j = 0; j < properties.length; ++j) {
                                    infoValues.values.put(properties[j], newValues.values.get(properties[j]));
                                }
                            }
                            int numExistingAnims = runningAnimators.size();
                            for (int j = 0; j < numExistingAnims; ++j) {
                                Animator anim = runningAnimators.keyAt(j);
                                AnimationInfo info = runningAnimators.get(anim);
                                if (info.values != null && info.view == view
                                        && ((info.name == null && getName() == null)
                                                || info.name.equals(getName()))) {
                                    if (info.values.equals(infoValues)) {
                                        // Favor the old animator
                                        animator = null;
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        view = start.view;
                    }
                    if (animator != null) {
                        AnimationInfo info = new AnimationInfo(view, getName(),
                                WindowIdPort.getWindowId(sceneRoot), infoValues);
                        runningAnimators.put(animator, info);
                        mAnimators.add(animator);
                    }
                }
            }
        }
    }
}

From source file:android.support.transition.Transition.java

/**
 * This method, essentially a wrapper around all calls to createAnimator for all
 * possible target views, is called with the entire set of start/end
 * values. The implementation in Transition iterates through these lists
 * and calls {@link #createAnimator(android.view.ViewGroup, android.support.transition.TransitionValues, android.support.transition.TransitionValues)}
 * with each set of start/end values on this transition. The
 * TransitionSet subclass overrides this method and delegates it to
 * each of its children in succession./*from   w  w  w .  ja  v  a  2s.  c  o  m*/
 *
 * @hide
 */
protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues,
        TransitionValuesMaps endValues) {
    if (DBG) {
        Log.d(LOG_TAG, "createAnimators() for " + this);
    }
    ArrayMap<View, TransitionValues> endCopy = new ArrayMap<View, TransitionValues>(endValues.viewValues);
    SparseArray<TransitionValues> endIdCopy = new SparseArray<TransitionValues>(endValues.idValues.size());
    for (int i = 0; i < endValues.idValues.size(); ++i) {
        int id = endValues.idValues.keyAt(i);
        endIdCopy.put(id, endValues.idValues.valueAt(i));
    }
    LongSparseArray<TransitionValues> endItemIdCopy = new LongSparseArray<TransitionValues>(
            endValues.itemIdValues.size());
    for (int i = 0; i < endValues.itemIdValues.size(); ++i) {
        long id = endValues.itemIdValues.keyAt(i);
        endItemIdCopy.put(id, endValues.itemIdValues.valueAt(i));
    }
    // Walk through the start values, playing everything we find
    // Remove from the end set as we go
    ArrayList<TransitionValues> startValuesList = new ArrayList<TransitionValues>();
    ArrayList<TransitionValues> endValuesList = new ArrayList<TransitionValues>();
    for (View view : startValues.viewValues.keySet()) {
        TransitionValues start = null;
        TransitionValues end = null;
        boolean isInListView = false;
        if (view.getParent() instanceof ListView) {
            isInListView = true;
        }
        if (!isInListView) {
            int id = view.getId();
            start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view)
                    : startValues.idValues.get(id);
            if (endValues.viewValues.get(view) != null) {
                end = endValues.viewValues.get(view);
                endCopy.remove(view);
            } else if (id != View.NO_ID) {
                end = endValues.idValues.get(id);
                View removeView = null;
                for (View viewToRemove : endCopy.keySet()) {
                    if (viewToRemove.getId() == id) {
                        removeView = viewToRemove;
                    }
                }
                if (removeView != null) {
                    endCopy.remove(removeView);
                }
            }
            endIdCopy.remove(id);
            if (isValidTarget(view, id)) {
                startValuesList.add(start);
                endValuesList.add(end);
            }
        } else {
            ListView parent = (ListView) view.getParent();
            if (parent.getAdapter().hasStableIds()) {
                int position = parent.getPositionForView(view);
                long itemId = parent.getItemIdAtPosition(position);
                start = startValues.itemIdValues.get(itemId);
                endItemIdCopy.remove(itemId);
                // TODO: deal with targetIDs for itemIDs for ListView items
                startValuesList.add(start);
                endValuesList.add(end);
            }
        }
    }
    int startItemIdCopySize = startValues.itemIdValues.size();
    for (int i = 0; i < startItemIdCopySize; ++i) {
        long id = startValues.itemIdValues.keyAt(i);
        if (isValidTarget(null, id)) {
            TransitionValues start = startValues.itemIdValues.get(id);
            TransitionValues end = endValues.itemIdValues.get(id);
            endItemIdCopy.remove(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    // Now walk through the remains of the end set
    for (View view : endCopy.keySet()) {
        int id = view.getId();
        if (isValidTarget(view, id)) {
            TransitionValues start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view)
                    : startValues.idValues.get(id);
            TransitionValues end = endCopy.get(view);
            endIdCopy.remove(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    int endIdCopySize = endIdCopy.size();
    for (int i = 0; i < endIdCopySize; ++i) {
        int id = endIdCopy.keyAt(i);
        if (isValidTarget(null, id)) {
            TransitionValues start = startValues.idValues.get(id);
            TransitionValues end = endIdCopy.get(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    int endItemIdCopySize = endItemIdCopy.size();
    for (int i = 0; i < endItemIdCopySize; ++i) {
        long id = endItemIdCopy.keyAt(i);
        // TODO: Deal with targetIDs and itemIDs
        TransitionValues start = startValues.itemIdValues.get(id);
        TransitionValues end = endItemIdCopy.get(id);
        startValuesList.add(start);
        endValuesList.add(end);
    }
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    for (int i = 0; i < startValuesList.size(); ++i) {
        TransitionValues start = startValuesList.get(i);
        TransitionValues end = endValuesList.get(i);
        // Only bother trying to animate with values that differ between start/end
        if (start != null || end != null) {
            if (start == null || !start.equals(end)) {
                if (DBG) {
                    View view = (end != null) ? end.view : start.view;
                    Log.d(LOG_TAG, "  differing start/end values for view " + view);
                    if (start == null || end == null) {
                        Log.d(LOG_TAG, "    "
                                + ((start == null) ? "start null, end non-null" : "start non-null, end null"));
                    } else {
                        for (String key : start.values.keySet()) {
                            Object startValue = start.values.get(key);
                            Object endValue = end.values.get(key);
                            if (startValue != endValue && !startValue.equals(endValue)) {
                                Log.d(LOG_TAG,
                                        "    " + key + ": start(" + startValue + "), end(" + endValue + ")");
                            }
                        }
                    }
                }
                // TODO: what to do about targetIds and itemIds?
                Animator animator = createAnimator(sceneRoot, start, end);
                if (animator != null) {
                    // Save animation info for future cancellation purposes
                    View view = null;
                    TransitionValues infoValues = null;
                    if (end != null) {
                        view = end.view;
                        String[] properties = getTransitionProperties();
                        if (view != null && properties != null && properties.length > 0) {
                            infoValues = new TransitionValues();
                            infoValues.view = view;
                            TransitionValues newValues = endValues.viewValues.get(view);
                            if (newValues != null) {
                                for (int j = 0; j < properties.length; ++j) {
                                    infoValues.values.put(properties[j], newValues.values.get(properties[j]));
                                }
                            }
                            int numExistingAnims = runningAnimators.size();
                            for (int j = 0; j < numExistingAnims; ++j) {
                                Animator anim = runningAnimators.keyAt(j);
                                AnimationInfo info = runningAnimators.get(anim);
                                if (info.values != null && info.view == view
                                        && ((info.name == null && getName() == null)
                                                || info.name.equals(getName()))) {
                                    if (info.values.equals(infoValues)) {
                                        // Favor the old animator
                                        animator = null;
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        view = (start != null) ? start.view : null;
                    }
                    if (animator != null) {
                        AnimationInfo info = new AnimationInfo(view, getName(), infoValues);
                        runningAnimators.put(animator, info);
                        mAnimators.add(animator);
                    }
                }
            }
        }
    }
}