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

The following are top voted examples for showing how to use android.support.v7.widget.LinearLayoutManager. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: mobile-app-dev-book   File: JournalFragment.java   View source code 9 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_journal_list, container, false);

    // Set the adapter
    if (view instanceof RecyclerView) {
        FirebaseDatabase dbRef = FirebaseDatabase.getInstance();
        FirebaseAuth auth = FirebaseAuth.getInstance();
        FirebaseUser user = auth.getCurrentUser();
        DatabaseReference userRef = dbRef.getReference(user.getUid());
        userRef.addChildEventListener (chEvListener);
        userRef.addValueEventListener(valEvListener);
        Context context = view.getContext();
        RecyclerView recyclerView = (RecyclerView) view;
        if (mColumnCount <= 1) {
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
        } else {
            recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
        }
        adapter = new JournalAdapter(allTrips, mListener);
        recyclerView.setAdapter(adapter);
    }
    return view;
}
 
Example 2
Project: RLibrary   File: RecyclerViewPager.java   View source code 7 votes vote down vote up
/**
 * 计算每个Item的宽度
 */
public int getItemWidth() {
    final LayoutManager layoutManager = getLayoutManager();
    int itemWidth = 0;
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final int spanCount = gridLayoutManager.getSpanCount();
        if (gridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
            itemWidth = getRawWidth() / (mItemCount / spanCount);
        } else {
            itemWidth = getRawWidth() / spanCount;
        }

    } else if (layoutManager instanceof LinearLayoutManager) {
        final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
            itemWidth = getRawWidth() / mItemCount;
        } else {
            itemWidth = getRawWidth();
        }
    }

    return itemWidth;
}
 
Example 3
Project: MeetMusic   File: ThemeActivity.java   View source code 6 votes vote down vote up
private void init(){
    for (int i = 0 ;i < themeType.length;i++){
        ThemeInfo info = new ThemeInfo();
        info.setName(themeType[i]);
        info.setColor(colors[i]);
        info.setSelect((selectTheme == i) ? true : false);
        if (i == themeType.length-1){
            info.setBackground(R.color.nightBg);
        }else {
            info.setBackground(R.color.colorWhite);
        }
        themeInfoList.add(info);
    }
    recyclerView = (RecyclerView)findViewById(R.id.theme_rv);
    adapter = new ThemeAdapter();
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setAdapter(adapter);

}
 
Example 4
Project: GitHub   File: MainFragment.java   View source code 6 votes vote down vote up
@Override
protected void initData() {
    List<ItemModel> items = new ArrayList<>();
    fillData(items);

    adapter = new MainAdapter(items);
    adapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
    adapter.isFirstOnly(false);
    adapter.setOnLoadMoreListener(this);

    refreshLayout.setColorSchemeColors(Color.RED, Color.BLUE, Color.GREEN);
    refreshLayout.setOnRefreshListener(this);

    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new DividerItemDecoration(context, LinearLayoutManager.VERTICAL));

    recyclerView.setAdapter(adapter);
}
 
Example 5
Project: adapters-android   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RecyclerView rcViewList = (RecyclerView) findViewById(R.id.rc_item);
    rcViewList.setAdapter(new ItemAdapter(generateFakeItems(), new OnItemClickListener() {
        @Override
        public void onItemClick(int position) {
            startActivity(new Intent(MainActivity.this, FragmentPagerActivity.class));
        }
    }));
    rcViewList.setLayoutManager(new LinearLayoutManager(this));
    rcViewList.addItemDecoration(new DividerItemDecoration(this,
                                                           DividerItemDecoration.VERTICAL));
}
 
Example 6
Project: Mix   File: BackTopActivity.java   View source code 6 votes vote down vote up
private void initView(List<String> list) {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setHasFixedSize(true);
    linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setSmoothScrollbarEnabled(true);
    recyclerView.setLayoutManager(linearLayoutManager);
    ListRecyclerAdapter adapter = new ListRecyclerAdapter(list);
    recyclerView.setAdapter(adapter);

    FAB = (FloatingActionButton) findViewById(R.id.fab);
    FAB.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            linearLayoutManager.scrollToPosition(0);
            hideFAB();
        }
    });
}
 
