com.google.android.material.card.MaterialCardView Java Examples

The following examples show how to use com.google.android.material.card.MaterialCardView. 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: ThemeView.java    From SAI with GNU General Public License v3.0 6 votes vote down vote up
private void init() {
    LinearLayoutCompat container = new LinearLayoutCompat(getContext());
    container.setOrientation(LinearLayoutCompat.VERTICAL);
    MaterialCardView.LayoutParams containerLayoutParams = new MaterialCardView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    containerLayoutParams.gravity = Gravity.CENTER;
    addView(container, containerLayoutParams);

    mThemeTitle = new AppCompatTextView(getContext());
    mThemeTitle.setGravity(Gravity.CENTER);
    mThemeTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
    LinearLayoutCompat.LayoutParams titleLayoutParams = new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    container.addView(mThemeTitle, titleLayoutParams);

    mThemeMessage = new AppCompatTextView(getContext());
    mThemeMessage.setGravity(Gravity.CENTER);
    mThemeMessage.setVisibility(GONE);
    LinearLayoutCompat.LayoutParams messageLayoutParams = new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    container.addView(mThemeMessage, messageLayoutParams);
}
 
Example #2
Source File: CardStatesFragment.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view = layoutInflater
      .inflate(R.layout.cat_card_states_fragment, viewGroup, false /* attachToRoot */);
  RadioGroup radioGroup = view.findViewById(R.id.cat_card_radio_group);
  final MaterialCardView card = view.findViewById(R.id.card);
  final MaterialCardView checkableCard = view.findViewById(R.id.checkable_card);

  checkableCard.setOnLongClickListener(
      v -> {
        checkableCard.setChecked(!checkableCard.isChecked());
        return true;
      });

  radioGroup.setOnCheckedChangeListener(
      (group, checkedId) -> {
        card.setHovered(checkedId == R.id.hovered);
        card.setPressed(checkedId == R.id.pressed);
        checkableCard.setHovered(checkedId == R.id.hovered);
        checkableCard.setPressed(checkedId == R.id.pressed);
      });

  return view;
}
 
Example #3
Source File: LauncherAdapter.java    From candybar with Apache License 2.0 5 votes vote down vote up
ViewHolder(View itemView, int viewType) {
    super(itemView);
    if (viewType == TYPE_HEADER) {
        name = itemView.findViewById(R.id.name);
        holderId = TYPE_HEADER;
    } else if (viewType == TYPE_CONTENT) {
        icon = itemView.findViewById(R.id.icon);
        name = itemView.findViewById(R.id.name);
        container = itemView.findViewById(R.id.container);

        MaterialCardView card = itemView.findViewById(R.id.card);
        if (CandyBarApplication.getConfiguration().getApplyGrid() == CandyBarApplication.GridStyle.FLAT) {
            if (card.getLayoutParams() instanceof GridLayoutManager.LayoutParams) {
                card.setRadius(0f);
                card.setUseCompatPadding(false);
                int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
                GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) card.getLayoutParams();
                params.setMargins(0, 0, margin, margin);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    params.setMarginEnd(margin);
                }
            }
        }

        if (!Preferences.get(mContext).isCardShadowEnabled()) {
            if (card != null) card.setCardElevation(0);
        }

        holderId = TYPE_CONTENT;

        container.setOnClickListener(this);
    }
}
 
Example #4
Source File: ElevationMainDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("RestrictTo") // It's safe to use restricted MDC code in MDC Catalog.
private void updateCardsElevationLevel(View view, int newElevationLevel) {
  List<MaterialCardView> elevationCards =
      DemoUtils.findViewsWithType(view, MaterialCardView.class);

  if (newElevationLevel >= 0 && newElevationLevel <= getMaxElevationValue()) {
    setElevationLevel(newElevationLevel);
    for (MaterialCardView elevationCard : elevationCards) {
      elevationCard.setCardElevation(ViewUtils.dpToPx(view.getContext(), elevationInDp));
    }
    setElevationLevelTextView(view, getElevationLevelText());
  }
}
 
Example #5
Source File: CardSwipeDismissFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private static void onDragStateChanged(int state, MaterialCardView cardContentLayout) {
  switch (state) {
    case SwipeDismissBehavior.STATE_DRAGGING:
    case SwipeDismissBehavior.STATE_SETTLING:
      cardContentLayout.setDragged(true);
      break;
    case SwipeDismissBehavior.STATE_IDLE:
      cardContentLayout.setDragged(false);
      break;
    default: // fall out
  }
}
 
Example #6
Source File: CardSwipeDismissFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private static void resetCard(MaterialCardView cardContentLayout) {
  CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) cardContentLayout
      .getLayoutParams();
  params.setMargins(0, 0, 0, 0);
  cardContentLayout.setAlpha(1.0f);
  cardContentLayout.requestLayout();
}
 
Example #7
Source File: CardListDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(@Nullable ViewHolder viewHolder, int actionState) {
  super.onSelectedChanged(viewHolder, actionState);

  if (actionState == ItemTouchHelper.ACTION_STATE_DRAG && viewHolder != null) {
    dragCardView = (MaterialCardView) viewHolder.itemView;
    dragCardView.setDragged(true);
  } else if (actionState == ItemTouchHelper.ACTION_STATE_IDLE && dragCardView != null) {
    dragCardView.setDragged(false);
    dragCardView = null;
  }
}