Skip to content

Commit

Permalink
changed marker to show InfoWindows (PopupAdapter.java)
Browse files Browse the repository at this point in the history
hebrew works now
  • Loading branch information
samuelregev committed Jan 15, 2015
1 parent e0a0214 commit 63e7eb5
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 13 deletions.
10 changes: 2 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
Expand All @@ -40,13 +41,6 @@
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />

<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="il.co.anyway.app.MainActivity" />
</activity>
</application>

</manifest>
20 changes: 18 additions & 2 deletions app/src/main/java/il/co/anyway/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;


public class MainActivity extends ActionBarActivity {
public class MainActivity extends ActionBarActivity implements OnInfoWindowClickListener {

private final LatLng LOCATION_HOME = new LatLng(31.7459074,35.2303028);

private GoogleMap map;
private boolean needsInit=false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -32,9 +35,17 @@ protected void onCreate(Bundle savedInstanceState) {
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);

if (savedInstanceState == null) {
needsInit=true;
}

centerMapOnMyLocation();
if(needsInit) {
centerMapOnMyLocation();
}
addSomeMarkers();

map.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));
map.setOnInfoWindowClickListener(this);
}

@Override
Expand Down Expand Up @@ -90,4 +101,9 @@ private void addSomeMarkers() {
.snippet(getResources().getString(R.string.first_marker_desc))
.position(new LatLng(31.7459074,35.2303028)));
}

@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(this, marker.getTitle(), Toast.LENGTH_LONG).show();
}
}
40 changes: 40 additions & 0 deletions app/src/main/java/il/co/anyway/app/PopupAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package il.co.anyway.app;


import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Marker;

class PopupAdapter implements GoogleMap.InfoWindowAdapter {
private View popup=null;
private LayoutInflater inflater=null;

PopupAdapter(LayoutInflater inflater) {
this.inflater=inflater;
}

@Override
public View getInfoWindow(Marker marker) {
return(null);
}

@SuppressLint("InflateParams")
@Override
public View getInfoContents(Marker marker) {
if (popup == null) {
popup=inflater.inflate(R.layout.popup, null);
}

TextView tv=(TextView)popup.findViewById(R.id.title);

tv.setText(marker.getTitle());
tv=(TextView)popup.findViewById(R.id.snippet);
tv.setText(marker.getSnippet());

return(popup);
}
}
35 changes: 35 additions & 0 deletions app/src/main/res/layout/popup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="2dip"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/icon"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold"/>

<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"/>
</LinearLayout>

</LinearLayout>
8 changes: 5 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">AnyWay</string>
<string name="app_name" translatable="false">ANYWAY</string>
<string name="action_settings">הגדרות</string>
<string name="first_marker_desc">נסיון</string>
<string name="first_marker_title">fistuk home</string>
<string name="icon">Accident logo</string>

<string name="first_marker_desc">קאי שמעון ונמו מחכים לכם</string>
<string name="first_marker_title">הבית של פיסטוק</string>
</resources>

0 comments on commit 63e7eb5

Please sign in to comment.