Skip to content

Commit

Permalink
Mapa com 2 pinos
Browse files Browse the repository at this point in the history
  • Loading branch information
renatho committed Nov 10, 2013
1 parent 91bdd78 commit b0f8fba
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 1 deletion.
Binary file added libs/mysql-connector-java-3.0.17-ga-bin.jar
Binary file not shown.
Binary file added res/drawable-hdpi/marker_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/marker_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/marker_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/marker_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<resources>
<string name="app_name">Places</string>
<string name="action_settings">Settings</string>
<string name="txtLocaisProximos">Locais próximos</string>
<string name="txtLocaisProximos">Locais próximos:</string>
</resources>
52 changes: 52 additions & 0 deletions src/com/app/places/DatabaseHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.app.places;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DatabaseHelper {
Connection conn = null;
String url = "jdbc:mysql://174.123.233.90:3306/";
String dbName = "toctoc_places";
String driver = "com.mysql.jdbc.Driver";
String userName = "toctoc_places";
String password = "places123";
Statement statement;

public ResultSet executeQuery(String sql) {
ResultSet rs = null;
try {
rs = statement.executeQuery(sql);
} catch (Exception e) {
e.printStackTrace();
}
return rs;
}

public void executeUpdate(String sql) {
try {
statement.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
}
}

public void open() {
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
statement = conn.createStatement();
} catch (Exception e) {
e.printStackTrace();
}
}

public void close() {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
43 changes: 43 additions & 0 deletions src/com/app/places/MapItemizedOverlay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.app.places;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MapItemizedOverlay extends ItemizedOverlay {

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;

public MapItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}

public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}

@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}

@Override
public int size() {
return mOverlays.size();
}

@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
Util.alert(item.getTitle(), item.getSnippet(), mContext);
return true;
}

}
27 changes: 27 additions & 0 deletions src/com/app/places/MapViewActivity.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
package com.app.places;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.view.Menu;

public class MapViewActivity extends MapActivity {

MapView mapView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);

mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);

List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.marker_map);
MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable, this);

GeoPoint point = new GeoPoint(19240000,-99120000);
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");

GeoPoint point2 = new GeoPoint(35410000, 139460000);
OverlayItem overlayitem2 = new OverlayItem(point2, "Sekai, konichiwa!", "I'm in Japan!");

itemizedoverlay.addOverlay(overlayitem);
itemizedoverlay.addOverlay(overlayitem2);
mapOverlays.add(itemizedoverlay);
}

@Override
Expand Down
13 changes: 13 additions & 0 deletions src/com/app/places/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.app.places;

import android.app.AlertDialog;
import android.content.Context;

public class Util {
public static void alert(String title, String message, Context ctx) {
AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.show();
}
}

0 comments on commit b0f8fba

Please sign in to comment.