@Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    recyclerView = (RecyclerView) view.findViewById(R.id.list_recyclerViewFragment_content);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 4);
    gridLayoutManager.setSpanSizeLookup(
        new GridLayoutManager.SpanSizeLookup() {
          @Override
          public int getSpanSize(int position) {
            RecyclerView.Adapter adapter = recyclerView.getAdapter();
            if (adapter == null || !(adapter instanceof AssemblyRecyclerAdapter)) {
              return 1;
            }
            return ((AssemblyRecyclerAdapter) adapter).getSpanSize(position);
          }
        });
    recyclerView.setLayoutManager(gridLayoutManager);

    if (adapter != null) {
      recyclerView.setAdapter(adapter);
    } else {
      loadAppList();
    }
  }
Пример #2
0
  @Override
  public void onItemClick(MainEntity entity, int position) {

    View target;
    if (position == 0) {
      target =
          gridLayoutManager
              .findViewByPosition(position)
              .findViewById(R.id.list_item_header_temp_iv);
    } else {
      target =
          gridLayoutManager.findViewByPosition(position).findViewById(R.id.list_item_grid_temp_iv);
    }

    Rect startBounds = new Rect();
    target.getGlobalVisibleRect(startBounds);

    if (globalOffset == null) {
      globalOffset = new Point();
      Rect rootRect = new Rect();
      rootView.getGlobalVisibleRect(rootRect, globalOffset);
    }
    startBounds.offset(-globalOffset.x, -globalOffset.y);

    if (this.rxBus == null) {
      this.rxBus = MyApplication.get().getRxBus();
    }
    this.rxBus.postStickEvent(entity);

    DetailActivity.navigateToDetail(ListActivity.this, startBounds, globalOffset);
    overridePendingTransition(0, 0);
  }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = gridLayoutManager.getItemCount();
    firstVisibleItem = gridLayoutManager.findFirstVisibleItemPosition();

    if (isVisible && scrollDist > MINIMUM) {
      onHideShow(true);
      scrollDist = 0;
      isVisible = false;
    } else if (!isVisible && scrollDist < -MINIMUM) {
      onHideShow(false);
      scrollDist = 0;
      isVisible = true;
    }
    if ((isVisible && dy > 0) || (!isVisible && dy < 0)) {
      scrollDist += dy;
    }

    if (loading) {
      if (totalItemCount > previousTotal + 1) {
        loading = false;
        previousTotal = totalItemCount;
      }
    }
    if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
      // End has been reached
      // Do something
      current_page++;
      onLoadMore(current_page, totalItemCount);
      loading = true;
    }
  }
Пример #4
0
  /**
   * 设置每个条目占用的列数
   *
   * @param recyclerView recycleView
   */
  private void setSpanCount(RecyclerView recyclerView) {
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

    if (layoutManager == null) {
      Log.e(TAG, "LayoutManager 为空,请先设置 recycleView.setLayoutManager(...)");
    }

    // 网格布局
    if (layoutManager instanceof GridLayoutManager) {
      final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
      gridLayoutManager.setSpanSizeLookup(
          new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
              int type = getItemViewType(position);
              if (type == TYPE_NORMAL_ITEM) {
                return 1;
              } else {
                return gridLayoutManager.getSpanCount();
              }
            }
          });
    }

    // 瀑布流布局
    if (layoutManager instanceof StaggeredGridLayoutManager) {
      mStaggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
    }
  }
  @Override
  public RecyclerView.LayoutManager getLayoutManager() {
    if (layoutManager == null) {
      final GridLayoutManager gridLayoutManager =
          new GridLayoutManager(getActivity(), SPAN_COUNT, LinearLayoutManager.VERTICAL, false);
      gridLayoutManager.setSpanSizeLookup(
          new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
              final int itemViewType = adapter.getItemViewType(position);
              switch (itemViewType) {
                case AvailableActorsListAdapter.DATA_ITEM:
                  return 1;
                case AvailableActorsListAdapter.LOADING_ITEM:
                  return SPAN_COUNT;
                default:
                  return GridLayoutManager.DEFAULT_SPAN_COUNT;
              }
            }
          });

      layoutManager = gridLayoutManager;
    }

    return layoutManager;
  }
  // Métodos de la interfaz
  @Override
  public void generarGridLayout() {
    GridLayoutManager glm = new GridLayoutManager(getActivity(), 3);
    glm.setOrientation(GridLayoutManager.VERTICAL);
    rvPerfilMascota.setLayoutManager(glm);

    Picasso.with(activity)
        .load(PerfilMascota.fotoUsuario)
        .placeholder(R.drawable.grumpy_cat_head)
        .into(imgFotoPerfil);

    tvNombrePerfil.setText(PerfilMascota.nombreUsuario);
  }
  private void selectShade(int position) {
    ImageView shellSelected;

    for (int i = 0; i < shadeAdapter.getItemCount(); i++) {
      if (recyclerView.getChildAt(i) != null) {
        shellSelected = ((ImageView) recyclerView.getChildAt(i).findViewById(R.id.shell_selected));
        if (shellSelected.getVisibility() == View.VISIBLE) {
          shellSelected.setVisibility(View.GONE);
        }
      }
    }

    GridLayoutManager layoutManager = (GridLayoutManager) recyclerView.getLayoutManager();

    if (getSelectionMode() == SelectionModeEnum.SINGLE_SELECTION_MODE) {

      View view = recyclerView.getChildAt(position - layoutManager.findFirstVisibleItemPosition());

      if (shadeAdapter.getSelectedShade() == position) {
        shadeAdapter.setSelectedShade(-1);

        view.findViewById(R.id.shell_selected).setVisibility(View.INVISIBLE);

      } else {
        shadeAdapter.setSelectedShade(position);

        view.findViewById(R.id.shell_selected).setVisibility(View.VISIBLE);
      }

    } else if (getSelectionMode() == SelectionModeEnum.MULTIPLE_SELECTION_MODE) {

      if (selected.contains(position)) {
        selected.remove((Integer) position);

      } else {
        selected.add(position);
      }

      shadeAdapter.setSelected(selected);

      for (int item : shadeAdapter.getSelected()) {

        if (item >= layoutManager.findFirstVisibleItemPosition()
            && item <= layoutManager.findLastVisibleItemPosition()) {

          View view = recyclerView.getChildAt(item - layoutManager.findFirstVisibleItemPosition());
          view.findViewById(R.id.shell_selected).setVisibility(View.VISIBLE);
        }
      }
    }
  }
  private void setupAdapter() {

    GridLayoutManager gridLayoutManager = new GridLayoutManager(SearchActivity.this, 5);
    gridLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    gridLayoutManager.setSmoothScrollbarEnabled(true);

    searchAdapter = new SearchAdapter(this);
    searchAdapter.setCallback(SearchActivity.this);

    recyclerView.setLayoutManager(gridLayoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(searchAdapter);
    recyclerView.addItemDecoration(new MarginDecoration(SearchActivity.this, R.dimen.material_4dp));
  }
Пример #9
0
  @Override
  public void onBindViewHolder(BindingHolder holder, final int position) {
    try {
      try {
        holder
            .getBinding()
            .setVariable(
                getBRClass().getDeclaredField("data").getInt(getBRClass().newInstance()),
                deals.get(position));
        ;
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InstantiationException e) {
        e.printStackTrace();
      }
    } catch (NoSuchFieldException e) {
      e.printStackTrace();
    }

    holder.getBinding().executePendingBindings();

    // add footer
    if (holder.getBinding() instanceof LceLoadingFooterBinding && recycle != null) {
      RecyclerView.LayoutManager manager = recycle.getLayoutManager();
      if (manager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager.LayoutParams layoutParams =
            new StaggeredGridLayoutManager.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        layoutParams.setFullSpan(true);
        holder.getBinding().getRoot().setLayoutParams(layoutParams);
      } else if (manager instanceof LinearLayoutManager) {
      } else if (manager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) manager;
        final GridLayoutManager.SpanSizeLookup lookup = gridLayoutManager.getSpanSizeLookup();
        gridLayoutManager.setSpanSizeLookup(
            new GridLayoutManager.SpanSizeLookup() {
              @Override
              public int getSpanSize(int inner_position) {
                if (position == inner_position) {
                  return gridLayoutManager.getSpanCount();
                } else {
                  return lookup.getSpanSize(inner_position);
                }
              }
            });
      }
    } else {
      onBind(holder, deals.get(position), mv.getModel(getItemViewType(position)), position);
    }
  }