Example 7
Project: BilibiliClient   File: VideoIntroductionFragment.java   View source code 6 votes vote down vote up
private void setVideoRelated() {

    List<VideoDetailsInfo.DataBean.RelatesBean> relates = mVideoDetailsInfo.getRelates();
    if (relates == null) {
      mVideoRelatedLayout.setVisibility(View.GONE);
      return;
    }
    VideoRelatedAdapter mVideoRelatedAdapter = new VideoRelatedAdapter(mRecyclerView, relates);
    mRecyclerView.setHasFixedSize(false);
    mRecyclerView.setNestedScrollingEnabled(false);
    mRecyclerView.setLayoutManager(
        new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, true));
    mRecyclerView.setAdapter(mVideoRelatedAdapter);
    mVideoRelatedAdapter.setOnItemClickListener(
        (position, holder) -> VideoDetailsActivity.launch(getActivity(),
            relates.get(position).getAid(), relates.get(position).getPic()));
  }
 
Example 8
Project: vlayout   File: OnePlusNLayoutHelper.java   View source code 6 votes vote down vote up
@Override
public int computeAlignOffset(int offset, boolean isLayoutEnd, boolean useAnchor,
        LayoutManagerHelper helper) {
    //Log.d(TAG,
    //    "range " + getRange() + " offset " + offset + " isLayoutEnd " + isLayoutEnd + " useAnchor " + useAnchor
    //        + " helper " + this.hashCode());
    final boolean layoutInVertical = helper.getOrientation() == LinearLayoutManager.VERTICAL;

    if (useAnchor) {
        return 0;
    }
    if (isLayoutEnd) {
        if (offset == getItemCount() - 1) {
            return layoutInVertical ? mMarginBottom + mPaddingBottom : mMarginRight + mPaddingRight;
        }
    } else {
        if (offset == 0) {
            return layoutInVertical ? -mMarginTop - mPaddingTop : -mMarginLeft - mPaddingLeft;
        }
    }
    return 0;
}
 
Example 9
Project: SuperNatives   File: HeroesListActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    AndroidInjection.inject(this);
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_heroes_list);
    context = this;

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context,
            LinearLayoutManager.VERTICAL, false);
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(context,
            linearLayoutManager.getOrientation());
    binding.rvHeroes.setLayoutManager(linearLayoutManager);
    binding.rvHeroes.addItemDecoration(dividerItemDecoration);
    binding.rvHeroes.setAdapter(heroesAdapter);
    binding.fastScroll.setRecyclerView(binding.rvHeroes);

    heroesAdapter.setOnClickListener(position -> presenter.onSuperHeroClicked(position));

    binding.btnTryAgain.setOnClickListener(v -> presenter.getSuperHeroes());

    binding.btnTryAgain.performClick();
}
 
Example 10
Project: Remindy   File: TaskDetailActivity.java   View source code 6 votes vote down vote up
private void setUpRecyclerView() {

        if(mTask.getAttachments().size() > 0) {
            mAttachmentsSubtitle.setVisibility(View.VISIBLE);

            mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
            mAdapter = new AttachmentAdapter(this, mTask.getAttachments(), true);
            mAdapter.setAttachmentDataUpdatedListener(new AttachmentAdapter.AttachmentDataUpdatedListener() {
                @Override
                public void onAttachmentDataUpdated() {
                    mTaskDataUpdated = true;
                }
            });
            DividerItemDecoration itemDecoration = new DividerItemDecoration(this, mLayoutManager.getOrientation());
            itemDecoration.setDrawable(ContextCompat.getDrawable(this, R.drawable.item_decoration_half_line));
            mRecyclerView.addItemDecoration(itemDecoration);
            mRecyclerView.setNestedScrollingEnabled(false);

            mRecyclerView.setLayoutManager(mLayoutManager);
            mRecyclerView.setAdapter(mAdapter);
        }
    }
 
