Java Code Examples for androidx.recyclerview.widget.RecyclerView#getContext()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#getContext() .
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 File: GalleryNoteFragment.java From science-journal with Apache License 2.0 | 6 votes |
@Nullable @Override public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.gallery_note_fragment, null); RecyclerView gallery = rootView.findViewById(R.id.gallery); GridLayoutManager layoutManager = new GridLayoutManager( gallery.getContext(), gallery.getContext().getResources().getInteger(R.integer.gallery_column_count)); gallery.setLayoutManager(layoutManager); gallery.setItemAnimator(new DefaultItemAnimator()); gallery.setAdapter(galleryAdapter); addButton = rootView.findViewById(R.id.btn_add); requestPermission(); attachAddButton(addButton); actionController.attachAddButton(addButton); actionController.attachProgressBar(rootView.findViewById(R.id.recording_progress_bar)); setUpTitleBar(rootView, false, R.string.action_bar_gallery, R.drawable.ic_gallery); return rootView; }
Example 2
Source File: SimpleRecyclerViewActivity.java From Android with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_simple_recycler_view); RecyclerView simpleRecyclerView = findViewById(R.id.simple_recycler_view); // add data in the mPersonList addPersonData(); // set layout manager LinearLayoutManager layoutManager = new LinearLayoutManager(this); simpleRecyclerView.setLayoutManager(layoutManager); // set divider between two rows DividerItemDecoration divider = new DividerItemDecoration(simpleRecyclerView.getContext(), layoutManager.getOrientation()); simpleRecyclerView.addItemDecoration(divider); // set adapter RecyclerViewJavaAdapter adapter = new RecyclerViewJavaAdapter(personModelList,this); simpleRecyclerView.setAdapter(adapter); }
Example 3
Source File: OpenTypeListActivity.java From ProjectX with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setSupportActionBar(R.id.otl_toolbar); final RecyclerView list = findViewById(R.id.otl_content); final Drawable divider = ContextCompat.getDrawable(this, R.drawable.divider_common); if (divider != null) { final DividerItemDecoration decoration = new DividerItemDecoration(list.getContext(), DividerItemDecoration.VERTICAL); decoration.setDrawable(divider); list.addItemDecoration(decoration); } list.setAdapter(mAdapter); mPresenter.loadOpenType(); }
Example 4
Source File: RecyclerViewHeader.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
private void setupAlignment(RecyclerView recycler) { if (!mAlreadyAligned) { //setting alignment of header ViewGroup.LayoutParams currentParams = getLayoutParams(); FrameLayout.LayoutParams newHeaderParams; int width = ViewGroup.LayoutParams.WRAP_CONTENT; int height = ViewGroup.LayoutParams.WRAP_CONTENT; int gravity = (mReversed ? Gravity.BOTTOM : Gravity.TOP) | Gravity.CENTER_HORIZONTAL; if (currentParams != null) { newHeaderParams = new FrameLayout.LayoutParams(getLayoutParams()); //to copy all the margins newHeaderParams.width = width; newHeaderParams.height = height; newHeaderParams.gravity = gravity; } else { newHeaderParams = new FrameLayout.LayoutParams(width, height, gravity); } RecyclerViewHeader.this.setLayoutParams(newHeaderParams); //setting alignment of recycler FrameLayout newRootParent = new FrameLayout(recycler.getContext()); newRootParent.setLayoutParams(recycler.getLayoutParams()); ViewParent currentParent = recycler.getParent(); if (currentParent instanceof ViewGroup) { int indexWithinParent = ((ViewGroup) currentParent).indexOfChild(recycler); ((ViewGroup) currentParent).removeViewAt(indexWithinParent); recycler.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); newRootParent.addView(recycler); newRootParent.addView(RecyclerViewHeader.this); ((ViewGroup) currentParent).addView(newRootParent, indexWithinParent); } } }
Example 5
Source File: SmoothCalendarLayoutManager.java From material-components-android with Apache License 2.0 | 5 votes |
@Override public void smoothScrollToPosition( RecyclerView recyclerView, RecyclerView.State state, int position) { final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) { @Override protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) { return MILLISECONDS_PER_INCH / displayMetrics.densityDpi; } }; linearSmoothScroller.setTargetPosition(position); startSmoothScroll(linearSmoothScroller); }
Example 6
Source File: ScannerActivity.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scanner); ButterKnife.bind(this); // Create view model containing utility methods for scanning mViewModel = new ViewModelProvider(this, mViewModelFactory).get(ScannerViewModel.class); final Toolbar toolbar = findViewById(R.id.toolbar); toolbar.setTitle(R.string.title_scanner); setSupportActionBar(toolbar); //noinspection ConstantConditions getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (getIntent() != null) { mScanWithProxyService = getIntent().getBooleanExtra(Utils.EXTRA_DATA_PROVISIONING_SERVICE, true); if (mScanWithProxyService) { getSupportActionBar().setSubtitle(R.string.sub_title_scanning_nodes); } else { getSupportActionBar().setSubtitle(R.string.sub_title_scanning_proxy_node); } } // Configure the recycler view final RecyclerView recyclerViewDevices = findViewById(R.id.recycler_view_ble_devices); recyclerViewDevices.setLayoutManager(new LinearLayoutManager(this)); final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerViewDevices.getContext(), DividerItemDecoration.VERTICAL); recyclerViewDevices.addItemDecoration(dividerItemDecoration); final SimpleItemAnimator itemAnimator = (SimpleItemAnimator) recyclerViewDevices.getItemAnimator(); if (itemAnimator != null) itemAnimator.setSupportsChangeAnimations(false); final DevicesAdapter adapter = new DevicesAdapter(this, mViewModel.getScannerRepository().getScannerResults()); adapter.setOnItemClickListener(this); recyclerViewDevices.setAdapter(adapter); mViewModel.getScannerRepository().getScannerState().observe(this, this::startScan); }
Example 7
Source File: SaveActivity.java From Chimee with MIT License | 5 votes |
private void setupRecyclerView(List<String> files) { RecyclerView recyclerView = findViewById(R.id.rv_document_list); LinearLayoutManager horizontalLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); recyclerView.setLayoutManager(horizontalLayoutManager); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), horizontalLayoutManager.getOrientation()); recyclerView.addItemDecoration(dividerItemDecoration); adapter = new SimpleListRvAdapter(this, files); adapter.setClickListener(this); recyclerView.setAdapter(adapter); }
Example 8
Source File: ItemTouchListenerAdapter.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
public ItemTouchListenerAdapter( RecyclerView recyclerView, RecyclerViewOnItemClickListener listener) { if (recyclerView == null || listener == null) { throw new IllegalArgumentException("RecyclerView and Listener arguments can not be null"); } this.recyclerView = recyclerView; this.listener = listener; this.gestureDetector = new GestureDetector(recyclerView.getContext(), this); }
Example 9
Source File: LinearLayoutManagerWithSmoothScroller.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { RecyclerView.SmoothScroller smoothScroller = new TopSnappedSmoothScroller(recyclerView.getContext()); smoothScroller.setTargetPosition(position); startSmoothScroll(smoothScroller); }
Example 10
Source File: SelectionTracker.java From FairEmail with GNU General Public License v3.0 | 5 votes |
/** * Creates a new SelectionTracker.Builder useful for configuring and creating * a new SelectionTracker for use with your {@link RecyclerView}. * * @param selectionId A unique string identifying this selection in the context * of the activity or fragment. * @param recyclerView the owning RecyclerView * @param keyProvider the source of selection keys * @param detailsLookup the source of information about RecyclerView items. * @param storage Strategy for type-safe storage of selection state in * {@link Bundle}. */ public Builder( @NonNull String selectionId, @NonNull RecyclerView recyclerView, @NonNull ItemKeyProvider<K> keyProvider, @NonNull ItemDetailsLookup<K> detailsLookup, @NonNull StorageStrategy<K> storage) { checkArgument(selectionId != null); checkArgument(!selectionId.trim().isEmpty()); checkArgument(recyclerView != null); mSelectionId = selectionId; mRecyclerView = recyclerView; mContext = recyclerView.getContext(); mAdapter = recyclerView.getAdapter(); checkArgument(mAdapter != null); checkArgument(keyProvider != null); checkArgument(detailsLookup != null); checkArgument(storage != null); mDetailsLookup = detailsLookup; mKeyProvider = keyProvider; mStorage = storage; mBandPredicate = new BandPredicate.NonDraggableArea(mRecyclerView, detailsLookup); }
Example 11
Source File: OpenActivity.java From Chimee with MIT License | 5 votes |
private void setupRecyclerView(List<String> files) { RecyclerView recyclerView = findViewById(R.id.rv_document_list); LinearLayoutManager horizontalLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); recyclerView.setLayoutManager(horizontalLayoutManager); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), horizontalLayoutManager.getOrientation()); recyclerView.addItemDecoration(dividerItemDecoration); adapter = new SimpleListRvAdapter(this, files); adapter.setClickListener(this); recyclerView.setAdapter(adapter); }
Example 12
Source File: SmsTemplateListAsyncAdapter.java From financisto with GNU General Public License v2.0 | 5 votes |
public SmsTemplateListAsyncAdapter(int chunkSize, DatabaseAdapter db, SmsTemplateListSource itemSource, RecyclerView recyclerView, SmsDragListActivity activity) { super(chunkSize, itemSource, recyclerView); this.context = recyclerView.getContext(); this.db = db; this.activity = activity; }
Example 13
Source File: NotificationRulesAdapter.java From revolution-irc with GNU General Public License v3.0 | 4 votes |
public void enableDragDrop(RecyclerView recyclerView) { ItemTouchHelper.Callback callback = new MyItemTouchHelperCallback(recyclerView.getContext()); mItemTouchHelper = new ItemTouchHelper(callback); mItemTouchHelper.attachToRecyclerView(recyclerView); }
Example 14
Source File: StickyRecyclerHeadersTouchListener.java From UltimateRecyclerView with Apache License 2.0 | 4 votes |
public StickyRecyclerHeadersTouchListener(final RecyclerView recyclerView, final com.marshalchen.ultimaterecyclerview.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration decor) { mTapDetector = new GestureDetector(recyclerView.getContext(), new SingleTapDetector()); mRecyclerView = recyclerView; mDecor = decor; }
Example 15
Source File: RangesActivity.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@SuppressWarnings("ConstantConditions") @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ranges); ButterKnife.bind(this); mViewModel = new ViewModelProvider(this, mViewModelFactory).get(RangesViewModel.class); mType = getIntent().getExtras().getInt(Utils.RANGE_TYPE); //Bind ui final Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); final RecyclerView recyclerView = findViewById(R.id.recycler_view); final View rangesContainer = findViewById(R.id.info_ranges); rangesContainer.findViewById(R.id.container).setVisibility(View.VISIBLE); mRangeView = rangesContainer.findViewById(R.id.range); final TextView startAddress = rangesContainer.findViewById(R.id.start_address); final TextView endAddress = rangesContainer.findViewById(R.id.end_address); final ExtendedFloatingActionButton fab_add = findViewById(R.id.fab_add); mProvisioner = mViewModel.getSelectedProvisioner().getValue(); switch (mType) { case Utils.GROUP_RANGE: startAddress.setText(MeshAddress.formatAddress(MeshAddress.START_GROUP_ADDRESS, true)); endAddress.setText(MeshAddress.formatAddress(MeshAddress.END_GROUP_ADDRESS, true)); getSupportActionBar().setTitle(R.string.title_edit_group_ranges); mRangeAdapter = new RangeAdapter(this, mProvisioner.getProvisionerUuid(), mProvisioner.getAllocatedGroupRanges(), mViewModel.getNetworkLiveData().getProvisioners()); break; case Utils.SCENE_RANGE: startAddress.setText(MeshAddress.formatAddress(0x0000, true)); endAddress.setText(MeshAddress.formatAddress(0xFFFF, true)); getSupportActionBar().setTitle(R.string.title_edit_scene_ranges); mRangeAdapter = new RangeAdapter(this, mProvisioner.getProvisionerUuid(), mProvisioner.getAllocatedSceneRanges(), mViewModel.getNetworkLiveData().getProvisioners()); break; default: case Utils.UNICAST_RANGE: startAddress.setText(MeshAddress.formatAddress(MeshAddress.START_UNICAST_ADDRESS, true)); endAddress.setText(MeshAddress.formatAddress(MeshAddress.END_UNICAST_ADDRESS, true)); getSupportActionBar().setTitle(R.string.title_edit_unicast_ranges); mRangeAdapter = new RangeAdapter(this, mProvisioner.getProvisionerUuid(), mProvisioner.getAllocatedUnicastRanges(), mViewModel.getNetworkLiveData().getProvisioners()); break; } mRangeAdapter.setOnItemClickListener(this); recyclerView.setLayoutManager(new LinearLayoutManager(this)); final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL); recyclerView.addItemDecoration(dividerItemDecoration); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(mRangeAdapter); final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this); final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback); itemTouchHelper.attachToRecyclerView(recyclerView); fab_add.setOnClickListener(v -> { switch (mType) { case Utils.GROUP_RANGE: final DialogFragmentGroupRange groupRange = DialogFragmentGroupRange.newInstance(null); groupRange.show(getSupportFragmentManager(), null); break; case Utils.SCENE_RANGE: final DialogFragmentSceneRange sceneRange = DialogFragmentSceneRange.newInstance(null); sceneRange.show(getSupportFragmentManager(), null); break; default: case Utils.UNICAST_RANGE: final DialogFragmentUnicastRange unicastRange = DialogFragmentUnicastRange.newInstance(null); unicastRange.show(getSupportFragmentManager(), null); break; } }); mFabResolve.setOnClickListener(v -> resolveRanges()); updateRanges(); updateOtherRanges(); updateEmptyView(); updateResolveFab(); }
Example 16
Source File: GroupsFragment.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Nullable @Override public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { @SuppressLint("InflateParams") final View rootView = inflater.inflate(R.layout.fragment_groups, null); mViewModel = new ViewModelProvider(requireActivity(), mViewModelFactory).get(SharedViewModel.class); ButterKnife.bind(this, rootView); final ExtendedFloatingActionButton fab = rootView.findViewById(R.id.fab_add_group); // Configure the recycler view final RecyclerView recyclerViewGroups = rootView.findViewById(R.id.recycler_view_groups); recyclerViewGroups.setLayoutManager(new LinearLayoutManager(requireContext())); final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerViewGroups.getContext(), DividerItemDecoration.VERTICAL); recyclerViewGroups.addItemDecoration(dividerItemDecoration); final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this); final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback); itemTouchHelper.attachToRecyclerView(recyclerViewGroups); final GroupAdapter adapter = new GroupAdapter(requireContext()); adapter.setOnItemClickListener(this); recyclerViewGroups.setAdapter(adapter); mViewModel.getNetworkLiveData().observe(getViewLifecycleOwner(), meshNetworkLiveData -> { if (meshNetworkLiveData != null) { if (meshNetworkLiveData.getMeshNetwork().getGroups().isEmpty()) { mEmptyView.setVisibility(View.VISIBLE); } else { mEmptyView.setVisibility(View.INVISIBLE); } } }); mViewModel.getGroups().observe(getViewLifecycleOwner(), groups -> { final MeshNetwork network = mViewModel.getNetworkLiveData().getMeshNetwork(); adapter.updateAdapter(network, groups); }); fab.setOnClickListener(v -> { DialogFragmentCreateGroup fragmentCreateGroup = DialogFragmentCreateGroup.newInstance(); fragmentCreateGroup.show(getChildFragmentManager(), null); }); recyclerViewGroups.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) { super.onScrolled(recyclerView, dx, dy); final LinearLayoutManager m = (LinearLayoutManager) recyclerView.getLayoutManager(); if (m != null) { if (m.findFirstCompletelyVisibleItemPosition() == 0) { fab.extend(); } else { fab.shrink(); } } } }); return rootView; }
Example 17
Source File: StickyRecyclerHeadersTouchListener.java From toktok-android with GNU General Public License v3.0 | 4 votes |
public StickyRecyclerHeadersTouchListener(@NonNull final RecyclerView recyclerView, final StickyRecyclerHeadersDecoration decor) { mTapDetector = new GestureDetector(recyclerView.getContext(), new SingleTapDetector()); mRecyclerView = recyclerView; mDecor = decor; }
Example 18
Source File: AppKeysActivity.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_keys); mViewModel = new ViewModelProvider(this, mViewModelFactory).get(AppKeysViewModel.class); //Bind ui ButterKnife.bind(this); final Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); //noinspection ConstantConditions getSupportActionBar().setDisplayHomeAsUpEnabled(true); final ExtendedFloatingActionButton fab = findViewById(R.id.fab_add); final RecyclerView appKeysRecyclerView = findViewById(R.id.recycler_view_keys); appKeysRecyclerView.setLayoutManager(new LinearLayoutManager(this)); final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(appKeysRecyclerView.getContext(), DividerItemDecoration.VERTICAL); appKeysRecyclerView.addItemDecoration(dividerItemDecoration); appKeysRecyclerView.setItemAnimator(new DefaultItemAnimator()); final Bundle bundle = getIntent().getExtras(); if (bundle != null) { switch (bundle.getInt(EXTRA_DATA)) { case MANAGE_APP_KEY: break; case ADD_APP_KEY: getSupportActionBar().setTitle(R.string.title_select_app_key); fab.hide(); mAdapter = new ManageAppKeyAdapter(this, mViewModel.getNetworkLiveData()); mAdapter.setOnItemClickListener(this); appKeysRecyclerView.setAdapter(mAdapter); setUpObserver(); break; case BIND_APP_KEY: case PUBLICATION_APP_KEY: getSupportActionBar().setTitle(R.string.title_select_app_key); fab.hide(); //Get selected mesh node final ProvisionedMeshNode node = mViewModel.getSelectedMeshNode().getValue(); if (node != null) { final List<NodeKey> applicationKeys = node.getAddedAppKeys(); if (!applicationKeys.isEmpty()) { mAdapter = new ManageAppKeyAdapter(mViewModel.getNetworkLiveData().getAppKeys(), applicationKeys); mAdapter.setOnItemClickListener(this); appKeysRecyclerView.setAdapter(mAdapter); } else { final TextView textView = mEmptyView.findViewById(R.id.rationale); textView.setText(R.string.no_added_app_keys_rationale); mEmptyView.setVisibility(View.VISIBLE); } } break; } } else { getSupportActionBar().setTitle(R.string.title_manage_app_keys); final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this); final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback); itemTouchHelper.attachToRecyclerView(appKeysRecyclerView); mAdapter = new ManageAppKeyAdapter(this, mViewModel.getNetworkLiveData()); mAdapter.setOnItemClickListener(this); appKeysRecyclerView.setAdapter(mAdapter); setUpObserver(); } fab.setOnClickListener(v -> { final Intent intent = new Intent(this, AddAppKeyActivity.class); startActivity(intent); }); appKeysRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) { super.onScrolled(recyclerView, dx, dy); final LinearLayoutManager m = (LinearLayoutManager) recyclerView.getLayoutManager(); if (m != null) { if (m.findFirstCompletelyVisibleItemPosition() == 0) { fab.extend(); } else { fab.shrink(); } } } }); }
Example 19
Source File: SnappingLinearLayoutManager.java From GetApk with MIT License | 4 votes |
@Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { RecyclerView.SmoothScroller smoothScroller = new TopSnappedSmoothScroller(recyclerView.getContext()); smoothScroller.setTargetPosition(position); startSmoothScroll(smoothScroller); }
Example 20
Source File: FindBookFragment.java From MyBookshelf with GNU General Public License v3.0 | 4 votes |
@Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { RecyclerView.SmoothScroller smoothScroller = new CenterSmoothScroller(recyclerView.getContext()); smoothScroller.setTargetPosition(position); startSmoothScroll(smoothScroller); }