List of usage examples for android.app Activity findViewById
@Nullable public <T extends View> T findViewById(@IdRes int id)
From source file:com.handlerexploit.news.fragments.WeatherFragment.java
private void render(WeatherInfo weatherInfo) { Activity activity = getActivity(); if (activity != null && weatherInfo != null) { View root = getView();//from ww w. ja v a 2s . c o m TextView city = (TextView) root.findViewById(R.id.city); city.setText(weatherInfo.getCity()); CurrentWeather currentWeather = weatherInfo.getCurrentWeather(); RemoteImageView icon = (RemoteImageView) root.findViewById(R.id.icon); int resId = activity.getResources().getIdentifier(currentWeather.getIcon(), "drawable", activity.getPackageName()); if (resId != 0) { ((ImageView) activity.findViewById(R.id.weather_small_logo)).setImageResource(resId); icon.setImageResource(resId); } else { ((ImageView) activity.findViewById(R.id.weather_small_logo)).setImageResource(R.drawable.unknown); icon.setImageResource(R.drawable.unknown); } TextView temp = (TextView) root.findViewById(R.id.temp); temp.setText(currentWeather.getTempF() + " \u00B0F | " + currentWeather.getTempC() + " \u00B0C"); ((TextView) activity.findViewById(R.id.weather_small_text)) .setText(currentWeather.getTempF() + "\u00B0"); TextView condition = (TextView) root.findViewById(R.id.condition); String conditionText = currentWeather.getCondition(); if (conditionText != null && !conditionText.equals("")) { condition.setText(conditionText); } else { condition.setText("N/A"); } TextView windCondition = (TextView) root.findViewById(R.id.windCondition); windCondition.setText(currentWeather.getWindCondition()); TextView humidity = (TextView) root.findViewById(R.id.humidity); humidity.setText(currentWeather.getHumidity()); LinearLayout forcastConditions = (LinearLayout) root.findViewById(R.id.forcastConditions); forcastConditions.removeAllViews(); LayoutInflater inflater = LayoutInflater.from(activity); LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); params.weight = 1f; ArrayList<Condition> forcastArray = weatherInfo.getForcastConditions(); for (int i = 0; i < forcastArray.size(); i++) { Condition forcastCondition = forcastArray.get(i); View forcastRoot = inflater.inflate(R.layout.fragment_weather_condition_item, null); TextView forcastDay = (TextView) forcastRoot.findViewById(R.id.day); forcastDay.setText(forcastCondition.getDay()); RemoteImageView forcastIcon = (RemoteImageView) forcastRoot.findViewById(R.id.icon); int forcastResId = activity.getResources().getIdentifier(forcastCondition.getIcon(), "drawable", activity.getPackageName()); if (forcastResId != 0) { forcastIcon.setImageResource(forcastResId); } else { forcastIcon.setImageResource(R.drawable.unknown); } TextView forcastHigh = (TextView) forcastRoot.findViewById(R.id.high); forcastHigh.setText(forcastCondition.getHigh() + "\u00B0"); TextView forcastLow = (TextView) forcastRoot.findViewById(R.id.low); forcastLow.setText(forcastCondition.getLow() + "\u00B0"); forcastConditions.addView(forcastRoot, params); } } }
From source file:org.schabi.newpipe.detail.VideoItemDetailFragment.java
@Override public void onActivityCreated(Bundle savedInstanceBundle) { super.onActivityCreated(savedInstanceBundle); Activity a = getActivity(); infoItemBuilder = new InfoItemBuilder(a, a.findViewById(android.R.id.content)); if (android.os.Build.VERSION.SDK_INT < 18) { playVideoButton = (FloatingActionButton) a.findViewById(R.id.play_video_button); }/*from w w w.j a va 2s. c om*/ thumbnailWindowLayout = a.findViewById(R.id.detail_stream_thumbnail_window_layout); Button backgroundButton = (Button) a.findViewById(R.id.detail_stream_thumbnail_window_background_button); // Sometimes when this fragment is not visible it still gets initiated // then we must not try to access objects of this fragment. // Otherwise the applications would crash. if (backgroundButton != null) { streamingServiceId = getArguments().getInt(STREAMING_SERVICE); String videoUrl = getArguments().getString(VIDEO_URL); StreamInfoWorker siw = StreamInfoWorker.getInstance(); siw.search(streamingServiceId, videoUrl, getActivity()); autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY); if (Build.VERSION.SDK_INT >= 18) { ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detail_thumbnail_view); thumbnailView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { // This is used to synchronize the thumbnailWindowButton and the playVideoButton // inside the ScrollView with the actual size of the thumbnail. //todo: onLayoutChage sometimes not triggered // background buttons area seem to overlap the thumbnail view // So although you just clicked slightly beneath the thumbnail the action still // gets triggered. @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { RelativeLayout.LayoutParams newWindowLayoutParams = (RelativeLayout.LayoutParams) thumbnailWindowLayout .getLayoutParams(); newWindowLayoutParams.height = bottom - top; thumbnailWindowLayout.setLayoutParams(newWindowLayoutParams); //noinspection SuspiciousNameCombination initialThumbnailPos.set(top, left); } }); } } }
From source file:com.vanisty.ui.MenuActivity.java
private void showPopup(final Activity context, Point p) { int popupWidth = 200; int popupHeight = 150; // Inflate the popup_layout.xml LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup); LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup); // Creating the PopupWindow final PopupWindow popup = new PopupWindow(context); popup.setContentView(layout);/*from www . j av a 2 s . co m*/ popup.setWidth(popupWidth); popup.setHeight(popupHeight); popup.setFocusable(true); // Some offset to align the popup a bit to the right, and a bit down, relative to button's position. int OFFSET_X = 30; int OFFSET_Y = 30; // Clear the default translucent background popup.setBackgroundDrawable(new BitmapDrawable()); // Displaying the popup at the specified location, + offsets. popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y); // Getting a reference to Close button, and close the popup when clicked. Button close = (Button) layout.findViewById(R.id.close); close.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { popup.dismiss(); } }); }
From source file:org.ado.minesync.gui.fragment.HistoryFragment.java
private void displayListView(Activity activity) { String[] fromColumns = new String[] { TableWorldColumns.WORLD_NAME_COLUMN, TableHistoryColumns.HISTORY_DATE, TableHistoryColumns.HISTORY_ACTION, TableHistoryColumns.HISTORY_SIZE }; int[] toLayoutIDs = new int[] { R.id.textViewWorldName, R.id.textViewHistoryDate, R.id.imageViewHistoryAction, R.id.textViewHistorySize }; Cursor cursor = dbHelper.getHistoryViewCursorAll(LIST_VIEW_SIZE); SimpleCursorAdapter cursorAdapter = new CustomSimpleCursorAdapter(activity, R.layout.list_history_entry, cursor, fromColumns, toLayoutIDs, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); listViewHistory = (ListView) activity.findViewById(R.id.listViewHistory); listViewHistory.setFastScrollEnabled(true); listViewHistory.setAdapter(cursorAdapter); }
From source file:com.ninetwozero.battlelog.fragments.PlatoonStatsFragment.java
public void showStats(PlatoonInformation pi) { // Get the activity Activity activity = getActivity(); Log.d(Constants.DEBUG_TAG, "pi => " + pi); Log.d(Constants.DEBUG_TAG, "activity => " + activity); if (activity == null) { return;/*from w ww .j a va 2 s .c om*/ } // Let's see what we can do platoonInformation = pi; PlatoonStats pd = platoonInformation.getStats(); // Let's start drawing the... layout ((TextView) activity.findViewById(R.id.text_name_platoon_tab2)).setText( platoonInformation.getName() + " [" + platoonInformation.getTag() + "]" ); // Do we have it?? if (pd == null) { return; } // Are they null? if (wrapGeneral == null) { // General ones wrapGeneral = (RelativeLayout) activity.findViewById(R.id.wrap_general); // Kits & vehicles wrapScore = (RelativeLayout) activity.findViewById(R.id.wrap_score); wrapSPM = (RelativeLayout) activity.findViewById(R.id.wrap_spm); wrapTime = (RelativeLayout) activity.findViewById(R.id.wrap_time); tableScores = (TableLayout) wrapScore.findViewById(R.id.tbl_stats); tableSPM = (TableLayout) wrapSPM.findViewById(R.id.tbl_stats); tableTime = (TableLayout) wrapTime.findViewById(R.id.tbl_stats); // Top list wrapTopList = (RelativeLayout) activity.findViewById(R.id.wrap_toplist); tableTopList = (TableLayout) wrapTopList.findViewById(R.id.tbl_stats); } else { tableScores.removeAllViews(); tableSPM.removeAllViews(); tableTime.removeAllViews(); tableTopList.removeAllViews(); } // Let's grab the different data PlatoonStatsItem generalSPM = pd.getGlobalTop().get(0); PlatoonStatsItem generalKDR = pd.getGlobalTop().get(1); PlatoonStatsItem generalRank = pd.getGlobalTop().get(2); // Set the general stats ((TextView) wrapGeneral.findViewById(R.id.text_average_spm)).setText(generalSPM.getAvg() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_max_spm)).setText(generalSPM.getMax() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_mid_spm)).setText(generalSPM.getMid() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_min_spm)).setText(generalSPM.getMin() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_average_rank)).setText(generalRank.getAvg() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_max_rank)).setText(generalRank.getMax() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_mid_rank)).setText(generalRank.getMid() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_min_rank)).setText(generalRank.getMin() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_average_kdr)).setText(generalKDR.getDAvg() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_max_kdr)).setText(generalKDR.getDMax() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_mid_kdr)).setText(generalKDR.getDMid() + ""); ((TextView) wrapGeneral.findViewById(R.id.text_min_kdr)).setText(generalKDR.getDMin() + ""); // Top Players List<PlatoonTopStatsItem> topStats = pd.getTopPlayers(); PlatoonTopStatsItem tempTopStats = null; // Loop over them, *one* by *one* int numCols = 2; for (int i = 0, max = topStats.size(); i < max; i++) { // Oh well, couldn't quite cache it could we? cacheView = (RelativeLayout) layoutInflater.inflate(R.layout.grid_item_platoon_top_stats, null); // Add the new TableRow if (cacheTableRow == null || (i % numCols) == 0) { tableTopList.addView(cacheTableRow = new TableRow(context)); cacheTableRow.setLayoutParams( new TableRow.LayoutParams( TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT ) ); } // Add the *layout* into the TableRow cacheTableRow.addView(cacheView); // Grab *this* item tempTopStats = topStats.get(i); // Say cheese... (mister Bitmap) if (tempTopStats.getProfile() != null) { ((ImageView) cacheView.findViewById(R.id.image_avatar)).setImageBitmap( BitmapFactory.decodeFile( PublicUtils.getCachePath(context) + tempTopStats.getProfile().getGravatarHash() + ".png" ) ); } else { ((ImageView) cacheView.findViewById(R.id.image_avatar)).setImageResource(R.drawable.default_avatar); } // Set the TextViews accordingly ((TextView) cacheView.findViewById(R.id.text_label)) .setText(tempTopStats.getLabel().toUpperCase() + ""); if (tempTopStats.getProfile() != null) { ((TextView) cacheView.findViewById(R.id.text_name)) .setText(tempTopStats.getProfile().getUsername() + ""); ((TextView) cacheView.findViewById(R.id.text_spm)).setText(tempTopStats.getSPM() + ""); } else { ((TextView) cacheView.findViewById(R.id.text_name)).setText("N/A"); ((TextView) cacheView.findViewById(R.id.text_spm)).setText("0"); } } // Let's generate the table rows! generateTableRows(tableScores, pd.getScores(), false); generateTableRows(tableSPM, pd.getSpm(), false); generateTableRows(tableTime, pd.getTime(), true); }
From source file:com.ultramegasoft.flavordex2.fragment.EntryListFragment.java
/** * Show or hide the export Toolbar./*from ww w.j av a2 s. co m*/ * * @param show Whether to show the export Toolbar */ private void showExportToolbar(boolean show, boolean animate) { final Activity activity = getActivity(); if (activity != null && mExportToolbar == null) { mExportToolbar = activity.findViewById(R.id.export_toolbar); mExportToolbar.inflateMenu(R.menu.export_menu); mExportToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_export_selected: final FragmentManager fm = getFragmentManager(); if (fm != null) { ExportDialog.showDialog(fm, getListView().getCheckedItemIds()); setExportMode(false, true); } return true; case R.id.menu_cancel: setExportMode(false, true); return true; case R.id.menu_check_all: case R.id.menu_uncheck_all: final ListView listView = getListView(); final boolean check = item.getItemId() == R.id.menu_check_all; for (int i = 0; i < mAdapter.getCount(); i++) { listView.setItemChecked(i, check); } invalidateExportMenu(); return true; } return false; } }); mExportInAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.toolbar_slide_in_bottom); mExportOutAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.toolbar_slide_out_bottom); } invalidateExportMenu(); mExportToolbar.setVisibility(show ? View.VISIBLE : View.GONE); if (animate) { mExportToolbar.startAnimation(show ? mExportInAnimation : mExportOutAnimation); } }
From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java
/*** * Reveal the searchbox from a menu item. Specify the menu item id and pass the activity so the item can be found * @param id View ID/*from w w w. j a va 2 s . c om*/ * @param activity Activity */ public void revealFromMenuItem(int id, Activity activity) { setVisibility(View.VISIBLE); View menuButton = activity.findViewById(id); if (menuButton != null) { FrameLayout layout = (FrameLayout) activity.getWindow().getDecorView() .findViewById(android.R.id.content); if (layout.findViewWithTag("searchBox") == null) { int[] location = new int[2]; menuButton.getLocationInWindow(location); revealFrom((float) location[0], (float) location[1], activity, this); } } }
From source file:com.keylesspalace.tusky.fragment.NotificationsFragment.java
@Override public void onDestroyView() { Activity activity = getActivity(); if (activity == null) { Log.e(TAG, "Activity is null"); } else {//from w w w . j a v a 2s.c om TabLayout tabLayout = activity.findViewById(R.id.tab_layout); tabLayout.removeOnTabSelectedListener(onTabSelectedListener); } super.onDestroyView(); }
From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java
/** * Initializes the UI and creates the detector pipeline. *///ww w . ja v a2 s . c om // @Override // public void onActivityResult(int requestCode, int resultCode, Intent data) { // super.onActivityResult(requestCode, resultCode, data); // // if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) { // Toast.makeText(getContext(), "pic saved", Toast.LENGTH_LONG).show(); // Log.d("CameraDemo", "Pic saved"); // } // } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.view_ocr_capture, container, false); final Activity activity = getActivity(); final Context context = getContext(); ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger)) .setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent)); final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/picFolder/"; File newdir = new File(dir); newdir.mkdirs(); mPreview = (CameraSourcePreview) view.findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) view.findViewById(R.id.graphicOverlay); StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); // Set good defaults for capturing text. boolean autoFocus = true; boolean useFlash = false; // createNewThread(); // t.start(); final ImageView upArrow = (ImageView) view.findViewById(R.id.arrow_up); upArrow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (rotationAngle == 0) { // arrow up //mCameraSource.takePicture(null, mPicture); //mGraphicOverlay.clear(); // mGraphicOverlay.clear(); // mGraphicOverlay.amountItem = null; onPause(); //shouldContinue = false; //mCamera.takePicture(null, null, mPicture); File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } try { FileOutputStream fos = new FileOutputStream(pictureFile); Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap); receiptBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos); picPath = pictureFile.getAbsolutePath(); //fos.write(mCameraSource.mostRecentBitmap); fos.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } upArrow.animate().rotation(180).setDuration(500).start(); TextView amount = (TextView) view.findViewById(R.id.text_amount_value); if (mGraphicOverlay.amountItem == null) { amount.setText("0.00"); } else { amount.setText(String.format("%.2f", mGraphicOverlay.amountItemAfterFormat)); } TextView desc = (TextView) view.findViewById(R.id.text_name_value); desc.setText(mGraphicOverlay.description); RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box); box.setVisibility(View.VISIBLE); Animation slide_up = AnimationUtils.loadAnimation(activity.getApplicationContext(), R.anim.slide_up); box.startAnimation(slide_up); rotationAngle = 180; } else { // t.interrupt(); // t = null; RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box); Animation slide_down = AnimationUtils.loadAnimation(activity.getApplicationContext(), R.anim.slide_down); upArrow.animate().rotation(0).setDuration(500).start(); box.startAnimation(slide_down); box.setVisibility(View.INVISIBLE); //shouldContinue = true; mGraphicOverlay.amountItem = null; mGraphicOverlay.amountItemAfterFormat = 0f; mGraphicOverlay.description = ""; onResume(); // createNewThread(); // t.start(); rotationAngle = 0; } } }); ImageView addButton = (ImageView) view.findViewById(R.id.add_icon); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // takePicture(); EditText description = (EditText) view.findViewById(R.id.text_name_value); EditText amount = (EditText) view.findViewById(R.id.text_amount_value); float floatAmount = Float.parseFloat(amount.getText().toString()); Summary t = new Summary(description.getText().toString(), floatAmount); Bundle bundle = new Bundle(); bundle.putSerializable("splitTransaction", t); // ByteArrayOutputStream stream = new ByteArrayOutputStream(); // mCameraSource.mostRecentBitmap.compress(Bitmap.CompressFormat.PNG, 80, stream); // byte[] byteArray = stream.toByteArray(); //Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap); //bundle.putParcelable("receiptPicture",receiptBitmap); bundle.putString("receiptPicture", picPath); FriendsSelectionFragment fragment = new FriendsSelectionFragment(); fragment.setArguments(bundle); ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger)).setVisibility(View.INVISIBLE); getActivity().getSupportFragmentManager().beginTransaction() .add(R.id.fragment_holder, fragment, "FriendsSelectionFragment").addToBackStack(null) .commit(); } }); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(context, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener()); // Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", // Snackbar.LENGTH_LONG) // .show(); // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { if (status == TextToSpeech.SUCCESS) { Log.d("OnInitListener", "Text to speech engine started successfully."); tts.setLanguage(Locale.US); } else { Log.d("OnInitListener", "Error starting the text to speech engine."); } } }; tts = new TextToSpeech(activity.getApplicationContext(), listener); return view; }
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;/* w w w. j av a 2 s . c o 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; }