Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** inner classes **/
- public class ShipKitAdapter extends CursorAdapter {
- public ShipKitAdapter(Context context, Cursor cur) {
- super(context, cur, true);
- }
- public void bindView(View view, Context context, Cursor cursor) {
- try {
- ((TextView)view.findViewById(R.id.kit_id)).setText(cursor.getString(cursor.getColumnIndex(DbSchema.KitSchema.TABLE_NAME+DbSchema.KitSchema.COLUMN_ID)));
- ((TextView)view.findViewById(R.id.net_units)).setText(cursor.getString(cursor.getColumnIndex(DbSchema.KitSchema.TABLE_NAME+DbSchema.KitSchema.COLUMN_NET)));
- ((TextView)view.findViewById(R.id.net_uom)).setText("lbs");
- ((TextView)view.findViewById(R.id.product_name)).setText(cursor.getString(cursor.getColumnIndex(DbSchema.ProductSchema.TABLE_NAME+DbSchema.ProductSchema.COLUMN_NAME)));
- ((TextView)view.findViewById(R.id.gross_units)).setText(cursor.getString(cursor.getColumnIndex(DbSchema.KitSchema.TABLE_NAME+DbSchema.KitSchema.COLUMN_GROSS)));
- ((TextView)view.findViewById(R.id.gross_uom)).setText("lbs");
- } catch(Exception e) {
- Log.i(LOG_TAG, "error getting a field: "+e.getMessage());
- }
- }
- public View newView(Context context, Cursor cursor, ViewGroup parent) {
- return mInflater.inflate(R.layout.ship_list_item, parent, false);
- }
- };
- ////////////////////////////////////////////////////////////
- class DashboardCursorAdapter extends SimpleCursorAdapter {
- int[] mTo;
- String[] mFrom;
- Context mCtx;
- LayoutInflater mInflater;
- public DashboardCursorAdapter(Context ctx, int layout, Cursor cur, String[] from, int[] to) {
- super(ctx, layout, cur, from, to);
- mFrom = from;
- mTo = to;
- mCtx = ctx;
- mInflater = LayoutInflater.from(ctx);
- }
- @Override
- public View getView(int position, View view, ViewGroup parent) {
- view = mInflater.inflate(R.layout.list_view_item_2, null);
- SharedPreferences prefs = mCtx.getSharedPreferences("dashboardprefs", 0);
- Cursor cursor = getCursor();
- cursor.moveToPosition(position);
- String productText = new String("");
- String uomText = new String("");
- String totalText = new String("");
- String unitsText = new String("");
- String acogText = new String("");
- int tempCount = 0;
- try {
- productText = cursor.getString(cursor.getColumnIndex(mFrom[tempCount])); tempCount++;
- uomText = cursor.getString(cursor.getColumnIndex(mFrom[tempCount])); tempCount++;
- totalText = cursor.getString(cursor.getColumnIndex(mFrom[tempCount])); tempCount++;
- unitsText = cursor.getString(cursor.getColumnIndex(mFrom[tempCount])); tempCount++;
- acogText = cursor.getString(cursor.getColumnIndex(mFrom[tempCount]));
- } catch(Exception e) {
- Log.d(LOG_TAG, "Exception retrieving: ");
- String[] colNames = cursor.getColumnNames();
- for(int i=0; i<colNames.length; i++) {
- Log.d(LOG_TAG, "Column: "+colNames[i]);
- }
- }
- TextView product = (TextView)view.findViewById(R.id.item_text_product);
- TextView uom = (TextView)view.findViewById(R.id.item_text_uom);
- TextView total = (TextView)view.findViewById(R.id.item_text_total);
- TextView units = (TextView)view.findViewById(R.id.item_text_units);
- TextView acog = (TextView)view.findViewById(R.id.item_text_acog);
- TextView acogQualifier = (TextView)view.findViewById(R.id.text_acog);
- if(prefs.getInt("color_mode", ColorActivity.LAYOUT_BRIGHT) == ColorActivity.LAYOUT_BRIGHT) {
- view.setBackgroundColor(prefs.getInt("bg_bright", Color.YELLOW));
- product.setTextColor(prefs.getInt("product_bright", Color.DKGRAY));
- uom.setTextColor(prefs.getInt("units_bright", Color.DKGRAY));
- total.setTextColor(prefs.getInt("total_bright", Color.DKGRAY));
- units.setTextColor(prefs.getInt("units_bright", Color.DKGRAY));
- acog.setTextColor(prefs.getInt("cost_bright", Color.DKGRAY));
- acogQualifier.setTextColor(prefs.getInt("cost_bright", Color.DKGRAY));
- } else {
- view.setBackgroundColor(prefs.getInt("bg_normal", Color.BLACK));
- product.setTextColor(prefs.getInt("product_normal", Color.LTGRAY));
- uom.setTextColor(prefs.getInt("units_normal", Color.LTGRAY));
- total.setTextColor(prefs.getInt("total_normal", Color.LTGRAY));
- units.setTextColor(prefs.getInt("units_normal", Color.LTGRAY));
- acog.setTextColor(prefs.getInt("cost_normal", Color.LTGRAY));
- acogQualifier.setTextColor(prefs.getInt("cost_normal", Color.LTGRAY));
- }
- product.setText(productText);
- uom.setText(uomText);
- total.setText(totalText);
- units.setText(unitsText);
- acog.setText(acogText);
- return view;
- }
- };
- /////////////////////////////////////////////////
- class CustomExpandableListAdapter extends SimpleExpandableListAdapter {
- Context mCtx;
- LayoutInflater vi;
- public List<List<Boolean>> checkData;
- String[] mChildFrom;
- int[] mChildTo;
- public CustomExpandableListAdapter(Context ctx, List<? extends Map<String, ?>> groupData, int groupLayout, String[] groupFrom, int[] groupTo, List<? extends List<? extends Map<String, ?>>>childData, int childLayout, String[] childFrom, int[] childTo, List<List<Boolean>> checkData) {
- super(ctx, groupData, groupLayout, groupFrom, groupTo, childData, childLayout, childFrom, childTo);
- this.mCtx=ctx;
- this.vi = (LayoutInflater)mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- this.checkData = checkData;
- this.mChildFrom = childFrom;
- this.mChildTo = childTo;
- }
- public boolean updateChecked(List<List<Boolean>> newData) {
- checkData = newData;
- return true;
- }
- public boolean isChecked(int groupPosition, int childPosition) {
- return checkData.get(groupPosition).get(childPosition);
- }
- private void bindView(View view, Map<String, ?> data, String[] from, int[] to) {
- int len = to.length;
- for (int i = 0; i < len; i++) {
- TextView v = (TextView)view.findViewById(to[i]);
- if (v != null) {
- v.setText((String)data.get(from[i]));
- }
- }
- }
- public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
- View rowView;
- rowView = new RelativeLayout(mCtx);
- if(vi != null) {
- vi.inflate(R.layout.call_list_item, (RelativeLayout)rowView, true);
- }
- if(this.checkData.get(groupPosition).get(childPosition)) {
- ((CheckedTextView)rowView.findViewById(R.id.checkmark)).setChecked(true);
- } else {
- ((CheckedTextView)rowView.findViewById(R.id.checkmark)).setChecked(false);
- }
- switch(mMode) {
- case MODE_PENDING:
- if(((TextView)rowView.findViewById(R.id.item_text_job))!=null){
- ((TextView)rowView.findViewById(R.id.item_text_job)).setVisibility(View.VISIBLE);
- }
- break;
- case MODE_BILLING:
- //rowView.forceLayout();
- break;
- default:
- break;
- }
- //if the child is in the "Not Registered" group, display different fields
- String display_name = null;
- if(groupData.get(groupPosition).containsValue("Not Registered")) {
- display_name = childData.get(groupPosition).get(childPosition).get("display_name");
- if(display_name != null && !display_name.equals("")) {
- TextView displayNameView = ((TextView)rowView.findViewById(R.id.text_minutes_billed));
- RelativeLayout.LayoutParams displayNameParams = ((RelativeLayout.LayoutParams)(displayNameView.getLayoutParams()));
- displayNameParams.addRule(RelativeLayout.BELOW, R.id.item_hidden_number);
- displayNameView.setLayoutParams(displayNameParams);
- displayNameView.setText(display_name);
- }
- }
- bindView(rowView, childData.get(groupPosition).get(childPosition), mChildFrom, mChildTo);
- if(groupData.get(groupPosition).containsValue("Not Registered")) {
- if(display_name!=null && !display_name.equals("")) {
- ((TextView)rowView.findViewById(R.id.text_minutes_billed)).setText(display_name);
- ((TextView)rowView.findViewById(R.id.text_minutes_billed)).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
- } else {
- ((TextView)rowView.findViewById(R.id.text_minutes_billed)).setVisibility(View.GONE);
- }
- ((TextView)rowView.findViewById(R.id.item_text_duration_billed)).setVisibility(View.GONE);
- }
- //return super.getChildView(groupPosition, childPosition, isLastChild, rowView, parent);
- return rowView;
- }
- public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
- RelativeLayout rowView;
- if(convertView == null) {
- rowView = new RelativeLayout(mCtx);
- if(vi!=null){
- vi.inflate(R.layout.call_group_item, rowView, true);
- }
- } else {
- rowView = (RelativeLayout)convertView;
- }
- if(!(((TextView)rowView.findViewById(R.id.item_text_job)) == null) )
- {
- ((TextView)rowView.findViewById(R.id.item_text_job)).setVisibility(View.GONE);
- }
- switch(mMode) {
- case MODE_PENDING:
- break;
- case MODE_BILLING:
- if(((TextView)rowView.findViewById(R.id.item_text_job))!=null) {
- ((TextView)rowView.findViewById(R.id.item_text_job)).setVisibility(View.VISIBLE);
- }
- //rowView.forceLayout();
- break;
- default:
- break;
- }
- //TODO: add code to resize the item when showing the job, as it is not done automagically.
- //parent.forceLayout();
- return super.getGroupView(groupPosition, isExpanded, rowView, parent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement