public static LinearLayout createLayoutWithAd(Activity activity) { LinearLayout layout = new LinearLayout(activity); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); lp.gravity = Gravity.CENTER_HORIZONTAL; AdView goodAdv = new AdView(activity); //, com.google.ads.AdSize.BANNER, GOOGLE_AD_ID if (LiveWallpaperSettings.DEBUG) { goodAdv.setAdUnitId(""); } else { goodAdv.setAdUnitId("ca-app-pub-7879767097814866/4363554030"); } goodAdv.setAdSize(AdSize.BANNER); layout.addView(goodAdv); AdRequest.Builder builder = new Builder(); goodAdv.loadAd(builder.build()); return layout; }
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){ builder.addTestDevice(testDevice); } final AdView adView = (AdView) view.findViewById(R.id.adView); adView.loadAd(builder.build()); }
public static void sendNotification(final Context context,final String postfix,final String message){ final Notification.Builder mBuilder = new Notification.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getText(R.string.app_name)+" "+postfix) .setContentText(message); // 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) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (mNotificationManager!=null) { // mId allows you to update the notification later on. int mId = 0; mNotificationManager.notify(mId, mBuilder.build()); Analytics.getInstance().logEvent(TAG, "sendNotification", "message"); } }
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.setTitle(title); ad.setMessage(Html.fromHtml(message)); ad.setIcon(imageResource); ad.setNeutralButton("OK", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface arg0, int arg1) { if (listener!=null){ listener.onImagePopupDispose(id); } } }); final AlertDialog alert = ad.create(); alert.show(); if (automaticDismissDelay != null) { final Handler handler = new Handler(); final Runnable runnable = new Runnable() { public void run() { if (alert.isShowing()) { try { alert.dismiss(); } catch (IllegalArgumentException e) { // FIXME: Ugly fix (View not attached to window manager) Log.e(TAG,tag+"Auto dismiss", e); } } } }; handler.postDelayed(runnable, automaticDismissDelay); } } }); }