Java Code Examples for android.support.v7.widget.LinearLayoutManager

The following examples show how to use android.support.v7.widget.LinearLayoutManager. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: BaoKanAndroid   Source File: CollectionRecordActivity.java    License: MIT License 6 votes vote down vote up
/**
 * 准备数据
 */
private void prepareData() {
    mCollectionRecordRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
    mAdapter = new CollectionRecordRecyclerViewAdapter(mContext);
    mCollectionRecordRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.HORIZONTAL));
    mCollectionRecordRecyclerView.setAdapter(mAdapter);
    mAdapter.setOnItemTapListener(new CollectionRecordRecyclerViewAdapter.OnItemTapListener() {
        @Override
        public void onItemTapListener(CollectionRecordBean collectionRecordBean) {
            if (collectionRecordBean.getTbname().equals("photo")) {
                PhotoDetailActivity.start(mContext, collectionRecordBean.getClassid(), collectionRecordBean.getId());
            } else {
                NewsDetailActivity.start(mContext, collectionRecordBean.getClassid(), collectionRecordBean.getId());
            }
        }
    });
}
 
Example 2
private void setUpMetrics() {

        Context context = this.getActivity();
        SQLStore<Metric> store = openStore(context);
        store.openSync();

        Collection<Metric> array = store.readAll();
        metrics = new ArrayList<>(array);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        FavMetricsAdapter favMetricsAdapter = new FavMetricsAdapter(getActivity(), this, metrics);
        recyclerView.setAdapter(favMetricsAdapter);
        hideRefreshing();

        if(metrics.isEmpty()) {
            showMessage();
        } else {
            showList();
        }

        store.close();

    }
 
Example 3
Source Project: Word-By-Word-Quran-Android   Source File: AyahWordFragment.java    License: MIT License 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {

    super.onViewCreated(view, savedInstanceState);

    //set Adapter with Animation
    //  ScaleInAnimationAdapter scaleInAnimationAdapter = new ScaleInAnimationAdapter(ayahWordAdapter);
    //  scaleInAnimationAdapter.setInterpolator(new OvershootInterpolator());
    mRecyclerView.setAdapter(ayahWordAdapter);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);

    mRecyclerView.setVerticalScrollBarEnabled(true);


    //set headerview
    RecyclerViewHeader recyclerViewHeader = (RecyclerViewHeader) view.findViewById(R.id.header);
    TextView headerTextView = (TextView) recyclerViewHeader.findViewById(R.id.headerTextView);
    headerTextView.setText(getString(R.string.bismillah));
    recyclerViewHeader.attachTo(mRecyclerView, true);

}
 
Example 4
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  try {
    WXSDKEngine.registerModule("searchEvent", SearchModule.class);
  } catch (WXException e) {
    e.printStackTrace();
  }
  setContentView(R.layout.activity_slice_test);
  mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
  mReportTextView = (TextView) findViewById(R.id.report_text);

  mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
  mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
  mAdapter = new WXInstanceAdapter();
  mRecyclerView.setAdapter(mAdapter);
}
 
Example 5
Source Project: Orin   Source File: GravityDelegate.java    License: GNU General Public License v3.0 6 votes vote down vote up
public View findSnapView(RecyclerView.LayoutManager layoutManager) {
    View snapView = null;
    if (layoutManager instanceof LinearLayoutManager) {
        switch (gravity) {
            case Gravity.START:
                snapView = findStartView(layoutManager, getHorizontalHelper(layoutManager));
                break;
            case Gravity.END:
                snapView = findEndView(layoutManager, getHorizontalHelper(layoutManager));
                break;
            case Gravity.TOP:
                snapView = findStartView(layoutManager, getVerticalHelper(layoutManager));
                break;
            case Gravity.BOTTOM:
                snapView = findEndView(layoutManager, getVerticalHelper(layoutManager));
                break;
        }
    }
    snapping = snapView != null;
    return snapView;
}
 
Example 6
Source Project: bridgefy-android-samples   Source File: DevicesActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_devices);
    ButterKnife.bind(this);

    // initialize the DevicesAdapter and the RecyclerView
    devicesAdapter = new DevicesAdapter();
    devicesRecyclerView.setAdapter(devicesAdapter);
    devicesRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    // check that we have Location permissions
    if (ContextCompat.checkSelfPermission(getApplicationContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        initializeBridgefy();
    } else {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);
    }
}
 
