Java Code Examples for

The following are top voted examples for showing how to use These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: AndroidLiveWallpaper   File:   Source Code and License 6 votes vote down vote up
public static LinearLayout createLayoutWithAd(Activity activity) {
      LinearLayout layout = new LinearLayout(activity);
      LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
      lp.gravity = Gravity.CENTER_HORIZONTAL;
      AdView goodAdv = new AdView(activity); //,, GOOGLE_AD_ID
      if (LiveWallpaperSettings.DEBUG) {
} else {
      AdRequest.Builder builder = new Builder();
      return layout;
Example 2
Project: Ships   File:   Source Code and License 5 votes vote down vote up
public static void loadAd(final View view){
	final Builder builder = new AdRequest.Builder();		
	builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); // Emulator
	// Add test devices
	final String[] testDevices = view.getContext().getString(R.string.testDevices).split(",");		
    for (String testDevice:testDevices){
    final AdView adView = (AdView) view.findViewById(;
Example 3
Project: Ships   File:   Source Code and License 5 votes vote down vote up
public static void sendNotification(final Context context,final String postfix,final String message){
	final Notification.Builder mBuilder =
	        new Notification.Builder(context)
	        .setContentTitle(context.getText(R.string.app_name)+" "+postfix)
	// Creates an explicit intent for an Activity in your app
	final Intent resultIntent = new Intent(context, MainActivity.class);

	// The stack builder object will contain an artificial back stack for the
	// started Activity.
	// This ensures that navigating backward from the Activity leads out of
	// your application to the Home screen.
	final TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
	// Adds the back stack for the Intent (but not the Intent itself)
	// Adds the Intent that starts the Activity to the top of the stack
	PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
	final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
	if (mNotificationManager!=null) {
           // mId allows you to update the notification later on.
           int mId = 0;

           Analytics.getInstance().logEvent(TAG, "sendNotification", "message");
Example 4
Project: Ships   File:   Source Code and License 5 votes vote down vote up
public static void showPopup(final int id,final Activity activity,final ImagePopupListener listener,final String title,final String message,final int imageResource,final Long automaticDismissDelay){
	final String tag="showPopup - ";

	activity.runOnUiThread(new Runnable() {
	    public void run() {
	    	final AlertDialog.Builder ad = new AlertDialog.Builder(activity);
			ad.setNeutralButton("OK", new DialogInterface.OnClickListener(){
				public void onClick(DialogInterface arg0, int arg1) {
					if (listener!=null){

			final AlertDialog alert = ad.create();;

			if (automaticDismissDelay != null) {
				final Handler handler = new Handler();
				final Runnable runnable = new Runnable() {
					public void run() {
						if (alert.isShowing()) {
							try {
							} catch (IllegalArgumentException e) {
								// FIXME: Ugly fix (View not attached to window manager)
								Log.e(TAG,tag+"Auto dismiss", e);
				handler.postDelayed(runnable, automaticDismissDelay);