List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:com.cnlms.wear.NotificationHelper.java
public static void raiseAddToCartNotification(final Context context) { final int notificationId = 1; final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notif).setContentTitle("Hello Wearable!").setContentText("Sample text") .setContentIntent(browserPendingIntent(context)) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.notif_bg2)) .addAction(R.drawable.ic_add_to_cart, "Add to Cart", addToCartIntent(context)); NotificationManagerCompat.from(context).notify(notificationId, builder.build()); }
From source file:name.gumartinm.weather.information.fragment.current.CurrentFragment.java
private void updateUI(final Current current) { // 1. Update units of measurement. final UnitsConversor tempUnitsConversor = new TempUnitsConversor( this.getActivity().getApplicationContext()); final UnitsConversor windConversor = new WindUnitsConversor(this.getActivity().getApplicationContext()); final UnitsConversor pressureConversor = new PressureUnitsConversor( this.getActivity().getApplicationContext()); // 2. Formatters final DecimalFormat numberFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); numberFormatter.applyPattern("###.##"); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss", Locale.US); // 3. Prepare data for UI. String tempMax = ""; if (current.getMain().getTemp_max() != null) { double conversion = (Double) current.getMain().getTemp_max(); conversion = tempUnitsConversor.doConversion(conversion); tempMax = numberFormatter.format(conversion) + tempUnitsConversor.getSymbol(); }//from w ww .j av a 2 s .c om String tempMin = ""; if (current.getMain().getTemp_min() != null) { double conversion = (Double) current.getMain().getTemp_min(); conversion = tempUnitsConversor.doConversion(conversion); tempMin = numberFormatter.format(conversion) + tempUnitsConversor.getSymbol(); } Bitmap picture; if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null) && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) { final String icon = current.getWeather().get(0).getIcon(); picture = BitmapFactory.decodeResource(this.getResources(), IconsList.getIcon(icon).getResourceDrawable()); } else { picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert); } String description = this.getString(R.string.text_field_description_when_error); if (current.getWeather().size() > 0) { description = current.getWeather().get(0).getDescription(); } String humidityValue = ""; if ((current.getMain() != null) && (current.getMain().getHumidity() != null)) { final double conversion = (Double) current.getMain().getHumidity(); humidityValue = numberFormatter.format(conversion); } String pressureValue = ""; if ((current.getMain() != null) && (current.getMain().getPressure() != null)) { double conversion = (Double) current.getMain().getPressure(); conversion = pressureConversor.doConversion(conversion); pressureValue = numberFormatter.format(conversion); } String windValue = ""; if ((current.getWind() != null) && (current.getWind().getSpeed() != null)) { double conversion = (Double) current.getWind().getSpeed(); conversion = windConversor.doConversion(conversion); windValue = numberFormatter.format(conversion); } String rainValue = ""; if ((current.getRain() != null) && (current.getRain().get3h() != null)) { final double conversion = (Double) current.getRain().get3h(); rainValue = numberFormatter.format(conversion); } String cloudsValue = ""; if ((current.getClouds() != null) && (current.getClouds().getAll() != null)) { final double conversion = (Double) current.getClouds().getAll(); cloudsValue = numberFormatter.format(conversion); } String snowValue = ""; if ((current.getSnow() != null) && (current.getSnow().get3h() != null)) { final double conversion = (Double) current.getSnow().get3h(); snowValue = numberFormatter.format(conversion); } String feelsLike = ""; if (current.getMain().getTemp() != null) { double conversion = (Double) current.getMain().getTemp(); conversion = tempUnitsConversor.doConversion(conversion); feelsLike = numberFormatter.format(conversion); } String sunRiseTime = ""; if (current.getSys().getSunrise() != null) { final long unixTime = (Long) current.getSys().getSunrise(); final Date unixDate = new Date(unixTime * 1000L); sunRiseTime = dateFormat.format(unixDate); } String sunSetTime = ""; if (current.getSys().getSunset() != null) { final long unixTime = (Long) current.getSys().getSunset(); final Date unixDate = new Date(unixTime * 1000L); sunSetTime = dateFormat.format(unixDate); } // 4. Update UI. final TextView tempMaxView = (TextView) getActivity().findViewById(R.id.weather_current_temp_max); tempMaxView.setText(tempMax); final TextView tempMinView = (TextView) getActivity().findViewById(R.id.weather_current_temp_min); tempMinView.setText(tempMin); final ImageView pictureView = (ImageView) getActivity().findViewById(R.id.weather_current_picture); pictureView.setImageBitmap(picture); final TextView descriptionView = (TextView) getActivity().findViewById(R.id.weather_current_description); descriptionView.setText(description); ((TextView) getActivity().findViewById(R.id.weather_current_humidity_value)).setText(humidityValue); ((TextView) getActivity().findViewById(R.id.weather_current_humidity_units)) .setText(this.getActivity().getApplicationContext().getString(R.string.text_units_percent)); ((TextView) getActivity().findViewById(R.id.weather_current_pressure_value)).setText(pressureValue); ((TextView) getActivity().findViewById(R.id.weather_current_pressure_units)) .setText(pressureConversor.getSymbol()); ((TextView) getActivity().findViewById(R.id.weather_current_wind_value)).setText(windValue); ((TextView) getActivity().findViewById(R.id.weather_current_wind_units)).setText(windConversor.getSymbol()); ((TextView) getActivity().findViewById(R.id.weather_current_rain_value)).setText(rainValue); ((TextView) getActivity().findViewById(R.id.weather_current_rain_units)) .setText(this.getActivity().getApplicationContext().getString(R.string.text_units_mm3h)); ((TextView) getActivity().findViewById(R.id.weather_current_clouds_value)).setText(cloudsValue); ((TextView) getActivity().findViewById(R.id.weather_current_clouds_units)) .setText(this.getActivity().getApplicationContext().getString(R.string.text_units_percent)); ((TextView) getActivity().findViewById(R.id.weather_current_snow_value)).setText(snowValue); ((TextView) getActivity().findViewById(R.id.weather_current_snow_units)) .setText(this.getActivity().getApplicationContext().getString(R.string.text_units_mm3h)); ((TextView) getActivity().findViewById(R.id.weather_current_feelslike_value)).setText(feelsLike); ((TextView) getActivity().findViewById(R.id.weather_current_feelslike_units)) .setText(tempUnitsConversor.getSymbol()); ((TextView) getActivity().findViewById(R.id.weather_current_sunrise_value)).setText(sunRiseTime); ((TextView) getActivity().findViewById(R.id.weather_current_sunset_value)).setText(sunSetTime); this.getActivity().findViewById(R.id.weather_current_data_container).setVisibility(View.VISIBLE); this.getActivity().findViewById(R.id.weather_current_progressbar).setVisibility(View.GONE); this.getActivity().findViewById(R.id.weather_current_error_message).setVisibility(View.GONE); }
From source file:by.zatta.pilight.connection.ConnectionService.java
private static Bitmap bigPic(int png) { Bitmap mBitmap = BitmapFactory.decodeResource(aCtx.getResources(), png); int height = (int) aCtx.getResources().getDimension(android.R.dimen.notification_large_icon_height); int width = (int) aCtx.getResources().getDimension(android.R.dimen.notification_large_icon_width); mBitmap = Bitmap.createScaledBitmap(mBitmap, width / 3, height / 3, false); return mBitmap; }
From source file:com.atinternet.tracker.Tool.java
/** * Resize an image/*w w w .jav a2s .c om*/ * * @param imageID int * @param context Context * @param width int * @param height int * @return Drawable */ static Drawable getResizedImage(int imageID, Context context, int width, int height) { Bitmap b = BitmapFactory.decodeResource(context.getResources(), imageID); Bitmap bitmapResized = Bitmap.createScaledBitmap(b, width, height, false); return new BitmapDrawable(context.getResources(), bitmapResized); }
From source file:com.wojtechnology.sunami.TheBrain.java
@Override public void onCreate() { mSaveCount = 0;/*from w w w .j a v a 2 s . co m*/ mIsInit = false; mBound = false; mHasAudioFocus = false; mLoaded = false; mPreparing = false; mPauseAfterLoad = false; mUpNext = new UpNext(); mPlayTimer = new PlayTimer(); mMainPrefs = new MainPrefs(this); mThumbnail = BitmapFactory.decodeResource(getResources(), R.drawable.fire_mixtape_default_large); mNoisyAudioStreamReceiver = new NoisyAudioStreamReceiver(); mMPPreparedListener = new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { if (!mPauseAfterLoad) { resumePlayback(); setUI(true); } else { setUI(false); mPauseAfterLoad = false; } mPreparing = false; } }; super.onCreate(); }
From source file:com.example.sergey.currentweather.ui.fragment.MainFragment.java
private void initSwipe() { ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {//from w w w . j ava 2 s. c o m @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { int position = viewHolder.getAdapterPosition(); if (direction == ItemTouchHelper.LEFT) { deleteData(mCityListAdapter.removeItem(position)); } } @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { Bitmap icon; if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { View itemView = viewHolder.itemView; float height = (float) itemView.getBottom() - (float) itemView.getTop(); float width = height / 3; if (dX < 0) { mPoint.setColor(Color.parseColor("#D32F2F")); RectF background = new RectF((float) itemView.getRight() + dX, (float) itemView.getTop(), (float) itemView.getRight(), (float) itemView.getBottom()); c.drawRect(background, mPoint); icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_delete_white); RectF icon_dest = new RectF((float) itemView.getRight() - 2 * width, (float) itemView.getTop() + width, (float) itemView.getRight() - width, (float) itemView.getBottom() - width); c.drawBitmap(icon, null, icon_dest, mPoint); } } super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } }; ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); itemTouchHelper.attachToRecyclerView(mRecyclerView); }
From source file:com.android.browser.BookmarksPageCallbacks.java
private void populateBookmarkItem(Cursor cursor, BookmarkItem item, boolean isFolder) { item.setName(cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE)); if (isFolder) { item.setUrl(null);//w w w . j a v a2s .com Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_folder_holo_dark); item.setFavicon(bitmap); new LookupBookmarkCount(getActivity(), item).execute(cursor.getLong(BookmarksLoader.COLUMN_INDEX_ID)); } else { String url = cursor.getString(BookmarksLoader.COLUMN_INDEX_URL); item.setUrl(url); Bitmap bitmap = getBitmap(cursor, BookmarksLoader.COLUMN_INDEX_FAVICON); item.setFavicon(bitmap); } }
From source file:com.carver.paul.truesight.Ui.MainActivity.java
protected Bitmap getSamplePhoto() { return BitmapFactory.decodeResource(getResources(), R.drawable.sample_photo); }
From source file:com.appdevper.mediaplayer.app.MediaNotificationManager.java
private Notification createNotification() { LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata); if (mMetadata == null || mPlaybackState == null) { return null; }/*from ww w . j a v a 2 s .c om*/ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService); int playPauseButtonPosition = 0; // If skip to previous action is enabled if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, mService.getString(R.string.label_previous), mPreviousIntent); playPauseButtonPosition = 1; } addPlayPauseAction(notificationBuilder); // If skip to next action is enabled if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, mService.getString(R.string.label_next), mNextIntent); } MediaDescriptionCompat description = mMetadata.getDescription(); String fetchArtUrl = null; Bitmap art = null; if (description.getIconUri() != null) { String artUrl = description.getIconUri().toString(); art = AlbumArtCache.getInstance().getBigImage(artUrl); if (art == null) { fetchArtUrl = artUrl; art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art); } } notificationBuilder .setStyle(new NotificationCompat.MediaStyle() .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view .setMediaSession(mSessionToken)) .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification) .setVisibility(Notification.VISIBILITY_PUBLIC).setUsesChronometer(true) .setContentIntent(createContentIntent(description)).setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()).setLargeIcon(art); if (mController != null && mController.getExtras() != null) { String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST); if (castName != null) { String castInfo = mService.getResources().getString(R.string.casting_to_device, castName); notificationBuilder.setSubText(castInfo); notificationBuilder.addAction(R.drawable.ic_close_black_24dp, mService.getString(R.string.stop_casting), mStopCastIntent); } } setNotificationPlaybackState(notificationBuilder); fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder); return notificationBuilder.build(); }
From source file:com.appsimobile.appsii.module.weather.WeatherActivity.java
Bitmap loadBitmapBlocking(String woeid, boolean isDay, int conditionCode) { File[] files = mWeatherUtils.getCityPhotos(WeatherActivity.this, woeid); Bitmap bitmap;/* ww w.j a v a2s . c o m*/ if (files != null) { int N = files.length; Random random = new Random(); int idx = random.nextInt(N); File file = files[idx]; WindowManager windowManager = mWindowManager; Display defaultDisplay = windowManager.getDefaultDisplay(); int dimen = Math.max(defaultDisplay.getWidth(), defaultDisplay.getHeight()); bitmap = mBitmapUtils.decodeSampledBitmapFromFile(file, dimen, dimen); return bitmap; } int resId = ImageDownloadHelper.getFallbackDrawableForConditionCode(isDay, conditionCode); return BitmapFactory.decodeResource(getResources(), resId); }