List of usage examples for android.app Activity addContentView
public void addContentView(View view, ViewGroup.LayoutParams params)
From source file:de.manumaticx.crouton.Manager.java
/** * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}. * * @param crouton//w w w . j a v a 2 s . c o m * The {@link Crouton} that should be added. */ private void addCroutonToView(final Crouton crouton) { // don't add if it is already showing if (crouton.isShowing()) { return; } final View croutonView = crouton.getView(); if (null == croutonView.getParent()) { ViewGroup.LayoutParams params = croutonView.getLayoutParams(); if (null == params) { params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } // display Crouton in ViewGroup is it has been supplied if (null != crouton.getViewGroup()) { // TODO implement add to last position feature (need to align with how this will be requested for activity) if (crouton.getViewGroup() instanceof FrameLayout) { crouton.getViewGroup().addView(croutonView, params); } else { crouton.getViewGroup().addView(croutonView, 0, params); } } else { Activity activity = crouton.getActivity(); if (null == activity || activity.isFinishing()) { return; } handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity); if (Looper.myLooper() == Looper.getMainLooper()) { activity.addContentView(croutonView, params); } else { final Activity mActivity = activity; final ViewGroup.LayoutParams mParams = params; activity.runOnUiThread(new Runnable() { @Override public void run() { mActivity.addContentView(croutonView, mParams); } }); } } } croutonView.requestLayout(); // This is needed so the animation can use the measured with/height ViewTreeObserver observer = croutonView.getViewTreeObserver(); if (null != observer) { observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override @TargetApi(16) public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } croutonView.startAnimation(crouton.getInAnimation()); announceForAccessibilityCompat(crouton.getActivity(), crouton.getText()); if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) { sendMessageDelayed(crouton, Messages.REMOVE_CROUTON, crouton.getConfiguration().durationInMilliseconds + crouton.getInAnimation().getDuration()); } } }); } }
From source file:com.scoreflex.Scoreflex.java
/** * Shows a view of the specified url to the user. * * @param activity/* www . j a v a 2 s.c o m*/ * The activity that will host the view. * @param url * the url to show * @return The displayed view call close() to hide it. */ public static ScoreflexView showFullScreenView(Activity activity, String url) { ScoreflexView view = Scoreflex.view(activity, url, true); activity.addContentView(view, view.getLayoutParams()); view.requestFocus(); view.requestFocusFromTouch(); return view; }
From source file:com.scoreflex.Scoreflex.java
/** * Shows a view of the specified resource to the user. * * @param activity/*from ww w . j av a 2s . c o m*/ * The activity that will host the view. * @param resource * The string of the Scoreflex resource you want to display. * @param params * The parameter to be given to the resource (query string). * @return The displayed view call close() to hide it. */ public static ScoreflexView showFullScreenView(Activity activity, String resource, Scoreflex.RequestParams params) { ScoreflexView view = Scoreflex.view(activity, resource, params, true); activity.addContentView(view, view.getLayoutParams()); view.requestFocus(); view.requestFocusFromTouch(); return view; }
From source file:nirwan.cordova.plugin.printer.Printer.java
private void loadContentAsBitmapIntoPrintController(String content, final Intent intent) { Activity ctx = cordova.getActivity(); final WebView page = new WebView(ctx); final Printer self = this; page.setVisibility(View.INVISIBLE); page.getSettings().setJavaScriptEnabled(false); page.setWebViewClient(new WebViewClient() { @Override/*from w w w .j a v a 2 s. c o m*/ public void onPageFinished(final WebView page, String url) { new Handler().postDelayed(new Runnable() { @Override public void run() { Bitmap screenshot = self.takeScreenshot(page); File tmpFile = self.saveScreenshotToTmpFile(screenshot); ViewGroup vg = (ViewGroup) (page.getParent()); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tmpFile)); vg.removeView(page); } }, 1000); } }); //Set base URI to the assets/www folder String baseURL = webView.getUrl(); baseURL = baseURL.substring(0, baseURL.lastIndexOf('/') + 1); ctx.addContentView(page, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); page.loadDataWithBaseURL(baseURL, content, "text/html", "UTF-8", null); }
From source file:org.chronotext.MobileTest.Bridge.java
public Bridge(Activity activity) { super(activity); // ---/*w w w . j a v a 2 s . co m*/ switch (testMode) { case GLVIEW_ATTACHED_AND_VISIBLE_AT_START: hidden = false; detached = false; break; case GLVIEW_ATTACHED_AND_HIDDEN_AT_START: hidden = true; detached = false; break; default: case GLVIEW_NOT_ATTACHED_AT_START: hidden = false; detached = true; break; } hasRootView = CAN_BE_HIDDEN || CAN_BE_DETACHED || hidden || detached; // --- setViewProperties(new GLView.Properties().setEGLContextClientVersion(1).setPreserveEGLContextOnPause(true)); if (hasRootView) { rootView = new RelativeLayout(activity); rootView.setBackgroundColor(Color.YELLOW); activity.setContentView(rootView); } if (!detached) { if (hidden) { getView().setVisibility(View.GONE); } if (hasRootView) { rootView.addView(getView()); } else { activity.setContentView(getView()); } } // --- overlayView = new RelativeLayout(activity); activity.addContentView(overlayView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); button1 = addButton(100, 100, 1); button2 = addButton(100, 200, 2); refreshButtons(); }
From source file:com.partypoker.poker.engagement.reach.EngagementDefaultNotifier.java
@Override public Boolean handleNotification(EngagementReachInteractiveContent content) throws RuntimeException { /* System notification case */ if (content.isSystemNotification()) { /* Big picture handling */ Bitmap bigPicture = null;// www. ja v a2 s .co m String bigPictureURL = content.getNotificationBigPicture(); if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16) { /* Schedule picture download if needed, or load picture if download completed. */ Long downloadId = content.getDownloadId(); if (downloadId == null) { EngagementNotificationUtilsV11.downloadBigPicture(mContext, content); return null; } else bigPicture = EngagementNotificationUtilsV11.getBigPicture(mContext, downloadId); } /* Generate notification identifier */ int notificationId = getNotificationId(content); /* Build notification using support lib to manage compatibility with old Android versions */ NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); /* Icon for ticker and content icon */ builder.setSmallIcon(mNotificationIcon); /* * Large icon, handled only since API Level 11 (needs down scaling if too large because it's * cropped otherwise by the system). */ Bitmap notificationImage = content.getNotificationImage(); if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) builder.setLargeIcon(scaleBitmapForLargeIcon(mContext, notificationImage)); /* Texts */ String notificationTitle = content.getNotificationTitle(); String notificationMessage = content.getNotificationMessage(); String notificationBigText = content.getNotificationBigText(); builder.setContentTitle(notificationTitle); builder.setContentText(notificationMessage); /* * Replay: display original date and don't replay all the tickers (be as quiet as possible * when replaying). */ Long notificationFirstDisplayedDate = content.getNotificationFirstDisplayedDate(); if (notificationFirstDisplayedDate != null) builder.setWhen(notificationFirstDisplayedDate); else builder.setTicker(notificationTitle); /* Big picture */ if (bigPicture != null) builder.setStyle(new BigPictureStyle().bigPicture(bigPicture).setBigContentTitle(notificationTitle) .setSummaryText(notificationMessage)); /* Big text */ else if (notificationBigText != null) builder.setStyle(new BigTextStyle().bigText(notificationBigText)); /* Vibration/sound if not a replay */ if (notificationFirstDisplayedDate == null) { int defaults = 0; if (content.isNotificationSound()) defaults |= Notification.DEFAULT_SOUND; if (content.isNotificationVibrate()) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); } /* Launch the receiver on action */ Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION); com.microsoft.azure.engagement.reach.EngagementReachAgent.setContentIdExtra(actionIntent, content); actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); Intent intent = content.getIntent(); if (intent != null) actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.getComponent()); actionIntent.setPackage(mContext.getPackageName()); PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), actionIntent, FLAG_CANCEL_CURRENT); builder.setContentIntent(contentIntent); /* Also launch receiver if the notification is exited (clear button) */ Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION); exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); EngagementReachAgent.setContentIdExtra(exitIntent, content); exitIntent.setPackage(mContext.getPackageName()); PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), exitIntent, FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deleteIntent); /* Can be dismissed ? */ Notification notification = builder.build(); if (!content.isNotificationCloseable()) notification.flags |= Notification.FLAG_NO_CLEAR; /* Allow overriding */ if (onNotificationPrepared(notification, content)) /* * Submit notification, replacing the previous one if any (this should happen only if the * application process is restarted). */ mNotificationManager.notify(notificationId, notification); } /* Activity embedded notification case */ else { /* Get activity */ Activity activity = EngagementActivityManager.getInstance().getCurrentActivity().get(); /* Cannot notify in app if no activity provided */ if (activity == null) return false; /* Get notification area */ String category = content.getCategory(); int areaId = getInAppAreaId(category); View notificationAreaView = activity.findViewById(areaId); /* No notification area, check if we can install overlay */ if (notificationAreaView == null) { /* Check overlay is not disabled in this activity */ Bundle activityConfig = EngagementUtils.getActivityMetaData(activity); if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true)) return false; /* Inflate overlay layout and get reference to notification area */ View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null); activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); notificationAreaView = activity.findViewById(areaId); } /* Otherwise check if there is an overlay containing the area to restore visibility */ else { View overlay = activity.findViewById(getOverlayViewId(category)); if (overlay != null) overlay.setVisibility(View.VISIBLE); } /* Make the notification area visible */ notificationAreaView.setVisibility(View.VISIBLE); /* Prepare area */ prepareInAppArea(content, notificationAreaView); } /* Success */ return true; }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainDefaultNotifier.java
@Override public Boolean handleNotification(CapptainReachInteractiveContent content) throws RuntimeException { /* System notification case */ if (content.isSystemNotification()) { /* Big picture handling */ Bitmap bigPicture = null;/*from ww w . j a v a2 s .co m*/ String bigPictureURL = content.getNotificationBigPicture(); if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16) { /* Schedule picture download if needed, or load picture if download completed. */ Long downloadId = content.getDownloadId(); if (downloadId == null) { NotificationUtilsV11.downloadBigPicture(mContext, content); return null; } else bigPicture = NotificationUtilsV11.getBigPicture(mContext, downloadId); } /* Generate notification identifier */ int notificationId = getNotificationId(content); /* Build notification using support lib to manage compatibility with old Android versions */ NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); /* Icon for ticker and content icon */ builder.setSmallIcon(mNotificationIcon); /* * Large icon, handled only since API Level 11 (needs down scaling if too large because it's * cropped otherwise by the system). */ Bitmap notificationImage = content.getNotificationImage(); if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) builder.setLargeIcon(scaleBitmapForLargeIcon(mContext, notificationImage)); /* Texts */ String notificationTitle = content.getNotificationTitle(); String notificationMessage = content.getNotificationMessage(); String notificationBigText = content.getNotificationBigText(); builder.setContentTitle(notificationTitle); builder.setContentText(notificationMessage); /* * Replay: display original date and don't replay all the tickers (be as quiet as possible * when replaying). */ Long notificationFirstDisplayedDate = content.getNotificationFirstDisplayedDate(); if (notificationFirstDisplayedDate != null) builder.setWhen(notificationFirstDisplayedDate); else builder.setTicker(notificationTitle); /* Big picture */ if (bigPicture != null) builder.setStyle(new BigPictureStyle().bigPicture(bigPicture).setBigContentTitle(notificationTitle) .setSummaryText(notificationMessage)); /* Big text */ else if (notificationBigText != null) builder.setStyle(new BigTextStyle().bigText(notificationBigText)); /* Vibration/sound if not a replay */ if (notificationFirstDisplayedDate == null) { int defaults = 0; if (content.isNotificationSound()) defaults |= Notification.DEFAULT_SOUND; if (content.isNotificationVibrate()) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); } /* Launch the receiver on action */ Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION); CapptainReachAgent.setContentIdExtra(actionIntent, content); actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); Intent intent = content.getIntent(); if (intent != null) actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.getComponent()); actionIntent.setPackage(mContext.getPackageName()); PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), actionIntent, FLAG_CANCEL_CURRENT); builder.setContentIntent(contentIntent); /* Also launch receiver if the notification is exited (clear button) */ Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION); exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); CapptainReachAgent.setContentIdExtra(exitIntent, content); exitIntent.setPackage(mContext.getPackageName()); PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), exitIntent, FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deleteIntent); /* Can be dismissed ? */ Notification notification = builder.build(); if (!content.isNotificationCloseable()) notification.flags |= Notification.FLAG_NO_CLEAR; /* Allow overriding */ if (onNotificationPrepared(notification, content)) /* * Submit notification, replacing the previous one if any (this should happen only if the * application process is restarted). */ mNotificationManager.notify(notificationId, notification); } /* Activity embedded notification case */ else { /* Get activity */ Activity activity = CapptainActivityManager.getInstance().getCurrentActivity().get(); /* Cannot notify in app if no activity provided */ if (activity == null) return false; /* Get notification area */ String category = content.getCategory(); int areaId = getInAppAreaId(category); View notificationAreaView = activity.findViewById(areaId); /* No notification area, check if we can install overlay */ if (notificationAreaView == null) { /* Check overlay is not disabled in this activity */ Bundle activityConfig = CapptainUtils.getActivityMetaData(activity); if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true)) return false; /* Inflate overlay layout and get reference to notification area */ View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null); activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); notificationAreaView = activity.findViewById(areaId); } /* Otherwise check if there is an overlay containing the area to restore visibility */ else { View overlay = activity.findViewById(getOverlayViewId(category)); if (overlay != null) overlay.setVisibility(View.VISIBLE); } /* Make the notification area visible */ notificationAreaView.setVisibility(View.VISIBLE); /* Prepare area */ prepareInAppArea(content, notificationAreaView); } /* Success */ return true; }
From source file:com.scoreflex.Scoreflex.java
/** * A helper method that submits turn data and directly show challenge * detail.//from w w w .j av a 2 s. c om * * @param activity * The activity that will host the view. * @param challengeInstanceId * The challenge instance id. * @param turn * The turn data. */ public static void submitTurnAndShowChallengeDetail(final Activity activity, final String challengeInstanceId, RequestParams turn) { final String resource = "/web/challenges/instances/" + challengeInstanceId; submitTurn(challengeInstanceId, turn, new Scoreflex.ResponseHandler() { @Override public void onFailure(Throwable e, Response errorResponse) { Log.d("Scoreflex", "Could not submit score, Chalenge detail wont be shown"); } @Override public void onSuccess(Response response) { View view = Scoreflex.view(activity, resource, null, true); activity.addContentView(view, view.getLayoutParams()); view.requestFocus(); view.requestFocusFromTouch(); } }); }