Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 package com.github.rosjava.android_remocons.rocon_remocon;
00035
00036 import android.content.Context;
00037 import android.graphics.Bitmap;
00038 import android.graphics.BitmapFactory;
00039 import android.view.LayoutInflater;
00040 import android.view.View;
00041 import android.view.ViewGroup;
00042 import android.widget.BaseAdapter;
00043 import android.widget.ImageView;
00044 import android.widget.TextView;
00045
00046 import org.jboss.netty.buffer.ChannelBuffer;
00047
00048 import java.util.ArrayList;
00049
00050 import rocon_interaction_msgs.Interaction;
00051
00052 public class AppAdapter extends BaseAdapter {
00053 private Context context;
00054 private ArrayList<Interaction> interactions;
00055
00056 public AppAdapter(Context c, ArrayList<Interaction> interactions) {
00057 context = c;
00058 this.interactions = interactions;
00059 }
00060
00061 @Override
00062 public int getCount() {
00063 if (interactions == null) {
00064 return 0;
00065 }
00066 return interactions.size();
00067 }
00068
00069 @Override
00070 public Object getItem(int position) {
00071 return null;
00072 }
00073
00074 @Override
00075 public long getItemId(int position) {
00076 return 0;
00077 }
00078
00082 @Override
00083 public View getView(int position, View convertView, ViewGroup parent) {
00084 LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
00085
00086 View view = inflater.inflate(R.layout.app_item, null);
00087 Interaction interaction = interactions.get(position);
00088 if( interaction.getIcon().getData().array().length > 0 && interaction.getIcon().getFormat() != null &&
00089 (interaction.getIcon().getFormat().equals("jpeg") || interaction.getIcon().getFormat().equals("png")) ) {
00090 ChannelBuffer buffer = interaction.getIcon().getData();
00091 Bitmap iconBitmap = BitmapFactory.decodeByteArray( interaction.getIcon().getData().array(), buffer.arrayOffset(), buffer.readableBytes());
00092
00093 if( iconBitmap != null ) {
00094 ImageView iv = (ImageView) view.findViewById(R.id.icon);
00095 iv.setImageBitmap(iconBitmap);
00096 }
00097 }
00098 TextView tv = (TextView) view.findViewById(R.id.name);
00099 tv.setText(interaction.getDisplayName());
00100
00101 return view;
00102 }
00103 }