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;
}
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) {
};
}
Aggregations