commit 8c0695621088d27e3b4c6f7cbe373397dca18263
parent 71200e251d69a7991c4ed36aa255c866edabdf1b
Author: dankert <devnull@localhost>
Date: Mon, 19 Sep 2011 23:06:29 +0200
Uebertragen von Daten an die Detailseite.
Diffstat:
2 files changed, 64 insertions(+), 48 deletions(-)
diff --git a/src/de/jandankert/hansemerkur/PVODetail.java b/src/de/jandankert/hansemerkur/PVODetail.java
@@ -1,17 +1,35 @@
package de.jandankert.hansemerkur;
+import java.io.IOException;
+
+import de.jandankert.hansemerkur.adapter.PVOCursorAdapter;
+import de.jandankert.hansemerkur.db.DataBaseHelper;
import android.app.Activity;
+import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.CursorAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
import android.widget.Toast;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
public class PVODetail extends Activity
{
+ private long plz;
+ private String ort;
+ private String strasse;
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
@@ -19,6 +37,34 @@ public class PVODetail extends Activity
super.onCreate(savedInstanceState);
setContentView(R.layout.pvo_detail);
+ DataBaseHelper db = new DataBaseHelper(this);
+ try
+ {
+ db.createDataBase();
+ } catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ db.openDataBase();
+ SQLiteDatabase database = db.getReadableDatabase();
+
+ plz = this.getIntent().getExtras().getLong("id");
+ final String sql = "SELECT * from vms where plz='" + plz + "'";
+
+ final Cursor cursor = database.rawQuery(sql, new String[] {});
+
+ startManagingCursor(cursor);
+
+ cursor.moveToFirst();
+ TextView v = (TextView) findViewById(R.id.pvo_ort);
+ v.setText(cursor.getString(cursor.getColumnIndex("Ort")));
+ TextView vs = (TextView) findViewById(R.id.pvo_str);
+ vs.setText(cursor.getString(cursor.getColumnIndex("Strasse")));
+
+ this.strasse = cursor.getString(cursor.getColumnIndex("Strasse"));
+ this.ort = cursor.getString(cursor.getColumnIndex("Ort"));
+
+ cursor.close();
}
public boolean onCreateOptionsMenu(Menu menu)
@@ -40,7 +86,7 @@ public class PVODetail extends Activity
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:+494041190"));
startActivity(callIntent);
-
+
} catch (ActivityNotFoundException e)
{
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
@@ -50,10 +96,10 @@ public class PVODetail extends Activity
case R.id.itemNav:
try
{
- Intent i = new Intent(
- Intent.ACTION_VIEW,
- Uri
- .parse("google.navigation:q=Germany,Siegfried-Wedells-Platz+1,Hamburg"));
+ Intent i = new Intent(Intent.ACTION_VIEW, Uri
+ .parse("google.navigation:q=Germany,"
+ + strasse.replace(' ', '+') + ","
+ + ort.replace(' ', '+')));
startActivity(i);
} catch (ActivityNotFoundException e)
{
diff --git a/src/de/jandankert/hansemerkur/PVOList.java b/src/de/jandankert/hansemerkur/PVOList.java
@@ -16,9 +16,9 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
import android.widget.CursorAdapter;
import android.widget.ListView;
+import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
@@ -27,6 +27,8 @@ import de.jandankert.hansemerkur.db.DataBaseHelper;
public class PVOList extends ListActivity
{
+ private static final int MAX_ENTFERNUNG = 100;
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
@@ -96,13 +98,12 @@ public class PVOList extends ListActivity
* Math.cos(Math.cos(Math.toRadians(lat)));
laengeBreitengrad = 67;
- final String sql = "SELECT "
- + "(? * (?-plz.lat)* ? * (?-plz.lat)) + (? * (? - plz.lon)*(? * (? - plz.lon))) AS entfernung,"
- + "vms.strasse,vms.plz,vms.ort,vms.vorname,vms.nachname,"
+ final String sql = "SELECT *,"
+ + "(? * (?-vms.lat)* ? * (?-vms.lat)) + (? * (? - vms.lon)*(? * (? - vms.lon))) AS entfernung,"
+ // + "vms.strasse,vms.plz,vms.ort,vms.vorname,vms.nachname,"
+ " vms.plz as _id" + " FROM vms"
- + " left join plz on vms.plz=plz.plz"
- + " where lon is not null and entfernung < (100*100)"
- + " order by entfernung";
+ + " where lon is not null and entfernung < (" + MAX_ENTFERNUNG
+ + "*" + MAX_ENTFERNUNG + ")" + " order by entfernung";
String[] param = new String[] { "" + laengeBreitengrad, "" + lat,
"" + laengeBreitengrad, "" + lat, "" + laengeLaengengrad,
@@ -110,39 +111,13 @@ public class PVOList extends ListActivity
Cursor cursor = database.rawQuery(sql, param);
- for (String c : cursor.getColumnNames())
- {
-
- System.out.println("***" + c);
- }
-
startManagingCursor(cursor);
-
- // Create an array of Strings, that will be put to our ListActivity
- String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
- "Ubuntu", "Solaris", "Android", "iPhone" };
- // Create an ArrayAdapter, that will actually make the Strings above
- // appear in the ListView
- // this.setListAdapter(new ArrayAdapter<String>(this,
- // R.layout.pvo_entry,R.id.pvo_title, names));
-
- String[] from = new String[] { "Ort", "entfernung", "Nachname", "Plz",
- "Strasse", "Nachname" };
- int[] to = new int[] { R.id.pvo_ort, R.id.pvo_entfernung,
- R.id.pvo_name, R.id.pvo_plz, R.id.pvo_str, R.id.pvo_title };
-
+
// Now create an array adapter and set it to display using our row
CursorAdapter pvoAdapter = new PVOCursorAdapter(this, cursor);
- // CursorAdapter notes = new SimpleCursorAdapter(this,
- // R.layout.pvo_entry,cursor,from,to);
-
- // if ( cursor.isAfterLast() ) {
- //
- // Toast.makeText(this, "Nichts gefunden", Toast.LENGTH_SHORT).show();
- // }
ListView list = getListView();
- // list.settou
+
list.setOnItemLongClickListener(new OnItemLongClickListener()
{
@@ -150,7 +125,6 @@ public class PVOList extends ListActivity
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id)
{
- System.out.println("long clicked");
Toast.makeText(PVOList.this,
"Item in position " + position + " long clicked",
Toast.LENGTH_LONG).show();
@@ -166,13 +140,9 @@ public class PVOList extends ListActivity
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
-// System.out.println("short clicked");
- Toast.makeText(PVOList.this,
- "Item in position " + position + " short clicked",
- Toast.LENGTH_LONG).show();
-
-
- final Intent i = new Intent(PVOList.this,PVODetail.class);
+ final Intent i = new Intent(PVOList.this, PVODetail.class);
+ i.putExtra("id",id);
+ i.putExtra("ort",((TextView)view.findViewById(R.id.pvo_ort)).getText());
startActivity(i);
}
});