Example 7
Source Project: OkSocket   Source File: ComplexDemoActivity.java    License: MIT License 6 votes vote down vote up
private void initData() {
    mIPET.setEnabled(false);
    mPortET.setEnabled(false);

    LinearLayoutManager manager1 = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mSendList.setLayoutManager(manager1);
    mSendList.setAdapter(mSendLogAdapter);

    LinearLayoutManager manager2 = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mReceList.setLayoutManager(manager2);
    mReceList.setAdapter(mReceLogAdapter);

    mInfo = new ConnectionInfo("104.238.184.237", 8080);

    final Handler handler = new Handler(Looper.getMainLooper());
    OkSocketOptions.Builder builder = new OkSocketOptions.Builder();
    builder.setReconnectionManager(new NoneReconnect());
    builder.setCallbackThreadModeToken(new OkSocketOptions.ThreadModeToken() {
        @Override
        public void handleCallbackEvent(ActionDispatcher.ActionRunnable runnable) {
            handler.post(runnable);
        }
    });
    mManager = OkSocket.open(mInfo).option(builder.build());
}
 
Example 8
Source Project: funcodetuts   Source File: PageFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_page, container, false);

    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.main_recycler);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity().getBaseContext());
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setHasFixedSize(true);

    List<String> list = new ArrayList<>();

    for (int i = 0; i < 10; i++) {
        list.add("Item " + i);
    }

    SimpleRecyclerAdapter adapter = new SimpleRecyclerAdapter(list);
    recyclerView.setAdapter(adapter);
    adapter.setOnItemTapListener(mListItemClickListener);
    return view;
}
 
Example 9
Source Project: Android-StickyNavLayout   Source File: TabFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.fragment_tab, container, false);
    mRecyclerView = (RecyclerView) view
            .findViewById(R.id.id_stickynavlayout_innerscrollview);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    // mTextView = (TextView) view.findViewById(R.id.id_info);
    // mTextView.setText(mTitle);
    for (int i = 0; i < 50; i++)
    {
        mDatas.add(mTitle + " -> " + i);
    }
    mRecyclerView.setAdapter(new CommonAdapter<String>(getActivity(), R.layout.item, mDatas)
    {
        @Override
        public void convert(ViewHolder holder, String o)
        {
            holder.setText(R.id.id_info, o);
        }
    });

    return view;

}
 
Example 10
Source Project: material-components-android   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.shr_main);

    Toolbar appBar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(appBar);

    ArrayList<ProductEntry> products = readProductsList();
    ImageRequester imageRequester = ImageRequester.getInstance(this);

    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.product_list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter = new ProductAdapter(products, imageRequester);
    recyclerView.setAdapter(adapter);
}
 
Example 11
Source Project: Android   Source File: ConversationFragment.java    License: MIT License 6 votes vote down vote up
/**
 * The view has been created
 *
 * @param savedInstanceState
 */
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    LogManager.getLogger().d(Tag, "onActivityCreated()");
    activity = getActivity();

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
    recyclerFragmentChat.setLayoutManager(linearLayoutManager);
    chatFragmentAdapter = new ChatListAdapter(activity, recyclerFragmentChat);
    recyclerFragmentChat.setAdapter(chatFragmentAdapter);
    recyclerFragmentChat.addItemDecoration(new LineDecoration(activity));
    recyclerFragmentChat.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            chatFragmentAdapter.closeMenu();
        }
    });

    loadRooms();
    EventBus.getDefault().register(this);
}
 
Example 12
Source Project: AccountBook   Source File: CountFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 初始化适配器
 */
private void initAdapter() {
    mRecyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(mContext)
            .color(R.color.colorDivide)
            .size(2)
            .build());
    mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
    mAdapter = new CountListAdapter(R.layout.item_count_list, new ArrayList<CountList>());
    mAdapter.setEmptyView(UiUtils.getEmptyView(mContext, mRecyclerView
            , UiUtils.getString(R.string.empty_count_data), R.mipmap.ic_pie_empty));
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.addOnItemTouchListener(new OnSimpleClickListener(){
        @Override
        public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
            CountList count = (CountList) baseQuickAdapter.getData().get(i);
            startActivity(new Intent(mContext, TypeCountDetailActivity.class)
                    .putExtra(AppConstants.EXTRA_TYPE_NAME, count.getTypeName())
                    .putExtra(AppConstants.EXTRA_TYPE, mCountType)
                    .putExtra(AppConstants.EXTRA_START_DATE, mStartDate)
                    .putExtra(AppConstants.EXTRA_END_DATE, mEndDate));
        }
    });
}
 
Example 13
Source Project: imsdk-android   Source File: WorkWorldAtListActivity.java    License: MIT License 6 votes vote down vote up
private void initAdapter() {
    workWorldAtListPresenter = new WorkWorldAtListManagerPresenter();
    workWorldAtListPresenter.setView(this);
    adapter = new WorkWorldAtListAdapter(this);
    isSelectAdapter = new WorkWorldAtListIsSelectAdapter(this);
    LinearLayoutManager manager = new LinearLayoutManager(this);
    manager.setOrientation(LinearLayoutManager.HORIZONTAL);
    work_world_isselect_rc.setLayoutManager(manager);
    work_world_isselect_rc.setAdapter(isSelectAdapter);
    adapter.setOnSelectChanage(list -> isSelectAdapter.setNewData(list));

    isSelectAdapter.setOnCancelLis(str -> {
        //操作树形列表
        adapter.setCancelInfo(str);
    });

    work_world_atlist_rc.setLayoutManager(new LinearLayoutManager(this));
    work_world_atlist_rc.addItemDecoration(new RecycleViewDivider(
            this, LinearLayoutManager.VERTICAL, 1, R.color.atom_ui_primary_color));
    work_world_atlist_rc.setAdapter(adapter);
}
 
Example 14
Source Project: alpha-wallet-android   Source File: SelectLocaleActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    toolbar();
    setTitle(getString(R.string.settings_locale_lang));

    currentLocale = getIntent().getStringExtra(C.EXTRA_LOCALE);

    ArrayList<LocaleItem> localeItems = getIntent().getParcelableArrayListExtra(C.EXTRA_STATE);

    if (localeItems != null) {
        recyclerView = findViewById(R.id.list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new CustomAdapter(localeItems, currentLocale);
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new ListDivider(this));
    }
}
 
Example 15
Source Project: talk-android   Source File: MessageSearchFragment.java    License: MIT License 6 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(adapter);
    recyclerView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP && recyclerViewState == RecyclerView.SCROLL_STATE_IDLE) {
                getActivity().getSupportFragmentManager()
                        .beginTransaction()
                        .setCustomAnimations(R.anim.anim_fade_in, R.anim.anim_fade_out)
                        .remove(MessageSearchFragment.this)
                        .commit();
                if (listener != null) {
                    listener.onRemoveFragment();
                }
            }
            return false;
        }
    });
    recyclerView.addOnScrollListener(scrollListener);
}
 
Example 16
Source Project: Loop   Source File: RelatedVideosFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);

        videosAdapter = new VideosAdapter();
        videosAdapter.setOnItemClickListener(this);
        videosAdapter.setOnReloadClickListener(this);

        recyclerView.setItemAnimator(new SlideInUpAnimator());
//        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(videosAdapter);

        // Pagination
        recyclerView.addOnScrollListener(recyclerViewOnScrollListener);

        Call findRelatedVideosCall = vimeoService.findRelatedVideos(videoId, currentPage, PAGE_SIZE);
        calls.add(findRelatedVideosCall);
        findRelatedVideosCall.enqueue(findRelatedVideosFirstFetchCallback);
    }
 
Example 17
Source Project: httplite   Source File: PostFrag.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.frag_get,container,false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.file_list);
    mPathTv = (TextView) view.findViewById(R.id.tv_request_path);
    mAdapter = new FileAdapter(null,this);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.addItemDecoration(new RecycleViewDivider(getContext(), LinearLayoutManager.HORIZONTAL));
    mBackUpBtn = (Button) view.findViewById(R.id.btn_back_up);
    mBackUpBtn.setOnClickListener(this);
    if(basePath==null){
        File file = getActivity().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
        if(file==null){
            file = getActivity().getCacheDir();
        }
        basePath = file.getAbsolutePath();
    }
    if(currentPath==null){
        currentPath = basePath;
    }
    mHttpLite = App.httpLite(getActivity());
    loadFiles(currentPath);
    return view;
}
 
Example 18
Source Project: styT   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    recyclerView.getItemAnimator().setAddDuration(100);
    recyclerView.getItemAnimator().setRemoveDuration(100);
    recyclerView.getItemAnimator().setMoveDuration(200);
    recyclerView.getItemAnimator().setChangeDuration(100);

    myAdapter = new RecyclerAdapter(this);
    recyclerView.setAdapter(myAdapter);
    myAdapter.setOnScrollToListener(new OnScrollToListener() {

        @Override
        public void scrollTo(int position) {
            recyclerView.scrollToPosition(position);
        }
    });
    initDatas();
}
 
