List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:com.alchemiasoft.book.service.BookActionService.java
@Override protected void onHandleIntent(Intent intent) { final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, NOT_VALID_NOTIFICATION); // Cancelling any shown notification if (notificationId != NOT_VALID_NOTIFICATION) { Log.d(TAG_LOG, "Dismissing notification with id=" + notificationId); NotificationManagerCompat.from(this).cancel(notificationId); }/*from w ww .j ava2s .c o m*/ final long bookId = intent.getLongExtra(EXTRA_BOOK_ID, NOT_VALID_BOOK); if (bookId != NOT_VALID_BOOK) { final ContentResolver cr = getContentResolver(); final Action action = Action.valueOf(intent.getAction()); Log.d(TAG_LOG, "Performing action=" + action + " on book with id=" + bookId); final ContentValues cv = new ContentValues(); switch (action) { case BUY: cv.put(BookDB.Book.OWNED, 1); if (cr.update(BookDB.Book.create(bookId), cv, null, null) == 1 && intent.getBooleanExtra(EXTRA_WEARABLE_INPUT, false)) { final Book book = getBook(bookId); if (book != null) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true) .setContentTitle(getString(R.string.book_purchased)) .setContentText(book.getTitle()); builder.setContentIntent(PendingIntent.getActivity(this, 0, HomeActivity.createFor(this, book), PendingIntent.FLAG_UPDATE_CURRENT)); // ONLY 4 WEARABLE(s) final NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); wearableExtender .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.background)); // ACTION TO SELL A BOOK FROM A WEARABLE final PendingIntent sellIntent = PendingIntent.getService( this, 0, BookActionService.IntentBuilder.sell(this, book) .notificationId(NOTIFICATION_ID).wearableInput().build(), PendingIntent.FLAG_UPDATE_CURRENT); wearableExtender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_action_sell, getString(R.string.action_sell), sellIntent).build()); // Finally extending the notification builder.extend(wearableExtender); NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, builder.build()); } } break; case SELL: cv.put(BookDB.Book.OWNED, 0); if (cr.update(BookDB.Book.create(bookId), cv, null, null) == 1 && intent.getBooleanExtra(EXTRA_WEARABLE_INPUT, false)) { final Book book = getBook(bookId); if (book != null) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true) .setContentTitle(getString(R.string.book_sold)).setContentText(book.getTitle()); builder.setContentIntent(PendingIntent.getActivity(this, 0, HomeActivity.createFor(this, book), PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, builder.build()); } } break; case ADD_NOTE: final CharSequence notes = getExtraNotes(intent); if (!TextUtils.isEmpty(notes)) { cv.put(BookDB.Book.NOTES, notes.toString()); cr.update(BookDB.Book.create(bookId), cv, null, null); } break; default: break; } } }
From source file:com.baseproject.image.ImageWorker.java
/** * Set placeholder bitmap that shows when the the background thread is * running./*from w w w.j ava 2 s .c o m*/ * * @param resId */ public void setLoadingImage(int resId) { mLoadingBitmap = BitmapFactory.decodeResource(mContext.getResources(), resId); }
From source file:com.lovejoy777sarootool.rootool.preview.IconPreview.java
private static Bitmap getPreview(File file) { final boolean isImage = MimeTypes.isPicture(file); final boolean isVideo = MimeTypes.isVideo(file); final boolean isApk = file.getName().endsWith(".apk"); Bitmap mBitmap = null;/* w ww . j av a 2s . c o m*/ String path = file.getAbsolutePath(); if (isImage) { BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, o); o.inJustDecodeBounds = false; if (o.outWidth != -1 && o.outHeight != -1) { final int originalSize = (o.outHeight > o.outWidth) ? o.outWidth : o.outHeight; o.inSampleSize = originalSize / mWidth; } mBitmap = BitmapFactory.decodeFile(path, o); cache.put(path, mBitmap); return mBitmap; } else if (isVideo) { mBitmap = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.MICRO_KIND); cache.put(path, mBitmap); return mBitmap; } else if (isApk) { final PackageInfo packageInfo = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES); if (packageInfo != null) { final ApplicationInfo appInfo = packageInfo.applicationInfo; if (appInfo != null) { appInfo.sourceDir = path; appInfo.publicSourceDir = path; final Drawable icon = appInfo.loadIcon(pm); if (icon != null) { mBitmap = ((BitmapDrawable) icon).getBitmap(); } } } else { // load apk icon from /res/drawable/.. mBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.type_apk); } cache.put(path, mBitmap); return mBitmap; } return null; }
From source file:calibrationapp.spectoccular.com.keyboardtolinux.MainActivity.java
private BitmapDrawable toDrawable(int rid) { return new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), rid)); }
From source file:com.andreadec.musicplayer.MusicService.java
/** * Called when the service is created./*w w w. jav a 2 s. c om*/ */ @Override public void onCreate() { PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MusicServiceWakelock"); // Initialize the telephony manager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); phoneStateListener = new MusicPhoneStateListener(); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Initialize pending intents quitPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.quit"), 0); previousPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.previous"), 0); playpausePendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.playpause"), 0); nextPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.next"), 0); pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), PendingIntent.FLAG_UPDATE_CURRENT); // Read saved user preferences preferences = PreferenceManager.getDefaultSharedPreferences(this); // Initialize the media player mediaPlayer = new MediaPlayer(); mediaPlayer.setOnCompletionListener(this); mediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK); // Enable the wake lock to keep CPU running when the screen is switched off shuffle = preferences.getBoolean(Constants.PREFERENCE_SHUFFLE, Constants.DEFAULT_SHUFFLE); repeat = preferences.getBoolean(Constants.PREFERENCE_REPEAT, Constants.DEFAULT_REPEAT); repeatAll = preferences.getBoolean(Constants.PREFERENCE_REPEATALL, Constants.DEFAULT_REPEATALL); try { // This may fail if the device doesn't support bass boost bassBoost = new BassBoost(1, mediaPlayer.getAudioSessionId()); bassBoost.setEnabled( preferences.getBoolean(Constants.PREFERENCE_BASSBOOST, Constants.DEFAULT_BASSBOOST)); setBassBoostStrength(preferences.getInt(Constants.PREFERENCE_BASSBOOSTSTRENGTH, Constants.DEFAULT_BASSBOOSTSTRENGTH)); bassBoostAvailable = true; } catch (Exception e) { bassBoostAvailable = false; } try { // This may fail if the device doesn't support equalizer equalizer = new Equalizer(1, mediaPlayer.getAudioSessionId()); equalizer.setEnabled( preferences.getBoolean(Constants.PREFERENCE_EQUALIZER, Constants.DEFAULT_EQUALIZER)); setEqualizerPreset( preferences.getInt(Constants.PREFERENCE_EQUALIZERPRESET, Constants.DEFAULT_EQUALIZERPRESET)); equalizerAvailable = true; } catch (Exception e) { equalizerAvailable = false; } random = new Random(System.nanoTime()); // Necessary for song shuffle shakeListener = new ShakeListener(this); if (preferences.getBoolean(Constants.PREFERENCE_SHAKEENABLED, Constants.DEFAULT_SHAKEENABLED)) { shakeListener.enable(); } telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); // Start listen for telephony events // Inizialize the audio manager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName()); audioManager.registerMediaButtonEventReceiver(mediaButtonReceiverComponent); audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); // Initialize remote control client if (Build.VERSION.SDK_INT >= 14) { icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mediaButtonReceiverComponent); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0); remoteControlClient = new RemoteControlClient(mediaPendingIntent); remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT); audioManager.registerRemoteControlClient(remoteControlClient); } updateNotificationMessage(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("com.andreadec.musicplayer.quit"); intentFilter.addAction("com.andreadec.musicplayer.previous"); intentFilter.addAction("com.andreadec.musicplayer.previousNoRestart"); intentFilter.addAction("com.andreadec.musicplayer.playpause"); intentFilter.addAction("com.andreadec.musicplayer.next"); intentFilter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals("com.andreadec.musicplayer.quit")) { sendBroadcast(new Intent("com.andreadec.musicplayer.quitactivity")); stopSelf(); return; } else if (action.equals("com.andreadec.musicplayer.previous")) { previousItem(false); } else if (action.equals("com.andreadec.musicplayer.previousNoRestart")) { previousItem(true); } else if (action.equals("com.andreadec.musicplayer.playpause")) { playPause(); } else if (action.equals("com.andreadec.musicplayer.next")) { nextItem(); } else if (action.equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { if (preferences.getBoolean(Constants.PREFERENCE_STOPPLAYINGWHENHEADSETDISCONNECTED, Constants.DEFAULT_STOPPLAYINGWHENHEADSETDISCONNECTED)) { pause(); } } } }; registerReceiver(broadcastReceiver, intentFilter); if (!isPlaying()) { loadLastSong(); } startForeground(Constants.NOTIFICATION_MAIN, notification); }
From source file:com.app.easyblood.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), com.app.easyblood.R.drawable.logo_notif); if (intType == 2) { Intent question = new Intent(this, MainActivity.class); question.putExtra("type", "Replies"); question.putExtra("askedby", askedby); question.putExtra("userid_questions", userid_questions); question.putExtra("questionmessage", questionmessage); question.putExtra("asked_time_questions", asked_time_questions); question.putExtra("imagepath", imagepath); question.putExtra("Category", category); question.putExtra("questionid", questionid); question.putExtra("userprofession_questions", userprofession_questions); PendingIntent contentIntent = PendingIntent.getActivity(this, Integer.parseInt(questionid), question, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(com.app.easyblood.R.drawable.logo_notif).setLargeIcon(bitmap) .setContentTitle("New Answer") .setStyle(new NotificationCompat.BigTextStyle().bigText(repliedby + " says " + replymessage)) .setContentText(repliedby + " says " + replymessage).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (intType == 3) { Intent requestIntent = new Intent(this, MainActivity.class); requestIntent.putExtra("type", "request"); requestIntent.putExtra("NotificationRequestId", requestId); PendingIntent contentIntent = PendingIntent.getActivity(this, Integer.parseInt(requestId), requestIntent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(com.app.easyblood.R.drawable.logo_notif).setLargeIcon(bitmap) .setContentTitle("New Request") .setStyle(new NotificationCompat.BigTextStyle().bigText(username + " : " + message)) .setContentText(username + " : " + message).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (intType == 4) { Intent responseIntent = new Intent(this, MainActivity.class); responseIntent.putExtra("type", "response"); responseIntent.putExtra("NotificationResponseId", responseId); responseIntent.putExtra("NotificationRequestId", requestId); responseIntent.putExtra("NotificationResponseUserId", userId); responseIntent.putExtra("NotificationResponseUserName", username); responseIntent.putExtra("NotificationResponseMessage", message); responseIntent.putExtra("NotificationResponseUserProfession", responseUserProfession); responseIntent.putExtra("NotificationResponseUserProfilePhotoServerPath", responseUserProfilePath); PendingIntent contentIntent = PendingIntent.getActivity(this, Integer.parseInt(responseId), responseIntent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(com.app.easyblood.R.drawable.logo_notif).setContentTitle("New Response") .setLargeIcon(bitmap)/* ww w. j av a 2s . c om*/ .setStyle(new NotificationCompat.BigTextStyle().bigText(username + " : " + message)) .setContentText(username + " : " + message).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else if (intType == 5) { Intent chatIntent = new Intent(getApplicationContext(), ChatActivity.class); chatIntent.putExtra("ChatId", chatChatId); chatIntent.putExtra("Message", chatMessage); chatIntent.putExtra("SentOn", chatMessageTime); chatIntent.putExtra("SenderId", chatSenderId); chatIntent.putExtra("UserName", chatSenderName); chatIntent.putExtra("received", true); ChatIdMap chatIdMap = new ChatIdMap(); chatIdMap.chatId = chatChatId; chatIdMap.userId = chatSenderId; chatIdMap.userName = chatSenderName; ChatIdMapDBHandler.InsertChatIdMap(getApplicationContext(), chatIdMap); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), Integer.parseInt(chatChatId), chatIntent, PendingIntent.FLAG_ONE_SHOT); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); String time = dateFormat.format(date); time = time.substring(11, time.lastIndexOf(':')); ChatInfo newMessage = new ChatInfo(); newMessage.setMessage(chatMessage); newMessage.setSentBy(false); newMessage.setTimeStamp(time); newMessage.setChatId(chatChatId); ChatInfoDBHandler.InsertChatInfo(getApplicationContext(), newMessage); if (TempDataClass.alreadyAdded == true) { TempDataClass.alreadyAdded = false; return; } Notification mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(com.app.easyblood.R.drawable.logo_notif).setLargeIcon(bitmap) .setContentTitle("Chat Notification").setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(chatSenderName + ":" + chatMessage)) .setContentText(chatSenderName + ":" + chatMessage).setAutoCancel(true).build(); mNotificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ID, mBuilder); } else { } }
From source file:uk.bowdlerize.service.CensorCensusService.java
private void warnOnPrep() { mBuilder.setStyle(new NotificationCompat.InboxStyle() .setBigContentTitle(getString(R.string.notifTitle) + " - " + getString(R.string.notifRequstURL)) .addLine(getString(R.string.notifRequesting)) .addLine("( " + getString(R.string.notifPolling) + " blocked.org.uk )") .setSummaryText(Integer.toString(checkedCount) + " " + getString(R.string.notifChecked) + " / " + Integer.toString(censoredCount) + " " + getString(R.string.notifPossBlock))) .setSmallIcon(R.drawable.ic_stat_in_progress) .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_ooni_large)) .setPriority(Notification.PRIORITY_MAX) .setTicker(getString(R.string.notifTitle) + " - " + getString(R.string.notifRequstURL)) .setAutoCancel(false);/*from w w w .jav a 2s . c o m*/ mBuilder.setProgress(2, 1, true); mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build()); /*Intent newIntent = new Intent(); newIntent.setAction(ProgressFragment.ORG_BROADCAST); newIntent.putExtra(ProgressFragment.ORG_BROADCAST,ProgressFragment.TALKING_TO_ORG); sendBroadcast(newIntent);*/ }
From source file:com.android.mms.ui.MessageListItem.java
public MessageListItem(Context context, AttributeSet attrs) { super(context, attrs); Resources res = context.getResources(); mColorSpan = new ForegroundColorSpan(res.getColor(R.color.timestamp_color)); mDefaultCountryIso = MmsApp.getApplication().getCurrentCountryIso(); if (sDefaultContactImage == null) { Bitmap defaultImage = BitmapFactory.decodeResource(res, R.drawable.ic_contact_picture); sDefaultContactImage = RoundedBitmapDrawableFactory.create(res, defaultImage); sDefaultContactImage.setAntiAlias(true); sDefaultContactImage//from www. j av a 2s .c om .setCornerRadius(Math.max(defaultImage.getWidth() / 2, defaultImage.getHeight() / 2)); } }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
private void setupImageShow(Context context) { Resources res = context.getResources(); mTextSize = res.getDimensionPixelSize(R.dimen.photoeditor_text_size); mTextPadding = res.getDimensionPixelSize(R.dimen.photoeditor_text_padding); mOriginalTextMargin = res.getDimensionPixelSize(R.dimen.photoeditor_original_text_margin); mOriginalTextSize = res.getDimensionPixelSize(R.dimen.photoeditor_original_text_size); mBackgroundColor = res.getColor(R.color.background_screen); mOriginalText = res.getString(R.string.original_picture_text); mShadow = (NinePatchDrawable) res.getDrawable(R.drawable.geometry_shadow); setupGestureDetector(context);/* w ww . j a v a2 s . c o m*/ mActivity = (FilterShowActivity) context; if (sMask == null) { Bitmap mask = BitmapFactory.decodeResource(res, R.drawable.spot_mask); sMask = convertToAlphaMask(mask); } mEdgeEffect = new EdgeEffectCompat(context); mEdgeSize = res.getDimensionPixelSize(R.dimen.edge_glow_size); }
From source file:com.adam.aslfms.service.ScrobblingService.java
@Override public int onStartCommand(Intent i, int flags, int startId) { handleCommand(i, startId);//from ww w.ja v a 2 s.co m if (settings.isOnGoingEnabled(Util.checkPower(mCtx))) { if (mCurrentTrack != null) { String ar = mCurrentTrack.getArtist(); String tr = mCurrentTrack.getTrack(); String api = mCurrentTrack.getMusicAPI().readAPIname(); // Heart intent Intent heartIntent = new Intent(mCtx, ScrobblingService.class); heartIntent.setAction(ScrobblingService.ACTION_HEART); PendingIntent heartPendingIntent = PendingIntent.getService(mCtx, 0, heartIntent, 0); NotificationCompat.Action heartAction = new NotificationCompat.Action.Builder( R.mipmap.ic_status_wail_love_track, "", heartPendingIntent).build(); Intent targetIntent = new Intent(mCtx, SettingsActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(mCtx, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(mCtx).setContentTitle(tr) .setSmallIcon(R.mipmap.ic_notify).setContentText(ar + " :" + api) .setPriority(NotificationCompat.PRIORITY_MIN).addAction(heartAction) .setContentIntent(contentIntent); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) { builder.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher)); } this.startForeground(14619, builder.build()); if (!settings.isNotifyEnabled(Util.checkPower(mCtx))) { Intent iNoti = new Intent(mCtx, ForegroundHide.class); startService(iNoti); } } } else { this.stopForeground(true); // TODO: test if this conflicts/stops scrobbles } return Service.START_STICKY; }