Copyright (c) 2014, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are m...
If you think the Android project sdl_tester_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.livio.sdl.adapters;
//fromwww.java2s.comimport java.util.List;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.livio.sdl.R;
import com.livio.sdl.SdlLogMessage;
/**
* A custom adapter class for showing SDL log messages in a listview. The adapter shows the message
* name, details and a timestamp of when the message was first logged.
*
* @author Mike Burke
*
*/publicclass SdlMessageAdapter extends ArrayAdapter<SdlLogMessage> {
privatestaticfinalint REQUEST_COLOR = Color.BLUE;
privatestaticfinalint RESPONSE_SUCCESS_COLOR = 0xFF2D9C08; // dark green
privatestaticfinalint RESPONSE_FAILURE_COLOR = Color.RED;
privatestaticfinalint NOTIFICATION_COLOR = Color.BLACK;
public SdlMessageAdapter(Context context, List<SdlLogMessage> objects) {
super(context, R.layout.sdl_message_listview_row, objects);
}
public SdlMessageAdapter(Context context) {
super(context, R.layout.sdl_message_listview_row);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.sdl_message_listview_row, null);
}
SdlLogMessage item = getItem(position);
if(item != null){
populateView(view, item);
}
return view;
}
/**
* Populate the input parent view with information from the SDL log message.
*
* @param view The view to populate
* @param item The data with which to populate the view
*/privatevoid populateView(View view, SdlLogMessage item){
TextView tv_messageName = (TextView) view.findViewById(R.id.tv_messageName);
TextView tv_messageDetails = (TextView) view.findViewById(R.id.tv_messageDetail);
TextView tv_timestamp = (TextView) view.findViewById(R.id.tv_timestamp);
// set text values based on input message
tv_messageName.setText(item.getFunctionName());
tv_messageDetails.setText(item.getDetails());
tv_timestamp.setText(item.getTimeStamp());
String messageType = item.getMessageType();
// set the text colors based on the inputs
if(messageType.equals(SdlLogMessage.REQUEST)){
tv_messageName.setTextColor(REQUEST_COLOR);
}
elseif(messageType.equals(SdlLogMessage.RESPONSE)){
if(item.getSuccess()){
tv_messageName.setTextColor(RESPONSE_SUCCESS_COLOR);
tv_messageDetails.setTextColor(RESPONSE_SUCCESS_COLOR);
}
else{
tv_messageName.setTextColor(RESPONSE_FAILURE_COLOR);
tv_messageDetails.setTextColor(RESPONSE_FAILURE_COLOR);
}
}
elseif(messageType.equals(SdlLogMessage.NOTIFICATION)){
tv_messageName.setTextColor(NOTIFICATION_COLOR);
}
}
}