Пример #10
0
 protected void initViews(View fragmentView) {
   textView.setVisibility(View.GONE);
   if (getArguments() != null && getArguments().getInt(SearchActivity.TAG_NONE) > 1) {
     String text = getArguments().getString(SearchActivity.TAG_KEY);
     textView.setText(getString(R.string.search_none, text));
     textView.setVisibility(View.VISIBLE);
   }
   adapter = new SearchKeysAdapter();
   recyclerView.setAdapter(adapter);
   GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), COUNT_COLUMS);
   gridLayoutManager.setSpanSizeLookup(adapter.getSpanSizeLookup());
   recyclerView.setLayoutManager(gridLayoutManager);
   loadHistory();
 }
  public SectionedGridRecyclerViewAdapter(
      Context context,
      int sectionResourceId,
      int textResourceId,
      RecyclerView recyclerView,
      RecyclerView.Adapter baseAdapter) {
    mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mSectionResourceId = sectionResourceId;
    mTextResourceId = textResourceId;
    mBaseAdapter = baseAdapter;
    mContext = context;
    mRecyclerView = recyclerView;
    mBaseAdapter.registerAdapterDataObserver(
        new RecyclerView.AdapterDataObserver() {
          @Override
          public void onChanged() {
            mValid = mBaseAdapter.getItemCount() > 0;
            notifyDataSetChanged();
          }

          @Override
          public void onItemRangeChanged(int positionStart, int itemCount) {
            mValid = mBaseAdapter.getItemCount() > 0;
            notifyItemRangeChanged(positionStart, itemCount);
          }

          @Override
          public void onItemRangeInserted(int positionStart, int itemCount) {
            mValid = mBaseAdapter.getItemCount() > 0;
            notifyItemRangeInserted(positionStart, itemCount);
          }

          @Override
          public void onItemRangeRemoved(int positionStart, int itemCount) {
            mValid = mBaseAdapter.getItemCount() > 0;
            notifyItemRangeRemoved(positionStart, itemCount);
          }
        });

    final GridLayoutManager layoutManager = (GridLayoutManager) (mRecyclerView.getLayoutManager());
    layoutManager.setSpanSizeLookup(
        new GridLayoutManager.SpanSizeLookup() {
          @Override
          public int getSpanSize(int position) {
            return (isSectionHeaderPosition(position)) ? layoutManager.getSpanCount() : 1;
          }
        });
  }
  public GridAdapter(final Context context) {
    super(context);
    layoutManager =
        new GridLayoutManager(context, 2) {
          private final int columnWidth =
              context.getResources().getDimensionPixelSize(R.dimen.columnWidth);
          private boolean columnWidthChanged = true;

          @Override
          public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
            if (columnWidthChanged && columnWidth > 0) {
              int totalSpace;
              if (getOrientation() == VERTICAL) {
                totalSpace = getWidth() - getPaddingRight() - getPaddingLeft();
              } else {
                totalSpace = getHeight() - getPaddingTop() - getPaddingBottom();
              }
              int spanCount = Math.max(1, totalSpace / columnWidth);
              setSpanCount(spanCount);
              columnsChanged();
              columnWidthChanged = false;
            }
            super.onLayoutChildren(recycler, state);
          }
        };
    layoutManager.setSpanSizeLookup(
        new GridLayoutManager.SpanSizeLookup() {
          @Override
          public int getSpanSize(int position) {
            return getSpan(position);
          }
        });
  }
Пример #13
0
 /**
  * *********************************************************************************************
  */
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
   swipeRefreshLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW);
   swipeRefreshLayout.setOnRefreshListener(
       new SwipeRefreshLayout.OnRefreshListener() {
         @Override
         public void onRefresh() {
           swipeRefreshLayout.setRefreshing(true);
           layoutManager.scrollToPosition(0);
           imageItemList.clear();
           currentPage = 1;
           refreshItems(currentPage);
         }
       });
   layoutManager = new GridLayoutManager(this, 3);
   layoutManager.setOrientation(GridLayoutManager.VERTICAL);
   sharkRecyclerView = (RecyclerView) findViewById(R.id.sharkRecyclerView);
   sharkRecyclerView.setLayoutManager(layoutManager);
   imageItemAdapter = new ImageItemAdapter(imageItemList, this);
   sharkRecyclerView.setAdapter(imageItemAdapter);
   sharkRecyclerView.setItemAnimator(new DefaultItemAnimator());
   addScrollListener();
 }
Пример #14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (getActionBar() != null) {
      getActionBar().setDisplayHomeAsUpEnabled(true);
    }
    String[] projection = new String[] {MediaStore.MediaColumns.DATA};
    mGalleryCursor =
        getContentResolver()
            .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    GridLayoutManager glm = new GridLayoutManager(this, COUNT_ITEMS_IN_LINE);
    mRecyclerView.setLayoutManager(glm);
    mRecyclerView.setAdapter(new MyRecyclerAdapter(this, mGalleryCursor, glm.getSpanCount()));
  }
 @Override
 protected void onMeasure(int widthSpec, int heightSpec) {
   super.onMeasure(widthSpec, heightSpec);
   if (gridWidthPx != -1 && gridManager != null && lastMeasuredWidth != getMeasuredWidth()) {
     int spanCount = Math.max(1, getMeasuredWidth() / gridWidthPx);
     gridManager.setSpanCount(spanCount);
     lastMeasuredWidth = getMeasuredWidth();
   }
 }
Пример #16
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   // Se salva el estado del RecyclerView.
   mEstadoLista = mGridLayoutManager.onSaveInstanceState();
   outState.putParcelable(STATE_LISTA, mEstadoLista);
   outState.putParcelableArrayList(STATE_LISTA_DATOS, mAdaptador.getData());
   outState.putString(STATE_MAX_TAG_ID, mMaxTagId);
 }
Пример #17
0
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    int lastVisibleItem = 0;
    int firstVisibleItem = 0;
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int totalItemCount = layoutManager.getItemCount();
    if (layoutManager instanceof LinearLayoutManager) {
      LinearLayoutManager linearLayoutManager = ((LinearLayoutManager) layoutManager);
      lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
      firstVisibleItem = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
    } else if (layoutManager instanceof GridLayoutManager) {
      GridLayoutManager gridLayoutManager = ((GridLayoutManager) layoutManager);
      // 通过LayoutManager找到当前显示的最后的item的position
      lastVisibleItem = gridLayoutManager.findLastVisibleItemPosition();
      firstVisibleItem = gridLayoutManager.findFirstCompletelyVisibleItemPosition();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
      StaggeredGridLayoutManager staggeredGridLayoutManager =
          ((StaggeredGridLayoutManager) layoutManager);
      // 因为StaggeredGridLayoutManager的特殊性可能导致最后显示的item存在多个,所以这里取到的是一个数组
      // 得到这个数组后再取到数组中position值最大的那个就是最后显示的position值了
      int[] lastPositions = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
      staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
      lastVisibleItem = findMax(lastPositions);
      firstVisibleItem = staggeredGridLayoutManager.findFirstVisibleItemPositions(lastPositions)[0];
    }
    if (firstVisibleItem == 0) {
      if (!mPullLoadMoreRecyclerView.isLoadMore()) {
        mPullLoadMoreRecyclerView.setPullRefreshEnable(true);
      }
    } else {
      mPullLoadMoreRecyclerView.setPullRefreshEnable(false);
    }

    /** 无论水平还是垂直 */
    if (!mPullLoadMoreRecyclerView.isRefresh()
        && mPullLoadMoreRecyclerView.isHasMore()
        && (lastVisibleItem >= totalItemCount - 1)
        && !mPullLoadMoreRecyclerView.isLoadMore()
        && (dx > 0 || dy > 0)) {
      mPullLoadMoreRecyclerView.setIsLoadMore(true);
      mPullLoadMoreRecyclerView.loadMore();
    }
  }
 @Override
 public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
   RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
   if (layoutManager instanceof GridLayoutManager) {
     final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
     if (gridLayoutManager.getSpanSizeLookup() == null)
       gridLayoutManager.setSpanSizeLookup(
           new GridLayoutManager.SpanSizeLookup() {
             @Override
             public int getSpanSize(int position) {
               BaseTurboAdapter adapter = (BaseTurboAdapter) recyclerView.getAdapter();
               if (isFullSpanType(adapter.getItemViewType(position))) {
                 return gridLayoutManager.getSpanCount();
               }
               return 1;
             }
           });
   }
 }
