mirror of https://github.com/ThmmyNoLife/mTHMMY
Thodoris1999
6 years ago
5 changed files with 69 additions and 71 deletions
@ -0,0 +1,51 @@ |
|||||
|
package gr.thmmy.mthmmy.utils; |
||||
|
|
||||
|
import android.content.Context; |
||||
|
import android.graphics.drawable.Drawable; |
||||
|
import android.support.annotation.NonNull; |
||||
|
import android.support.v7.widget.AppCompatImageView; |
||||
|
import android.support.v7.widget.RecyclerView; |
||||
|
import android.view.LayoutInflater; |
||||
|
import android.view.View; |
||||
|
import android.view.ViewGroup; |
||||
|
import android.widget.BaseAdapter; |
||||
|
import android.widget.GridView; |
||||
|
import android.widget.ImageView; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
|
||||
|
import gr.thmmy.mthmmy.R; |
||||
|
|
||||
|
public class EmojiKeyboardAdapter extends RecyclerView.Adapter<EmojiKeyboardAdapter.EmojiViewHolder> { |
||||
|
private int[] emojiIds; |
||||
|
|
||||
|
public EmojiKeyboardAdapter(int[] emojiIds) { |
||||
|
this.emojiIds = emojiIds; |
||||
|
} |
||||
|
|
||||
|
@NonNull |
||||
|
@Override |
||||
|
public EmojiViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
|
AppCompatImageView imageView = (AppCompatImageView) LayoutInflater.from(parent.getContext()) |
||||
|
.inflate(R.layout.emoji_keyboard_grid_cell, parent, false); |
||||
|
return new EmojiViewHolder(imageView); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onBindViewHolder(@NonNull EmojiViewHolder holder, int position) { |
||||
|
holder.imageView.setImageResource(emojiIds[position]); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getItemCount() { |
||||
|
return emojiIds.length; |
||||
|
} |
||||
|
|
||||
|
public static class EmojiViewHolder extends RecyclerView.ViewHolder { |
||||
|
AppCompatImageView imageView; |
||||
|
public EmojiViewHolder(AppCompatImageView imageView) { |
||||
|
super(imageView); |
||||
|
this.imageView = imageView; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -1,53 +0,0 @@ |
|||||
package gr.thmmy.mthmmy.utils; |
|
||||
|
|
||||
import android.content.Context; |
|
||||
import android.graphics.drawable.Drawable; |
|
||||
import android.view.View; |
|
||||
import android.view.ViewGroup; |
|
||||
import android.widget.BaseAdapter; |
|
||||
import android.widget.GridView; |
|
||||
import android.widget.ImageView; |
|
||||
|
|
||||
import java.util.Arrays; |
|
||||
|
|
||||
public class ImageKeyboardAdapter extends BaseAdapter { |
|
||||
|
|
||||
private Context context; |
|
||||
private Integer[] emojiIds; |
|
||||
|
|
||||
public ImageKeyboardAdapter(Context context, Integer[] emojiIds) { |
|
||||
this.context = context; |
|
||||
this.emojiIds = emojiIds; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public int getCount() { |
|
||||
return emojiIds.length; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public Object getItem(int position) { |
|
||||
return null; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public long getItemId(int position) { |
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public View getView(int position, View convertView, ViewGroup parent) { |
|
||||
ImageView emoji; |
|
||||
if (convertView == null) { |
|
||||
emoji = new ImageView(context); |
|
||||
emoji.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); |
|
||||
emoji.setScaleType(ImageView.ScaleType.CENTER_CROP); |
|
||||
|
|
||||
emoji.setPadding(8, 8, 8, 8); |
|
||||
} else { |
|
||||
emoji = (ImageView) convertView; |
|
||||
} |
|
||||
emoji.setImageResource(emojiIds[position]); |
|
||||
return emoji; |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<android.support.v7.widget.AppCompatImageView |
||||
|
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:padding="8dp"/> |
Loading…
Reference in new issue