Example 11
Project: BounceView   File: BounceMenu.java   View source code 6 votes vote down vote up
private BounceMenu(View view, int resId, final MyAdapter myAdapter) {
    parentVG = findParentVG(view);

    rootView = LayoutInflater.from(view.getContext()).inflate(resId,null,false);
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
    bounceView = (BounceView) rootView.findViewById(R.id.bounceview);

    recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
    bounceView.setAnimatorListener(new BounceView.BounceAnimatorListener() {
        @Override
        public void showContent() {
            recyclerView.setVisibility(View.VISIBLE);
            recyclerView.setAdapter(myAdapter);
            recyclerView.scheduleLayoutAnimation();
        }
    });
}
 
Example 12
Project: Pilem   File: MovieInfoFragment.java   View source code 6 votes vote down vote up
private void setUpInfo(View view) {
    RecyclerView rvInfo = (RecyclerView) view.findViewById(R.id.rv_movie_detail_info);
    ArrayList<ItemInfo> infoItems = new ArrayList<>();
    String overviewValStr = view.getResources().getString(R.string.lorem_ipsum_long);

    infoItems.add(new ItemInfo("Overview", overviewValStr));
    infoItems.add(new ItemInfo("Tagline", "Divided We Fall"));
    infoItems.add(new ItemInfo("Status", "Releases"));
    infoItems.add(new ItemInfo("Budget", "250.000.000"));
    infoItems.add(new ItemInfo("Revenue", "1.153.304.495"));
    infoItems.add(new ItemInfo("Homepage", "http://marvel.com/captainamericapremiere"));

    RecyclerAdapter infoAdapter = new RecyclerAdapter<ItemInfo, MovieInfoViewHolder>(
            R.layout.item_movie_info, ItemInfo.class, infoItems, MovieInfoViewHolder.class) {
        @Override
        protected void bindView(MovieInfoViewHolder holder, ItemInfo model, int position) {
            holder.getLabel().setText(model.getLabel());
            holder.getValue().setText(model.getValue());
        }
    };

    rvInfo.setLayoutManager(new LinearLayoutManager(view.getContext()));
    rvInfo.setAdapter(infoAdapter);
    rvInfo.addItemDecoration(new MovieInfoViewHolder.ItemDecoration());
}
 
Example 13
Project: RunMap   File: V2MainFragment.java   View source code 6 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
        int firstItemPosition = linearManager.findFirstVisibleItemPosition();
        if(firstItemPosition == 0 || mContentListAdapter.getItemCount() == 0){
            mRefreshLayout.setEnabled(true);
            CFLog.e("V2MainFragment", "arrive top");
        }
        else{
            mRefreshLayout.setEnabled(false);
        }
    }
}
 
Example 14
Project: GCSApp   File: YearDelegate.java   View source code 6 votes vote down vote up
public void setData(ArrayList<FinancingInfo> data,boolean isRefresh) {
    if (isRefresh){
        mData.clear();
    }
    mData.addAll(data);
    if (null == adapter) {
        manager = new LinearLayoutManager(getActivity());
        mRec.addItemDecoration(new DividerGridItemDecoration(getActivity()));
        adapter = new YearAdapter(mData, getActivity());
        mRec.setAdapter(adapter);
        mRec.setLayoutManager(manager);
    } else {
        adapter.notifyDataSetChanged();

    }
}
 
Example 15
Project: Guanajoven   File: PromocionFragment.java   View source code 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_promociones, container, false);
    rvPromociones = (RecyclerView) view.findViewById(R.id.rv_promociones);
    textViewEmptyPromociones = (TextView) view.findViewById(R.id.textview_empty_promociones);

    LinearLayoutManager llm = new LinearLayoutManager(getContext());
    adapter = new RVPromocionAdapter(getContext(), empresa.getPromociones(), empresa);

    rvPromociones.setLayoutManager(llm);
    rvPromociones.setAdapter(adapter);

    if (empresa.getPromociones().isEmpty()) {
        textViewEmptyPromociones.setVisibility(View.VISIBLE);
    }

    return view;
}
 
