Search in sources :

Example 96 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project PhotoPicker by donglua.

the class PhotoPickerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.__picker_fragment_photo_picker, container, false);
    RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.rv_photos);
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(column, OrientationHelper.VERTICAL);
    layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(photoGridAdapter);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    final Button btSwitchDirectory = (Button) rootView.findViewById(R.id.button);
    listPopupWindow = new ListPopupWindow(getActivity());
    listPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
    listPopupWindow.setAnchorView(btSwitchDirectory);
    listPopupWindow.setAdapter(listAdapter);
    listPopupWindow.setModal(true);
    listPopupWindow.setDropDownGravity(Gravity.BOTTOM);
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            PhotoDirectory directory = directories.get(position);
            btSwitchDirectory.setText(directory.getName());
            photoGridAdapter.setCurrentDirectoryIndex(position);
            photoGridAdapter.notifyDataSetChanged();
        }
    });
    photoGridAdapter.setOnPhotoClickListener(new OnPhotoClickListener() {

        @Override
        public void onClick(View v, int position, boolean showCamera) {
            final int index = showCamera ? position - 1 : position;
            List<String> photos = photoGridAdapter.getCurrentPhotoPaths();
            ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(photos, index);
            ((PhotoPickerActivity) getActivity()).addImagePagerFragment(imagePagerFragment);
        }
    });
    photoGridAdapter.setOnCameraClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!PermissionsUtils.checkCameraPermission(PhotoPickerFragment.this))
                return;
            if (!PermissionsUtils.checkWriteStoragePermission(PhotoPickerFragment.this))
                return;
            openCamera();
        }
    });
    btSwitchDirectory.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (listPopupWindow.isShowing()) {
                listPopupWindow.dismiss();
            } else if (!getActivity().isFinishing()) {
                adjustHeight();
                listPopupWindow.show();
            }
        }
    });
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            // Log.d(">>> Picker >>>", "dy = " + dy);
            if (Math.abs(dy) > SCROLL_THRESHOLD) {
                mGlideRequestManager.pauseRequests();
            } else {
                resumeRequestsIfNotDestroyed();
            }
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                resumeRequestsIfNotDestroyed();
            }
        }
    });
    return rootView;
}
Also used : PhotoDirectory(me.iwf.photopicker.entity.PhotoDirectory) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ListPopupWindow(android.support.v7.widget.ListPopupWindow) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) RecyclerView(android.support.v7.widget.RecyclerView) AdapterView(android.widget.AdapterView) ArrayList(java.util.ArrayList) List(java.util.List) OnPhotoClickListener(me.iwf.photopicker.event.OnPhotoClickListener)

Example 97 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project SuperRecyclerView by Malinskiy.

the class SuperRecyclerView method caseStaggeredGrid.

private int caseStaggeredGrid(RecyclerView.LayoutManager layoutManager) {
    StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
    if (lastScrollPositions == null)
        lastScrollPositions = new int[staggeredGridLayoutManager.getSpanCount()];
    staggeredGridLayoutManager.findLastVisibleItemPositions(lastScrollPositions);
    return findMax(lastScrollPositions);
}
Also used : StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Example 98 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project InstaMaterial by frogermcs.

the class UserProfileActivity method setupUserProfileGrid.

private void setupUserProfileGrid() {
    final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    rvUserProfile.setLayoutManager(layoutManager);
    rvUserProfile.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            userPhotosAdapter.setLockedAnimations(true);
        }
    });
}
Also used : StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView)

Example 99 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project XRecyclerView by jianghejie.

the class XRecyclerView method onScrollStateChanged.

/**
 * ======================================================= end =======================================================
 */
