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);
}
}
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);
}
}
}
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));
}
}
});
}
}
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);
}
}
}
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);
}
}
}
Aggregations