Example 16
Project: Expert-Android-Programming   File: FollowingFragment.java   View source code 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    this.context = getActivity();

    list = new ArrayList<>();
    recyclerViewAdapter = new FriendAdapter(getActivity(), list);
   /* recyclerViewAdapter.setClickListener(new FriendAdapter.ClickListener() {
        @Override
        public void onItemClickListener(View v, int pos) {
            gotoDetailsActivity();
        }

        @Override
        public void onFriendListener(int pos, boolean isFollowing) {

        }
    });*/

    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setAdapter(recyclerViewAdapter);

    getFollowing();
}
 
Example 17
Project: SimpleBible   File: BookSelectionFragment.java   View source code 6 votes vote down vote up
@Override
public void update(Observable observable, Object o) {
    mBooks.clear();
    if (o instanceof IBookProvider && ((IBookProvider)o).getBooks() != null) {
        mBooks.addAll(((IBookProvider)o).getBooks());
        mAdapter.notifyDataSetChanged();

        if (CurrentSelected.getBook() != null) {
            for (IBook book : mBooks) {
                if (book.getId().equalsIgnoreCase(CurrentSelected.getBook().getId())) {
                    ((LinearLayoutManager)mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(mBooks.indexOf(book), mRecyclerView.getHeight()/2);
                }
            }
        }
    }
}
 
Example 18
Project: Aequorea   File: TagActivity.java   View source code 6 votes vote down vote up
@Override
protected void initView() {
    ButterKnife.bind(this);
    
    mToolbar.setNavigationIcon(R.drawable.icon_ab_back_material);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    mToolbar.setTitle(mModel.getTitle());
    mCoordinatorLayout.setPadding(0, DisplayUtils.getStatusBarHeight(getResources()), 0, 0);
    
    mAdapter = new SimpleArticleListAdapter(this, null);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.addOnScrollListener(mScrollListener);
    
    setStatusBarStyle();
}
 
Example 19
Project: GitHub   File: RecyclerViewActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view);
    mRecyclerView = (RecyclerView) findViewById(R.id.rv_pop);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    List<String> list = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        list.add("");
    }
    mPopAdapter = new RecyclerPopAdapter();
    mPopAdapter.setNewData(list);
    mRecyclerView.setAdapter(mPopAdapter);
    initPop();
    initEvents();
}
 
Example 20
Project: mobile-app-dev-book   File: JournalFragment.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_journal_list, container, false);

    // Set the adapter
    if (view instanceof RecyclerView) {
        FirebaseDatabase dbRef = FirebaseDatabase.getInstance();
        FirebaseAuth auth = FirebaseAuth.getInstance();
        FirebaseUser user = auth.getCurrentUser();
        DatabaseReference userRef = dbRef.getReference(user.getUid());
        userRef.addChildEventListener (chEvListener);
        userRef.addValueEventListener(valEvListener);
        Context context = view.getContext();
        RecyclerView recyclerView = (RecyclerView) view;
        if (mColumnCount <= 1) {
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
        } else {
            recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
        }
        adapter = new JournalAdapter(allTrips, mListener);
        recyclerView.setAdapter(adapter);
    }
    return view;
}
 
Example 21
Project: QMUI_Android   File: QDSnapHelperFragment.java   View source code 6 votes vote down vote up
private void showBottomSheetList() {
    new QMUIBottomSheet.BottomListSheetBuilder(getActivity())
            .addItem("水平方向")
            .addItem("垂直方向")
            .setOnSheetItemClickListener(new QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener() {
                @Override
                public void onClick(QMUIBottomSheet dialog, View itemView, int position, String tag) {
                    dialog.dismiss();
                    switch (position) {
                        case 0:
                            mPagerLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                            break;
                        case 1:
                            mPagerLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                            break;
                        default:
                            break;
                    }
                }
            })
            .build()
            .show();
}
 
