RobotCardScrollAdapter.java
Go to the documentation of this file.
00001 package com.riverlab.robotmanager.robot;
00002 
00003 import android.app.ActionBar.LayoutParams;
00004 import android.bluetooth.BluetoothDevice;
00005 import android.content.Context;
00006 import android.view.Gravity;
00007 import android.view.View;
00008 import android.view.ViewGroup;
00009 import android.webkit.WebView.FindListener;
00010 import android.widget.ImageView;
00011 import android.widget.LinearLayout;
00012 import android.widget.TextView;
00013 
00014 import com.google.android.glass.widget.CardScrollAdapter;
00015 import com.google.android.search.core.util.HttpHelper.GetRequest;
00016 import com.riverlab.robotmanager.R;
00017 import com.riverlab.robotmanager.R.id;
00018 import com.riverlab.robotmanager.R.layout;
00019 
00020 import java.util.ArrayList;
00021 import java.util.Collection;
00022 import java.util.List;
00023 
00024 public class RobotCardScrollAdapter extends CardScrollAdapter {
00025         List<Robot> mRobotList;
00026         Context context;
00027 
00028         public RobotCardScrollAdapter(Context context, Collection<Robot> robots) {
00029                 mRobotList = new ArrayList<Robot>(robots);
00030                 this.context = context;
00031         }
00032 
00033         public void addRobot(Robot robot) {
00034                 mRobotList.add(robot);
00035         }
00036 
00037         @Override
00038         public int getCount() {
00039                 return mRobotList.size();
00040         }
00041 
00042         @Override
00043         public Robot getItem(int position) {
00044                 return mRobotList.get(position);
00045         }
00046 
00047         class ViewHolder {
00048                 TextView name;
00049                 TextView infoTextView;
00050                 TextView prevTxt;
00051                 TextView nextTxt;
00052                 TextView robotCounter;
00053         }
00054 
00055         @Override
00056         public View getView(int position, View convertView, ViewGroup parent) {
00057                 ViewHolder holder;
00058                 int nextID = 3;
00059 
00060                 if (convertView == null)
00061                 {
00062                         convertView = View.inflate(context, R.layout.robot_card, null);
00063                         holder = new ViewHolder();
00064 
00065                         Robot robot = mRobotList.get(position);
00066 
00067                         LinearLayout ll = (LinearLayout) convertView
00068                                         .findViewById(R.id.scrollLinearLayout);
00069                         LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
00070                                         LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
00071 
00072                         holder.name = new TextView(this.context);
00073                         holder.name.setId(nextID);
00074                         nextID++;
00075                         holder.name.setTextSize(50);
00076                         holder.name.setText(robot.getName());
00077                         holder.name.setLayoutParams(lp);
00078                         holder.name.setGravity(Gravity.CENTER);
00079                         ll.addView(holder.name);
00080 
00081                         holder.infoTextView = new TextView(this.context);
00082                         holder.infoTextView.setId(nextID);
00083                         holder.infoTextView.setTextSize(24);
00084                         holder.infoTextView.setText(robot.getInfo());
00085                         holder.infoTextView.setLayoutParams(lp);
00086                         holder.infoTextView.setGravity(Gravity.LEFT);
00087                         holder.infoTextView.setPadding(30, 10, 30, 10);
00088                         holder.infoTextView.setTextColor(context.getResources().getColor(R.color.blue));
00089                         ll.addView(holder.infoTextView);
00090                         
00091                         holder.prevTxt = (TextView) convertView.findViewById(R.id.robotPreviousText);
00092                         holder.nextTxt = (TextView) convertView.findViewById(R.id.robotNextText);
00093                         holder.robotCounter = (TextView) convertView.findViewById(R.id.robotCounterText);
00094                         
00095                         convertView.setTag(holder);
00096                 } else 
00097                 {
00098                         holder = (ViewHolder) convertView.getTag();
00099                 }
00100                 
00101                 if (hasNext(position))
00102         {
00103                 holder.nextTxt.setVisibility(View.VISIBLE);
00104                 holder.nextTxt.setText(R.string.next);
00105         }
00106         else
00107         {
00108                 holder.nextTxt.setVisibility(View.INVISIBLE);
00109                 //holder.nextTxt.setText(R.string.no_next);
00110         }
00111         
00112         if (hasPrevious(position))
00113         {
00114                 holder.prevTxt.setVisibility(View.VISIBLE);
00115                 holder.prevTxt.setText(R.string.previous);
00116         }
00117         else
00118         {
00119                 holder.prevTxt.setVisibility(View.INVISIBLE);
00120                 //holder.prevTxt.setText(R.string.no_previous);
00121         }
00122         
00123         holder.robotCounter.setText((position + 1) + " of " + mRobotList.size());
00124 
00125                 return convertView;
00126         }
00127         
00128         private boolean hasNext(int position)
00129         {
00130                 int last = mRobotList.size();
00131                 int next = position + 1;
00132 
00133                 return next < last;
00134         }
00135         
00136         private boolean hasPrevious(int position)
00137         {
00138                 return position > 0;
00139         }
00140 
00141         @Override
00142         public int getPosition(Object arg0) {
00143                 // TODO Auto-generated method stub
00144                 return 0;
00145         }
00146 }


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