You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
14 years ago
|
package org.r3pek.pharmacies;
|
||
|
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
|
||
|
import org.r3pek.pharmacies.utils.GeoUtils;
|
||
|
import org.r3pek.pharmacies.utils.GlobalVars;
|
||
|
import org.r3pek.pharmacies.widgets.Arrow;
|
||
|
import org.r3pek.pharmacies.widgets.ImageRotater;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.view.View;
|
||
|
import android.view.ViewGroup;
|
||
|
import android.widget.ImageView;
|
||
|
import android.widget.SimpleAdapter;
|
||
|
import android.widget.TextView;
|
||
|
|
||
|
public class PharmacyListSimpleAdapter extends SimpleAdapter {
|
||
|
private ImageRotater arrowCallback;
|
||
|
|
||
|
public PharmacyListSimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to, ImageRotater arrowCallback) {
|
||
|
super(context, data, resource, from, to);
|
||
|
this.arrowCallback = arrowCallback;
|
||
|
}
|
||
|
|
||
|
private Pharmacy getPharmacyWithName(String name) {
|
||
|
for (Pharmacy p : GlobalVars.getPharmacies())
|
||
|
if (p.getName().equals(name)) return p;
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||
|
View v = super.getView(position, convertView, parent);
|
||
|
|
||
|
ImageView ivStatus = (ImageView) v.findViewById(R.id.ivStatus);
|
||
|
Arrow ivDirection = (Arrow) v.findViewById(R.id.ivDirection);
|
||
|
TextView tvNome = (TextView) v.findViewById(R.id.tvNome);
|
||
|
Pharmacy p = getPharmacyWithName(tvNome.getText().toString());
|
||
|
|
||
|
ivDirection.setBearing(GeoUtils.bearing(GlobalVars.positioner.getLastGeoPoint(), p.getGeoPoint()));
|
||
|
ivDirection.setOrientation(arrowCallback.getLastOrientation());
|
||
|
arrowCallback.addImage(ivDirection);
|
||
|
|
||
|
if (p.isAtService())
|
||
|
ivStatus.setImageResource(R.drawable.status_on);
|
||
|
else
|
||
|
ivStatus.setImageResource(R.drawable.status_off);
|
||
|
|
||
|
return v;
|
||
|
}
|
||
|
}
|