Example 22
Project: GracefulMovies   File: OpenLicenseActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_open_license);
    ButterKnife.bind(this);

    initializeToolbar();

    String[] libs = getResources().getStringArray(R.array.libraries);
    String[] licenses = getResources().getStringArray(R.array.licenses);
    List<OpenModel> list = new ArrayList<>();
    OpenModel openModel;
    for (int i = 0; i < libs.length; i++) {
        openModel = new OpenModel();
        openModel.setName(libs[i]);
        openModel.setLicense(licenses[i]);
        list.add(openModel);
    }
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setAdapter(new LicenseListAdapter(list));
}
 
Example 23
Project: GitHub   File: CardViewRecyclerActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.card_view_recycler_layout);
    top_bar_linear_back=(LinearLayout)this.findViewById(R.id.top_bar_linear_back);
    top_bar_linear_back.setOnClickListener(new CustomOnClickListener());
    top_bar_title=(TextView)this.findViewById(R.id.top_bar_title);
    top_bar_title.setText("CardView结合RecyclerView使用实例");

    recycler_cardview=(RecyclerView)this.findViewById(R.id.recycler_cardview);
    LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);
    recycler_cardview.setLayoutManager(linearLayoutManager);
    recycler_cardview.setAdapter(new CardViewAdapter(this));


}
 
Example 24
Project: gdgApp   File: HomeSection.java   View source code 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    recyclerView.setHasFixedSize(true);
    LinearLayoutManager manager = new LinearLayoutManager(getContext());
    manager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recyclerView.setLayoutManager(manager);
    recyclerView.setAdapter(adapter);
    UpdateMessages();
    UpdateEvents();
    //noinspection ConstantConditions
    typeface = Typeface.createFromAsset(getActivity().getAssets(), Constants.PathConstants.PRODUCT_SANS_FONT);

    notificationTitle.setTypeface(typeface);
    notificationMessage.setTypeface(typeface);
    notificationAuthorTime.setTypeface(typeface);
}
 
Example 25
Project: tubik   File: PopularFragment.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_popular_grid, container, false);
    Context context = view.getContext();

    RecyclerView gridTracksView = (RecyclerView) view.findViewById(R.id.gridLastFMTopTracks);

    mTracksAdapter = new TrackAdapter(getContext(), mListener);
    gridTracksView.setLayoutManager(new GridLayoutManager(context, mColumnCount, LinearLayoutManager.HORIZONTAL, false));
    gridTracksView.setAdapter(mTracksAdapter);

    RecyclerView gridAlbumsView = (RecyclerView) view.findViewById(R.id.gridTopAlbums);

    mAlbumsAdapter = new AlbumAdapter(getContext(), mListener);
    gridAlbumsView.setLayoutManager(new GridLayoutManager(context, mColumnCount, LinearLayoutManager.HORIZONTAL, false));
    gridAlbumsView.setAdapter(mAlbumsAdapter);

    return view;
}
 
Example 26
Project: OpenEyesReading-android   File: NewsActivity.java   View source code 6 votes vote down vote up
private int calculateRecyclerViewFirstPosition() {
    RecyclerView.LayoutManager manager = mRecyclerView.getLayoutManager();
    if (manager instanceof StaggeredGridLayoutManager) {
        if (mVisiblePositions == null)
            mVisiblePositions = new int[((StaggeredGridLayoutManager) manager).getSpanCount()];
        ((StaggeredGridLayoutManager) manager).findLastCompletelyVisibleItemPositions(mVisiblePositions);
        int max = -1;
        for (int pos : mVisiblePositions) {
            max = Math.max(max, pos);
        }
        return max;
    } else if (manager instanceof GridLayoutManager) {
        return ((GridLayoutManager) manager).findFirstCompletelyVisibleItemPosition();
    } else {
        return ((LinearLayoutManager) manager).findLastCompletelyVisibleItemPosition();
    }
}
 
Example 27
Project: recyclerview-android   File: CursorDatasourceExampleActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cursor_datasource_example);
    
    mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator);
    
    mAdapter = new CallsAdapter();
    
    mRecyclerView = (RecyclerView) findViewById(android.R.id.list);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    mRecyclerView.setAdapter(mAdapter);
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(this, CALL_LOG_PERMISSION) == PackageManager.PERMISSION_GRANTED) {
            onCallLogPermissionGranted();
        } else {
            ActivityCompat.requestPermissions(this, CALL_LOG_PERMISSIONS,
                    REQUEST_CODE_CALL_LOG_PERMISSION);
        }
    } else {
        onCallLogPermissionGranted();
    }
}
 
Example 28
Project: Phoenix-for-VK   File: SelectSchoolsDialog.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    View root = inflater.inflate(R.layout.dialog_country_or_city_select, container, false);

    EditText input = root.findViewById(R.id.input);
    input.setText(filter);
    input.addTextChangedListener(new TextWatcherAdapter() {
        @Override
        public void afterTextChanged(Editable s) {
            filter = s.toString();
            mHandler.removeCallbacks(runSearchRunnable);
            mHandler.postDelayed(runSearchRunnable, RUN_SEACRH_DELAY);
        }
    });

    mRecyclerView = root.findViewById(R.id.list);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));

    return root;
}
 
Example 29
Project: black-mirror   File: NewsWidgetView.java   View source code 6 votes vote down vote up
private void init() {
    inflate(getContext(), R.layout.view_news_widget, this);
    this.polsatNewsRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_polsat_news);
    this.tvnNewsRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_tvn_news);
    this.polsatNewsTitle = (TextView) findViewById(R.id.polsat_text);
    this.tvnNewsTitle = (TextView) findViewById(R.id.tvn_text);
    this.polsatNewsAdapter = new NewsRecyclerAdapter(getContext());
    this.tvnNewsAdapter = new NewsRecyclerAdapter(getContext());
    tvnNewsRecyclerView.setLayoutManager(new ScrollingLinearLayoutManager(getContext(),
            LinearLayoutManager.HORIZONTAL, false, 5000));
    tvnNewsRecyclerView.setAdapter(tvnNewsAdapter);
    polsatNewsRecyclerView.setAdapter(polsatNewsAdapter);
    polsatNewsRecyclerView.setLayoutManager(new ScrollingLinearLayoutManager(getContext(),
            LinearLayoutManager.HORIZONTAL, false, 11000));
    this.setVisibility(GONE);
}
 
Example 30
Project: Gesture   File: ItemTouchListener.java   View source code 5 votes vote down vote up
private int chooseDropTarget(RecyclerView rv, int dragPosition, int curY) {
    LinearLayoutManager layoutManager = ((LinearLayoutManager) rv.getLayoutManager());
    int firstVisiblePosition = layoutManager.findFirstVisibleItemPosition();

    if (mView.getY() < 0 && firstVisiblePosition == 0) {
        return firstVisiblePosition;
    }

    float referenceUp = mView.getY() - mView.getTranslationY();
    if ((referenceUp > curY) && mView.getTranslationY() < 0) {
        if (referenceUp - curY > mView.getHeight()) {
            return dragPosition - 2;
        }
        if (referenceUp - curY < mView.getHeight() && referenceUp - curY > 0) {
            return dragPosition - 1;
        }
    }
    float referenceDown = mView.getY() - mView.getTranslationY() + mView.getHeight();
    if ((referenceDown < curY) && mView.getTranslationY() > 0) {
        if (curY - referenceDown > mView.getHeight()) {
            return dragPosition + 2;
        }
        if (curY - referenceDown < mView.getHeight() && curY - referenceDown > 0) {
            return dragPosition + 1;
        }
    }

    return -1;
}
 
Example 31
Project: Aurora   File: RecyclerSnapHelper.java   View source code 5 votes vote down vote up
@Override
public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
    int targetPos = super.findTargetSnapPosition(layoutManager, velocityX, velocityY);
    this.position = targetPos;
    final View currentView = findSnapView(layoutManager);
    if (targetPos != RecyclerView.NO_POSITION && currentView != null) {
        int currentPos = layoutManager.getPosition(currentView);
        int first = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
        int last = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
        currentPos = targetPos < currentPos ? last : (targetPos > currentPos ? first : currentPos);
        targetPos = targetPos < currentPos ? currentPos - 1 : (targetPos > currentPos ? currentPos + 1 : currentPos);
    }
    return targetPos;
}
 
Example 32
Project: android-dev-challenge   File: MainActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /*
     * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to
     * do things like set the adapter of the RecyclerView and toggle the visibility.
     */
    mNumbersList = (RecyclerView) findViewById(R.id.rv_numbers);

    /*
     * A LinearLayoutManager is responsible for measuring and positioning item views within a
     * RecyclerView into a linear list. This means that it can produce either a horizontal or
     * vertical list depending on which parameter you pass in to the LinearLayoutManager
     * constructor. By default, if you don't specify an orientation, you get a vertical list.
     * In our case, we want a vertical list, so we don't need to pass in an orientation flag to
     * the LinearLayoutManager constructor.
     *
     * There are other LayoutManagers available to display your data in uniform grids,
     * staggered grids, and more! See the developer documentation for more details.
     */
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    mNumbersList.setLayoutManager(layoutManager);

    /*
     * Use this setting to improve performance if you know that changes in content do not
     * change the child layout size in the RecyclerView
     */
    mNumbersList.setHasFixedSize(true);

    /*
     * The GreenAdapter is responsible for displaying each item in the list.
     */
    mAdapter = new GreenAdapter(NUM_LIST_ITEMS);
    mNumbersList.setAdapter(mAdapter);
}
 
Example 33
Project: XFrame   File: DividerDecoration.java   View source code 5 votes vote down vote up
/**
 * 返回条目之间的间隔,例如我们想仿照ListView一样添加分割线,那么就需要设置outRect的下边距。
 * @param outRect
 * @param view
 * @param parent
 * @param state
 */
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int position = parent.getChildAdapterPosition(view);
    int orientation = 0;
    int headerCount = 0,footerCount = 0;
    if (parent.getAdapter() instanceof XRecyclerViewAdapter){
        headerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getHeaderCount();
        footerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getFooterCount();
    }

    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof StaggeredGridLayoutManager){
        orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
    }else if (layoutManager instanceof GridLayoutManager){
        orientation = ((GridLayoutManager) layoutManager).getOrientation();
    }else if (layoutManager instanceof LinearLayoutManager){
        orientation = ((LinearLayoutManager) layoutManager).getOrientation();
    }

    if (position>=headerCount&&position<parent.getAdapter().getItemCount()-footerCount||mDrawHeaderFooter){
        if (orientation == OrientationHelper.VERTICAL){
            outRect.bottom = mHeight;
        }else {
            outRect.right = mHeight;
        }
    }
}
 
Example 34
Project: NoChat   File: MainActivity.java   View source code 5 votes vote down vote up
private void setupChatAdapter() {
    chatAdapter = new ChatAdapter();
    LinearLayoutManager manager = new LinearLayoutManager(this);
    manager.setStackFromEnd(true);
    rvChat.setLayoutManager(manager);
    rvChat.setAdapter(chatAdapter);
}
 
Example 35
Project: Cash   File: frmVendaItens.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frm_venda_itens);

    iVenda = getIntent().getExtras().getInt("Venda");

    RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.rvItens);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(frmVendaItens.this));
    mRecyclerView.addItemDecoration(new SpacesItemDecoration(Funcoes.SPACE_BETWEEN_ITEMS));

    mAdapter = new adpVendaItens(frmVendaItens.this, mRecyclerView, iVenda);
    mRecyclerView.setAdapter(mAdapter);

    ImageButton btnAdd = (ImageButton) findViewById(R.id.btnAdd);
    btnAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(frmVendaItens.this, frmManutencaoVendaItens.class);
            intent.putExtra("Operacao", "I");
            intent.putExtra("Venda", iVenda);
            startActivity(intent);
        }
    });

}
 
Example 36
Project: CXJPadProject   File: CombinationActivity.java   View source code 5 votes vote down vote up
public void initSkuDetailBRAdapter() {
    skuDetailBRAdapter = new BRAdapter<CombinateQuoteInfo.SKUDetail>(this, R.layout.item_combination_product, combiSkuList) {
        @Override
        protected void convert(RvHolder holder, CombinateQuoteInfo.SKUDetail skuDetail, int position) {
            holder.setText(R.id.tv_proCtgName, skuDetail.getSkuCtgName());
            holder.setText(R.id.tv_proNo, skuDetail.getSkuNo());
            holder.setText(R.id.tv_proName, skuDetail.getSkuName());
            holder.setText(R.id.tv_proPrice, skuDetail.getStdPrice());
            holder.setText(R.id.tv_proQuantity, skuDetail.getSkuQuantity());
        }
    };

    yrvCombPro.setLayoutManager(new LinearLayoutManager(this));
    yrvCombPro.setAdapter(skuDetailBRAdapter);
}
 
Example 37
Project: Tribe   File: LifeFragment.java   View source code 5 votes vote down vote up
private void initRecyclerView() {
    mData = new ArrayList<>();
    mAdapter = new LifeAdapter(getContext(),mData,getActivity());
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false);
    mLifeRecyclerView.setLayoutManager(layoutManager);
    mLifeRecyclerView.setAdapter(mAdapter);
}
 
Example 38
Project: GitHub   File: FastAdapterDialog.java   View source code 5 votes vote down vote up
/**
 * Start the dialog and display it on screen.  The window is placed in the
 * application layer and opaque.  Note that you should not override this
 * method to do initialization when the dialog is shown, instead implement
 * that in {@link #onStart}.
 */
public void show() {
    if (mRecyclerView.getLayoutManager() == null) {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    }
    if (mFastItemAdapter == null && mRecyclerView.getAdapter() == null) {
        mFastItemAdapter = new FastItemAdapter<>();
        mRecyclerView.setAdapter(mFastItemAdapter);
    }
    super.show();
}
 
Example 39
Project: Pigeon   File: ToolsFragment.java   View source code 5 votes vote down vote up
@Override
public void initData() {
    query = new BmobQuery<>();
    boolean isCache = query.hasCachedResult(Tools.class);

    if(isCache){
        query.setCachePolicy(BmobQuery.CachePolicy.CACHE_ELSE_NETWORK);    // 如果有缓存的话,则设置策略为CACHE_ELSE_NETWORK
    }else{
        query.setCachePolicy(BmobQuery.CachePolicy.NETWORK_ELSE_CACHE);    // 如果没有缓存的话,则设置策略为NETWORK_ELSE_CACHE
    }

    query.setMaxCacheAge(TimeUnit.DAYS.toMillis(3));//此表示缓存一天
    query.setLimit(10);
    query.findObjects(new FindListener<Tools>() {
        @Override
        public void done(List<Tools> list, BmobException e) {
            if (e == null) {
                if (list.size() != 0) {
                    toolsAdapter = new ToolsAdapter(getContext(), list);
                    mRvTools.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
                    mRvTools.setAdapter(toolsAdapter);

                }
            }
        }
    });


}
 
Example 40
Project: Nearby   File: AllInOneInquiryVitalListCustomAdapter.java   View source code 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();

    totalItemCount = linearLayoutManager.getItemCount();
    lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
    if (!loading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
        // End has been reached
        // Do something
        loading = true;
        if (onLoadMoreListener != null) {
            onLoadMoreListener.onLoadMore();
        }
    }
    // 여기까지 무한 스크롤

    if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
        onHide();
        controlsVisible = false;
        scrolledDistance = 0;
    } else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) {
        onShow();
        controlsVisible = true;
        scrolledDistance = 0;
    }

    if((controlsVisible && dy>0) || (!controlsVisible && dy<0)) {
        scrolledDistance += dy;
    }
    // 여기까지 툴바 숨기기
}