Skip to content

Instantly share code, notes, and snippets.

@ishitcno1
Created November 20, 2013 12:30
Show Gist options
  • Save ishitcno1/7562397 to your computer and use it in GitHub Desktop.
Save ishitcno1/7562397 to your computer and use it in GitHub Desktop.
A Preference to show amazon banner ads.
import android.app.Activity;
import android.content.Context;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.amazon.device.ads.AdLayout;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.AdTargetingOptions;
public class AdPreference extends Preference {
public AdPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public AdPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AdPreference(Context context) {
super(context);
}
@Override
protected View onCreateView(ViewGroup parent) {
parent.setPadding(0, 0, 0, 0);
View view = super.onCreateView(parent);
AdRegistration.setAppKey("app key");
Activity activity = (Activity) getContext();
AdLayout adview = new AdLayout(activity);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
((LinearLayout)view).addView(adview, lp);
adview.loadAd(new AdTargetingOptions());
return view;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment