public class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter
{
private static final String TAG = CustomInfoWindowAdapter.class.getSimpleName();
private LayoutInflater inflater = null;
private Context context;
private static final String DEVICE_ID_ZTE = "14212121212121212121121212";
private static final String DEVICE_ID_MOTO_G = "565645543543434343434343";
public CustomInfoWindowAdapter(Context context)
{
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.context = context;
}
@Override
public View getInfoContents(Marker marker)
{
return null;
}
@Override
public View getInfoWindow(Marker marker)
{
Logger.log(TAG, "getInfoWindow()", LogController.isLoggingEnabled(), Log.DEBUG);
View popup = inflater.inflate(R.layout.popup, null);
AdView adView = (AdView)popup.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(DEVICE_ID_MOTO_G).addTestDevice(DEVICE_ID_ZTE).build();
adView.loadAd(adRequest);
adView.setVisibility(View.VISIBLE);
//more common code
return popup;
}
}<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#B3FFFFFF" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/snippet_text_color"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/snippet_text_color"
android:textSize="12sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-foooooooo/baaaaaar" >
</com.google.android.gms.ads.AdView>
</RelativeLayout>
</LinearLayout>public class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter
{
private static final String TAG = CustomInfoWindowAdapter.class.getSimpleName();
private LayoutInflater inflater = null;
private Context context;
private View popup;
private AdView adView;
private AdRequest adRequest;
private long lastUpdateInterval;
public static final String DEVICE_ID_ZTE = "1111111111111111111111111";
public static final String DEVICE_ID_MOTO_G = "22222222222222222222222222";
public CustomInfoWindowAdapter(Context context)
{
this.context = context;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
popup = inflater.inflate(R.layout.popup, null);
adView = (AdView)popup.findViewById(R.id.adView);
adRequest = new AdRequest.Builder().addTestDevice(DEVICE_ID_MOTO_G).addTestDevice(DEVICE_ID_ZTE).build();
}
@Override
public View getInfoContents(Marker marker)
{
return null;
}
@Override
public View getInfoWindow(Marker marker)
{
Logger.log(TAG, "getInfoWindow()", LogController.isLoggingEnabled(), Log.DEBUG);
if (System.currentTimeMillis() - 30000 > lastUpdateInterval)
{
Logger.log(TAG, "last update was more than 30s behind. loading new ad request...", LogController.isLoggingEnabled(), Log.DEBUG);
adView.loadAd(adRequest);
lastUpdateInterval = System.currentTimeMillis();
}
Logger.log(TAG, "refreshing adView...", LogController.isLoggingEnabled(), Log.DEBUG);
adView.requestLayout();
return popup;
}
}<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:background="#B3FFFFFF"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/snippet_text_color"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/snippet_text_color"
android:textSize="12sp" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-12121212/23232323" >
</com.google.android.gms.ads.AdView>
</LinearLayout>