List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:com.perm.DoomPlay.PlayingService.java
private RemoteViews getNotifViews(int layoutId) { RemoteViews views = new RemoteViews(getPackageName(), layoutId); Audio audio = audios.get(indexCurrentTrack); views.setTextViewText(R.id.notifTitle, audio.getTitle()); views.setTextViewText(R.id.notifArtist, audio.getArtist()); Bitmap cover = AlbumArtGetter.getBitmapFromStore(audio.getAid(), this); if (cover == null) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); views.setImageViewBitmap(R.id.notifAlbum, tempBitmap); tempBitmap.recycle();// w ww .j ava 2 s .c o m } else { //TODO: java.lang.IllegalArgumentException: RemoteViews for widget update exceeds // maximum bitmap memory usage (used: 3240000, max: 2304000) // The total memory cannot exceed that required to fill the device's screen once try { views.setImageViewBitmap(R.id.notifAlbum, cover); } catch (IllegalArgumentException e) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); views.setImageViewBitmap(R.id.notifAlbum, tempBitmap); tempBitmap.recycle(); } finally { cover.recycle(); } } views.setImageViewResource(R.id.notifPlay, isPlaying ? R.drawable.widget_pause : R.drawable.widget_play); ComponentName componentName = new ComponentName(this, PlayingService.class); Intent intentPlay = new Intent(actionPlay); intentPlay.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifPlay, PendingIntent.getService(this, 0, intentPlay, 0)); Intent intentNext = new Intent(actionNext); intentNext.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifNext, PendingIntent.getService(this, 0, intentNext, 0)); Intent intentPrevious = new Intent(actionPrevious); intentPrevious.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifPrevious, PendingIntent.getService(this, 0, intentPrevious, 0)); Intent intentClose = new Intent(actionClose); intentClose.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifClose, PendingIntent.getService(this, 0, intentClose, 0)); return views; }
From source file:co.taqat.call.ChatFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); final View view = inflater.inflate(R.layout.chat, container, false); LinphoneManager.addListener(this); // Retain the fragment across configuration changes setRetainInstance(true);/*from w ww . j a va2 s. c o m*/ this.inflater = inflater; if (getArguments() == null || getArguments().getString("SipUri") == null) { newChatConversation = true; } else { //Retrieve parameter from intent sipUri = getArguments().getString("SipUri"); } //Initialize UI defaultBitmap = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.chat_picture_over); contactName = (TextView) view.findViewById(R.id.contact_name); messagesList = (ListView) view.findViewById(R.id.chat_message_list); searchContactField = (EditText) view.findViewById(R.id.search_contact_field); resultContactsSearch = (ListView) view.findViewById(R.id.result_contacts); editList = (LinearLayout) view.findViewById(R.id.edit_list); topBar = (LinearLayout) view.findViewById(R.id.top_bar); sendMessage = (ImageView) view.findViewById(R.id.send_message); sendMessage.setOnClickListener(this); remoteComposing = (TextView) view.findViewById(R.id.remote_composing); remoteComposing.setVisibility(View.GONE); cancel = (ImageView) view.findViewById(R.id.cancel); cancel.setOnClickListener(this); edit = (ImageView) view.findViewById(R.id.edit); edit.setOnClickListener(this); startCall = (ImageView) view.findViewById(R.id.start_call); startCall.setOnClickListener(this); backToCall = (ImageView) view.findViewById(R.id.back_to_call); backToCall.setOnClickListener(this); selectAll = (ImageView) view.findViewById(R.id.select_all); selectAll.setOnClickListener(this); deselectAll = (ImageView) view.findViewById(R.id.deselect_all); deselectAll.setOnClickListener(this); delete = (ImageView) view.findViewById(R.id.delete); delete.setOnClickListener(this); if (newChatConversation) { initNewChatConversation(); } message = (EditText) view.findViewById(R.id.message); sendImage = (ImageView) view.findViewById(R.id.send_picture); if (!getResources().getBoolean(R.bool.disable_chat_send_file)) { sendImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pickImage(); LinphoneActivity.instance().checkAndRequestPermissionsToSendImage(); } }); //registerForContextMenu(sendImage); } else { sendImage.setEnabled(false); } back = (ImageView) view.findViewById(R.id.back); if (getResources().getBoolean(R.bool.isTablet)) { back.setVisibility(View.INVISIBLE); } else { back.setOnClickListener(this); } mListener = new LinphoneCoreListenerBase() { @Override public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) { LinphoneAddress from = cr.getPeerAddress(); if (from.asStringUriOnly().equals(sipUri)) { LinphoneService.instance().removeMessageNotification(); cr.markAsRead(); LinphoneActivity.instance().updateMissedChatCount(); adapter.addMessage(cr.getHistory(1)[0]); String externalBodyUrl = message.getExternalBodyUrl(); LinphoneContent fileTransferContent = message.getFileTransferInformation(); if (externalBodyUrl != null || fileTransferContent != null) { LinphoneActivity.instance().checkAndRequestExternalStoragePermission(); } } } @Override public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom room) { if (chatRoom != null && room != null && chatRoom.getPeerAddress().asStringUriOnly() .equals(room.getPeerAddress().asStringUriOnly())) { remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE); } } }; textWatcher = new TextWatcher() { public void afterTextChanged(Editable arg0) { } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { if (message.getText().toString().equals("")) { sendMessage.setEnabled(false); } else { if (chatRoom != null) chatRoom.compose(); sendMessage.setEnabled(true); } } }; return view; }
From source file:arun.com.chromer.fragments.AboutFragment.java
private void populateData(View rootView) { ListView chromerList = (ListView) rootView.findViewById(R.id.about_app_version_list); ListView authorList = (ListView) rootView.findViewById(R.id.about_author_version_list); View daniel = rootView.findViewById(R.id.daniel); daniel.setOnClickListener(new View.OnClickListener() { @Override//from w w w .j ava2s. com public void onClick(View v) { Intent googleIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/u/0/+DanielCiao/about")); getActivity().startActivity(googleIntent); } }); // Loading the header chromerList.setAdapter(new ExtendedBaseAdapter() { final Context context = getActivity().getApplicationContext(); @Override public int getCount() { return 4; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater mInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.fragment_about_listview_template, parent, false); holder.imageView = (ImageView) convertView.findViewById(R.id.about_row_item_image); holder.subtitle = (TextView) convertView.findViewById(R.id.about_app_subtitle); holder.title = (TextView) convertView.findViewById(R.id.about_app_title); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } int materialdarkColor = ContextCompat.getColor(context, R.color.accent); holder.subtitle.setVisibility(View.VISIBLE); switch (position) { case 0: holder.title.setText(R.string.version); holder.subtitle.setText(Util.getPackageVersion(context)); holder.imageView.setBackground(new IconicsDrawable(context) .icon(GoogleMaterial.Icon.gmd_info_outline).color(materialdarkColor).sizeDp(24)); break; case 1: holder.title.setText(R.string.changelog); holder.subtitle.setVisibility(View.GONE); holder.imageView.setBackground(new IconicsDrawable(context) .icon(GoogleMaterial.Icon.gmd_track_changes).color(materialdarkColor).sizeDp(24)); break; case 2: holder.title.setText(R.string.join_google_plus); holder.subtitle.setText(R.string.share_ideas); holder.imageView.setBackground( new IconicsDrawable(context).icon(CommunityMaterial.Icon.cmd_google_circles_communities) .color(materialdarkColor).sizeDp(24)); break; case 3: holder.title.setText(R.string.licenses); holder.subtitle.setVisibility(View.GONE); holder.imageView.setBackground(new IconicsDrawable(context) .icon(GoogleMaterial.Icon.gmd_card_membership).color(materialdarkColor).sizeDp(24)); break; } return convertView; } }); authorList.setAdapter(new ExtendedBaseAdapter() { final Context context = getActivity().getApplicationContext(); @Override public int getCount() { return 5; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater mInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.fragment_about_listview_template, parent, false); holder.imageView = (ImageView) convertView.findViewById(R.id.about_row_item_image); holder.subtitle = (TextView) convertView.findViewById(R.id.about_app_subtitle); holder.title = (TextView) convertView.findViewById(R.id.about_app_title); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } switch (position) { case 0: holder.title.setText(StringConstants.ME); holder.subtitle.setText(StringConstants.LOCATION); holder.imageView.getLayoutParams().height = (int) getResources() .getDimension(R.dimen.arun_height); holder.imageView.getLayoutParams().width = (int) getResources() .getDimension(R.dimen.arun_width); Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.arun); RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory .create(getResources(), imageBitmap); roundedBitmapDrawable.setAntiAlias(true); roundedBitmapDrawable.setCircular(true); holder.imageView.setImageDrawable(roundedBitmapDrawable); break; case 1: holder.title.setText(R.string.add_to_circles); holder.subtitle.setVisibility(View.GONE); holder.imageView.setBackground( new IconicsDrawable(context).icon(CommunityMaterial.Icon.cmd_google_circles) .color(ContextCompat.getColor(getActivity(), R.color.google_plus)).sizeDp(24)); break; case 2: holder.title.setText(R.string.follow_twitter); holder.subtitle.setVisibility(View.GONE); holder.imageView .setBackground(new IconicsDrawable(context).icon(CommunityMaterial.Icon.cmd_twitter) .color(ContextCompat.getColor(getActivity(), R.color.twitter)).sizeDp(24)); break; case 3: holder.title.setText(R.string.connect_linkedIn); holder.subtitle.setVisibility(View.GONE); holder.imageView.setBackground( new IconicsDrawable(context).icon(CommunityMaterial.Icon.cmd_linkedin_box) .color(ContextCompat.getColor(getActivity(), R.color.linkedin)).sizeDp(24)); break; case 4: holder.title.setText(R.string.more_apps); holder.subtitle.setVisibility(View.GONE); holder.imageView.setBackground(new IconicsDrawable(context) .icon(CommunityMaterial.Icon.cmd_google_play) .color(ContextCompat.getColor(getActivity(), R.color.playstore_green)).sizeDp(24)); break; } return convertView; } }); chromerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: return; case 1: ChangelogUtil.showChangelogDialog(getActivity()); break; case 2: Intent googleIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/communities/109754631011301174504")); getActivity().startActivity(googleIntent); break; case 3: new LicensesDialog.Builder(getActivity()).setNotices(Licenses.getNotices()) .setTitle(R.string.licenses).build().showAppCompat(); break; } } }); authorList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: return; case 1: Intent googleIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com/+arunkumar5592")); getActivity().startActivity(googleIntent); break; case 2: Intent twitterIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/arunkumar_9t2")); getActivity().startActivity(twitterIntent); break; case 3: Intent linkedinIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://in.linkedin.com/in/arunkumar9t2")); getActivity().startActivity(linkedinIntent); break; case 4: try { getActivity().startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:Arunkumar"))); } catch (android.content.ActivityNotFoundException anfe) { getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/search?q=pub:Arunkumar"))); } break; } } }); }
From source file:com.allenxuan.xuanyihuang.littledownloadhelper.DownloadService.java
private Notification getNotification(String title) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); if (useNotificationTargetActivity && notificationTargetActivity != null) { Intent intent = new Intent(this, notificationTargetActivity); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); builder.setContentIntent(pi);/*from w w w .j av a2 s .c o m*/ } if (useNotificationSmallIcon) { builder.setSmallIcon(notificationSmallIconResId); } if (useNotificationLargeIcon) { builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), notificationLargeIconResId)); } builder.setContentTitle(title); builder.setWhen(notificationCreateTime); return builder.build(); }
From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.receiver.NotificationHelper.java
/** * Returns a notification builder set with non-item specific properties. *//* w w w . j av a 2s .c o m*/ private static NotificationCompat.Builder getNotificationBuilder(final Context context, final int lightAndVibrate, final Uri ringtone, final boolean alertOnce) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setWhen(0) .setSmallIcon(R.drawable.ic_stat_notification_edit) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.app_icon)) .setPriority(NotificationCompat.PRIORITY_DEFAULT).setDefaults(lightAndVibrate).setAutoCancel(true) .setOnlyAlertOnce(alertOnce).setSound(ringtone); return builder; }
From source file:com.c4mprod.utils.ImageManager.java
/** * Get a the default image from a resource ID. * //w w w .ja v a 2 s .c o m * @param defaultDrawableId * @return */ public Bitmap getDefaultImage(int defaultDrawableId) { Bitmap bitmap = mDefaultImageCache.get(defaultDrawableId); if (bitmap == null) { bitmap = BitmapFactory.decodeResource(mContext.getResources(), defaultDrawableId); mDefaultImageCache.put(defaultDrawableId, bitmap); } return bitmap; }
From source file:com.chilliworks.chillisource.core.GCMService.java
private void generateNotification(Context context, HashMap<String, String> inParams) { //if the application is active then pass this information on to the application. if (CSApplication.get() != null && CSApplication.get().isActive() == true) { //build the array of keys and values int dwNumEntries = inParams.size(); String[] astrKeys = new String[dwNumEntries]; String[] astrValues = new String[dwNumEntries]; int dwCount = 0; for (String strKey : inParams.keySet()) { astrKeys[dwCount] = strKey;// w w w.j a v a2s. co m astrValues[dwCount] = inParams.get(strKey); dwCount++; } // Send this to the native side of the engine. mNativeInterface.OnRemoteNotificationReceived(astrKeys, astrValues); } // Otherwise display a notification. else { String strTitle = context.getString(R.getId(context, R.Type.STRING, "app_name")); String strMessage = inParams.get("message"); Intent notificationIntent = new Intent(context, CSActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); int smallIconId = 0; if (R.doesExist(context, R.Type.DRAWABLE, "ic_stat_notify") == true) { smallIconId = R.getId(context, R.Type.DRAWABLE, "ic_stat_notify"); } int largeIconId = smallIconId; if (R.doesExist(context, R.Type.DRAWABLE, "ic_stat_notify_large") == true) { largeIconId = R.getId(context, R.Type.DRAWABLE, "ic_stat_notify_large"); } Bitmap largeIconBitmap = null; if (largeIconId > 0) { largeIconBitmap = BitmapFactory.decodeResource(context.getResources(), largeIconId); } Notification notification = new NotificationCompat.Builder(context).setContentTitle(strTitle) .setContentText(strMessage).setSmallIcon(smallIconId).setLargeIcon(largeIconBitmap) .setContentIntent(intent).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); } }
From source file:ar.com.martinrevert.argenteam.GcmIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*www . j a v a 2 s .c o m*/ private void generarNotification(Context context, String message, String urlimagen, String urlarticulo, String tipo, String fecha) { SharedPreferences preferencias = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); boolean vib = preferencias.getBoolean("vibraoff", false); boolean movieoff = preferencias.getBoolean("movieoff", false); boolean tvoff = preferencias.getBoolean("tvoff", false); String ringmovie = preferencias.getString("prefRingtonemovie", ""); String ringtv = preferencias.getString("prefRingtonetv", ""); //Todo traducir ticker String ticker = "Nuevo subttulo " + tipo + " en aRGENTeaM"; Random randomGenerator = new Random(); int randomInt = randomGenerator.nextInt(100); Bitmap bitmap = getRemoteImage(urlimagen, tipo); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); int dash = 500; int short_gap = 200; long[] pattern = { 0, // Start immediately dash, short_gap, dash, short_gap, dash }; Intent notificationIntent; String ringtone; int ledlight; if (tipo.equalsIgnoreCase("Movie")) { ringtone = ringmovie; notificationIntent = new Intent(context, Peli.class); ledlight = preferencias.getInt("ledMovie", 0); } else { notificationIntent = new Intent(context, Tv.class); ringtone = ringtv; ledlight = preferencias.getInt("ledTV", 0); System.out.println(ledlight); } notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("passed", urlarticulo); PendingIntent pendingIntent; pendingIntent = PendingIntent.getActivity(context, randomInt, notificationIntent, 0); Notification myNotification; myNotification = new NotificationCompat.Builder(context).setPriority(1).setContentTitle(message) .setTicker(ticker).setLights(ledlight, 300, 300).setWhen(System.currentTimeMillis()) .setContentIntent(pendingIntent).setSound(Uri.parse(ringtone)).setAutoCancel(true) .setSmallIcon(R.drawable.ic_stat_ic_argenteam_gcm).build(); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews views; views = new RemoteViews(getPackageName(), R.layout.custom_notification); views.setImageViewBitmap(R.id.big_picture, bitmap); views.setImageViewBitmap(R.id.big_icon, BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_ic_argenteam_gcm)); views.setTextViewText(R.id.title, message); myNotification.bigContentView = views; } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (movieoff && tipo.equalsIgnoreCase("Movie")) { if (vib) { v.vibrate(pattern, -1); } notificationManager.notify(randomInt, myNotification); } if (tvoff && tipo.equalsIgnoreCase("Serie TV")) { if (vib) { v.vibrate(pattern, -1); } notificationManager.notify(randomInt, myNotification); } }
From source file:com.google.android.gms.location.sample.geofencing.GeofenceTransitionsIntentService.java
/** * Posts a notification in the notification bar when a transition is detected. * If the user clicks the notification, control goes to the MainActivity. *///from ww w . j av a2s . c om private void sendNotification(String notificationDetails) { // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(MainActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Define the notification settings. builder.setSmallIcon(R.drawable.ic_launcher) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setColor(Color.RED).setContentTitle(notificationDetails) .setContentText(getString(R.string.geofence_transition_notification_text)) .setContentIntent(notificationPendingIntent); // Dismiss notification once the user touches it. builder.setAutoCancel(true); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(0, builder.build()); }
From source file:com.android.usbtuner.setup.TunerSetupActivity.java
/** * Sends the recommendation card to start the USB tuner TV input setup activity. * * @param context a {@link Context} instance *//*from w ww . j a v a 2 s .c om*/ private static void sendRecommendationCard(Context context) { Resources resources = context.getResources(); String focusedTitle = resources.getString(R.string.ut_setup_recommendation_card_focused_title); String title = resources.getString(R.string.ut_setup_recommendation_card_title); Bitmap largeIcon = BitmapFactory.decodeResource(resources, R.drawable.recommendation_antenna); // Build and send the notification. Notification notification = new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(context) .setAutoCancel(false).setContentTitle(focusedTitle).setContentText(title).setContentInfo(title) .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(largeIcon) .setSmallIcon(resources.getIdentifier(TAG_ICON, TAG_DRAWABLE, context.getPackageName())) .setContentIntent(createPendingIntentForSetupActivity(context))).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFY_TAG, NOTIFY_ID, notification); }