|
|
|
package org.r3pek.pharmacies;
|
|
|
|
|
|
|
|
import com.admob.android.ads.AdView;
|
|
|
|
|
|
|
|
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.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.hardware.Sensor;
|
|
|
|
import android.hardware.SensorManager;
|
|
|
|
import android.location.Location;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.ClipboardManager;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
public class PharmacyInfo extends Activity {
|
|
|
|
private final static int MENU_DIAL = 0;
|
|
|
|
private final static int MENU_SHARE = 1;
|
|
|
|
private final static int MENU_NAVIGATE = 2;
|
|
|
|
private final static int MENU_COPY = 3;
|
|
|
|
private final static int MENU_SHOWONMAP = 4;
|
|
|
|
|
|
|
|
private SensorManager sm;
|
|
|
|
private Pharmacy p;
|
|
|
|
private ImageRotater arrowChangerSensor;
|
|
|
|
private int pharmacyIndex;
|
|
|
|
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.pharmacyinfo);
|
|
|
|
|
|
|
|
p = (Pharmacy)getIntent().getSerializableExtra("org.r3pek.pharmacies.Pharmacy");
|
|
|
|
pharmacyIndex = getIntent().getIntExtra("org.r3pek.pharmacies.PharmacyIndex", -1);
|
|
|
|
TextView tvName = (TextView)findViewById(R.id.tvName);
|
|
|
|
TextView tvAddress = (TextView)findViewById(R.id.tvAddress);
|
|
|
|
TextView tvParish = (TextView)findViewById(R.id.tvParish);
|
|
|
|
TextView tvPhoneNumber = (TextView)findViewById(R.id.tvPhoneNumber);
|
|
|
|
TextView tvLatitude = (TextView)findViewById(R.id.tvLatitude);
|
|
|
|
TextView tvLongitude = (TextView)findViewById(R.id.tvLongitude);
|
|
|
|
TextView tvDist = (TextView)findViewById(R.id.tvDistance);
|
|
|
|
Arrow arrow = (Arrow)findViewById(R.id.ivInfoDirection);
|
|
|
|
TextView tvService = (TextView)findViewById(R.id.tvOnDuty);
|
|
|
|
|
|
|
|
sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
|
|
|
|
arrowChangerSensor = new ImageRotater();
|
|
|
|
arrow.setBearing(GeoUtils.bearing(GlobalVars.positioner.getLastGeoPoint(), p.getGeoPoint()));
|
|
|
|
arrow.setOrientation(arrowChangerSensor.getLastOrientation());
|
|
|
|
|
|
|
|
tvName.setText(p.getName());
|
|
|
|
tvAddress.setText(p.getAddress());
|
|
|
|
tvParish.setText(p.getParish());
|
|
|
|
tvPhoneNumber.setText(p.getPhoneNumber().equals("") ? getString(R.string.na) : p.getPhoneNumber());
|
|
|
|
tvLatitude.setText(p.getLatitude());
|
|
|
|
tvLongitude.setText(p.getLongitude());
|
|
|
|
tvDist.setText(p.getDistance().substring(0, p.getDistance().indexOf(".")) + "m");
|
|
|
|
tvService.setText(p.isAtService() ? getString(R.string.yes) : getString(R.string.no));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
sm.registerListener(arrowChangerSensor, sm.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
|
|
|
|
arrowChangerSensor.addImage((Arrow)findViewById(R.id.ivInfoDirection));
|
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
arrowChangerSensor.delImage((Arrow)findViewById(R.id.ivInfoDirection));
|
|
|
|
sm.unregisterListener(arrowChangerSensor);
|
|
|
|
AdView ad = (AdView) findViewById(R.id.ad);
|
|
|
|
ad.cleanup();
|
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
menu.add(0, MENU_DIAL, 0, getString(R.string.dial)).setIcon(android.R.drawable.ic_menu_call);
|
|
|
|
menu.add(0, MENU_SHARE, 1, getString(R.string.share)).setIcon(android.R.drawable.ic_menu_share);
|
|
|
|
menu.add(0, MENU_NAVIGATE, 2, getString(R.string.navigate)).setIcon(android.R.drawable.ic_menu_directions);
|
|
|
|
menu.add(0, MENU_COPY, 3, getString(R.string.copy_to_clipboard)).setIcon(R.drawable.copy);
|
|
|
|
menu.add(0, MENU_SHOWONMAP, 4, getString(R.string.show_on_map)).setIcon(android.R.drawable.ic_menu_mapmode);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
menu.findItem(MENU_DIAL).setEnabled(!p.getPhoneNumber().equals(""));
|
|
|
|
menu.findItem(MENU_SHOWONMAP).setEnabled(pharmacyIndex != -1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case MENU_DIAL:
|
|
|
|
makeCall();
|
|
|
|
break;
|
|
|
|
case MENU_SHARE:
|
|
|
|
share();
|
|
|
|
break;
|
|
|
|
case MENU_NAVIGATE:
|
|
|
|
openNavigation();
|
|
|
|
break;
|
|
|
|
case MENU_COPY:
|
|
|
|
copyAddrToClipboard();
|
|
|
|
break;
|
|
|
|
case MENU_SHOWONMAP:
|
|
|
|
showOnMap();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showOnMap() {
|
|
|
|
GlobalVars.pharmaciesOverlay.onTap(pharmacyIndex);
|
|
|
|
Toast.makeText(getApplicationContext(), R.string.go_back, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void share() {
|
|
|
|
Intent i = new Intent(Intent.ACTION_SEND);
|
|
|
|
i.setType("text/plain");
|
|
|
|
i.putExtra(Intent.EXTRA_TEXT, p.getName() + '\n' +
|
|
|
|
getString(R.string.address) + " " + p.getAddress() + '\n' +
|
|
|
|
getString(R.string.distance) + " " + p.getDistance().substring(0, p.getDistance().indexOf(".")) + "m" + '\n' +
|
|
|
|
getString(R.string.phone_number) + " " + (p.getPhoneNumber().equals("") ? getString(R.string.na) : p.getPhoneNumber()) + '\n' +
|
|
|
|
getString(R.string.at_service) + " " + (p.isAtService() ? getString(R.string.yes) : getString(R.string.no)));
|
|
|
|
startActivity(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void copyAddrToClipboard() {
|
|
|
|
ClipboardManager cm = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
|
|
|
|
cm.setText(p.getAddress());
|
|
|
|
Toast.makeText(getApplicationContext(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void makeCall() {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + p.getPhoneNumber()));
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openNavigation() {
|
|
|
|
double lat = Double.parseDouble(p.getLatitude());
|
|
|
|
double lng = Double.parseDouble(p.getLongitude());
|
|
|
|
Location loc = GlobalVars.positioner.getLastLocation();
|
|
|
|
|
|
|
|
StringBuilder url = new StringBuilder();
|
|
|
|
url.append("http://maps.google.com/maps?f=d&hl=en");
|
|
|
|
url.append("&saddr=");
|
|
|
|
url.append( Double.toString(loc.getLatitude()));
|
|
|
|
url.append(",");
|
|
|
|
url.append( Double.toString(loc.getLongitude()));
|
|
|
|
url.append("&daddr=");
|
|
|
|
url.append( Double.toString(lat));
|
|
|
|
url.append(",");
|
|
|
|
url.append( Double.toString(lng));
|
|
|
|
url.append("&ie=UTF8&0&om=0");
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
intent.setData(Uri.parse(url.toString()));
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|