Example usage for android.view ViewGroup PERSISTENT_ANIMATION_CACHE

List of usage examples for android.view ViewGroup PERSISTENT_ANIMATION_CACHE

Introduction

In this page you can find the example usage for android.view ViewGroup PERSISTENT_ANIMATION_CACHE.

Prototype

int PERSISTENT_ANIMATION_CACHE

To view the source code for android.view ViewGroup PERSISTENT_ANIMATION_CACHE.

Click Source Link

Document

Used to indicate that the animation drawing cache should be kept in memory.

Usage

From source file:us.shandian.blacklight.ui.statuses.TimeLineFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    initTitle();/*from   w w w . ja  v a  2 s  . c om*/

    View v = inflater.inflate(R.layout.home_timeline, null);
    mList = (ListView) v.findViewById(R.id.home_timeline);
    mCache = bindApiCache();
    mCache.loadFromCache();
    mAdapter = new WeiboAdapter(getActivity(), mList, mCache.mMessages, mBindOrig, mShowCommentStatus);
    mList.setAdapter(mAdapter);

    mList.setDrawingCacheEnabled(true);
    mList.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    mList.setPersistentDrawingCache(
            ViewGroup.PERSISTENT_ANIMATION_CACHE | ViewGroup.PERSISTENT_SCROLLING_CACHE);

    // Swipe To Refresh
    bindSwipeToRefresh((ViewGroup) v);

    if (mCache.mMessages.getSize() == 0) {
        new Refresher().execute(new Boolean[] { true });
    }

    // Floating "New" button
    bindNewButton(v);

    return v;
}

From source file:info.papdt.blacklight.ui.statuses.TimeLineFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mActionBar = ((ToolbarActivity) getActivity()).getSupportActionBar();
    mToolbar = ((ToolbarActivity) getActivity()).getToolbar();
    initTitle();//from  www. ja  va2 s  .c o m
    mSettings = Settings.getInstance(getActivity().getApplicationContext());

    final View v = inflater.inflate(R.layout.home_timeline, null);

    // Initialize views
    mList = Utility.findViewById(v, R.id.home_timeline);
    mShadow = Utility.findViewById(v, R.id.action_shadow);

    mCache = bindApiCache();
    mCache.loadFromCache();

    mList.setDrawingCacheEnabled(true);
    mList.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    mList.setPersistentDrawingCache(
            ViewGroup.PERSISTENT_ANIMATION_CACHE | ViewGroup.PERSISTENT_SCROLLING_CACHE);

    mManager = new LinearLayoutManager(getActivity());
    mList.setLayoutManager(mManager);

    // Swipe To Refresh
    bindSwipeToRefresh((ViewGroup) v);

    if (mCache.mMessages.getSize() == 0) {
        new Refresher().execute(true);
    }

    // Adapter
    mAdapter = new WeiboAdapter(getActivity(), mList, mCache.mMessages, mBindOrig, mShowCommentStatus);

    // Content Margin
    if (getActivity() instanceof MainActivity && mAllowHidingActionBar) {
        View header = new View(getActivity());
        RecyclerView.LayoutParams p = new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT,
                Utility.getDecorPaddingTop(getActivity()));
        header.setLayoutParams(p);
        mAdapter.setHeaderView(header);
        mSwipeRefresh.setProgressViewOffset(false, 0,
                (int) ((p.height + Utility.dp2px(getActivity(), 20)) * 1.2));
    }

    mList.setAdapter(mAdapter);

    // Listener
    if (getActivity() instanceof MainActivity) {
        mAdapter.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView view, int dx, int dy) {
                int deltaY = -dy;
                boolean shouldShow = deltaY > 0;
                if (shouldShow != mFABShowing) {
                    if (shouldShow) {
                        showFAB();
                    } else {
                        hideFAB();
                    }
                }

                if (mAllowHidingActionBar) {
                    if ((mTranslationY > -mActionBarHeight && deltaY < 0)
                            || (mTranslationY < 0 && deltaY > 0)) {

                        mTranslationY += deltaY;
                    }

                    if (mTranslationY < -mActionBarHeight) {
                        mTranslationY = -mActionBarHeight;
                    } else if (mTranslationY > 0) {
                        mTranslationY = 0;
                    }

                    updateTranslation();
                }

                mFABShowing = shouldShow;
                mLastY = dy;
            }
        });
    }

    mAdapter.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView v, int dx, int dy) {
            if (!mRefreshing && mManager.findLastVisibleItemPosition() >= mAdapter.getItemCount() - 5) {
                new Refresher().execute(false);
            }
        }
    });

    mShadow.bringToFront();

    v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (getActivity() instanceof MainActivity && mAllowHidingActionBar) {
                mActionBarHeight = mToolbar.getHeight();
                mShadow.setTranslationY(mActionBarHeight);
                RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) mAdapter.getHeaderView()
                        .getLayoutParams();
                lp.height = mActionBarHeight;
                mAdapter.getHeaderView().setLayoutParams(lp);
                mSwipeRefresh.setProgressViewOffset(false, 0, (int) (mActionBarHeight * 1.2));
                mSwipeRefresh.invalidate();
                v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });

    return v;
}