Search in sources :

Example 21 with CardView

use of androidx.cardview.widget.CardView in project Slide by ccrama.

the class CreateCardView method CreateView.

public static View CreateView(ViewGroup viewGroup) {
    CardEnum cardEnum = SettingValues.defaultCardView;
    View v = null;
    switch(cardEnum) {
        case LARGE:
            if (SettingValues.middleImage) {
                v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.submission_largecard_middle, viewGroup, false);
            } else {
                v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.submission_largecard, viewGroup, false);
            }
            break;
        case LIST:
            v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.submission_list, viewGroup, false);
            // if the radius is set to 0 on KitKat--it crashes.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                ((CardView) v.findViewById(R.id.card)).setRadius(0f);
            }
            break;
        case DESKTOP:
            v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.submission_list_desktop, viewGroup, false);
            // if the radius is set to 0 on KitKat--it crashes.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                ((CardView) v.findViewById(R.id.card)).setRadius(0f);
            }
            break;
    }
    View thumbImage = v.findViewById(R.id.thumbimage2);
    /**
     * If the user wants small thumbnails, revert the list style to the "old" list view.
     * The "old" thumbnails were (70dp x 70dp).
     * Adjusts the paddingTop of the innerrelative, and adjusts the margins on the thumbnail.
     */
    if (!SettingValues.bigThumbnails) {
        if (SettingValues.defaultCardView == CardEnum.DESKTOP) {
            final int SQUARE_THUMBNAIL_SIZE = 48;
            thumbImage.getLayoutParams().height = DisplayUtil.dpToPxVertical(SQUARE_THUMBNAIL_SIZE);
            thumbImage.getLayoutParams().width = DisplayUtil.dpToPxHorizontal(SQUARE_THUMBNAIL_SIZE);
        } else {
            final int SQUARE_THUMBNAIL_SIZE = 70;
            thumbImage.getLayoutParams().height = DisplayUtil.dpToPxVertical(SQUARE_THUMBNAIL_SIZE);
            thumbImage.getLayoutParams().width = DisplayUtil.dpToPxHorizontal(SQUARE_THUMBNAIL_SIZE);
            final int EIGHT_DP_Y = DisplayUtil.dpToPxVertical(8);
            final int EIGHT_DP_X = DisplayUtil.dpToPxHorizontal(8);
            ((RelativeLayout.LayoutParams) thumbImage.getLayoutParams()).setMargins(EIGHT_DP_X * 2, EIGHT_DP_Y, EIGHT_DP_X, EIGHT_DP_Y);
            v.findViewById(R.id.innerrelative).setPadding(0, EIGHT_DP_Y, 0, 0);
        }
    }
    if (SettingValues.noThumbnails) {
        final int SQUARE_THUMBNAIL_SIZE = 0;
        thumbImage.getLayoutParams().height = DisplayUtil.dpToPxVertical(SQUARE_THUMBNAIL_SIZE);
        thumbImage.getLayoutParams().width = DisplayUtil.dpToPxHorizontal(SQUARE_THUMBNAIL_SIZE);
    }
    doHideObjects(v);
    return v;
}
Also used : CardView(androidx.cardview.widget.CardView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) CardView(androidx.cardview.widget.CardView)

Example 22 with CardView

use of androidx.cardview.widget.CardView in project MTweaks-KernelAdiutorMOD by morogoku.

the class RecyclerViewAdapter method onCreateViewHolder.

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
    RecyclerViewItem item = mItems.get(position);
    View view;
    if (item.cacheable()) {
        if (mViews.containsKey(item)) {
            view = mViews.get(item);
        } else {
            mViews.put(item, view = LayoutInflater.from(parent.getContext()).inflate(item.getLayoutRes(), parent, false));
        }
    } else {
        try {
            view = LayoutInflater.from(parent.getContext()).inflate(item.getLayoutRes(), parent, false);
        } catch (Exception ignored) {
            throw new IllegalArgumentException("Couldn't inflate " + item.getClass().getSimpleName());
        }
    }
    ViewGroup viewGroup = (ViewGroup) view.getParent();
    if (viewGroup != null) {
        viewGroup.removeView(view);
    }
    if (item.cardCompatible() && AppSettings.isForceCards(parent.getContext())) {
        CardView cardView = new CardView(view.getContext());
        cardView.setRadius(view.getResources().getDimension(R.dimen.cardview_radius));
        cardView.setCardElevation(view.getResources().getDimension(R.dimen.cardview_elevation));
        cardView.setUseCompatPadding(true);
        cardView.setFocusable(false);
        cardView.addView(view);
        view = cardView;
    }
    if (position == 0) {
        mFirstItem = view;
    }
    item.setOnViewChangeListener(mOnViewChangedListener);
    item.onCreateHolder(parent, view);
    return new RecyclerView.ViewHolder(view) {
    };
}
Also used : ViewGroup(android.view.ViewGroup) CardView(androidx.cardview.widget.CardView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) NonNull(androidx.annotation.NonNull)

Aggregations

CardView (androidx.cardview.widget.CardView)22 View (android.view.View)17 TextView (android.widget.TextView)13 ViewGroup (android.view.ViewGroup)7 ImageView (android.widget.ImageView)6 Context (android.content.Context)5 Nullable (androidx.annotation.Nullable)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 Objects (java.util.Objects)5 NonNull (androidx.annotation.NonNull)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 ColorStateList (android.content.res.ColorStateList)2 Drawable (android.graphics.drawable.Drawable)2 Bundle (android.os.Bundle)2 Spannable (android.text.Spannable)2 SpannableString (android.text.SpannableString)2 AttributeSet (android.util.AttributeSet)2 LayoutInflater (android.view.LayoutInflater)2 Menu (android.view.Menu)2