Пример #19
0
 @Override
 public void onResume() {
   super.onResume();
   // Se retaura el estado de la lista.
   if (mEstadoLista != null) {
     mGridLayoutManager.onRestoreInstanceState(mEstadoLista);
   }
   // Se resetea el detector de scroll.
   mEndlessScrollListener.reset(0, true);
 }
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   View view = inflater.inflate(R.layout.icon_fragment, container, false);
   Display display = getActivity().getWindowManager().getDefaultDisplay();
   Point size = new Point();
   display.getSize(size);
   int numOfRows = (int) (size.x / getResources().getDimension(R.dimen.size_of_grid_item));
   RecyclerView gridview = (RecyclerView) view.findViewById(R.id.icons_rv);
   GridLayoutManager layoutManager = new GridLayoutManager(view.getContext(), numOfRows);
   layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
   layoutManager.scrollToPosition(0);
   gridview.setLayoutManager(layoutManager);
   gridview.setHasFixedSize(true);
   gridview.addItemDecoration(new SpacesItemDecoration(10, 5));
   gridview.setAdapter(
       new IconsAdapter(view.getContext(), getArguments().getInt("iconsArrayId", 0)));
   return view;
 }
Пример #21
0
  /**
   * Sets the content spans of grid count of this view
   *
   * @param span
   */
  public void setContentSpan(int span) {
    if (span < 1) return;
    if (mContentWrapper.getLayoutManager() == null) return;

    RecyclerView.LayoutManager lManager = mContentWrapper.getLayoutManager();
    if (lManager instanceof GridLayoutManager) {
      ((GridLayoutManager) lManager).setSpanCount(span);
      mContentWrapper.invalidate();
    }
  }
  private void measureScrapChild(
      RecyclerView.Recycler recycler,
      int position,
      int widthSpec,
      int heightSpec,
      int[] measuredDimension) {

    if (position < getItemCount()) {
      try {
        View view = recycler.getViewForPosition(position); // fix 动态添加时报IndexOutOfBoundsException
        if (view.getVisibility() == View.GONE) {
          measuredDimension[0] = 0;
          measuredDimension[1] = 0;
          return;
        }
        RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
        // For adding Item Decor Insets to view
        super.measureChildWithMargins(view, 0, 0);
        /*  全部 0
        final int l = getLeftDecorationWidth(view);
          final int r = getRightDecorationWidth(view);
          final int t = getTopDecorationHeight(view);
          final int b = getBottomDecorationHeight(view);
          System.out.println("measureScrapChild  Decoration [ position_"+position+"]:  left = "
                  + l +" ,right = " + r +" ,top = " + t +" ,bottom = " + b);*/
        //  measureChild(view, widthSpec, heightSpec);
        // measureChildWithMargins(view,0,0);
        int childWidthSpec =
            ViewGroup.getChildMeasureSpec(
                widthSpec,
                getPaddingLeft()
                    + getPaddingRight()
                    + getLeftDecorationWidth(view)
                    + getRightDecorationWidth(view),
                p.width);
        int childHeightSpec =
            ViewGroup.getChildMeasureSpec(
                heightSpec,
                getPaddingTop()
                    + getPaddingBottom()
                    + getTopDecorationHeight(view)
                    + getBottomDecorationHeight(view),
                p.height);
        view.measure(childWidthSpec, childHeightSpec);

        measuredDimension[0] = getDecoratedMeasuredWidth(view) + p.leftMargin + p.rightMargin;
        measuredDimension[1] = getDecoratedMeasuredHeight(view) + p.bottomMargin + p.topMargin;
        // measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
        // measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
        recycler.recycleView(view);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Пример #23
0
  /**
   * Sets the orientation of content display of this view
   *
   * @param orientation
   */
  public void setContentOrientation(int orientation) {
    if (orientation != CONTENT_ORIENTATION_HORIZONTAL
        && orientation != CONTENT_ORIENTATION_VERTICAL) return;
    if (mContentWrapper.getLayoutManager() == null) return;

    RecyclerView.LayoutManager lManager = mContentWrapper.getLayoutManager();
    if (lManager instanceof GridLayoutManager) {
      ((GridLayoutManager) lManager).setOrientation(orientation);
      mContentOrientation = orientation;
      mContentWrapper.invalidate();
    }
  }
  public void setLayoutManager(LayoutManager layoutManager) {
    super.setLayoutManager(layoutManager);
    if (mWrapperAdapter != null) {

      if (layoutManager instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final int spanCount = gridLayoutManager.getSpanCount();
        gridLayoutManager.setSpanSizeLookup(
            new GridLayoutManager.SpanSizeLookup() {
              @Override
              public int getSpanSize(int position) {
                return (mWrapperAdapter.isHeader(position)
                            || mWrapperAdapter.isFooter(position)
                            || mWrapperAdapter.isLoadMoreView(position))
                        || mWrapperAdapter.isPullRefreshView(position)
                    ? spanCount
                    : 1;
              }
            });
      }
    }
  }
Пример #25
0
  private void setupAdapter() {

    this.swipeRefreshLayout.setColorSchemeResources(Constants.colors);

    this.compositeSubscription.add(
        RxSwipeRefreshLayout.refreshes(swipeRefreshLayout)
            .compose(ListActivity.this.<Void>bindUntilEvent(ActivityEvent.DESTROY))
            .subscribe(
                new SimpleObserver<Void>() {
                  @Override
                  public void onNext(Void o) {
                    /*refresh*/
                    listPresenter.loadData();
                  }
                }));

    gridLayoutManager = new GridLayoutManager(ListActivity.this, 2);
    gridLayoutManager.setSmoothScrollbarEnabled(true);

    gridLayoutManager.setSpanSizeLookup(
        new GridLayoutManager.SpanSizeLookup() {
          @Override
          public int getSpanSize(int position) {
            /*position == 0*/
            return forecastAdapter.isHeader(position) ? gridLayoutManager.getSpanCount() : 1;
          }
        });

    forecastAdapter = new ForecastAdapter(ListActivity.this);
    forecastAdapter.setCallback(ListActivity.this);

    recyclerView.setLayoutManager(gridLayoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(forecastAdapter);
    recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    recyclerView.addItemDecoration(new GridDecoration(ListActivity.this));
  }
Пример #26
0
 @Override
 public void onListLoaded(String jsonResult) {
   try {
     if (jsonResult != null) {
       try {
         JSONObject jsonResponse = new JSONObject(jsonResult);
         JSONArray jsonMainNode = jsonResponse.optJSONArray("walls");
         for (int i = 0; i < jsonMainNode.length(); i++) {
           JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
           items.add(
               new WallpaperItem(
                   jsonChildNode.optString("name"),
                   jsonChildNode.optString("author"),
                   jsonChildNode.optString("url")));
         }
       } catch (JSONException e) {
         e.printStackTrace();
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   RecyclerView gridview = (RecyclerView) findViewById(R.id.wall_rv);
   Display display = getWindowManager().getDefaultDisplay();
   Point size = new Point();
   display.getSize(size);
   (findViewById(R.id.progressBar_wall)).setVisibility(View.GONE);
   int numOfRows = (int) (size.x / getResources().getDimension(R.dimen.size_of_grid_item));
   GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
   layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
   layoutManager.scrollToPosition(0);
   gridview.setLayoutManager(layoutManager);
   gridview.setHasFixedSize(true);
   gridview.addItemDecoration(new SpacesItemDecoration(8, 2));
   gridview.setAdapter(new WallAdapter(this, items, display));
 }
Пример #27
0
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ButterKnife.bind(this, view);
    mRecyclerView.setPadding(0, mActivity.getFragmentTopInset(), 0, 0);
    mAdapter = new CourseListAdapter(mActivity.getScreenHalfWidth());
    CircularRevealItemAnimator animator = new CircularRevealItemAnimator();
    animator.setAddDuration(150);

    GridLayoutManager mGridManager = new GridLayoutManager(mActivity, 2);
    mGridManager.setSpanSizeLookup(
        new GridLayoutManager.SpanSizeLookup() {
          @Override
          public int getSpanSize(int position) {
            return mAdapter.getItemColumnSpan(position);
          }
        });
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(mGridManager);
    mRecyclerView.setItemAnimator(animator);
    mRecyclerView.setOnScrollListener(mActivity.getScrollOverToolbarListener());
    mRecyclerView.setAdapter(mAdapter);
    mUserActionsListener.onFragmentResumed();
  }
 @Override
 public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
   if (mColumnWidthChanged && mColumnWidth > 0) {
     int totalSpace;
     if (getOrientation() == VERTICAL) {
       totalSpace = getWidth() - getPaddingRight() - getPaddingLeft();
     } else {
       totalSpace = getHeight() - getPaddingTop() - getPaddingBottom();
     }
     int spanCount = Math.max(1, totalSpace / mColumnWidth);
     setSpanCount(spanCount);
     mColumnWidthChanged = false;
   }
   super.onLayoutChildren(recycler, state);
 }
  @Override
  public void setLayoutManager(LayoutManager layout) {
    super.setLayoutManager(layout);

    if (null == layout) return;

    if (layout instanceof GridLayoutManager) {
      mCurGridLayoutManager = ((GridLayoutManager) layout);
      mCurGridLayoutManager.setSpanSizeLookup(
          new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
              if (position < getHeaderViewsCount()
                  || position >= mReqAdapter.getItemCount() + getHeaderViewsCount()) {
                // header or footer span
                return mCurGridLayoutManager.getSpanCount();
              } else {
                // default item span
                return 1;
              }
            }
          });

      mLayoutManagerType = LAYOUT_MANAGER_TYPE_GRID;
      setDivider(mVerticalDivider, mHorizontalDivider);
    } else if (layout instanceof StaggeredGridLayoutManager) {
      mLayoutManagerType = LAYOUT_MANAGER_TYPE_STAGGERED_GRID;
      setDivider(mVerticalDivider, mHorizontalDivider);
    } else if (layout instanceof LinearLayoutManager) {
      mLayoutManagerType = LAYOUT_MANAGER_TYPE_LINEAR;
      if (((LinearLayoutManager) layout).getOrientation() == LinearLayoutManager.HORIZONTAL) {
        setDividerVertical(mVerticalDivider);
      } else {
        setDividerHorizontal(mHorizontalDivider);
      }
    }
  }
 @Override
 public void onConfigurationChanged(Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   if (gridManager != null)
     gridManager.setSpanCount(getResources().getInteger(R.integer.media_overview_cols));
 }