@Override
public void onScrollStateChanged(int state) {
    super.onScrollStateChanged(state);
    if (state == RecyclerView.SCROLL_STATE_IDLE && mLoadingListener != null && !isLoadingData && loadingMoreEnabled) {
        LayoutManager layoutManager = getLayoutManager();
        int lastVisibleItemPosition;
        if (layoutManager instanceof GridLayoutManager) {
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
            ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(into);
            lastVisibleItemPosition = findMax(into);
        } else {
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
        }
        int adjAdapterItemCount = layoutManager.getItemCount() + getHeaders_includingRefreshCount();
        // Log.e("aaaaa","adjAdapterItemCount "+adjAdapterItemCount +" getItemCount "+layoutManager.getItemCount());
        int status = STATE_DONE;
        if (mRefreshHeader != null)
            status = mRefreshHeader.getState();
        if (layoutManager.getChildCount() > 0 && lastVisibleItemPosition >= adjAdapterItemCount - limitNumberToCallLoadMore && adjAdapterItemCount >= layoutManager.getChildCount() && !isNoMore && status < ArrowRefreshHeader.STATE_REFRESHING) {
            isLoadingData = true;
            if (mFootView instanceof LoadingMoreFooter) {
                ((LoadingMoreFooter) mFootView).setState(LoadingMoreFooter.STATE_LOADING);
            } else {
                if (footerViewCallBack != null) {
                    footerViewCallBack.onLoadingMore(mFootView);
                }
            }
            mLoadingListener.onLoadMore();
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 100 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project EasyRecyclerView by Jude95.

the class StaggeredGridActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);
    recyclerView = (EasyRecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setAdapter(adapter = new ImageAdapter(this));
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4);
    gridLayoutManager.setSpanSizeLookup(adapter.obtainGridSpanSizeLookUp(4));
    recyclerView.setLayoutManager(gridLayoutManager);
    adapter.addHeader(new RecyclerArrayAdapter.ItemView() {

        @Override
        public View onCreateView(ViewGroup parent) {
            RollPagerView header = new RollPagerView(StaggeredGridActivity.this);
            header.setHintView(new ColorPointHintView(StaggeredGridActivity.this, Color.YELLOW, Color.GRAY));
            header.setHintPadding(0, 0, 0, (int) Utils.convertDpToPixel(8, StaggeredGridActivity.this));
            header.setPlayDelay(2000);
            header.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) Utils.convertDpToPixel(200, StaggeredGridActivity.this)));
            header.setAdapter(new BannerAdapter(StaggeredGridActivity.this));
            return header;
        }

        @Override
        public void onBindView(View headerView) {
        }
    });
    SpaceDecoration itemDecoration = new SpaceDecoration((int) Utils.convertDpToPixel(8, this));
    itemDecoration.setPaddingEdgeSide(true);
    itemDecoration.setPaddingStart(true);
    itemDecoration.setPaddingHeaderFooter(true);
    recyclerView.addItemDecoration(itemDecoration);
    adapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() {

        @Override
        public void onMoreShow() {
            addData();
        }

        @Override
        public void onMoreClick() {
        }
    });
    adapter.setNoMore(R.layout.view_nomore);
    recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            recyclerView.postDelayed(new Runnable() {

                @Override
                public void run() {
                    adapter.clear();
                    adapter.addAll(DataProvider.getPictures(0));
                }
            }, 1000);
        }
    });
    addData();
}
Also used : ViewGroup(android.view.ViewGroup) SpaceDecoration(com.jude.easyrecyclerview.decoration.SpaceDecoration) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) ColorPointHintView(com.jude.rollviewpager.hintview.ColorPointHintView) RecyclerView(android.support.v7.widget.RecyclerView) EasyRecyclerView(com.jude.easyrecyclerview.EasyRecyclerView) RollPagerView(com.jude.rollviewpager.RollPagerView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) BannerAdapter(com.jude.dome.header.BannerAdapter) ColorPointHintView(com.jude.rollviewpager.hintview.ColorPointHintView) RollPagerView(com.jude.rollviewpager.RollPagerView)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)125 RecyclerView (android.support.v7.widget.RecyclerView)76 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)62 View (android.view.View)50 GridLayoutManager (android.support.v7.widget.GridLayoutManager)38 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)11 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)10 TextView (android.widget.TextView)10 Handler (android.os.Handler)9 BindView (butterknife.BindView)9 Intent (android.content.Intent)8 Nullable (android.support.annotation.Nullable)8 AbsListView (android.widget.AbsListView)8 ArrayList (java.util.ArrayList)8 ViewGroup (android.view.ViewGroup)6 WebView (android.webkit.WebView)6 ScrollView (android.widget.ScrollView)6 List (java.util.List)5 SuppressLint (android.annotation.SuppressLint)4 Point (android.graphics.Point)4