List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:com.appgeneration.magmanager.imagefetcher.ImageWorker.java
/** * Load an image specified by the data parameter into an ImageView (override * {@link ImageWorker#processBitmap(Object)} to define the processing * logic). A memory and disk cache will be used if an {@link ImageCache} has * been set using {@link ImageWorker#addImageCache}. If the * image is found in the memory cache, it is set immediately, otherwise an * {@link AsyncTask} will be created to asynchronously load the bitmap. * * @param data The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. * @param resId Resource of placeholder bitmap while the image loads. *//* w ww . j a v a 2 s . c om*/ protected void loadImage(Object data, ImageView imageView, int resId) { if (!loadingBitmaps.containsKey(resId)) { // Store loading bitmap in a hash table to prevent continual decoding loadingBitmaps.put(resId, BitmapFactory.decodeResource(mResources, resId)); } loadImage(data, imageView, loadingBitmaps.get(resId)); }
From source file:com.cnlms.wear.NotificationHelper.java
public static void raiseNotificationWithBigStyle(final Context context) { final NotificationCompat.Builder builder = defaultBuilder(context); builder.setLargeIcon(/*from w w w. j av a 2 s . co m*/ BitmapFactory.decodeResource(context.getResources(), android.R.drawable.sym_action_chat)) .setContentIntent(viewPendingIntent(context)).addAction(replyAction(context)); // Big Style NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(); style.bigText(CONTENT_BIG_TEXT); builder.setStyle(style); raiseNotification(context, builder); }
From source file:alaindc.memenguage.RandomIntentService.java
private void sendNotification(long id_word) { String title = "Memenguage"; String description = "Do you remember?"; // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), GuessActivity.class); notificationIntent.setAction(Constants.ACTION_GUESS_ACTIVITY); notificationIntent.putExtra(Constants.EXTRA_GUESS_IDWORD, id_word); // 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.addNextIntentWithParentStack(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.icon) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo)).setColor(Color.RED) .setContentTitle(title).setContentText(description).setDefaults(Notification.DEFAULT_ALL) .setContentIntent(notificationPendingIntent); try {/* www . j a v a 2 s . c o m*/ String urisound = PreferenceManager.getDefaultSharedPreferences(this).getString("sound_notifications", ""); builder.setSound(Uri.parse(urisound)); } catch (Exception e) { Log.d("RandomIntentService", "Uri sound notification empty or wrong"); } try { Boolean vibrate = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("vibrate_notifications", false); if (vibrate) builder.setVibrate(new long[] { 1000, 1000 }); } catch (Exception e) { Log.d("RandomIntentService", "Vibrate notification wrong"); } builder.setDefaults(0); // 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(Constants.ID_NOTIFICATION_RANDOM_WORD, builder.build()); }
From source file:com.andreaszeiser.bob.ImageWorker.java
/** * Load an image specified by the data parameter into an ImageView (override * {@link ImageWorker#processBitmap(Object)} to define the processing * logic). A memory and disk cache will be used if an {@link ImageCache} has * been set using {@link ImageWorker#addImageCache}. If the image is found * in the memory cache, it is set immediately, otherwise an * {@link AsyncTask} will be created to asynchronously load the bitmap. * /*from www.j a v a 2 s. com*/ * @param data * The URL of the image to download. * @param imageView * The ImageView to bind the downloaded image to. * @param resId * Resource of placeholder bitmap while the image loads. */ protected void loadImage(Object data, ImageView imageView, int resId) { if (!loadingBitmaps.containsKey(resId)) { // Store loading bitmap in a hash table to prevent continual // decoding loadingBitmaps.put(resId, BitmapFactory.decodeResource(mResources, resId)); } loadImage(data, imageView, loadingBitmaps.get(resId), null); }
From source file:com.android.project.imagefetcher.ImageWorker.java
/** * Set placeholder bitmap that shows when the the background thread is * running.//from w ww . j a v a 2s .co m * * @param resId */ public void setLoadingImage(int resId) { if (!loadingBitmaps.containsKey(resId)) { // Store loading bitmap in a hash table to prevent continual // decoding loadingBitmaps.put(resId, BitmapFactory.decodeResource(mResources, resId)); } mLoadingBitmap = loadingBitmaps.get(resId); }
From source file:com.android.gallery3d.v5.filtershow.category.CategoryView.java
public void setAction(Action action, CategoryAdapter adapter) { mAction = action;/*from w w w .j a va2 s . co m*/ setText(mAction.getName()); mAdapter = adapter; mCanBeRemoved = action.canBeRemoved(); setUseOnlyDrawable(false); if (mAction.getType() == Action.ADD_ACTION) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.filtershow_add); setBitmap(bitmap); setUseOnlyDrawable(true); setText(getResources().getString(R.string.filtershow_add_button_looks)); } else { setBitmap(mAction.getImage()); } invalidate(); }
From source file:com.barcamppenang2014.tabfragment.ProfileFragment.java
License:asdf
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.update_profile_page, container, false); profilefrg = this; bt_save = (Button) v.findViewById(R.id.btnSave); bt_connect = (ImageButton) v.findViewById(R.id.btnfbconnect); bt_namecard = (ImageButton) v.findViewById(R.id.bt_namecard); et_name = (EditText) v.findViewById(R.id.editTextName); et_email = (EditText) v.findViewById(R.id.editTextEmail); et_phone = (EditText) v.findViewById(R.id.editTextPhone); et_profession = (EditText) v.findViewById(R.id.editTextProfession); et_fbId = (EditText) v.findViewById(R.id.editTextFbId); tv_imgtext = (TextView) v.findViewById(R.id.tx_namecard); tv_remove = (TextView) v.findViewById(R.id.tx_remove); final Bitmap defaultNamecard = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.default_namecard); //set default image for namecard bt_namecard.setImageBitmap(defaultNamecard); // Retrive the data from sqlite if profile is created. isProfileCreated = check();//www. j a v a2 s. com if (isProfileCreated.equalsIgnoreCase("true")) { String[] myInfo = fillTextField(); et_name.setText(myInfo[0]); et_email.setText(myInfo[1]); et_phone.setText(myInfo[2]); et_profession.setText(myInfo[3]); if (!myInfo[4].equals("none")) { et_fbId.setText(myInfo[4]); } String picUri = getSharePreferenceKey("picuri"); // myInfo[5] retrieved from sharedpreference if (!picUri.equals("none")) { Uri imageUri = Uri.parse(picUri); try { URIToBitmap(imageUri); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } } bt_connect.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { fbLogin(); } }); tv_remove.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { SharedPreferences sharedpreferences = getActivity().getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE); Editor editor = sharedpreferences.edit(); editor.putString("picuri", "none"); editor.commit(); //set default image for namecard bt_namecard.setImageBitmap(defaultNamecard); } }); bt_namecard.setOnClickListener(galleryOnClickListener); tv_imgtext.setOnClickListener(galleryOnClickListener); Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { Activity temp = getActivity(); session = new Session(temp); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } bt_save.setOnClickListener(new OnClickListener() { public void onClick(View v) { String name = et_name.getText().toString(); String email = et_email.getText().toString(); String phone = et_phone.getText().toString(); String profession = et_profession.getText().toString(); // fbId and picUri can be null String fbId = et_fbId.getText().toString().equals("") ? "none" : et_fbId.getText().toString(); // String picUri = getSharePreferenceKey("picuri"); if (name.equals("") || email.equals("") || phone.equals("") || profession.equals("")) { Toast.makeText(getActivity(), "Please fill in all the details.", Toast.LENGTH_LONG).show(); } else { // URLNamecard = // "http://chimou.com/barcamppg/namecard.php?get&email=yinsee@wsatp.com"; // If bitmap is not null, POST to php String picUri = getSharePreferenceKey("picuri"); if (!picUri.equals("none")) { // new POSTNamecard().execute(email); //new POSTNamecard().execute("baa@gmail.com"); } MyDatabase database = new MyDatabase(getActivity()); SQLiteDatabase sqliteDatabase = database.getWritableDatabase(); String sql = "INSERT OR REPLACE INTO USERPROFILE (ISPFOFILECREATED,MYKEYID, MYNAME, MYEMAIL, MYPHONE,MYPROFESSION, MYFBID )" + " VALUES ('true','" + "1','" + name + "', '" + email + "', '" + phone + "', '" + profession + "', '" + fbId + "'); "; sqliteDatabase.execSQL(sql); database.close(); sqliteDatabase.close(); MainActivity main = (MainActivity) getActivity(); // main.switchContentWithinTab(new ProfileQrFragment(), // TITLE); main.switchContent(new ProfileQrFragment()); } } }); return v; }
From source file:com.example.pyrkesa.shwc.OngoingNotificationListenerService.java
@Override public void onDataChanged(DataEventBuffer dataEvents) { final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); final String ACTION_DEMAND = "ACTION_DEMAND"; String EXTRA_CMD = "EXTRA_CMD"; dataEvents.close();// w w w . ja va 2 s . c om if (!mGoogleApiClient.isConnected()) { ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "Service failed to connect to GoogleApiClient."); return; } } for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (PATH.equals(path)) { // Get the data out of the event DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); //final String title = dataMapItem.getDataMap().getString(KEY_TITLE); final String room_devices = dataMapItem.getDataMap().getString(KEY_ROOM_DEVICES); final String room_name = dataMapItem.getDataMap().getString(KEY_ROOM_NAME); // Asset asset = dataMapItem.getDataMap().getAsset(KEY_BACKGROUND); try { JSONObject roomJSON = new JSONObject(room_devices); JSONArray devicesArray = roomJSON.getJSONArray("devices"); String firstPageText = "quipements :"; ArrayList<Device> devicess = new ArrayList<Device>(); for (int i = 0; i < devicesArray.length(); i++) { JSONObject d = devicesArray.getJSONObject(i); Device device = new Device(d.getString("id"), d.getString("name"), d.getInt("type"), d.getString("status")); String Newline = System.getProperty("line.separator"); firstPageText += Newline; firstPageText += device.name; devicess.add(device); } if (firstPageText.equalsIgnoreCase("quipements :")) { firstPageText = "Aucun quipement"; } Bitmap background = BitmapFactory.decodeResource(this.getResources(), R.drawable.bg_distance); NotificationCompat.WearableExtender notifExtender = new NotificationCompat.WearableExtender(); for (Device d : devicess) { try { notifExtender.addAction(d.getAction(OngoingNotificationListenerService.this)); } catch (Exception e) { Log.e("Erreur get Action :", e.getMessage()); } } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle("Pice : " + roomJSON.getString("name")) .setContentText(firstPageText).setSmallIcon(R.drawable.mini_logo) .extend(notifExtender.setBackground(background)).setOngoing(true); // Build the notification and show it NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } catch (Throwable t) { Log.e("JSON_WEAR_SHWC", "Could not parse malformed JSON: " + room_devices + t.getMessage()); } } else { Log.d(TAG, "Unrecognized path: " + path); } } } }
From source file:com.nextgis.maplibui.util.ControlHelper.java
public static Drawable getIconByVectorType(Context context, int geometryType, int color, int defaultIcon, boolean syncable) { int drawableId; switch (geometryType) { case GTPoint: drawableId = R.drawable.ic_type_point; break;/*from w w w .ja v a 2 s .c o m*/ case GTMultiPoint: drawableId = R.drawable.ic_type_multipoint; break; case GTLineString: drawableId = R.drawable.ic_type_line; break; case GTMultiLineString: drawableId = R.drawable.ic_type_multiline; break; case GTPolygon: drawableId = R.drawable.ic_type_polygon; break; case GTMultiPolygon: drawableId = R.drawable.ic_type_multipolygon; break; default: return ContextCompat.getDrawable(context, defaultIcon); } BitmapDrawable icon = (BitmapDrawable) ContextCompat.getDrawable(context, drawableId); if (icon != null) { Bitmap src = icon.getBitmap(); Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); canvas.drawBitmap(src, 0, 0, paint); if (syncable) { int syncIconId = isDarkTheme(context) ? R.drawable.ic_action_refresh_dark : R.drawable.ic_action_refresh_light; ; src = BitmapFactory.decodeResource(context.getResources(), syncIconId); src = Bitmap.createScaledBitmap(src, bitmap.getWidth() / 2, bitmap.getWidth() / 2, true); canvas.drawBitmap(src, bitmap.getWidth() - bitmap.getWidth() / 2, bitmap.getWidth() - bitmap.getWidth() / 2, new Paint()); } icon = new BitmapDrawable(context.getResources(), bitmap); } return icon; }
From source file:app.androidhive.info.realm.GCM.GcmIntentService.java
private void sendNotification(String title, String msg, String link) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); /* Intent intent = new Intent(this, MainActivity.class); intent.putExtra("phone", link);/*from w w w . ja v a 2 s . c o m*/ PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);*/ Phone = link; // getData(link); Intent dialogIntent = new Intent(getBaseContext(), MainActivity.class); dialogIntent.putExtra("Phone", link); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setLargeIcon(BitmapFactory.decodeResource(getBaseContext().getResources(), R.mipmap.ic_launcher)) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(link).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); // Set the notification vibrate option if (preferences.getBoolean("notifications_new_message_vibrate", true)) { mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }); } // Set the notification ringtone if (preferences.getString("notifications_new_message_ringtone", null) != null) { mBuilder.setSound(Uri.parse(preferences.getString("notifications_new_message_ringtone", null))); } else { Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); } // Show only if the notification are enabled if (preferences.getBoolean("notifications_new_message", true)) { // mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } }