add location; Map View; Location Updates, Storage;

This commit is contained in:
Tobias Klika
2011-07-10 17:51:49 +02:00
parent bb2e4ff43a
commit 6fb15496e4
60 changed files with 438 additions and 395 deletions
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+41 -40
View File
@@ -42,76 +42,77 @@ public final class R {
public static final int me=0x7f020011;
public static final int messages=0x7f020012;
public static final int nearby=0x7f020013;
public static final int reload_button=0x7f020014;
public static final int search=0x7f020015;
public static final int tab_bg_selected=0x7f020016;
public static final int tab_bg_selector=0x7f020017;
public static final int tab_bg_unselected=0x7f020018;
public static final int tab_divider=0x7f020019;
public static final int tab_text_selector=0x7f02001a;
public static final int top_bg=0x7f02001b;
public static final int user=0x7f02001c;
public static final int user_big=0x7f02001d;
public static final int nearby_list=0x7f020014;
public static final int reload_button=0x7f020015;
public static final int search=0x7f020016;
public static final int tab_bg_selected=0x7f020017;
public static final int tab_bg_selector=0x7f020018;
public static final int tab_bg_unselected=0x7f020019;
public static final int tab_divider=0x7f02001a;
public static final int tab_text_selector=0x7f02001b;
public static final int top_bg=0x7f02001c;
public static final int user=0x7f02001d;
public static final int user_big=0x7f02001e;
}
public static final class id {
public static final int ButtonLoginUser=0x7f080014;
public static final int ButtonLoginUser=0x7f080015;
public static final int ButtonRegisterUser=0x7f08002d;
public static final int ButtonUserRegistration=0x7f080017;
public static final int EditTextLoginMail=0x7f080010;
public static final int EditTextLoginPassword=0x7f080011;
public static final int ButtonUserRegistration=0x7f080018;
public static final int EditTextLoginMail=0x7f080011;
public static final int EditTextLoginPassword=0x7f080012;
public static final int EditTextRegistrationMail=0x7f08002b;
public static final int EditTextRegistrationName=0x7f08002a;
public static final int EditTextRegistrationPassword=0x7f08002c;
public static final int SearchInput=0x7f080031;
public static final int SpinnerLoginUserStatus=0x7f080013;
public static final int TextViewTitle=0x7f080012;
public static final int SpinnerLoginUserStatus=0x7f080014;
public static final int TextViewTitle=0x7f080013;
public static final int add=0x7f080038;
public static final int circlecc=0x7f080000;
public static final int circlecc_image=0x7f080001;
public static final int conversation=0x7f080002;
public static final int findmemenu=0x7f080004;
public static final int findmemenuItems=0x7f080005;
public static final int friends=0x7f080007;
public static final int friendslist=0x7f08000e;
public static final int friends=0x7f080008;
public static final int friendslist=0x7f08000f;
public static final int homebutton=0x7f080036;
public static final int logo=0x7f080015;
public static final int logout=0x7f08000b;
public static final int logo=0x7f080016;
public static final int logout=0x7f08000c;
public static final int mapView=0x7f080026;
public static final int me=0x7f08000a;
public static final int me=0x7f08000b;
public static final int message=0x7f080039;
public static final int messageInputLayout=0x7f080018;
public static final int messageOverview=0x7f08001b;
public static final int messageInputLayout=0x7f080019;
public static final int messageOverview=0x7f08001c;
public static final int messageOverviewList=0x7f080003;
public static final int message_item=0x7f080021;
public static final int message_overview_item=0x7f08001e;
public static final int message_overview_text=0x7f080020;
public static final int message_text=0x7f080022;
public static final int messageinput=0x7f080019;
public static final int messages=0x7f080008;
public static final int messagesubmit=0x7f08001a;
public static final int message_item=0x7f080022;
public static final int message_overview_item=0x7f08001f;
public static final int message_overview_text=0x7f080021;
public static final int message_text=0x7f080023;
public static final int messageinput=0x7f08001a;
public static final int messages=0x7f080009;
public static final int messagesubmit=0x7f08001b;
public static final int nearby=0x7f080006;
public static final int nearby_list_text=0x7f080025;
public static final int nearbylist=0x7f080024;
public static final int nearbylist=0x7f080007;
public static final int profile=0x7f080027;
public static final int profilemail=0x7f080029;
public static final int profilename=0x7f080028;
public static final int reloadbutton=0x7f080037;
public static final int request_dialog=0x7f08002e;
public static final int requests=0x7f08000f;
public static final int search=0x7f080009;
public static final int requests=0x7f080010;
public static final int search=0x7f08000a;
public static final int searchList=0x7f08002f;
public static final int search_dialog=0x7f080030;
public static final int tabhost=0x7f08000d;
public static final int tabhost=0x7f08000e;
public static final int tabsLayout=0x7f080032;
public static final int tabsText=0x7f080033;
public static final int test_image=0x7f080016;
public static final int test_image=0x7f080017;
public static final int title=0x7f080034;
public static final int title2138=0x7f08001d;
public static final int title2138=0x7f08001e;
public static final int titleText=0x7f080035;
public static final int topbb=0x7f080023;
public static final int topbb2=0x7f08000c;
public static final int topbb9864=0x7f08001c;
public static final int user_image=0x7f08001f;
public static final int topbb=0x7f080024;
public static final int topbb2=0x7f08000d;
public static final int topbb9864=0x7f08001d;
public static final int user_image=0x7f080020;
}
public static final class layout {
public static final int circle_counter=0x7f030000;
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

+7
View File
@@ -22,6 +22,13 @@
android:src="@drawable/nearby"
android:paddingBottom="15dip"
android:background="@null" />
<ImageButton android:id="@+id/nearbylist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="nearbyListMenuHandler"
android:src="@drawable/nearby_list"
android:paddingBottom="15dip"
android:background="@null" />
<ImageButton android:id="@+id/friends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+1 -1
View File
@@ -5,7 +5,7 @@
android:orientation="vertical"
android:layout_height="fill_parent">
<include layout="@layout/topbar" />
<include layout="@layout/topbar_noreload" />
<include layout="@layout/title" />
<com.google.android.maps.MapView
+2 -2
View File
@@ -28,7 +28,7 @@
<TextView
android:id="@+id/profilename"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text"
android:textSize="22sp"
@@ -38,7 +38,7 @@
</TextView>
<TextView
android:id="@+id/profilemail"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text"
android:textSize="22sp"
+6 -3
View File
@@ -25,7 +25,8 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Conversation extends Activity {
public class Conversation extends TimerActivity
{
public static final String PREFS_NAME = "LoginCredentials";
private String sender;
private String receiver;
@@ -40,6 +41,8 @@ public class Conversation extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.conversation);
super.run();
// get conversation partner
Bundle bundle = this.getIntent().getExtras();
receiver = bundle.getString("mail");
@@ -102,10 +105,10 @@ public class Conversation extends Activity {
private Handler uiCallback = new Handler() {
@Override
public void handleMessage(Message msg) {
messageOverview = (ListView) findViewById(R.id.messageOverviewList);
messageOverview = (ListView) Conversation.this.findViewById(R.id.messageOverviewList);
adapter = new ArrayAdapter<Spanned>
(Conversation.this, R.layout.messsage_item, R.id.message_text, list);
(Conversation.this.getApplicationContext(), R.layout.messsage_item, R.id.message_text, list);
messageOverview.setAdapter(adapter);
+14 -9
View File
@@ -8,6 +8,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -15,10 +16,13 @@ import android.view.Window;
import android.widget.EditText;
import android.widget.Toast;
public class FindMeMenu extends Activity
public class FindMeMenu extends TimerActivity
{
public static final String PREFS_NAME = "LoginCredentials";
private static final String TAG = "findMe";
private static final String TAG = "FindMeMenu";
@Override
public void onCreate(Bundle savedInstanceState)
@@ -27,10 +31,17 @@ public class FindMeMenu extends Activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.findmemenu);
super.run();
}
// Handler
public void nearbyMenuHandler(View button)
{
Intent myIntent = new Intent(button.getContext(), MapNearby.class);
startActivity(myIntent);
}
public void nearbyListMenuHandler(View button)
{
Intent myIntent = new Intent(button.getContext(), Nearby.class);
startActivity(myIntent);
@@ -93,13 +104,7 @@ public class FindMeMenu extends Activity
}
public void logoutMenuHandler(View button)
{
String logoutData[] = new String[2];
SharedPreferences preferences = this.getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE);
logoutData[0] = preferences.getString("mail", "");
logoutData[1] = preferences.getString("password", "");
String response = AccountHelper.logout(logoutData, this).trim();
String response = AccountHelper.logout(this).trim();
Log.v(TAG, response);
if(response.compareTo("06") == 0)
{
+4 -1
View File
@@ -34,7 +34,8 @@ import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;
public class Friends extends Activity {
public class Friends extends TimerActivity
{
private TabHost mTabHost;
private ListView friends;
private ListView requests;
@@ -57,6 +58,8 @@ public class Friends extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.friends);
super.run();
// get mail
SharedPreferences preferences = this.getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE);
mail = preferences.getString("mail", "");
+50 -91
View File
@@ -33,16 +33,16 @@ import android.widget.Toast;
public class MapNearby extends MapActivity
{
public int standardZoom = 12;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 0; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds
private static final String TAG = "test";
private MapController mapController;
private List<Overlay> mapOverlays;
private static final String TAG = "MapNearby";
private MapView mapView;
private GeoPoint geoPoint;
private PeopleItemizedOverlay itemizedoverlay;
protected LocationManager locationManager;
private String[] mails;
private String[] names;
@Override
public void onCreate(Bundle savedInstanceState)
@@ -67,9 +67,10 @@ public class MapNearby extends MapActivity
// go to my location
Location location = LocationHelper.getCurrentLocation(this);
String coordinates[] = new String[2];
coordinates[0] = String.valueOf("30");
coordinates[1] = String.valueOf("-122");
coordinates[0] = String.valueOf(location.getLatitude());
coordinates[1] = String.valueOf(location.getLongitude());
geoPoint = LocationHelper.toGeoPoint(coordinates);
mapController.animateTo(geoPoint);
mapController.setZoom(standardZoom);
@@ -79,41 +80,51 @@ public class MapNearby extends MapActivity
Drawable marker = MapNearby.this.getResources().getDrawable(R.drawable.marker);
addMe(mapOverlays);
// show people marker
itemizedoverlay = new PeopleItemizedOverlay(marker, MapNearby.this);
JSONObject json = RequestHelper.doHttpGet("get_online_user.php", this);
JSONObject json = RequestHelper.doHttpGet("get_online_user.php", this, "?mail="+AccountHelper.getMail(this));
//String[] onlineUser = new String[json.length()];
String cood[] = new String[2];
mails = new String[json.length()];
names = new String[json.length()];
JSONObject json_data = null;
String x;
try {
JSONObject json_data = null;
String x;
for(int i=0;i<json.length();i++)
{
x = (new Integer(i)).toString();
json_data = json.getJSONObject(x);
mails[i] = json_data.getString("mail");
names[i] = json_data.getString("name");
}
} catch (JSONException e) {
Log.v(TAG, "JSONError");
}
// show people marker
itemizedoverlay = new PeopleItemizedOverlay(marker, MapNearby.this, names, mails);
try {
json_data = null;
x = null;
for(int i=0;i<json.length();i++)
{
x = (new Integer(i)).toString();
json_data = json.getJSONObject(x);
cood[0] = String.valueOf(json_data.getDouble("longitude"));
cood[1] = String.valueOf(json_data.getDouble("latitude"));
cood[0] = String.valueOf(json_data.getDouble("latitude"));
cood[1] = String.valueOf(json_data.getDouble("longitude"));
addPerson(mapOverlays, cood);
//mails[i] = json_data.getString("mail");
//names[i] = json_data.getString("name");
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.v(TAG, "JSONError");
}
mapOverlays.add(itemizedoverlay);
@@ -129,8 +140,20 @@ public class MapNearby extends MapActivity
private void addMe(List<Overlay> mapOverlays) {
Drawable markerme = this.getResources().getDrawable(R.drawable.markerme);
JSONObject j = FriendsHelper.getUserInfo(AccountHelper.getMail(this), this);
String[] name = new String[1];
String[] mail = new String[1];
try {
name[0] = j.getString("name");
mail[0] = j.getString("mail");
} catch (JSONException e) {
Log.v(TAG, "JSONError");
}
// add my position
PeopleItemizedOverlay meitemizedoverlay = new PeopleItemizedOverlay(markerme, this);
PeopleItemizedOverlay meitemizedoverlay = new PeopleItemizedOverlay(markerme, this, name, mail);
OverlayItem meoverlayitem = new OverlayItem(geoPoint, "Me", "This is me!");
meitemizedoverlay.addOverlay(meoverlayitem);
mapOverlays.add(meitemizedoverlay);
@@ -140,7 +163,7 @@ public class MapNearby extends MapActivity
private void addPerson(List<Overlay> mapOverlays, String[] coord) {
GeoPoint point = LocationHelper.toGeoPoint(coord);
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
OverlayItem overlayitem = new OverlayItem(point, "Hola!", "I'm here!");
itemizedoverlay.addOverlay(overlayitem);
}
@@ -150,68 +173,4 @@ public class MapNearby extends MapActivity
Intent myIntent = new Intent(button.getContext(), FindMeMenu.class);
startActivity(myIntent);
}
public void updateLocationHandler(View button)
{
updateLocation();
}
public void updateLocation()
{
showCurrentLocation();
}
protected String[] showCurrentLocation() {
String[] loc = new String[2];
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
String message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
loc[0] = String.valueOf(location.getLatitude());
loc[1] = String.valueOf(location.getLongitude());
// Toast.makeText(Nearby.this, message, Toast.LENGTH_LONG).show();
}
return loc;
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Log.v(TAG, message);
//Toast.makeText(Nearby.this, message, Toast.LENGTH_LONG).show();
}
public void onStatusChanged(String s, int i, Bundle b) {
//Toast.makeText(Nearby.this, "Provider status changed", Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
Toast.makeText(MapNearby.this,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s) {
Toast.makeText(MapNearby.this,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
}
}
+6 -4
View File
@@ -22,7 +22,8 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class Messages extends Activity {
public class Messages extends TimerActivity
{
public static final String PREFS_NAME = "LoginCredentials";
private static final String TAG = "findme";
public ProgressDialog loadingDialog;
@@ -42,6 +43,8 @@ public class Messages extends Activity {
TextView title = (TextView) findViewById(R.id.titleText);
title.setText("Conversations");
super.run();
load();
}
@@ -66,10 +69,9 @@ public class Messages extends Activity {
String[] logPref = AccountHelper.getLoginPreferences(Messages.this);
mail = logPref[0];
messageOverview = (ListView) findViewById(R.id.messageOverviewList);
messageOverview = (ListView) Messages.this.findViewById(R.id.messageOverviewList);
// search results to string
Log.v(TAG, "XXX 00");
JSONObject j = MessagesHelper.getConversationOverview(mail, Messages.this);
list = new Spanned[j.length()];
@@ -105,7 +107,7 @@ public class Messages extends Activity {
@Override
public void handleMessage(Message msg) {
messageOverview.setAdapter(new ArrayAdapter<Spanned>
(Messages.this, R.layout.message_overview_item, R.id.message_overview_text, list));
(Messages.this.getApplicationContext(), R.layout.message_overview_item, R.id.message_overview_text, list));
messageOverview.setTextFilterEnabled(true);
@@ -0,0 +1,36 @@
package com.architects.findme;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.location.LocationListener;
class MyLocationListener implements LocationListener {
private static final String TAG = "LocationHelper";
public void onLocationChanged(Location location) {
/* String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Log.v(TAG, message);*/
//Toast.makeText(myContext, message, Toast.LENGTH_LONG).show();
}
public void onStatusChanged(String s, int i, Bundle b) {
// Toast.makeText(myContext, "Provider status changed", Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
/*Toast.makeText(myContext,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();*/
}
public void onProviderEnabled(String s) {
/* Toast.makeText(myContext,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();*/
}
}
+93 -126
View File
@@ -1,5 +1,7 @@
package com.architects.findme;
import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject;
@@ -7,12 +9,18 @@ import com.architects.findme.R;
import com.architects.helper.*;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;
import android.view.View;
import android.view.Window;
@@ -23,29 +31,23 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Nearby extends Activity {
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 100; // in Milliseconds
public class Nearby extends TimerActivity {
private static final String TAG = "test";
protected LocationManager locationManager;
private ListView nearby;
public ProgressDialog loadingDialog;
private ArrayAdapter<Spanned> adapter;
private Spanned[] list = null;
private String[] mails;
private String[] names;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.nearby);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
super.run();
load();
}
@@ -57,121 +59,86 @@ public class Nearby extends Activity {
private void load()
{
String[] logPref = AccountHelper.getLoginPreferences(this);
String params = "?mail=" + logPref[0];
JSONObject json = RequestHelper.doHttpGet("get_online_user.php", this, params);
String[] onlineUser = new String[json.length()];
final String[] mails = new String[json.length()];
final String[] names = new String[json.length()];
try {
Log.v(TAG, "Länge:"+json.length());
JSONObject json_data = null;
String x;
Location location = new Location("");
location.setLatitude(13.0443);
location.setLongitude(48.2557);
for(int i=0;i<json.length();i++)
{
x = (new Integer(i)).toString();
json_data = json.getJSONObject(x);
Location location2 = new Location("");
location2.setLatitude(json_data.getDouble("latitude"));
location2.setLongitude(json_data.getDouble("longitude"));;
float distance = location.distanceTo(location2);
String me = null;
int dis = 0;
if (distance >= 1000)
{
distance /= 1000;
dis = (int) Math.rint(distance);
me = dis + " km";
}
else me = distance + " m";
mails[i] = json_data.getString("mail");
names[i] = json_data.getString("name");
onlineUser[i] = json_data.getString("name") + "\n" + me;
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
nearby = (ListView) findViewById(R.id.nearbylist);
nearby.setAdapter(new ArrayAdapter<String>(this, R.layout.nearby_list_item, R.id.nearby_list_text, onlineUser));
loadingDialog = ProgressDialog.show(this, null, " Loading ...", true);
new Thread(new Runnable(){
public void run(){
String[] logPref = AccountHelper.getLoginPreferences(Nearby.this);
String params = "?mail=" + logPref[0];
JSONObject json = RequestHelper.doHttpGet("get_online_user.php", Nearby.this, params);
list = new Spanned[json.length()];
mails = new String[json.length()];
names = new String[json.length()];
try {
Log.v(TAG, "Länge:"+json.length());
JSONObject json_data = null;
String x;
Location location = LocationHelper.getCurrentLocation(Nearby.this);
for(int i=0;i<json.length();i++)
{
x = (new Integer(i)).toString();
json_data = json.getJSONObject(x);
Location location2 = new Location("");
location2.setLatitude(json_data.getDouble("latitude"));
location2.setLongitude(json_data.getDouble("longitude"));;
float distance = location.distanceTo(location2);
String me = null;
int dis = 0;
if (distance >= 1000)
{
distance /= 1000;
dis = (int) Math.rint(distance);
me = dis + " km";
}
else me = distance + " m";
mails[i] = json_data.getString("mail");
names[i] = json_data.getString("name");
list[i] = Html.fromHtml(json_data.getString("name") + "<br>" + me);
}
} catch (JSONException e) {
Log.v(TAG, "JSONError");
}
nearby.setTextFilterEnabled(true);
nearby.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Bundle bundle = new Bundle();
bundle.putString("mail", mails[position]);
bundle.putString("name", names[position]);
Looper.prepare();
uiCallback.sendEmptyMessage(0);
}
}).start();
}
Intent newIntent = new Intent(getApplicationContext(), Profile.class);
newIntent.putExtras(bundle);
startActivity(newIntent);
}
});
}
public void updateLocationHandler(View button)
{
updateLocation();
}
public void updateLocation()
{
showCurrentLocation();
}
protected void showCurrentLocation() {
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
String message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
// Toast.makeText(Nearby.this, message, Toast.LENGTH_LONG).show();
private Handler uiCallback = new Handler() {
@Override
public void handleMessage(Message msg) {
nearby = (ListView) findViewById(R.id.nearbylist);
adapter = new ArrayAdapter<Spanned>(Nearby.this, R.layout.nearby_list_item, R.id.nearby_list_text, list);
nearby.setAdapter(adapter);
nearby.setTextFilterEnabled(true);
nearby.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Bundle bundle = new Bundle();
bundle.putString("mail", mails[position]);
bundle.putString("name", names[position]);
Intent newIntent = new Intent(getApplicationContext(), Profile.class);
newIntent.putExtras(bundle);
startActivity(newIntent);
}
});
loadingDialog.dismiss();
}
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
//Toast.makeText(Nearby.this, message, Toast.LENGTH_LONG).show();
}
public void onStatusChanged(String s, int i, Bundle b) {
//Toast.makeText(Nearby.this, "Provider status changed", Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
Toast.makeText(Nearby.this,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s) {
Toast.makeText(Nearby.this,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
}
};
public void enterMenuHandler(View button)
{
@@ -2,10 +2,15 @@ package com.architects.findme;
import java.util.ArrayList;
import org.json.JSONObject;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import com.architects.helper.*;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
@@ -14,10 +19,14 @@ public class PeopleItemizedOverlay extends ItemizedOverlay
{
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
public PeopleItemizedOverlay(Drawable defaultMarker, Context context) {
private String[] mails;
private String[] names;
public PeopleItemizedOverlay(Drawable defaultMarker, Context context, String[] names, String[] mails) {
super(boundCenterBottom(defaultMarker));
mContext = context;
this.mails = mails;
this.names = names;
}
@Override
@@ -34,54 +43,16 @@ public class PeopleItemizedOverlay extends ItemizedOverlay
@Override
protected boolean onTap(int index) {
//OverlayItem item = mOverlays.get(index);
Log.v("test", "ID " + index);
Bundle bundle = new Bundle();
bundle.putString("mail", "klika@live.at");
bundle.putString("name", "Tobias Klika");
bundle.putString("mail", mails[index]);
bundle.putString("name", names[index]);
Intent newIntent = new Intent(mContext.getApplicationContext(), Profile.class);
newIntent.putExtras(bundle);
mContext.startActivity(newIntent);
return true;
/*
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
LayoutInflater factory = LayoutInflater.from(mContext);
final View input = factory.inflate(R.layout.map_dialog, null);
dialog.setView(input);
dialog.setPositiveButton("Profile", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// get the input value
EditText mText;
mText = (EditText) input.findViewById(R.id.MapInput);
String text = mText.getText().toString();
// redirect to search results
Bundle bundle = new Bundle();
bundle.putString("mail", text);
Log.v(TAG, "HI");
Intent newIntent = new Intent(mContext.getApplicationContext(), Login.class);
newIntent.putExtras(bundle);
mContext.startActivity(newIntent);
}
});
dialog.setNegativeButton("Hide", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
});
dialog.show();
return true;
*/
}
+2 -1
View File
@@ -14,7 +14,7 @@ import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;
public class Profile extends Activity
public class Profile extends TimerActivity
{
private static final String TAG = "findme";
private String userName;
@@ -28,6 +28,7 @@ public class Profile extends Activity
setContentView(R.layout.profile);
super.run();
Bundle bundle = this.getIntent().getExtras();
userMail = bundle.getString("mail");
+4 -1
View File
@@ -18,7 +18,8 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class Search extends Activity {
public class Search extends TimerActivity
{
private ListView resultsList;
public static final String PREFS_NAME = "LoginCredentials";
private String query = null;
@@ -31,6 +32,8 @@ public class Search extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.search);
super.run();
// get search query
Bundle bundle = this.getIntent().getExtras();
query = bundle.getString("query");
@@ -0,0 +1,104 @@
package com.architects.findme;
import com.architects.helper.*;
import com.google.android.maps.GeoPoint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
public class TimerActivity extends Activity {
private static final String TAG = "LocationTimer";
public static final String PREFS_NAME = "LoginCredentials";
private Handler handler = new Handler();
private LocationHelper locHelper;
private Location location;
protected LocationManager locationManager;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 300000; // in Milliseconds
private MyLocationListener locListener = new MyLocationListener();
@Override
public void onPause()
{
Log.v(TAG, "PAUSE");
handler.removeCallbacks(locationInterval);
super.onPause();
}
@Override
public void onResume()
{
Log.v(TAG, "RESUME");
super.onResume();
run();
}
private Runnable locationInterval = new Runnable() {
public void run() {
Log.v(TAG, "... timer");
TimerActivity.this.updateLocation();
TimerActivity.this.proofLogin();
// recursion
handler.removeCallbacks(locationInterval);
handler.postDelayed(this, MINIMUM_TIME_BETWEEN_UPDATES);
}
};
public void run() {
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationManager.removeUpdates(locListener);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
locListener
);
locationInterval.run();
}
protected void updateLocation() {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
SharedPreferences preferences = TimerActivity.this.getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE);
SharedPreferences.Editor prefsEditor = preferences.edit();
Log.v(TAG, "LONG: " + location.getLongitude() + ", LAT: " + location.getLatitude());
prefsEditor.putFloat("longitude", (float) location.getLongitude());
prefsEditor.putFloat("latitude", (float) location.getLatitude());
prefsEditor.commit();
LocationHelper.update(location, TimerActivity.this);
}
protected void proofLogin() {
if(!AccountHelper.isLogged(this))
{
Log.v(TAG, "NOT LOGGED IN! logging out ...");
AccountHelper.logout(this);
handler.removeCallbacks(locationInterval);
finish();
Intent myIntent = new Intent(this.getApplicationContext(), Main.class);
startActivity(myIntent);
}
}
}
+16 -4
View File
@@ -3,10 +3,12 @@ package com.architects.helper;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.location.Location;
public class AccountHelper
public class AccountHelper
{
public static final String PREFS_NAME = "LoginCredentials";
@@ -32,6 +34,13 @@ public class AccountHelper
return loginPreferences;
}
public static String getMail(Context c)
{
SharedPreferences preferences = c.getSharedPreferences(PREFS_NAME, 0);
return preferences.getString("mail", "");
}
public static Boolean clearLoginPreferences(Context c)
{
SharedPreferences preferences = c.getSharedPreferences(PREFS_NAME, 0);
@@ -48,12 +57,13 @@ public class AccountHelper
JSONObject j = new JSONObject();
try
{
Location loc = LocationHelper.getCurrentLocation(context);
j.put("mail", str[0]);
j.put("password", StandardHelper.createHashMd5(str[1]));
j.put("status", str[2]);
j.put("longitude", -122.084095);
j.put("latitude", 37.422006);
j.put("longitude", loc.getLongitude());
j.put("latitude", loc.getLatitude());
return RequestHelper.doHttpPost("login_user.php", context, j);
}
@@ -64,8 +74,10 @@ public class AccountHelper
}
}
public static String logout(String[] str, Context context)
public static String logout(Context context)
{
String str[] = getLoginPreferences(context);
JSONObject j = new JSONObject();
try
+38 -69
View File
@@ -1,84 +1,53 @@
package com.architects.helper;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.content.SharedPreferences;
import android.location.Location;
import android.util.Log;
import com.google.android.maps.GeoPoint;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class LocationHelper
{
private static final String TAG = "LocationHelper";
public static final String PREFS_NAME = "LoginCredentials";
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 100; // in Milliseconds
public static Location getCurrentLocation(Context c)
{
Location loc = new Location("");
SharedPreferences preferences = c.getSharedPreferences(PREFS_NAME, 0);
loc.setLongitude(preferences.getFloat("longitude", 0));
loc.setLatitude(preferences.getFloat("latitude", 0));
return loc;
}
protected LocationManager locationManager;
protected Context myContext;
public LocationHelper(Context myContext){
this.myContext = myContext;
locationManager = (LocationManager) myContext.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
}
public void updateLocationHandler(View button)
{
updateLocation();
}
public void updateLocation()
{
showCurrentLocation();
}
public static String update(Location location, Context context)
{
JSONObject j = new JSONObject();
try
{
String[] str = AccountHelper.getLoginPreferences(context);
j.put("longitude", location.getLongitude());
j.put("latitude", location.getLatitude());
j.put("mail", str[0]);
j.put("password", StandardHelper.createHashMd5(str[1]));
protected void showCurrentLocation() {
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
String message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
//Toast.makeText(myContext, message, Toast.LENGTH_LONG).show();
return RequestHelper.doHttpPost("set_location.php", context, j);
}
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
//Toast.makeText(myContext, message, Toast.LENGTH_LONG).show();
catch (JSONException e)
{
e.printStackTrace();
return "";
}
public void onStatusChanged(String s, int i, Bundle b) {
// Toast.makeText(myContext, "Provider status changed", Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
Toast.makeText(myContext,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s) {
Toast.makeText(myContext,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
}
}
public static GeoPoint toGeoPoint(String[] coord)
{