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.
148 lines
5.1 KiB
148 lines
5.1 KiB
package org.r3pek.pharmacies;
|
|
|
|
import java.text.DecimalFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.LinkedList;
|
|
|
|
import org.r3pek.pharmacies.utils.GeoUtils;
|
|
import org.r3pek.pharmacies.utils.GlobalVars;
|
|
import org.r3pek.pharmacies.widgets.ImageRotater;
|
|
import org.r3pek.pharmacies.widgets.ScrollTextView;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.hardware.Sensor;
|
|
import android.hardware.SensorManager;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.os.Handler.Callback;
|
|
import android.view.View;
|
|
import android.view.animation.AccelerateInterpolator;
|
|
import android.view.animation.Animation;
|
|
import android.view.animation.TranslateAnimation;
|
|
import android.view.animation.Animation.AnimationListener;
|
|
import android.widget.AdapterView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.ListView;
|
|
import android.widget.SimpleAdapter;
|
|
import android.widget.AdapterView.OnItemClickListener;
|
|
|
|
public class PharmacyList extends Activity implements OnItemClickListener {
|
|
private Context context;
|
|
private SensorManager sm;
|
|
private ImageRotater arrowChangerSensor;
|
|
private ListView list;
|
|
private ScrollTextView tvLocation;
|
|
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.list);
|
|
context = getApplicationContext();
|
|
|
|
list = (ListView)findViewById(R.id.list);
|
|
sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
|
|
arrowChangerSensor = new ImageRotater();
|
|
|
|
tvLocation = (ScrollTextView) findViewById(R.id.tvLocation);
|
|
tvLocation.setText(getString(R.string.loading));
|
|
tvLocation.setRndDuration(10000);
|
|
GeoUtils.getLocationName(context, new Handler(new Callback() {
|
|
@Override
|
|
public boolean handleMessage(Message msg) {
|
|
final String location = msg.getData().getString("location");
|
|
runOnUiThread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
tvLocation.setText(location);
|
|
}
|
|
});
|
|
if (location.equals(getString(R.string.not_available))) {
|
|
final LinearLayout ll02 = (LinearLayout)findViewById(R.id.LinearLayout02);
|
|
TranslateAnimation anim = new TranslateAnimation(
|
|
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
|
|
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f
|
|
);
|
|
anim.setAnimationListener(new AnimationListener() {
|
|
@Override
|
|
public void onAnimationStart(Animation animation) {
|
|
}
|
|
|
|
@Override
|
|
public void onAnimationRepeat(Animation animation) {
|
|
}
|
|
|
|
@Override
|
|
public void onAnimationEnd(Animation animation) {
|
|
ll02.setVisibility(View.GONE);
|
|
}
|
|
});
|
|
anim.setStartOffset(2000);
|
|
anim.setDuration(2000);
|
|
anim.setInterpolator(new AccelerateInterpolator(1));
|
|
ll02.startAnimation(anim);
|
|
} else
|
|
runOnUiThread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
tvLocation.startScroll();
|
|
}
|
|
});
|
|
return true;
|
|
}
|
|
}));
|
|
|
|
list.setOnItemClickListener(this);
|
|
|
|
LinkedList<Pharmacy> allPharm = GlobalVars.getPharmacies();
|
|
ArrayList<HashMap<String, String>> pharmacies = new ArrayList<HashMap<String, String>>();
|
|
for (Pharmacy p : allPharm) {
|
|
HashMap<String, String> pharmacy = new HashMap<String, String>();
|
|
pharmacy.put("name", p.getName());
|
|
pharmacy.put("addr", p.getAddress());
|
|
DecimalFormat df = new DecimalFormat("#.#");
|
|
double dist = Double.parseDouble(p.getDistance().substring(0, p.getDistance().indexOf("."))) / 1000;
|
|
pharmacy.put("dist", df.format(dist) + "km");
|
|
pharmacies.add(pharmacy);
|
|
}
|
|
|
|
/* Create the Adapter to show the information */
|
|
SimpleAdapter adap;
|
|
adap = new PharmacyListSimpleAdapter(context, pharmacies, R.layout.list_row,
|
|
new String[] {"name", "addr", "dist"},
|
|
new int[] {R.id.tvNome, R.id.tvMorada, R.id.tvDistancia},
|
|
arrowChangerSensor
|
|
);
|
|
list.setAdapter(adap);
|
|
}
|
|
|
|
@Override
|
|
protected void onResume() {
|
|
super.onResume();
|
|
sm.registerListener(arrowChangerSensor, sm.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
|
|
}
|
|
|
|
@Override
|
|
protected void onPause() {
|
|
sm.unregisterListener(arrowChangerSensor);
|
|
super.onPause();
|
|
}
|
|
|
|
@Override
|
|
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
|
|
Intent i = new Intent(getApplicationContext(), PharmacyInfo.class);
|
|
i.putExtra("org.r3pek.pharmacies.Pharmacy", GlobalVars.getPharmacies().get(position));
|
|
i.putExtra("org.r3pek.pharmacies.PharmacyIndex", position);
|
|
startActivity(i);
|
|
}
|
|
|
|
@Override
|
|
public void onWindowFocusChanged(boolean hasFocus) {
|
|
super.onWindowFocusChanged(hasFocus);
|
|
tvLocation.startScroll();
|
|
}
|
|
|
|
}
|
|
|