MessageCardScrollAdapter.java
Go to the documentation of this file.
00001 package com.riverlab.robotmanager.messages;
00002 
00003 import java.util.List;
00004 
00005 import android.bluetooth.BluetoothDevice;
00006 import android.content.Context;
00007 import android.util.Log;
00008 import android.view.View;
00009 import android.view.ViewGroup;
00010 import android.widget.ImageView;
00011 import android.widget.TextView;
00012 
00013 import com.google.android.glass.widget.CardScrollAdapter;
00014 import com.riverlab.robotmanager.R;
00015 
00016 public class MessageCardScrollAdapter extends CardScrollAdapter
00017 {
00018         private List<RobotMessage> mMessages;
00019         private Context context;
00020         ViewHolder holder;
00021         
00022         public MessageCardScrollAdapter(Context context, List<RobotMessage> messages) 
00023         {
00024         mMessages = messages;
00025         this.context = context;
00026     }
00027         
00028         public void addMessage(RobotMessage msg) {
00029         mMessages.add(msg);
00030     }
00031 
00032         @Override
00033         public int getCount() {
00034                 return mMessages.size();
00035         }
00036 
00037         @Override
00038         public RobotMessage getItem(int index) 
00039         {
00040                 return mMessages.get(index);
00041         }
00042 
00043         @Override
00044         public int getPosition(Object msg)
00045         {
00046                 return mMessages.indexOf((RobotMessage)msg);
00047         }
00048         
00049          class ViewHolder {
00050                 TextView headline;
00051                 TextView text;
00052                 ImageView img;
00053                 TextView timestamp;
00054                 TextView nextTxt;
00055                 TextView prevTxt;
00056                 TextView msgCounter;
00057                 ImageView indicator;
00058             }
00059 
00060         @Override
00061         public View getView(int position, View convertView, ViewGroup parent) {
00062         if (convertView == null) {
00063             convertView = View.inflate(context, R.layout.message_card, null);
00064             holder = new ViewHolder();
00065             Log.d("MessageActivity", "Getting views");
00066             holder.headline = (TextView) convertView.findViewById(R.id.headline);
00067             holder.text = (TextView) convertView.findViewById(R.id.messageText);
00068             holder.img = (ImageView) convertView.findViewById(R.id.imageView);
00069             holder.timestamp = (TextView) convertView.findViewById(R.id.timestampText);
00070             holder.nextTxt = (TextView) convertView.findViewById(R.id.msgNextText);
00071             holder.prevTxt = (TextView) convertView.findViewById(R.id.msgPreviousText);
00072             holder.msgCounter = (TextView) convertView.findViewById(R.id.msgCounterText);
00073             holder.indicator = (ImageView) convertView.findViewById(R.id.imageIndicator);
00074             
00075             convertView.setTag(holder);
00076         }
00077         else {
00078             holder = (ViewHolder) convertView.getTag();
00079         }
00080 
00081         RobotMessage msg = getItem(position);
00082         holder.headline.setText(msg.getSender() + ": ");
00083         holder.text.setText(msg.getText());
00084   
00085         if (msg.getType().equals("Image") && msg.getImage() != null)
00086         {
00087                 holder.img.setImageBitmap(msg.getImage());
00088                 holder.indicator.setVisibility(View.VISIBLE);
00089         }
00090         holder.timestamp.setText(msg.getTimestamp());
00091         
00092         
00093         if (hasNext(position))
00094         {
00095                 holder.nextTxt.setVisibility(View.VISIBLE);
00096                 holder.nextTxt.setText(R.string.next);
00097         }
00098         else
00099         {
00100                 holder.nextTxt.setVisibility(View.INVISIBLE);
00101                 //holder.nextTxt.setText(R.string.no_next);
00102         }
00103         
00104         if (hasPrevious(position))
00105         {
00106                 holder.prevTxt.setVisibility(View.VISIBLE);
00107                 holder.prevTxt.setText(R.string.previous);
00108         }
00109         else
00110         {
00111                 holder.prevTxt.setVisibility(View.INVISIBLE);
00112                 //holder.prevTxt.setText(R.string.no_previous);
00113         }
00114         
00115         holder.msgCounter.setText((position + 1) + " of " + mMessages.size());
00116 
00117         return convertView;
00118         }
00119         
00120         private boolean hasNext(int position)
00121         {
00122                 int last = mMessages.size();
00123                 int next = position + 1;
00124 
00125                 return next < last;
00126         }
00127         
00128         private boolean hasPrevious(int position)
00129         {
00130                 return position > 0;
00131         }
00132         
00133         public ViewHolder getHolder()
00134         {
00135                 return holder;
00136         }
00137 
00138 }


google_glass_driver
Author(s): Nicholas Otero
autogenerated on Fri Aug 28 2015 10:51:44