Java Code Examples for androidx.recyclerview.widget.RecyclerView#setId()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#setId() . 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: SwipeOpenItemTouchHelperTestActivity.java    From SwipeOpenItemTouchHelper with Apache License 2.0 6 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  RecyclerView recyclerView = new RecyclerView(this);
  recyclerView.setId(R.id.test_recycler);
  recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
      ViewGroup.LayoutParams.MATCH_PARENT));
  recyclerView.setLayoutManager(new LinearLayoutManager(this));
  recyclerView.setAdapter(new TestAdapter(this));
  setContentView(recyclerView);

  helper = new SwipeOpenItemTouchHelper(
      new SwipeOpenItemTouchHelper.SimpleCallback(
          SwipeOpenItemTouchHelper.START | SwipeOpenItemTouchHelper.END));
  helper.attachToRecyclerView(recyclerView);

  if (savedInstanceState != null) {
    helper.restoreInstanceState(savedInstanceState);
  }
}
 
Example 2
Source File: PictureMultiCuttingActivity.java    From Matisse-Kotlin with Apache License 2.0 5 votes vote down vote up
/**
 * 动态添加多图裁剪底部预览图片列表
 */
private void addPhotoRecyclerView() {
    mRecyclerView = new RecyclerView(this);
    mRecyclerView.setId(R.id.id_recycler);
    mRecyclerView.setBackgroundColor(ContextCompat.getColor(this, R.color.ucrop_color_widget_background));
    RelativeLayout.LayoutParams lp =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, dip2px(80));
    mRecyclerView.setLayoutParams(lp);
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    resetCutDataStatus();
    list.get(cutIndex).setCut(true);
    adapter = new PicturePhotoGalleryAdapter(this, list);
    mRecyclerView.setAdapter(adapter);
    adapter.setOnItemClickListener((position, view) -> {
        if (cutIndex == position) {
            return;
        }
        cutIndex = position;
        resetCutData();
    });

    uCropMultiplePhotoBox.addView(mRecyclerView);
    changeLayoutParams();
    FrameLayout uCropFrame = findViewById(R.id.ucrop_frame);
    ((RelativeLayout.LayoutParams) uCropFrame.getLayoutParams())
            .addRule(RelativeLayout.ABOVE, R.id.id_recycler);
}
 
Example 3
Source File: RecyclerSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext context,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) RecyclerView.ItemDecoration itemDecoration,
    @Prop(optional = true, resType = ResType.COLOR) @Nullable
        Integer refreshProgressBarBackgroundColor,
    @Prop(optional = true) SnapHelper snapHelper) {
  final RecyclerView recyclerView = sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout "
            + "before unmounting");
  }

  recyclerView.setId(RecyclerSpec.recyclerViewId);

  if (refreshProgressBarBackgroundColor != null) {
    sectionsRecycler.setProgressBackgroundColorSchemeColor(
        DEFAULT_REFRESH_SPINNER_BACKGROUND_COLOR);
  }

  if (itemDecoration != null) {
    recyclerView.removeItemDecoration(itemDecoration);
  }

  binder.unmount(recyclerView);

  if (snapHelper != null) {
    snapHelper.attachToRecyclerView(null);
  }

  sectionsRecycler.resetItemAnimator();
}
 
Example 4
Source File: ShadowPreferenceFragmentCompat.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Implementation
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    RecyclerView recyclerView = new RecyclerView(container.getContext());
    recyclerView.setId(android.R.id.list_container);
    ReflectionHelpers.setField(realObject, "mList", recyclerView);
    return recyclerView;
}
 
Example 5
Source File: FastScrollView.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
private void layout(Context context, AttributeSet attrs) {
    fastScroller = new FastScroller(context, attrs);
    fastScroller.setId(R.id.fast_scroller);
    recyclerView = new RecyclerView(context, attrs);
    recyclerView.setId(R.id.recycler_view);
}
 
Example 6
Source File: RecyclerSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) boolean hasFixedSize,
    @Prop(optional = true) boolean clipToPadding,
    @Prop(optional = true) int leftPadding,
    @Prop(optional = true) int rightPadding,
    @Prop(optional = true) int topPadding,
    @Prop(optional = true) int bottomPadding,
    @Prop(optional = true, resType = ResType.COLOR) @Nullable
        Integer refreshProgressBarBackgroundColor,
    @Prop(optional = true, resType = ResType.COLOR) int refreshProgressBarColor,
    @Prop(optional = true) boolean clipChildren,
    @Prop(optional = true) boolean nestedScrollingEnabled,
    @Prop(optional = true) int scrollBarStyle,
    @Prop(optional = true) RecyclerView.ItemDecoration itemDecoration,
    @Prop(optional = true) boolean horizontalFadingEdgeEnabled,
    @Prop(optional = true) boolean verticalFadingEdgeEnabled,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) int fadingEdgeLength,
    @Prop(optional = true) @IdRes int recyclerViewId,
    @Prop(optional = true) int overScrollMode,
    @Prop(optional = true, isCommonProp = true) CharSequence contentDescription,
    @Prop(optional = true) ItemAnimator itemAnimator) {
  final RecyclerView recyclerView = sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout");
  }
  recyclerView.setContentDescription(contentDescription);
  recyclerView.setHasFixedSize(hasFixedSize);
  recyclerView.setClipToPadding(clipToPadding);
  sectionsRecycler.setClipToPadding(clipToPadding);
  ViewCompat.setPaddingRelative(
      recyclerView, leftPadding, topPadding, rightPadding, bottomPadding);
  recyclerView.setClipChildren(clipChildren);
  sectionsRecycler.setClipChildren(clipChildren);
  recyclerView.setNestedScrollingEnabled(nestedScrollingEnabled);
  sectionsRecycler.setNestedScrollingEnabled(nestedScrollingEnabled);
  recyclerView.setScrollBarStyle(scrollBarStyle);
  recyclerView.setHorizontalFadingEdgeEnabled(horizontalFadingEdgeEnabled);
  recyclerView.setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled);
  recyclerView.setFadingEdgeLength(fadingEdgeLength);
  // TODO (t14949498) determine if this is necessary
  recyclerView.setId(recyclerViewId);
  recyclerView.setOverScrollMode(overScrollMode);
  if (refreshProgressBarBackgroundColor != null) {
    sectionsRecycler.setProgressBackgroundColorSchemeColor(refreshProgressBarBackgroundColor);
  }
  sectionsRecycler.setColorSchemeColors(refreshProgressBarColor);

  if (itemDecoration != null) {
    recyclerView.addItemDecoration(itemDecoration);
  }

  sectionsRecycler.setItemAnimator(
      itemAnimator != RecyclerSpec.itemAnimator ? itemAnimator : new NoUpdateItemAnimator());

  binder.mount(recyclerView);
}
 
Example 7
Source File: PictureMultiCuttingActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
/**
 * 动态添加多图裁剪底部预览图片列表
 */
private void addPhotoRecyclerView() {
    boolean isMultipleSkipCrop = getIntent().getBooleanExtra(UCrop.Options.EXTRA_SKIP_MULTIPLE_CROP, true);
    mRecyclerView = new RecyclerView(this);
    mRecyclerView.setId(R.id.id_recycler);
    mRecyclerView.setBackgroundColor(ContextCompat.getColor(this, R.color.ucrop_color_widget_background));
    RelativeLayout.LayoutParams lp =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                    ScreenUtils.dip2px(this, 80));
    mRecyclerView.setLayoutParams(lp);
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    if (isAnimation) {
        LayoutAnimationController animation = AnimationUtils
                .loadLayoutAnimation(getApplicationContext(), R.anim.ucrop_layout_animation_fall_down);
        mRecyclerView.setLayoutAnimation(animation);
    }
    mRecyclerView.setLayoutManager(mLayoutManager);
    // 解决调用 notifyItemChanged 闪烁问题,取消默认动画
    ((SimpleItemAnimator) mRecyclerView.getItemAnimator())
            .setSupportsChangeAnimations(false);
    resetCutDataStatus();
    list.get(cutIndex).setCut(true);
    mAdapter = new PicturePhotoGalleryAdapter(this, list);
    mRecyclerView.setAdapter(mAdapter);
    if (isMultipleSkipCrop) {
        mAdapter.setOnItemClickListener(new PicturePhotoGalleryAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, View view) {
                CutInfo cutInfo = list.get(position);
                if (MimeType.isHasVideo(cutInfo.getMimeType())) {
                    return;
                }
                if (cutIndex == position) {
                    return;
                }
                resetLastCropStatus();
                cutIndex = position;
                oldCutIndex = cutIndex;
                resetCutData();
            }
        });
    }
    uCropPhotoBox.addView(mRecyclerView);
    changeLayoutParams(mShowBottomControls);

    // 裁剪框居于RecyclerView之上
    FrameLayout uCropFrame = findViewById(R.id.ucrop_frame);
    ((RelativeLayout.LayoutParams) uCropFrame.getLayoutParams())
            .addRule(RelativeLayout.ABOVE, R.id.id_recycler);

    // RecyclerView居于BottomControls之上
    ((RelativeLayout.LayoutParams) mRecyclerView.getLayoutParams())
            .addRule(RelativeLayout.ABOVE, R.id.controls_wrapper);
}