EmojiAdapter.java 1.55 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
package com.yidianling.dynamic.common.emoji;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.ydl.ydlcommon.utils.emoji.EmojiManager;
import com.yidianling.dynamic.R;
public class EmojiAdapter extends BaseAdapter {

	private Context context;
	
	private int startIndex;
	
	public EmojiAdapter(Context mContext, int startIndex) {
		this.context = mContext;
		this.startIndex = startIndex;
	}

	public int getCount() {
		int count = EmojiManager.getDisplayCount() - startIndex + 1;
		count = Math.min(count, EmoticonView.EMOJI_PER_PAGE + 1);
		return count;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return startIndex + position;
	}
	 
	@SuppressLint({ "ViewHolder", "InflateParams" })
	public View getView(int position, View convertView, ViewGroup parent) {
konghaorui committed
42
		convertView = LayoutInflater.from(context).inflate(R.layout.dynamic_nim_emoji_item, null);
konghaorui committed
43 44 45 46
		ImageView emojiThumb = (ImageView) convertView.findViewById(R.id.imgEmoji);
		int count = EmojiManager.getDisplayCount();
		int index = startIndex + position;
		if (position == EmoticonView.EMOJI_PER_PAGE || index == count) {
konghaorui committed
47
			emojiThumb.setBackgroundResource(R.drawable.dynamic_nim_emoji_del);
konghaorui committed
48 49 50 51 52 53 54 55
		} else if (index < count) {
            emojiThumb.setBackgroundDrawable(EmojiManager.getDisplayDrawable(context, index));
		}	
			
		return convertView;
	}

}