Example 19
Source Project: YCRefreshView   Source File: EightCollapsingActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_collapsing);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    recyclerView = findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter = new PersonAdapter(this));
    adapter.setMore(R.layout.view_more, new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    adapter.addAll(DataProvider.getPersonList(0));
                }
            }, 1000);
        }
    });
    adapter.addAll(DataProvider.getPersonList(0));
    BannerView rollPagerView = findViewById(R.id.rollPagerView);
    rollPagerView.setHintView(new ColorPointHintView(this, Color.YELLOW,Color.GRAY));
    rollPagerView.setAdapter(new BannerAdapter());
}
 
Example 20
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);

  // Set the Recycler View adapter
  Context context = view.getContext();
  mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
  mRecyclerView.setAdapter(mEarthquakeAdapter);

  // Setup the Swipe to Refresh view
  mSwipeToRefreshView.setOnRefreshListener(
    new SwipeRefreshLayout.OnRefreshListener() {
      @Override
      public void onRefresh() {
        updateEarthquakes();
      }
    });
}
 
Example 21
Source Project: TestChat   Source File: DefaultItemTouchHelperCallback.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    //判断当前是否是swipe方式:侧滑。
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        //1.ItemView--ViewHolder; 2.侧滑条目的透明度程度关联谁?dX(delta增量,范围:当前条目-width~width)。
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        float alpha = 1;
        if (layoutManager instanceof LinearLayoutManager) {
            int orientation = ((LinearLayoutManager) layoutManager).getOrientation();
            if (orientation == LinearLayoutManager.HORIZONTAL) {
                alpha = 1 - Math.abs(dY) / viewHolder.itemView.getHeight();
            } else if (orientation == LinearLayoutManager.VERTICAL) {
                alpha = 1 - Math.abs(dX) / viewHolder.itemView.getWidth();
            }
        }
        viewHolder.itemView.setAlpha(alpha);//1~0
    }
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
 
Example 22
Source Project: ViewToImage   Source File: RecyclerViewActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initHorizontal() {
    mHorizontalRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_horizontal);

    // 创建一个线性布局管理器
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    // 设置布局管理器
    mHorizontalRecyclerView.setLayoutManager(layoutManager);

    // 创建数据集
    String[] dataset = new String[100];
    for (int i = 0; i < dataset.length; i++) {
        dataset[i] = "item" + i;
    }
    // 创建Adapter,并指定数据集
    MyRecyclerViewAdapter adapter = new MyRecyclerViewAdapter(dataset);
    // 设置Adapter
    mHorizontalRecyclerView.setAdapter(adapter);
}
 
Example 23
Source Project: SwipeRecyclerView-master   Source File: MenuFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(getContext(), R.color.divider_color)));

    mRecyclerView.setSwipeItemClickListener(mItemClickListener);
    mRecyclerView.setSwipeMenuCreator(mSwipeMenuCreator);
    mRecyclerView.setSwipeMenuItemClickListener(mMenuItemClickListener);

    MainAdapter menuAdapter = new MainAdapter(getContext());
    mRecyclerView.setAdapter(menuAdapter);
    List<String> dataList = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        dataList.add("我是第" + i + "个。");
    }
    menuAdapter.notifyDataSetChanged(dataList);
}
 
Example 24
Source Project: SimpleRecyclerView   Source File: StartSnapHelper.java    License: Apache License 2.0 6 votes vote down vote up
private View getStartView(RecyclerView.LayoutManager layoutManager,
                          OrientationHelper helper) {
  if (!(layoutManager instanceof LinearLayoutManager)) {
    return super.findSnapView(layoutManager);
  }

  LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;

  int firstChild = linearLayoutManager.findFirstVisibleItemPosition();

  boolean isLastItem = linearLayoutManager.findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1;

  if (firstChild == RecyclerView.NO_POSITION || isLastItem) {
    return null;
  }

  View child = layoutManager.findViewByPosition(firstChild);

  if (helper.getDecoratedEnd(child) >= helper.getDecoratedMeasurement(child) / 2
    && helper.getDecoratedEnd(child) > 0) {
    return child;
  } else {
    return layoutManager.findViewByPosition(firstChild + 1);
  }
}
 
Example 25
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_chat_groups_list, container, false);

    // init RecyclerView
    recyclerViewChatGroups = view.findViewById(R.id.chat_groups_list);
    recyclerViewChatGroups.addItemDecoration(new ItemDecoration(getContext(),
            DividerItemDecoration.VERTICAL,
            getResources().getDrawable(R.drawable.decorator_activity_my_groups_list)));
    lmRvChatGroups = new LinearLayoutManager(getActivity());
    recyclerViewChatGroups.setLayoutManager(lmRvChatGroups);
    updateChatGroupsListAdapter(chatGroupsSynchronizer.getChatGroups());

    // no contacts layout
    noChatGroupsLayout = view.findViewById(R.id.layout_no_groups);
    toggleNoContactsLayoutVisibility(chatGroupsListAdapter.getItemCount());

    chatGroupsSynchronizer.addGroupsListener(this);
    chatGroupsSynchronizer.connect();

    return view;
}
 
Example 26
Source Project: mosby   Source File: NotRetainingCountriesFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override public void onViewCreated(View view, @Nullable Bundle savedInstance) {
  super.onViewCreated(view, savedInstance);
  unbinder = ButterKnife.bind(this, view);

  // Setup contentView == SwipeRefreshView
  contentView.setOnRefreshListener(this);

  // Setup recycler view
  adapter = new CountriesAdapter(getActivity());
  recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
  recyclerView.setAdapter(adapter);
}
 
Example 27
Source Project: wallpaperboard   Source File: AboutAdapter.java    License: Apache License 2.0 5 votes vote down vote up
HeaderViewHolder(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);
    RecyclerView recyclerView = itemView.findViewById(R.id.recyclerview);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, true));
    recyclerView.setHasFixedSize(true);

    String[] urls = mContext.getResources().getStringArray(R.array.about_social_links);
    if (urls.length == 0) {
        recyclerView.setVisibility(View.GONE);

        subtitle.setPadding(
                subtitle.getPaddingLeft(),
                subtitle.getPaddingTop(),
                subtitle.getPaddingRight(),
                subtitle.getPaddingBottom() + mContext.getResources().getDimensionPixelSize(R.dimen.content_margin));
    } else {
        if (recyclerView.getLayoutParams() instanceof LinearLayout.LayoutParams) {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) recyclerView.getLayoutParams();
            if (urls.length < 7) {
                params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
                params.gravity = Gravity.CENTER_HORIZONTAL;
                recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
            }
        }
        recyclerView.setAdapter(new AboutSocialAdapter(mContext, urls));
    }

    subtitle.setHtml(mContext.getResources().getString(R.string.about_desc));

    CardView card = itemView.findViewById(R.id.card);
    if (!Preferences.get(mContext).isShadowEnabled()) {
        if (card != null) card.setCardElevation(0);

        profile.setShadowRadius(0f);
        profile.setShadowColor(Color.TRANSPARENT);
    }
}
 
Example 28
Source Project: AndroidPlayground   Source File: WrapContentMaxWidthManager.java    License: MIT License 5 votes vote down vote up
public WrapContentMaxWidthManager(Context context, boolean reverseLayout, int itemWidthDp,
        int itemMarginRightDp, int itemTotalHeightDp, int marginRightDp) {
    super(context, LinearLayoutManager.HORIZONTAL, reverseLayout);
    mContext = context;
    mItemWidthPx = dp2px(itemWidthDp);
    mItemTotalHeightPx = dp2px(itemTotalHeightDp);
    mItemMarginRightPx = dp2px(itemMarginRightDp);
    mMarginRightPx = dp2px(marginRightDp);
}
 
Example 29
public UpdatesViewBinder(final AppCompatActivity activity, FrameLayout parent) {
    this.activity = activity;
    View view = activity.getLayoutInflater().inflate(R.layout.main_tab_updates, parent, true);

    adapter = new UpdatesAdapter(activity);
    adapter.registerAdapterDataObserver(adapterChangeListener);

    list = (RecyclerView) view.findViewById(R.id.list);
    list.setHasFixedSize(true);
    list.setLayoutManager(new LinearLayoutManager(activity));
    list.setAdapter(adapter);

    ItemTouchHelper touchHelper = new ItemTouchHelper(new UpdatesItemTouchCallback(adapter));
    touchHelper.attachToRecyclerView(list);

    emptyState = (TextView) view.findViewById(R.id.empty_state);
    emptyImage = (ImageView) view.findViewById(R.id.image);
    emptyUpdatingProgress = view.findViewById(R.id.empty_updating_progress);

    final SwipeRefreshLayout swipeToRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipe_to_refresh);
    Utils.applySwipeLayoutColors(swipeToRefresh);
    swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            swipeToRefresh.setRefreshing(false);
            UpdateService.updateNow(activity);
        }
    });

}
 
Example 30
Source Project: CodePolitan   Source File: ArticlesByCategoryFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void setUpRecyclerView()
{
    recyclerView.clearOnScrollListeners();
    recyclerView.setUpAsList();
    recyclerView.addOnScrollListener(new BenihRecyclerListener((LinearLayoutManager) recyclerView.getLayoutManager())
    {
        @Override
        public void onLoadMore(int i)
        {
            currentPage++;
            articleController.loadArticles(data, currentPage);
        }
    });
}