1st version that works
This commit is contained in:
@ -0,0 +1,138 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.Alarm;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public class AlertGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Alarm> listAlarms;
|
||||
private Activity activity;
|
||||
private ArrayList<Boolean> acknowledged = new ArrayList<Boolean>();
|
||||
|
||||
public AlertGridViewAdapter(Activity activity, ArrayList<Alarm> listAlarms, Context context, ArrayList<Boolean> acknowledged) {
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listAlarms = listAlarms;
|
||||
this.acknowledged = acknowledged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listAlarms.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Alarm getItem(int position) {
|
||||
return listAlarms.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public LinearLayout layoutAlert;
|
||||
public ImageView imageViewAlert, imageViewRecycle;
|
||||
public TextView textViewUnitName, textViewType, textViewDate;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_alert, null);
|
||||
|
||||
view.textViewUnitName = (TextView) convertView.findViewById(R.id.textViewUnitName);
|
||||
view.textViewType = (TextView) convertView.findViewById(R.id.textViewType);
|
||||
view.textViewDate = (TextView) convertView.findViewById(R.id.textViewDate);
|
||||
view.imageViewRecycle = (ImageView) convertView.findViewById(R.id.imageViewRecycle);
|
||||
view.imageViewAlert = (ImageView) convertView.findViewById(R.id.imageViewAlert);
|
||||
view.layoutAlert = (LinearLayout) convertView.findViewById(R.id.layoutAlert);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
view.textViewUnitName.setText(listAlarms.get(position).unitName);
|
||||
view.textViewType.setText(listAlarms.get(position).typestr);
|
||||
|
||||
//view.txtViewDescription.setText(listAlarms.get(position).description);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
Date date = new Date((long)listAlarms.get(position).timeGMT * 1000);
|
||||
if(date.getDate() == Calendar.getInstance().get(Calendar.DAY_OF_MONTH))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm");
|
||||
view.textViewDate.setText(String.valueOf(sdf.format(date)));
|
||||
|
||||
// set ack/!ack image
|
||||
switch(acknowledged.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imageViewAlert.setImageResource(R.drawable.alert_off);
|
||||
//view.layoutAlarm.setBackgroundColor(0xffffffff);
|
||||
break;
|
||||
case 0:
|
||||
view.imageViewAlert.setImageResource(R.drawable.alert);
|
||||
//view.layoutAlarm.setBackgroundColor(0xffcccccc);
|
||||
break;
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public void changeACK(int position)
|
||||
{
|
||||
SM.Debug("ACK ON START: " + position + " | " + (acknowledged.get(position) ? "true": "false"));
|
||||
// change in list
|
||||
acknowledged.remove(position);
|
||||
acknowledged.add(position, true);
|
||||
|
||||
ViewHolder view = new ViewHolder();
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
View convertView = null;
|
||||
if(convertView==null)
|
||||
{
|
||||
convertView = inflator.inflate(R.layout.row_alert, null);
|
||||
try
|
||||
{
|
||||
view.imageViewAlert = (ImageView) convertView.findViewById(R.id.imageViewAlert);
|
||||
view.imageViewAlert.setImageResource(R.drawable.alert_off);
|
||||
convertView.setTag(view);
|
||||
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,107 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ContactsComboBoxAdapter extends ArrayAdapter<Contact>{
|
||||
|
||||
private Context context;
|
||||
int layoutResourceId;
|
||||
private ArrayList<Contact> listValues;
|
||||
|
||||
public ContactsComboBoxAdapter(Context context, int textViewResourceId, ArrayList<Contact> listValues) {
|
||||
super(context, textViewResourceId, listValues);
|
||||
this.context = context;
|
||||
this.layoutResourceId = textViewResourceId;
|
||||
this.listValues = listValues;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
public View getCustomView(int position, View convertView, ViewGroup parent) {
|
||||
View row = convertView;
|
||||
ImagesSpinnerHolder holder = null;
|
||||
|
||||
if(row == null) {
|
||||
|
||||
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||||
/*LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);*/
|
||||
|
||||
row = inflater.inflate(layoutResourceId, parent, false);
|
||||
|
||||
holder = new ImagesSpinnerHolder();
|
||||
holder.textSpinner = (TextView)row.findViewById(R.id.language);
|
||||
holder.imgSpinner = (ImageView)row.findViewById(R.id.icon);
|
||||
|
||||
row.setTag(holder);
|
||||
}
|
||||
else
|
||||
holder = (ImagesSpinnerHolder)row.getTag();
|
||||
|
||||
holder.textSpinner.setText(getTextFromArrayList(position));
|
||||
holder.imgSpinner.setImageResource(getImageFromArrayList(position));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find which generic type which is used in the array list and then display the string field for that class type
|
||||
* @param position The position in the array list which needs to be displayed
|
||||
* @return The string which will be used
|
||||
*/
|
||||
private String getTextFromArrayList(int position) {
|
||||
return listValues.get(position).name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find which generic type which is used in the array list and then get the icon which needs to be displayed
|
||||
* @param position The position in the array list which needs to be displayed
|
||||
* @return The Image Resource which will be displayed
|
||||
*/
|
||||
private int getImageFromArrayList(int position) {
|
||||
int contactType = listValues.get(position).contactType;
|
||||
|
||||
switch(contactType)
|
||||
{
|
||||
case AppParams.MotoManualDial:
|
||||
return R.drawable.dial;
|
||||
case AppParams.MotoAllCall:
|
||||
return R.drawable.call_all_green_small;
|
||||
case AppParams.MotoPrivate:
|
||||
return R.drawable.call_private_green_small;
|
||||
case AppParams.MotoGroup:
|
||||
return R.drawable.call_group_green_small;
|
||||
|
||||
default: return R.drawable.call_private_blue_small;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class ImagesSpinnerHolder {
|
||||
ImageView imgSpinner;
|
||||
TextView textSpinner;
|
||||
}
|
||||
}
|
@ -0,0 +1,200 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.Msg;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class ConversationGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Msg> listMessages;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
private ArrayList<Boolean> dispatcher_positions = new ArrayList<Boolean>();
|
||||
private ArrayList<Boolean> ackPositions = new ArrayList<Boolean>();
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
|
||||
public ConversationGridViewAdapter(Activity activity, ArrayList<Msg> listMessages, Context context, long sc_id, int unit_type, ArrayList<Boolean> dispatcher_positions, ArrayList<Boolean> ackPositions) {
|
||||
this.activity = activity;
|
||||
this.listMessages = listMessages;
|
||||
this.dispatcher_positions = dispatcher_positions;
|
||||
this.ackPositions = ackPositions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listMessages.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Msg getItem(int position) {
|
||||
return listMessages.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewContact;
|
||||
public TextView txtViewMsg;
|
||||
public TextView txtViewDateTime;
|
||||
public ImageView imgViewReceivedContact;
|
||||
public TextView txtViewReceivedMsg;
|
||||
public TextView txtViewReceivedDateTime;
|
||||
public ImageView imageAck;
|
||||
public TextView textViewNotACK;
|
||||
public LinearLayout layoutSend;
|
||||
public LinearLayout layoutReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_conversation, null);
|
||||
|
||||
view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewSenderIco);
|
||||
view.txtViewMsg = (TextView) convertView.findViewById(R.id.textViewSendMsg);
|
||||
view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewSendDate);
|
||||
view.imgViewReceivedContact = (ImageView) convertView.findViewById(R.id.imageViewReceivedIco);
|
||||
view.txtViewReceivedMsg = (TextView) convertView.findViewById(R.id.textViewReceivedMsg);
|
||||
view.txtViewReceivedDateTime = (TextView) convertView.findViewById(R.id.textViewReceivedDate);
|
||||
view.layoutSend = (LinearLayout) convertView.findViewById(R.id.layoutSend);
|
||||
view.layoutReceived = (LinearLayout) convertView.findViewById(R.id.layoutReceived);
|
||||
view.textViewNotACK = (TextView) convertView.findViewById(R.id.textViewNotACKSendMsg);
|
||||
view.imageAck = (ImageView) convertView.findViewById(R.id.imageAck);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
try
|
||||
{
|
||||
hash.put(position, convertView);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm MMM-dd");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
if(listMessages.get(position).received.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
else
|
||||
sdf = new SimpleDateFormat("HH:mm MMM-dd");
|
||||
|
||||
|
||||
//view.imgViewContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||||
view.imgViewContact.setImageResource(R.drawable.peoplegreen_large);
|
||||
view.txtViewMsg.setText(listMessages.get(position).message);
|
||||
view.txtViewDateTime.setText(sdf.format(listMessages.get(position).received));
|
||||
//view.imgViewReceivedContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||||
view.imgViewReceivedContact.setImageResource(listMessages.get(position).from.getLargeIcon());
|
||||
view.txtViewReceivedMsg.setText(listMessages.get(position).message);
|
||||
view.txtViewReceivedDateTime.setText(sdf.format(listMessages.get(position).received));
|
||||
|
||||
if(ackPositions.size() > 0)
|
||||
switch(ackPositions.get(position) ? 1: 0) {
|
||||
case 0:
|
||||
// show not ack
|
||||
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||||
view.imageAck.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case 1:
|
||||
// show not ack
|
||||
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||||
view.imageAck.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
switch(dispatcher_positions.get(position) ? 1 : 0) {
|
||||
case 1:
|
||||
view.layoutReceived.setVisibility(View.GONE);
|
||||
view.layoutSend.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case 0:
|
||||
view.layoutReceived.setVisibility(View.VISIBLE);
|
||||
view.layoutSend.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public void setACK(String seqID)
|
||||
{
|
||||
int position = -1, i=0;
|
||||
|
||||
for(Msg msg: listMessages)
|
||||
{
|
||||
if(msg.seqID.equals(seqID))
|
||||
position = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if(position > -1 && position < ackPositions.size()) {
|
||||
ackPositions.remove(position);
|
||||
ackPositions.add(position, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeView(String seqID)
|
||||
{
|
||||
int position = -1, i=0;
|
||||
|
||||
for(Msg msg: listMessages)
|
||||
{
|
||||
if(msg.seqID.equals(seqID))
|
||||
position = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if(position != -1 && hash.size() > position)
|
||||
{
|
||||
SM.Debug("POSITON : " + position);
|
||||
View con = hash.get(position);
|
||||
ViewHolder view = (ViewHolder) con.getTag();
|
||||
|
||||
switch(ackPositions.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imageAck.setVisibility(View.INVISIBLE);
|
||||
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||||
break;
|
||||
case 0:
|
||||
view.imageAck.setVisibility(View.VISIBLE);
|
||||
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import com.safemobile.lib.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class LanguageSpinnerAdapter extends ArrayAdapter<String>{
|
||||
|
||||
private String[] Languages;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
public LanguageSpinnerAdapter(Context context, int textViewResourceId,String[] Languages, LayoutInflater inflater) {
|
||||
super(context, textViewResourceId, Languages);
|
||||
this.Languages = Languages;
|
||||
this.inflater = inflater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
public View getCustomView(int position, View convertView, ViewGroup parent) {
|
||||
View row = inflater.inflate(R.layout.spinner, parent, false);
|
||||
TextView label=(TextView)row.findViewById(R.id.language);
|
||||
label.setText(Languages[position]);
|
||||
ImageView icon =(ImageView)row.findViewById(R.id.icon);
|
||||
|
||||
switch (position)
|
||||
{
|
||||
case 0: icon.setImageResource(R.drawable.en); break;
|
||||
case 1: icon.setImageResource(R.drawable.de); break;
|
||||
case 2: icon.setImageResource(R.drawable.tr); break;
|
||||
case 3: icon.setImageResource(R.drawable.ro); break;
|
||||
case 4: icon.setImageResource(R.drawable.ru); break;
|
||||
case 5: icon.setImageResource(R.drawable.es); break;
|
||||
case 6: icon.setImageResource(R.drawable.ara); break;
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
}
|
@ -0,0 +1,231 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
public class LiveGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Vehicle> listVehicle;
|
||||
private ArrayList<Boolean> displayedVehicles;
|
||||
public ArrayList<Boolean> disabledVehicles;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
public LiveGridViewAdapter(Activity activity, ArrayList<Vehicle> listVehicle, Context context, ArrayList<Boolean> displayedVehicles, ArrayList<Boolean> disabledVehicles)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listVehicle = listVehicle;
|
||||
//this.time = time;
|
||||
this.displayedVehicles = displayedVehicles;
|
||||
this.disabledVehicles = disabledVehicles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listVehicle.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vehicle getItem(int position) {
|
||||
return listVehicle.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewIcon, imgViewChecked;
|
||||
public TextView txtViewName;
|
||||
public LinearLayout layoutVehicle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_vehicle, null);
|
||||
|
||||
view.imgViewIcon = (ImageView) convertView.findViewById(R.id.imageViewIcon);
|
||||
view.txtViewName = (TextView) convertView.findViewById(R.id.textViewName);
|
||||
view.imgViewChecked = (ImageView) convertView.findViewById(R.id.imageViewChecked);
|
||||
|
||||
//view.linearLayoutChecked = (LinearLayout) convertView.findViewById(R.id.linearLayoutChecked);
|
||||
view.layoutVehicle = (LinearLayout) convertView.findViewById(R.id.layoutVehicle);
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
hash.put(position, convertView);
|
||||
|
||||
view.imgViewIcon.setImageResource(listVehicle.get(position).getSmallIcon());
|
||||
view.txtViewName.setText(listVehicle.get(position).name);
|
||||
// set color
|
||||
//int colorPos = position % colors.length;
|
||||
//view.layoutVehicle.setBackgroundColor(colors[colorPos]);
|
||||
switch(displayedVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
break;
|
||||
case 0:
|
||||
view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(disabledVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.layoutVehicle.setBackgroundColor(0xffcccccc);
|
||||
//view.imgViewIcon.setImageDrawable(convertToGrayscale(activity.getResources().getDrawable(listVehicle.get(position).getSmallIcon())));
|
||||
break;
|
||||
case 0:
|
||||
view.layoutVehicle.setBackgroundColor(0xffFFFFFF);
|
||||
//view.imgViewIcon.setImageResource(listVehicle.get(position).getSmallIcon());
|
||||
break;
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public void changeDisplayed(int position, int status)
|
||||
{
|
||||
SM.Debug("DISABLE ON START: " + position + " | " + (disabledVehicles.get(position) ? "true": "false"));
|
||||
SM.Debug("DISPLAY ON START: " + position + " | " + (displayedVehicles.get(position) ? "true": "false"));
|
||||
// if vehicle is enable
|
||||
if(status == 1)
|
||||
{
|
||||
// change icon
|
||||
//view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
// change in list
|
||||
disabledVehicles.remove(position);
|
||||
disabledVehicles.add(position, false);
|
||||
}
|
||||
else if(status == 0)
|
||||
{
|
||||
// change icon
|
||||
//view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
// change in list
|
||||
disabledVehicles.remove(position);
|
||||
disabledVehicles.add(position, true);
|
||||
}
|
||||
// change displayed
|
||||
else if (status == -1)
|
||||
{
|
||||
// check selected position
|
||||
displayedVehicles.remove(position);
|
||||
displayedVehicles.add(position, true);
|
||||
}
|
||||
|
||||
ViewHolder view = new ViewHolder();
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
View convertView = null;
|
||||
if(convertView==null)
|
||||
{
|
||||
convertView = inflator.inflate(R.layout.row_vehicle, null);
|
||||
try
|
||||
{
|
||||
view.layoutVehicle = (LinearLayout) convertView.findViewById(R.id.layoutVehicle);
|
||||
view.imgViewIcon = (ImageView) convertView.findViewById(R.id.imageViewIcon);
|
||||
view.imgViewChecked = (ImageView) convertView.findViewById(R.id.imageViewChecked);
|
||||
convertView.setTag(view);
|
||||
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
SM.Debug("DISABLE AFTER: " + position + " | " + (disabledVehicles.get(position) ? "true": "false"));
|
||||
SM.Debug("DISPLAY AFTER: " + position + " | " + (displayedVehicles.get(position) ? "true": "false"));
|
||||
switch(disabledVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.layoutVehicle.setBackgroundColor(0xffcccccc);
|
||||
//view.imgViewIcon.setImageDrawable(convertToGrayscale(activity.getResources().getDrawable(listVehicle.get(position).getSmallIcon())));
|
||||
break;
|
||||
case 0:
|
||||
view.layoutVehicle.setBackgroundColor(0xffFFFFFF);
|
||||
//view.imgViewIcon.setImageResource(listVehicle.get(position).getSmallIcon());
|
||||
break;
|
||||
}
|
||||
|
||||
switch(displayedVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
break;
|
||||
case 0:
|
||||
view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void changeView(int position)
|
||||
{
|
||||
View con = hash.get(position);
|
||||
ViewHolder view = (ViewHolder) con.getTag();
|
||||
switch(disabledVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.layoutVehicle.setBackgroundColor(0xffcccccc);
|
||||
//view.imgViewIcon.setImageDrawable(convertToGrayscale(activity.getResources().getDrawable(listVehicle.get(position).getSmallIcon())));
|
||||
break;
|
||||
case 0:
|
||||
view.layoutVehicle.setBackgroundColor(0xffFFFFFF);
|
||||
//view.imgViewIcon.setImageResource(listVehicle.get(position).getSmallIcon());
|
||||
break;
|
||||
}
|
||||
|
||||
switch(displayedVehicles.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
break;
|
||||
case 0:
|
||||
view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected Drawable convertToGrayscale(Drawable drawable)
|
||||
{
|
||||
ColorMatrix matrix = new ColorMatrix();
|
||||
matrix.setSaturation(0);
|
||||
|
||||
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
|
||||
|
||||
drawable.setColorFilter(filter);
|
||||
|
||||
return drawable;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.Msg;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class MessagesGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Msg> listMessages;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
|
||||
|
||||
public MessagesGridViewAdapter(Activity activity, ArrayList<Msg> listMessages, Context context) {
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listMessages = listMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listMessages.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Msg getItem(int position) {
|
||||
return listMessages.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewContact;
|
||||
public TextView txtViewContact;
|
||||
public TextView txtViewDateTime;
|
||||
public TextView txtViewLastMsg;
|
||||
public LinearLayout layoutMessage;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_message, null);
|
||||
|
||||
view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewContact);
|
||||
view.txtViewContact = (TextView) convertView.findViewById(R.id.textViewContact);
|
||||
view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewLastDate);
|
||||
view.txtViewLastMsg = (TextView) convertView.findViewById(R.id.textViewLastMsg);
|
||||
view.layoutMessage = (LinearLayout) convertView.findViewById(R.id.layoutMessage);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
view.imgViewContact.setImageResource(listMessages.get(position).from.getLargeIcon());
|
||||
//view.imgViewContact.setImageResource(R.drawable.peopleblue);
|
||||
view.txtViewContact.setText(listMessages.get(position).from.name+ " :");
|
||||
if(listMessages.get(position).message.length() > 25)
|
||||
view.txtViewLastMsg.setText(listMessages.get(position).message.substring(0, 25) + "...");
|
||||
else
|
||||
view.txtViewLastMsg.setText(listMessages.get(position).message);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
if(listMessages.get(position).received.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm");
|
||||
|
||||
view.txtViewDateTime.setText(sdf.format(listMessages.get(position).received));
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public int getIcon(int user_type, String username)
|
||||
{
|
||||
// if request was send by MessagesActivity -> Spinner
|
||||
if(user_type == -1)
|
||||
{
|
||||
// get unit_type for selected username
|
||||
for (Msg mes: listMessages)
|
||||
{
|
||||
// if user is selected
|
||||
if(mes.from.name.equals(username))
|
||||
{
|
||||
user_type = (int) mes.from.driver_id; // save user_type
|
||||
|
||||
return mes.from.getLargeIcon();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.libpad.PadTextMessage;
|
||||
|
||||
public class PadConversationGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<PadTextMessage> listMessages;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
private ArrayList<Boolean> outgoingPositions = new ArrayList<Boolean>();
|
||||
private ArrayList<Boolean> ackPositions = new ArrayList<Boolean>();
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
|
||||
public PadConversationGridViewAdapter(Activity activity, ArrayList<PadTextMessage> listMessages, Context context, ArrayList<Boolean> outgoingPositions, ArrayList<Boolean> ackPositions) {
|
||||
this.activity = activity;
|
||||
this.listMessages = listMessages;
|
||||
this.outgoingPositions = outgoingPositions;
|
||||
this.ackPositions = ackPositions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listMessages.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PadTextMessage getItem(int position) {
|
||||
return listMessages.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** return the list of messages in the adapter
|
||||
* @return an ArrayList of PadTextMessages
|
||||
*/
|
||||
public ArrayList<PadTextMessage> getMessages() {
|
||||
return listMessages;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewContact;
|
||||
public TextView txtViewMsg;
|
||||
public TextView txtViewDateTime;
|
||||
public ImageView imgViewReceivedContact;
|
||||
public TextView txtViewReceivedMsg;
|
||||
public TextView txtViewReceivedDateTime;
|
||||
public ImageView imageAck;
|
||||
public TextView textViewNotACK;
|
||||
public LinearLayout layoutSend;
|
||||
public LinearLayout layoutReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_conversation, null);
|
||||
|
||||
view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewSenderIco);
|
||||
view.txtViewMsg = (TextView) convertView.findViewById(R.id.textViewSendMsg);
|
||||
view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewSendDate);
|
||||
view.imgViewReceivedContact = (ImageView) convertView.findViewById(R.id.imageViewReceivedIco);
|
||||
view.txtViewReceivedMsg = (TextView) convertView.findViewById(R.id.textViewReceivedMsg);
|
||||
view.txtViewReceivedDateTime = (TextView) convertView.findViewById(R.id.textViewReceivedDate);
|
||||
view.layoutSend = (LinearLayout) convertView.findViewById(R.id.layoutSend);
|
||||
view.layoutReceived = (LinearLayout) convertView.findViewById(R.id.layoutReceived);
|
||||
view.textViewNotACK = (TextView) convertView.findViewById(R.id.textViewNotACKSendMsg);
|
||||
view.imageAck = (ImageView) convertView.findViewById(R.id.imageAck);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
try
|
||||
{
|
||||
hash.put(position, convertView);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm MMM-dd", Locale.getDefault());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Date date = new Date(listMessages.get(position).timeGMT * 1000);
|
||||
|
||||
if(date.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
else
|
||||
sdf = new SimpleDateFormat("HH:mm MMM-dd", Locale.getDefault());
|
||||
|
||||
// set gmt time
|
||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
//view.imgViewContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||||
view.imgViewContact.setImageResource(R.drawable.peoplegreen_large);
|
||||
view.txtViewMsg.setText(listMessages.get(position).message);
|
||||
view.txtViewDateTime.setText(sdf.format(date));
|
||||
//view.imgViewReceivedContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||||
view.imgViewReceivedContact.setImageResource(R.drawable.peopleblue_large);
|
||||
view.txtViewReceivedMsg.setText(listMessages.get(position).message);
|
||||
|
||||
view.txtViewReceivedDateTime.setText(sdf.format(date));
|
||||
|
||||
if(ackPositions.size() > 0)
|
||||
switch(ackPositions.get(position) ? 1: 0) {
|
||||
case 0:
|
||||
// show not ack
|
||||
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||||
view.imageAck.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case 1:
|
||||
// show not ack
|
||||
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||||
view.imageAck.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
switch(outgoingPositions.get(position) ? 1 : 0) {
|
||||
case 1:
|
||||
view.layoutReceived.setVisibility(View.GONE);
|
||||
view.layoutSend.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case 0:
|
||||
view.layoutReceived.setVisibility(View.VISIBLE);
|
||||
view.layoutSend.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
/*
|
||||
public void setACK(String seqID)
|
||||
{
|
||||
int position = -1, i=0;
|
||||
|
||||
for(Msg msg: listMessages)
|
||||
{
|
||||
if(msg.seqID.equals(seqID))
|
||||
position = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
ackPositions.remove(position);
|
||||
ackPositions.add(position, true);
|
||||
}
|
||||
|
||||
public void changeView(String seqID)
|
||||
{
|
||||
int position = -1, i=0;
|
||||
|
||||
for(Msg msg: listMessages)
|
||||
{
|
||||
if(msg.seqID.equals(seqID))
|
||||
position = i;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if(position != -1 && hash.size() > position)
|
||||
{
|
||||
SM.Debug("POSITON : " + position);
|
||||
View con = hash.get(position);
|
||||
ViewHolder view = (ViewHolder) con.getTag();
|
||||
|
||||
switch(ackPositions.get(position) ? 1 : 0)
|
||||
{
|
||||
case 1:
|
||||
view.imageAck.setVisibility(View.INVISIBLE);
|
||||
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||||
break;
|
||||
case 0:
|
||||
view.imageAck.setVisibility(View.VISIBLE);
|
||||
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.libpad.PadTextMessage;
|
||||
|
||||
public class PadMessagesGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<PadTextMessage> listMessages;
|
||||
private Activity activity;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
|
||||
|
||||
public PadMessagesGridViewAdapter(Activity activity, ArrayList<PadTextMessage> listMessages, Context context) {
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listMessages = listMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listMessages.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PadTextMessage getItem(int position) {
|
||||
return listMessages.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** return the list of messages in the adapter
|
||||
* @return an ArrayList of PadTextMessages
|
||||
*/
|
||||
public ArrayList<PadTextMessage> getMessages() {
|
||||
return listMessages;
|
||||
}
|
||||
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewContact;
|
||||
public TextView txtViewContact;
|
||||
public TextView txtViewDateTime;
|
||||
public TextView txtViewLastMsg;
|
||||
public LinearLayout layoutMessage;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_message, null);
|
||||
|
||||
view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewContact);
|
||||
view.txtViewContact = (TextView) convertView.findViewById(R.id.textViewContact);
|
||||
view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewLastDate);
|
||||
view.txtViewLastMsg = (TextView) convertView.findViewById(R.id.textViewLastMsg);
|
||||
view.layoutMessage = (LinearLayout) convertView.findViewById(R.id.layoutMessage);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
view.imgViewContact.setImageResource(R.drawable.peopleblue_large);
|
||||
//view.imgViewContact.setImageResource(R.drawable.peopleblue);
|
||||
view.txtViewContact.setText(Contact.getNameForRadioID(AppParams.listContacts, listMessages.get(position).radioID)+ " :");
|
||||
if(listMessages.get(position).message.length() > 25)
|
||||
view.txtViewLastMsg.setText(listMessages.get(position).message.substring(0, 25) + "...");
|
||||
else
|
||||
view.txtViewLastMsg.setText(listMessages.get(position).message);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss",Locale.getDefault());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
Date date = new Date(listMessages.get(position).timeGMT * 1000);
|
||||
|
||||
if(date.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm", Locale.getDefault());
|
||||
|
||||
// set gmt time
|
||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
view.txtViewDateTime.setText(sdf.format(date));
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
}
|
@ -0,0 +1,328 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.activities.AbstractRecordingsActivity;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.libpad.PadRecording;
|
||||
|
||||
public class PadRecordingsGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<PadRecording> listRecordings;
|
||||
private ArrayList<Boolean> recordingExists;
|
||||
private ArrayList<Boolean> playingPositions;
|
||||
private Activity activity;
|
||||
private Context context;
|
||||
private int removePosition = -1;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
public PadRecordingsGridViewAdapter(Activity activity, Context context, ArrayList<PadRecording> listRecordings)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.context = context;
|
||||
this.listRecordings = listRecordings;
|
||||
|
||||
this.recordingExists = new ArrayList<Boolean>();
|
||||
for(int i=0; i<listRecordings.size(); i++)
|
||||
recordingExists.add(true);
|
||||
|
||||
playingPositions = new ArrayList<Boolean>();
|
||||
for(int i=0; i<listRecordings.size(); i++)
|
||||
playingPositions.add(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listRecordings.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PadRecording getItem(int position) {
|
||||
return listRecordings.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ArrayList<PadRecording> getRecordings() {
|
||||
return listRecordings;
|
||||
}
|
||||
|
||||
/** Define Row Template */
|
||||
public static class ViewHolder
|
||||
{
|
||||
public LinearLayout layoutRecording;
|
||||
public ImageView imageViewPlay, imageViewRecycle;
|
||||
public TextView textViewSender, textViewDuration, textViewDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_recordings, null);
|
||||
view.layoutRecording = (LinearLayout) convertView.findViewById(R.id.layoutRecording);
|
||||
view.imageViewPlay = (ImageView) convertView.findViewById(R.id.imageViewPlay);
|
||||
view.textViewSender = (TextView) convertView.findViewById(R.id.textViewSender);
|
||||
view.textViewDuration = (TextView) convertView.findViewById(R.id.textViewDuration);
|
||||
view.textViewDate = (TextView) convertView.findViewById(R.id.textViewDate);
|
||||
view.imageViewRecycle = (ImageView) convertView.findViewById(R.id.imageViewRecycle);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
hash.put(position, convertView);
|
||||
|
||||
try {
|
||||
//SM.Debug("SIZE EXISTS : " + recordingExists.size() + " | " + playingPositions.size());
|
||||
/* if recording doesn't exists change background */
|
||||
/*
|
||||
if(recordingExists.size()> position && !recordingExists.get(position))
|
||||
view.layoutRecording.setBackgroundColor(0xFFDDDDDD);
|
||||
else
|
||||
*/
|
||||
|
||||
if(playingPositions.size() > position)
|
||||
{
|
||||
/* if recording is not playing let background to white */
|
||||
|
||||
if(!playingPositions.get(position))
|
||||
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
view.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
|
||||
}
|
||||
else
|
||||
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
|
||||
/* change icon according to call type [outgoing or incoming] */
|
||||
if(listRecordings.size() > position)
|
||||
switch(listRecordings.get(position).callType)
|
||||
{
|
||||
case AppParams.MotoAllCall:
|
||||
if(!listRecordings.get(position).isOutgoing)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received_all);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made_all);
|
||||
break;
|
||||
case AppParams.MotoPrivate:
|
||||
if(!listRecordings.get(position).isOutgoing)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
||||
break;
|
||||
case AppParams.MotoGroup:
|
||||
if(!listRecordings.get(position).isOutgoing)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received_group);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made_group);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(IndexOutOfBoundsException ex) {
|
||||
SM.Exception("IndexOutOfBounds Exception [PadRecordingsGridViewAdapter]" + ex.toString());
|
||||
}
|
||||
/*
|
||||
try
|
||||
{
|
||||
if(receivedPositions.get(position))
|
||||
{
|
||||
if(playingPositions.get(position))
|
||||
view.imageViewPlay.setImageResource(R.drawable.play_received);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(playingPositions.get(position))
|
||||
view.imageViewPlay.setImageResource(R.drawable.play_made);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("EXCeptioN", ex.toString());
|
||||
view.imageViewPlay.setImageResource(R.drawable.play);
|
||||
}*/
|
||||
|
||||
/* intercept Recycle click */
|
||||
view.imageViewRecycle.setVisibility(View.GONE);
|
||||
view.imageViewRecycle.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// save the position of the marked record
|
||||
removePosition = position;
|
||||
|
||||
// change the background for marked record
|
||||
View view = (View) hash.get(position);
|
||||
ViewHolder viewHolder = (ViewHolder) view.getTag();
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
((AbstractRecordingsActivity) activity).deleteSelected(position);
|
||||
}
|
||||
});
|
||||
|
||||
String sender = "", name="", initName="";
|
||||
|
||||
for(Contact cont: AppParams.listContacts)
|
||||
{
|
||||
if(cont.id == getItem(position).radioID)
|
||||
{
|
||||
// get name only if callType equals with the one from the ConfigFile
|
||||
if( (getItem(position).callType == AppParams.MotoPrivate && cont.contactType == Contact.PRIVATE)
|
||||
|| (getItem(position).callType == AppParams.MotoGroup && cont.contactType == Contact.GROUP)
|
||||
|| (getItem(position).callType == AppParams.MotoAllCall))
|
||||
// || getItem(position).type == AppParams.AllCall && cont.callType.equals("All Call"))
|
||||
name = cont.name;
|
||||
}
|
||||
if (cont.id == getItem(position).initRadioID) {
|
||||
// get name only if callType equals with the one from the ConfigFile
|
||||
if( (getItem(position).callType == AppParams.MotoPrivate && cont.contactType == Contact.PRIVATE)
|
||||
|| (getItem(position).callType == AppParams.MotoGroup && cont.contactType == Contact.GROUP)
|
||||
|| (getItem(position).callType == AppParams.MotoAllCall))
|
||||
// || getItem(position).type == AppParams.AllCall && cont.callType.equals("All Call"))
|
||||
initName = cont.name;
|
||||
}
|
||||
|
||||
// if call type is Group I should find a private
|
||||
if(getItem(position).callType == AppParams.MotoGroup && (cont.id == getItem(position).initRadioID && cont.contactType == Contact.PRIVATE))
|
||||
initName = cont.name;
|
||||
|
||||
}
|
||||
|
||||
// // set name to All Call if call was made from tabled
|
||||
if(getItem(position).callType == AppParams.MotoAllCall && getItem(position).isOutgoing)
|
||||
sender += context.getResources().getString(R.string.AllCall);
|
||||
else if(getItem(position).callType == AppParams.MotoAllCall) {
|
||||
name = context.getResources().getString(R.string.AllCall);
|
||||
if(initName.length() > 0)
|
||||
sender = name + " [" + initName + "]";
|
||||
else
|
||||
sender = name + " [" + getItem(position).initRadioID + "]";
|
||||
}
|
||||
// add the name/id of the contact that initiated the AllCall
|
||||
else if(name.length() < 1)
|
||||
sender += getItem(position).radioID;
|
||||
else
|
||||
sender += name;
|
||||
|
||||
// add caller name for group call
|
||||
if(listRecordings.get(position).callType == AppParams.MotoGroup)
|
||||
{
|
||||
if(!getItem(position).isOutgoing) {
|
||||
if(initName.length() > 0)
|
||||
sender = name + " [" + initName + "]";
|
||||
else
|
||||
sender = name + " [" + getItem(position).initRadioID + "]";
|
||||
}
|
||||
else
|
||||
sender = name;
|
||||
}
|
||||
// for private call that was received I have to get the id from the initRadioID
|
||||
else if(listRecordings.get(position).callType == AppParams.MotoPrivate)
|
||||
{
|
||||
if(!getItem(position).isOutgoing && initName.length()>0)
|
||||
sender = initName;
|
||||
else if (!getItem(position).isOutgoing)
|
||||
sender += getItem(position).initRadioID + "";
|
||||
}
|
||||
|
||||
view.textViewSender.setText(sender);
|
||||
view.textViewDuration.setText("[" + listRecordings.get(position).duration + " sec]");
|
||||
|
||||
/* Add call Date */
|
||||
Date date = new Date(getItem(position).timeGMT * 1000);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
if(date.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm", Locale.getDefault());
|
||||
|
||||
// set gmt time
|
||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
view.textViewDate.setText(sdf.format(date));
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
/** Reset row background when recycle was canceled */
|
||||
public void cancelDelete()
|
||||
{
|
||||
View view = (View) hash.get(removePosition);
|
||||
if(recordingExists.get(removePosition))
|
||||
view.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
view.setBackgroundColor(0xFFDDDDDD);
|
||||
|
||||
removePosition = -1;
|
||||
}
|
||||
|
||||
|
||||
/** Get the View for one row in the GridView */
|
||||
public View getView(int position)
|
||||
{
|
||||
return (View) hash.get(position);
|
||||
}
|
||||
|
||||
|
||||
/** Change playing recording background */
|
||||
public void changePlaying(int position, boolean playing)
|
||||
{
|
||||
// change value in the vector
|
||||
playingPositions.set(position, playing);
|
||||
|
||||
// make changes in the UI //
|
||||
try {
|
||||
PadRecordingsGridViewAdapter.ViewHolder viewHolder = (PadRecordingsGridViewAdapter.ViewHolder) getView(position).getTag();
|
||||
if(!playing)
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
}
|
||||
catch (NullPointerException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,254 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.activities.AbstractRecordingsActivity;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.Recording;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
public class RecordingsGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Recording> listRecordings;
|
||||
private ArrayList<Boolean> recordingExists;
|
||||
private ArrayList<Boolean> playingPositions;
|
||||
private Activity activity;
|
||||
private Context context;
|
||||
private int removePosition = -1;
|
||||
//public String time;
|
||||
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
public RecordingsGridViewAdapter(Activity activity, Context context, ArrayList<Recording> listRecordings, ArrayList<Boolean> recordingExists)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.context = context;
|
||||
this.listRecordings = listRecordings;
|
||||
this.recordingExists = recordingExists;
|
||||
|
||||
playingPositions = new ArrayList<Boolean>();
|
||||
for(int i=0; i<recordingExists.size(); i++) {
|
||||
playingPositions.add(false);
|
||||
|
||||
listRecordings.get(i).date = listRecordings.get(i).startGMT;
|
||||
listRecordings.get(i).duration = listRecordings.get(i).endGMT - listRecordings.get(i).startGMT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listRecordings.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recording getItem(int position) {
|
||||
return listRecordings.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Define Row Template */
|
||||
public static class ViewHolder
|
||||
{
|
||||
public LinearLayout layoutRecording;
|
||||
public ImageView imageViewPlay, imageViewRecycle;
|
||||
public TextView textViewSender, textViewDuration, textViewDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_recordings, null);
|
||||
view.layoutRecording = (LinearLayout) convertView.findViewById(R.id.layoutRecording);
|
||||
view.imageViewPlay = (ImageView) convertView.findViewById(R.id.imageViewPlay);
|
||||
view.textViewSender = (TextView) convertView.findViewById(R.id.textViewSender);
|
||||
view.textViewDuration = (TextView) convertView.findViewById(R.id.textViewDuration);
|
||||
view.textViewDate = (TextView) convertView.findViewById(R.id.textViewDate);
|
||||
view.imageViewRecycle = (ImageView) convertView.findViewById(R.id.imageViewRecycle);
|
||||
view.imageViewRecycle.setVisibility(View.GONE);
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
hash.put(position, convertView);
|
||||
|
||||
|
||||
|
||||
/* if recording doesn't exists change background */
|
||||
if(!recordingExists.get(position))
|
||||
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
{
|
||||
/* if recording is not playing let background to white */
|
||||
if(!playingPositions.get(position))
|
||||
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
view.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
}
|
||||
|
||||
/* change icon according to call type [outgoing or incoming] */
|
||||
SM.Exception("REC TYPE : " + listRecordings.get(position).type);
|
||||
switch(listRecordings.get(position).type)
|
||||
{
|
||||
case AppParams.AllCall:
|
||||
if(listRecordings.get(position).destinationRadioID == 0)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received_all);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made_all);
|
||||
break;
|
||||
case AppParams.PrivateCall:
|
||||
if(listRecordings.get(position).destinationRadioID == 0)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
||||
break;
|
||||
case AppParams.GroupCall:
|
||||
if(listRecordings.get(position).destinationRadioID == 0)
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received_group);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made_group);
|
||||
break;
|
||||
}
|
||||
/*
|
||||
try
|
||||
{
|
||||
if(receivedPositions.get(position))
|
||||
{
|
||||
if(playingPositions.get(position))
|
||||
view.imageViewPlay.setImageResource(R.drawable.play_received);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(playingPositions.get(position))
|
||||
view.imageViewPlay.setImageResource(R.drawable.play_made);
|
||||
else
|
||||
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("EXCeptioN", ex.toString());
|
||||
view.imageViewPlay.setImageResource(R.drawable.play);
|
||||
}*/
|
||||
|
||||
/* intercept Recycle click */
|
||||
view.imageViewRecycle.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// save the position of the marked record
|
||||
removePosition = position;
|
||||
|
||||
// change the background for marked record
|
||||
View view = (View) hash.get(position);
|
||||
ViewHolder viewHolder = (ViewHolder) view.getTag();
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
((AbstractRecordingsActivity) activity).deleteSelected(position);
|
||||
}
|
||||
});
|
||||
|
||||
// set recording image
|
||||
if(getItem(position).NameForDisplay.equals(AppParams.USERNAME))
|
||||
view.imageViewPlay.setImageDrawable(context.getResources().getDrawable(R.drawable.call_made_group));
|
||||
else
|
||||
view.imageViewPlay.setImageDrawable(context.getResources().getDrawable(R.drawable.call_received_group));
|
||||
|
||||
view.textViewSender.setText(getItem(position).NameForDisplay);
|
||||
view.textViewDuration.setText("[" + getItem(position).duration + " sec]");
|
||||
|
||||
/* Add call Date */
|
||||
Date date = new Date();
|
||||
date.setTime(listRecordings.get(position).date * 1000);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
|
||||
|
||||
if(date.after(calendar.getTime()))
|
||||
sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
else
|
||||
sdf = new SimpleDateFormat("MMM-dd HH:mm");
|
||||
|
||||
// set gmt time
|
||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
view.textViewDate.setText(sdf.format(date));
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
/** Reset row background when recycle was canceled */
|
||||
public void cancelDelete()
|
||||
{
|
||||
View view = (View) hash.get(removePosition);
|
||||
if(recordingExists.get(removePosition))
|
||||
view.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
view.setBackgroundColor(0xFFDDDDDD);
|
||||
|
||||
removePosition = -1;
|
||||
}
|
||||
|
||||
|
||||
/** Get the View for one row in the GridView */
|
||||
public View getView(int position)
|
||||
{
|
||||
return (View) hash.get(position);
|
||||
}
|
||||
|
||||
|
||||
/** Change playing recording background */
|
||||
public void changePlaying(int position, boolean playing)
|
||||
{
|
||||
// change value in the vector
|
||||
playingPositions.set(position, playing);
|
||||
|
||||
RecordingsGridViewAdapter.ViewHolder viewHolder = (RecordingsGridViewAdapter.ViewHolder) getView(position).getTag();
|
||||
if(!playing)
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
||||
else
|
||||
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
||||
|
||||
// update hash
|
||||
hash.get(position).setTag(viewHolder);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
public class VehiclesGridViewAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Vehicle> listVehicles;
|
||||
private ArrayList<Boolean> disabledVehicles;
|
||||
private ArrayList<Boolean> displayedVehicles;
|
||||
private Activity activity;
|
||||
|
||||
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||||
|
||||
public VehiclesGridViewAdapter(Activity activity, Context context, ArrayList<Vehicle> listVehicles, ArrayList<Boolean> disabledVehicles)
|
||||
{
|
||||
super();
|
||||
this.activity = activity;
|
||||
this.listVehicles = listVehicles;
|
||||
this.disabledVehicles = disabledVehicles;
|
||||
|
||||
// set displayed positions to false
|
||||
displayedVehicles = new ArrayList<Boolean>();
|
||||
for(Vehicle veh: listVehicles)
|
||||
{
|
||||
if(AppParams.DEMO && (veh.sc_id == 101 || veh.sc_id == 102))
|
||||
displayedVehicles.add(true);
|
||||
else
|
||||
displayedVehicles.add(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listVehicles.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vehicle getItem(int position) {
|
||||
return listVehicles.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Define Row Template */
|
||||
public static class ViewHolder
|
||||
{
|
||||
public ImageView imgViewIcon, imgViewChecked;
|
||||
public TextView txtViewName;
|
||||
public LinearLayout layoutVehicle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder view;
|
||||
LayoutInflater inflator = activity.getLayoutInflater();
|
||||
if(convertView==null)
|
||||
{
|
||||
view = new ViewHolder();
|
||||
convertView = inflator.inflate(R.layout.row_vehicle, null);
|
||||
|
||||
view.imgViewIcon = (ImageView) convertView.findViewById(R.id.imageViewIcon);
|
||||
view.txtViewName = (TextView) convertView.findViewById(R.id.textViewName);
|
||||
view.imgViewChecked = (ImageView) convertView.findViewById(R.id.imageViewChecked);
|
||||
view.layoutVehicle = (LinearLayout) convertView.findViewById(R.id.layoutVehicle);
|
||||
|
||||
convertView.setTag(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
hash.put(position, convertView);
|
||||
|
||||
/* if recording disabled change background */
|
||||
try
|
||||
{
|
||||
if(!disabledVehicles.get(position))
|
||||
view.layoutVehicle.setBackgroundColor(0xFFDDDDDD);
|
||||
else
|
||||
view.layoutVehicle.setBackgroundColor(0xFFFFFFFF);
|
||||
|
||||
}
|
||||
catch(IndexOutOfBoundsException ex) {
|
||||
view.layoutVehicle.setBackgroundColor(0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/* set vehicle name and icon */
|
||||
view.imgViewIcon.setImageResource(listVehicles.get(position).getSmallIcon());
|
||||
view.txtViewName.setText(listVehicles.get(position).name);
|
||||
|
||||
/* set checked or not */
|
||||
if(displayedVehicles.get(position))
|
||||
view.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
view.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Get the View for one row in the GridView */
|
||||
public View getView(int position)
|
||||
{
|
||||
return (View) hash.get(position);
|
||||
}
|
||||
|
||||
/** Change all vehicles checkBox */
|
||||
public void changeDisplayAll(boolean display)
|
||||
{
|
||||
for(int i=0; i<listVehicles.size(); i++)
|
||||
displayedVehicles.set(i, display);
|
||||
|
||||
for(int i=0; i<hash.size(); i++)
|
||||
{
|
||||
// change value in the vector
|
||||
displayedVehicles.set(i, display);
|
||||
|
||||
// make changes in the UI //
|
||||
ViewHolder viewHolder = (ViewHolder) getView(i).getTag();
|
||||
if(viewHolder!=null)
|
||||
{
|
||||
if(display)
|
||||
viewHolder.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
viewHolder.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Change displayed vehicle checkBox */
|
||||
public void changeDisplayed(int position, boolean display)
|
||||
{
|
||||
// change value in the vector
|
||||
displayedVehicles.set(position, display);
|
||||
|
||||
// make changes in the UI //
|
||||
ViewHolder viewHolder = (ViewHolder) getView(position).getTag();
|
||||
if(display)
|
||||
viewHolder.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
viewHolder.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
}
|
||||
|
||||
/** Change disabled vehicle background */
|
||||
public void changeDisabled(int position, boolean disabled)
|
||||
{
|
||||
// change value in the vector
|
||||
disabledVehicles.set(position, disabled);
|
||||
|
||||
// make changes in the UI //
|
||||
ViewHolder viewHolder = (ViewHolder) getView(position).getTag();
|
||||
if(disabled)
|
||||
viewHolder.layoutVehicle.setBackgroundColor(0xFFDDDDDD);
|
||||
else
|
||||
viewHolder.layoutVehicle.setBackgroundColor(0xFFFFFFFF);
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
package com.safemobile.adapters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.safemobile.lib.R;
|
||||
import com.safemobile.lib.radio.ZoneChannel;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ZoneChannelComboBoxAdapter extends ArrayAdapter<ZoneChannel>{
|
||||
|
||||
private static final int TYPE_ZONE = 0;
|
||||
private static final int TYPE_CHANNEL = 1;
|
||||
private static final int TYPE_MAX_COUNT = 2;
|
||||
|
||||
|
||||
private Context context;
|
||||
int layoutResourceId;
|
||||
private ArrayList<ZoneChannel> listValues;
|
||||
|
||||
public ZoneChannelComboBoxAdapter(Context context, int textViewResourceId, ArrayList<ZoneChannel> listValues) {
|
||||
super(context, textViewResourceId, listValues);
|
||||
this.context = context;
|
||||
this.layoutResourceId = textViewResourceId;
|
||||
this.listValues = listValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return listValues.get(position).isSection() ? TYPE_ZONE : TYPE_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return TYPE_MAX_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return listValues.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneChannel getItem(int position) {
|
||||
return listValues.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
if(getItemViewType(position) == TYPE_ZONE)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public View getCustomView(int position, View convertView, ViewGroup parent) {
|
||||
ImagesSpinnerHolder holder = null;
|
||||
int type = getItemViewType(position);
|
||||
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||||
|
||||
if(convertView == null) {
|
||||
holder = new ImagesSpinnerHolder();
|
||||
|
||||
switch (type) {
|
||||
case TYPE_ZONE:
|
||||
convertView = inflater.inflate(R.layout.combobox_section_header, parent, false);
|
||||
holder.title = (TextView) convertView.findViewById(R.id.txtHeader);
|
||||
break;
|
||||
|
||||
case TYPE_CHANNEL:
|
||||
convertView = inflater.inflate(R.layout.combobox_row, parent, false);
|
||||
holder.textSpinner = (TextView)convertView.findViewById(R.id.text);
|
||||
holder.imgSpinner = (ImageView)convertView.findViewById(R.id.icon);
|
||||
holder.imgSpinner.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
convertView.setTag(holder);
|
||||
}
|
||||
else
|
||||
holder = (ImagesSpinnerHolder) convertView.getTag();
|
||||
|
||||
switch(type) {
|
||||
case TYPE_ZONE:
|
||||
holder.title.setText(listValues.get(position).getZone().ZoneName);
|
||||
|
||||
break;
|
||||
|
||||
case TYPE_CHANNEL:
|
||||
holder.textSpinner.setText(listValues.get(position).getChannel().chName);
|
||||
holder.imgSpinner.setImageResource(R.drawable.channel_small);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
View row = convertView;
|
||||
|
||||
|
||||
if(row == null) {
|
||||
// check if section header -> isSection will return true
|
||||
if(sectionList.get(position))
|
||||
{
|
||||
row = inflater.inflate(R.layout.spinner_header, parent, false);
|
||||
holder.title = (TextView) row.findViewById(R.id.txtHeader);
|
||||
holder.title.setText(listValues.get(position).getZone().ZoneName);
|
||||
}
|
||||
else
|
||||
{
|
||||
row = inflater.inflate(R.layout.spinner, parent, false);
|
||||
holder.textSpinner = (TextView)row.findViewById(R.id.language);
|
||||
holder.imgSpinner = (ImageView)row.findViewById(R.id.icon);
|
||||
holder.imgSpinner.setVisibility(View.INVISIBLE);
|
||||
|
||||
holder.textSpinner.setText(listValues.get(position).getChannel().chName);
|
||||
holder.imgSpinner.setImageResource(R.drawable.channel_small);
|
||||
}
|
||||
|
||||
row.setTag(holder);
|
||||
}
|
||||
else {
|
||||
|
||||
holder = (ImagesSpinnerHolder)row.getTag();
|
||||
if(sectionList.get(position)){
|
||||
if(holder.title!= null)
|
||||
holder.title.setText(listValues.get(position).getZone().ZoneName);
|
||||
}
|
||||
else {
|
||||
if(holder.textSpinner!=null)
|
||||
holder.textSpinner.setText(listValues.get(position).getChannel().chName);
|
||||
if(holder.imgSpinner != null)
|
||||
holder.imgSpinner.setImageResource(R.drawable.channel_small);
|
||||
}
|
||||
}
|
||||
*/
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private class ImagesSpinnerHolder {
|
||||
ImageView imgSpinner;
|
||||
TextView textSpinner;
|
||||
TextView title;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user