Search in sources :

Example 1 with ViewGroupOverlay

use of android.view.ViewGroupOverlay in project weiciyuan by qii.

the class FriendsTimeLineFragment method addNewDataAndRememberPositionAutoRefresh.

private void addNewDataAndRememberPositionAutoRefresh(final MessageListBean newValue) {
    int initSize = getList().getSize();
    if (getActivity() != null && newValue.getSize() > 0) {
        if (hasActionMode()) {
            AppLogger.v("ListView have ActionMode, skip notifyDataSetChanged");
            return;
        }
        final HeaderListView headerListView = (HeaderListView) getListView();
        View firstChildView = getListView().getChildAt(0);
        boolean isFirstViewHeader = headerListView.isThisViewHeader(firstChildView);
        if (isFirstViewHeader && !headerListView.isInTouchByUser()) {
            //                //Overlay is Android 4.3 method
            if (!Utility.isJB2()) {
                getList().addNewData(newValue);
                getAdapter().notifyDataSetChanged();
                Utility.setListViewItemPosition(getListView(), 0, 0, null);
                return;
            }
            //animate add item
            final ListView listView = getListView();
            final ArrayList<Pair<Long, Bitmap>> previousViewsBitmap = new ArrayList<Pair<Long, Bitmap>>();
            final HashMap<Long, Integer> previousViewsTop = new HashMap<Long, Integer>();
            final HashMap<Long, View> previousViews = new HashMap<Long, View>();
            int childCount = listView.getChildCount();
            for (int i = 0; i < childCount; i++) {
                View childView = listView.getChildAt(i);
                if (headerListView.isThisViewHeader(childView)) {
                    continue;
                }
                int firstAdapterItemPosition = listView.getFirstVisiblePosition();
                int currentAdapterItemPosition = firstAdapterItemPosition + i - listView.getHeaderViewsCount();
                long currentAdapterItemId = getAdapter().getItemId(currentAdapterItemPosition);
                int childViewTop = childView.getTop();
                Bitmap bitmap = Utility.getBitmapFromView(childView);
                Pair<Long, Bitmap> pair = new Pair<Long, Bitmap>(currentAdapterItemId, bitmap);
                previousViewsBitmap.add(pair);
                previousViewsTop.put(currentAdapterItemId, childViewTop);
                childView.setHasTransientState(true);
                previousViews.put(currentAdapterItemId, childView);
            }
            getList().addNewData(newValue);
            getAdapter().notifyDataSetChanged();
            getListView().getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

                @Override
                public boolean onPreDraw() {
                    listView.getViewTreeObserver().removeOnPreDrawListener(this);
                    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();
                    final ViewGroupOverlay overlay = listView.getOverlay();
                    Set<Long> previousViewsId = previousViews.keySet();
                    boolean somePreviousViewsAreStillInScreen = false;
                    ArrayList<View> newAddedItemViews = new ArrayList<View>();
                    int deltaY = 0;
                    int childCount = listView.getChildCount();
                    for (int i = 0; i < childCount; i++) {
                        View childView = listView.getChildAt(i);
                        if (headerListView.isThisViewHeader(childView)) {
                            continue;
                        }
                        int firstAdapterItemPosition = listView.getFirstVisiblePosition();
                        int currentAdapterItemPosition = firstAdapterItemPosition + i - listView.getHeaderViewsCount();
                        long currentAdapterItemId = getAdapter().getItemId(currentAdapterItemPosition);
                        if (previousViewsId.contains(currentAdapterItemId)) {
                            somePreviousViewsAreStillInScreen = true;
                            deltaY = childView.getTop() - previousViewsTop.get(currentAdapterItemId);
                        } else {
                            newAddedItemViews.add(childView);
                        }
                    }
                    if (!somePreviousViewsAreStillInScreen) {
                        deltaY = listView.getHeight();
                    }
                    for (View view : newAddedItemViews) {
                        view.setTranslationY(-deltaY);
                        view.animate().translationY(0).setInterpolator(decelerateInterpolator);
                    }
                    for (Pair<Long, Bitmap> pair : previousViewsBitmap) {
                        long id = pair.first;
                        int top = previousViewsTop.get(id);
                        final View view = previousViews.get(id);
                        final Bitmap bitmap = pair.second;
                        final ImageView imageView = new ImageView(getActivity());
                        imageView.setImageBitmap(bitmap);
                        imageView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                        imageView.layout(0, 0, imageView.getMeasuredWidth(), imageView.getMeasuredHeight());
                        overlay.add(imageView);
                        imageView.setTranslationY(top);
                        view.setAlpha(0);
                        imageView.animate().translationY(top + deltaY).setInterpolator(decelerateInterpolator).withEndAction(new Runnable() {

                            @Override
                            public void run() {
                                overlay.remove(imageView);
                                bitmap.recycle();
                                view.setAlpha(1.0f);
                                view.setHasTransientState(false);
                            }
                        });
                    }
                    return true;
                }
            });
            return;
        }
        getList().addNewData(newValue);
        Runnable endAction = new Runnable() {

            @Override
            public void run() {
                newMsgTipBar.setValue(newValue, false);
                newMsgTipBar.setType(TopTipBar.Type.ALWAYS);
            }
        };
        //keep current read position when user touch listview
        if (isFirstViewHeader && headerListView.isInTouchByUser()) {
            int index = getListView().getFirstVisiblePosition();
            getAdapter().notifyDataSetChanged();
            int finalSize = getList().getSize();
            final int positionAfterRefresh = index + finalSize - initSize + getListView().getHeaderViewsCount();
            //use 1 px to show newMsgTipBar
            Utility.setListViewItemPosition(getListView(), positionAfterRefresh, 1, endAction);
            return;
        }
        //need to calc the first child view's top distance
        int index = getListView().getFirstVisiblePosition();
        View firstAdapterItemView = Utility.getListViewFirstAdapterItemView(getListView());
        final int top = (firstAdapterItemView == null) ? 0 : firstAdapterItemView.getTop();
        getAdapter().notifyDataSetChanged();
        int finalSize = getList().getSize();
        final int positionAfterRefresh = index + finalSize - initSize;
        Utility.setListViewItemPosition(getListView(), positionAfterRefresh, top, endAction);
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HeaderListView(org.qii.weiciyuan.support.lib.HeaderListView) Bitmap(android.graphics.Bitmap) ListView(android.widget.ListView) HeaderListView(org.qii.weiciyuan.support.lib.HeaderListView) VelocityListView(org.qii.weiciyuan.support.lib.VelocityListView) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) Pair(android.util.Pair) ViewGroupOverlay(android.view.ViewGroupOverlay) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) HeaderListView(org.qii.weiciyuan.support.lib.HeaderListView) VelocityListView(org.qii.weiciyuan.support.lib.VelocityListView) WifiAutoDownloadPictureRunnable(org.qii.weiciyuan.othercomponent.WifiAutoDownloadPictureRunnable)

Example 2 with ViewGroupOverlay

use of android.view.ViewGroupOverlay in project android_frameworks_base by DirtyUnicorns.

the class ActivityTransitionCoordinator method moveSharedElementsFromOverlay.

protected void moveSharedElementsFromOverlay() {
    int numListeners = mGhostViewListeners.size();
    for (int i = 0; i < numListeners; i++) {
        GhostViewListeners listener = mGhostViewListeners.get(i);
        ViewGroup parent = (ViewGroup) listener.getView().getParent();
        parent.getViewTreeObserver().removeOnPreDrawListener(listener);
    }
    mGhostViewListeners.clear();
    if (mWindow == null || !mWindow.getSharedElementsUseOverlay()) {
        return;
    }
    ViewGroup decor = getDecor();
    if (decor != null) {
        ViewGroupOverlay overlay = decor.getOverlay();
        int count = mSharedElements.size();
        for (int i = 0; i < count; i++) {
            View sharedElement = mSharedElements.get(i);
            GhostView.removeGhost(sharedElement);
        }
    }
}
Also used : ViewGroupOverlay(android.view.ViewGroupOverlay) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) GhostView(android.view.GhostView) View(android.view.View)

Example 3 with ViewGroupOverlay

use of android.view.ViewGroupOverlay in project android_frameworks_base by crdroidandroid.

the class EnterTransitionCoordinator method startRejectedAnimations.

private void startRejectedAnimations(final ArrayList<View> rejectedSnapshots) {
    if (rejectedSnapshots == null || rejectedSnapshots.isEmpty()) {
        return;
    }
    final ViewGroup decorView = getDecor();
    if (decorView != null) {
        ViewGroupOverlay overlay = decorView.getOverlay();
        ObjectAnimator animator = null;
        int numRejected = rejectedSnapshots.size();
        for (int i = 0; i < numRejected; i++) {
            View snapshot = rejectedSnapshots.get(i);
            overlay.add(snapshot);
            animator = ObjectAnimator.ofFloat(snapshot, View.ALPHA, 1, 0);
            animator.start();
        }
        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                ViewGroupOverlay overlay = decorView.getOverlay();
                int numRejected = rejectedSnapshots.size();
                for (int i = 0; i < numRejected; i++) {
                    overlay.remove(rejectedSnapshots.get(i));
                }
            }
        });
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ViewGroupOverlay(android.view.ViewGroupOverlay) ViewGroup(android.view.ViewGroup) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) View(android.view.View)

Example 4 with ViewGroupOverlay

use of android.view.ViewGroupOverlay in project android_frameworks_base by crdroidandroid.

the class ActivityTransitionCoordinator method moveSharedElementsFromOverlay.

protected void moveSharedElementsFromOverlay() {
    int numListeners = mGhostViewListeners.size();
    for (int i = 0; i < numListeners; i++) {
        GhostViewListeners listener = mGhostViewListeners.get(i);
        ViewGroup parent = (ViewGroup) listener.getView().getParent();
        parent.getViewTreeObserver().removeOnPreDrawListener(listener);
    }
    mGhostViewListeners.clear();
    if (mWindow == null || !mWindow.getSharedElementsUseOverlay()) {
        return;
    }
    ViewGroup decor = getDecor();
    if (decor != null) {
        ViewGroupOverlay overlay = decor.getOverlay();
        int count = mSharedElements.size();
        for (int i = 0; i < count; i++) {
            View sharedElement = mSharedElements.get(i);
            GhostView.removeGhost(sharedElement);
        }
    }
}
Also used : ViewGroupOverlay(android.view.ViewGroupOverlay) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) GhostView(android.view.GhostView) View(android.view.View)

Example 5 with ViewGroupOverlay

use of android.view.ViewGroupOverlay in project platform_frameworks_base by android.

the class ActivityTransitionCoordinator method moveSharedElementsFromOverlay.

protected void moveSharedElementsFromOverlay() {
    int numListeners = mGhostViewListeners.size();
    for (int i = 0; i < numListeners; i++) {
        GhostViewListeners listener = mGhostViewListeners.get(i);
        ViewGroup parent = (ViewGroup) listener.getView().getParent();
        parent.getViewTreeObserver().removeOnPreDrawListener(listener);
    }
    mGhostViewListeners.clear();
    if (mWindow == null || !mWindow.getSharedElementsUseOverlay()) {
        return;
    }
    ViewGroup decor = getDecor();
    if (decor != null) {
        ViewGroupOverlay overlay = decor.getOverlay();
        int count = mSharedElements.size();
        for (int i = 0; i < count; i++) {
            View sharedElement = mSharedElements.get(i);
            GhostView.removeGhost(sharedElement);
        }
    }
}
Also used : ViewGroupOverlay(android.view.ViewGroupOverlay) ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) GhostView(android.view.GhostView) View(android.view.View)

Aggregations

View (android.view.View)11 ViewGroupOverlay (android.view.ViewGroupOverlay)11 ViewGroup (android.view.ViewGroup)10 ImageView (android.widget.ImageView)6 Animator (android.animation.Animator)5 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)5 ObjectAnimator (android.animation.ObjectAnimator)5 GhostView (android.view.GhostView)5 Bitmap (android.graphics.Bitmap)1 Pair (android.util.Pair)1 ViewTreeObserver (android.view.ViewTreeObserver)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 WifiAutoDownloadPictureRunnable (org.qii.weiciyuan.othercomponent.WifiAutoDownloadPictureRunnable)1 HeaderListView (org.qii.weiciyuan.support.lib.HeaderListView)1 VelocityListView (org.qii.weiciyuan.support.lib.VelocityListView)1