Example usage for android.graphics Bitmap createScaledBitmap

List of usage examples for android.graphics Bitmap createScaledBitmap

Introduction

In this page you can find the example usage for android.graphics Bitmap createScaledBitmap.

Prototype

public static Bitmap createScaledBitmap(@NonNull Bitmap src, int dstWidth, int dstHeight, boolean filter) 

Source Link

Document

Creates a new bitmap, scaled from an existing bitmap, when possible.

Usage

From source file:de.escoand.readdaily.PlayerDialogFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container,
        @Nullable final Bundle savedInstanceState) {
    final View root = inflater.inflate(R.layout.fragment_player, null);
    final TextView playerTitle = (TextView) root.findViewById(R.id.player_title);
    final ImageView playerImage = (ImageView) root.findViewById(R.id.player_image);
    progressBar = (ProgressBar) root.findViewById(R.id.player_progress);
    progressText = (TextView) root.findViewById(R.id.player_text);

    if (savedInstanceState != null) {
        setDate(getContext(), Database.getDateFromInt(savedInstanceState.getInt(STATE_DATE)));
        player.seekTo(savedInstanceState.getInt(STATE_POSITION));
    }/*w  w  w.j  av  a  2  s  .  c  o m*/

    if (image > 0) {
        final Bitmap tmp = BitmapFactory.decodeResource(getResources(), image);
        final int width = Math.round(tmp.getWidth() / 100);
        final int height = Math.round(tmp.getHeight() / 100);
        root.setBackgroundDrawable(new BitmapDrawable(Bitmap.createScaledBitmap(tmp, width, height, false)));
        playerImage.setImageResource(image);
    }

    playerTitle.setText(title);

    return root;
}

From source file:mobisocial.musubi.util.OGUtil.java

public static OGData getOrGuess(String url) {
    DefaultHttpClient hc = new DefaultHttpClient();
    HttpResponse res;/*from  w ww  .ja  v  a  2 s .co m*/
    try {
        HttpGet hg = new HttpGet(url);
        res = hc.execute(hg);
    } catch (Exception e) {
        Log.e(TAG, "unable to fetch page to get og tags", e);
        return null;
    }
    String location = url;
    //TODO: if some kind of redirect magic happened, then
    //make the location match that

    OGData og = new OGData();
    HttpEntity he = res.getEntity();
    Header content_type = he.getContentType();
    //TODO: check the content directly if they forget the type header
    if (content_type == null || content_type.getValue() == null) {
        Log.e(TAG, "page missing content type ..abandoning: " + url);
        return null;
    }
    og.mMimeType = content_type.getValue();
    //just make a thumbnail if the shared item is an image
    if (og.mMimeType.startsWith("image/")) {
        Bitmap b;
        try {
            b = BitmapFactory.decodeStream(he.getContent());
        } catch (Exception e) {
            return null;
        }
        //TODO: scaling
        int w = b.getWidth();
        int h = b.getHeight();
        if (w > h) {
            h = h * 200 / w;
            w = 200;
        } else {
            w = w * 200 / h;
            h = 200;
        }

        Bitmap b2 = Bitmap.createScaledBitmap(b, w, h, true);
        b.recycle();
        b = b2;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        b.compress(CompressFormat.PNG, 100, baos);
        og.mImage = baos.toByteArray();
        b.recycle();
        return og;
    }
    //if its not html, we can't extract more details, the caller
    //should rely on what they already know.
    if (!og.mMimeType.startsWith("text/html") && !og.mMimeType.startsWith("application/xhtml")) {
        Log.e(TAG, "shared content is not a known type for meta data processing " + og.mMimeType);
        return og;
    }

    String html;
    try {
        html = IOUtils.toString(he.getContent());
    } catch (Exception e) {
        Log.e(TAG, "failed to read html content", e);
        return og;
    }

    Matcher m = sTitleRegex.matcher(html);
    if (m.find()) {
        og.mTitle = StringEscapeUtils.unescapeHtml4(m.group(1));

    }
    m = sMetaRegex.matcher(html);
    int offset = 0;
    String raw_description = null;
    while (m.find(offset)) {
        try {
            String meta_tag = m.group();
            Matcher mp = sPropertyOfMeta.matcher(meta_tag);
            if (!mp.find())
                continue;
            String type = mp.group(1);
            type = type.substring(1, type.length() - 1);
            Matcher md = sContentOfMeta.matcher(meta_tag);
            if (!md.find())
                continue;
            String data = md.group(1);
            //remove quotes
            data = data.substring(1, data.length() - 1);
            data = StringEscapeUtils.unescapeHtml4(data);
            if (type.equalsIgnoreCase("og:title")) {
                og.mTitle = data;
            } else if (type.equalsIgnoreCase("og:image")) {
                HttpResponse resi;
                try {
                    HttpGet hgi = new HttpGet(data);
                    resi = hc.execute(hgi);
                } catch (Exception e) {
                    Log.e(TAG, "unable to fetch og image url", e);
                    continue;
                }
                HttpEntity hei = resi.getEntity();
                if (!hei.getContentType().getValue().startsWith("image/")) {
                    Log.e(TAG, "image og tag points to non image data" + hei.getContentType().getValue());
                }
                try {
                    Bitmap b;
                    try {
                        b = BitmapFactory.decodeStream(hei.getContent());
                    } catch (Exception e) {
                        return null;
                    }
                    //TODO: scaling
                    int w = b.getWidth();
                    int h = b.getHeight();
                    if (w > h) {
                        h = h * Math.min(200, w) / w;
                        w = Math.min(200, w);
                    } else {
                        w = w * Math.min(200, h) / h;
                        h = Math.min(200, h);
                    }
                    Bitmap b2 = Bitmap.createScaledBitmap(b, w, h, true);
                    b.recycle();
                    b = b2;
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    b.compress(CompressFormat.PNG, 100, baos);
                    b.recycle();
                    og.mImage = baos.toByteArray();
                } catch (Exception e) {
                    Log.e(TAG, "failed to fetch image for og", e);
                    continue;
                }
            } else if (type.equalsIgnoreCase("description")) {
                raw_description = data;
            } else if (type.equalsIgnoreCase("og:description")) {
                og.mDescription = data;
            } else if (type.equalsIgnoreCase("og:url")) {
                og.mUrl = data;
            }
        } finally {
            offset = m.end();
        }
    }
    HashSet<String> already_fetched = new HashSet<String>();
    if (og.mImage == null) {
        int max_area = 0;
        m = sImageRegex.matcher(html);
        int img_offset = 0;
        while (m.find(img_offset)) {
            try {
                String img_tag = m.group();
                Matcher ms = sSrcOfImage.matcher(img_tag);
                if (!ms.find())
                    continue;
                String img_src = ms.group(1);
                img_src = img_src.substring(1, img_src.length() - 1);
                img_src = StringEscapeUtils.unescapeHtml4(img_src);
                //don't fetch an image twice (like little 1x1 images)
                if (already_fetched.contains(img_src))
                    continue;
                already_fetched.add(img_src);
                HttpResponse resi;
                try {
                    HttpGet hgi = new HttpGet(new URL(new URL(location), img_src).toString());
                    resi = hc.execute(hgi);
                } catch (Exception e) {
                    Log.e(TAG, "unable to fetch image url for biggest image search" + img_src, e);
                    continue;
                }
                HttpEntity hei = resi.getEntity();
                if (hei == null) {
                    Log.w(TAG, "image missing en ..trying entity response: " + url);
                    continue;
                }
                Header content_type_image = hei.getContentType();
                if (content_type_image == null || content_type_image.getValue() == null) {
                    Log.w(TAG, "image missing content type ..trying anyway: " + url);
                }
                if (!content_type_image.getValue().startsWith("image/")) {
                    Log.w(TAG, "image tag points to non image data " + hei.getContentType().getValue() + " "
                            + img_src);
                }
                try {
                    Bitmap b;
                    try {
                        b = BitmapFactory.decodeStream(hei.getContent());
                    } catch (Exception e) {
                        return null;
                    }
                    //TODO: scaling
                    int w = b.getWidth();
                    int h = b.getHeight();
                    if (w * h <= max_area) {
                        continue;
                    }
                    if (w < 32 || h < 32) {
                        //skip dinky crap
                        continue;
                    }
                    if (w > h) {
                        h = h * Math.min(200, w) / w;
                        w = Math.min(200, w);
                    } else {
                        w = w * Math.min(200, h) / h;
                        h = Math.min(200, h);
                    }
                    Bitmap b2 = Bitmap.createScaledBitmap(b, w, h, true);
                    b.recycle();
                    b = b2;
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    b.compress(CompressFormat.PNG, 100, baos);
                    og.mImage = baos.toByteArray();
                    b.recycle();
                    max_area = w * h;
                } catch (Exception e) {
                    Log.e(TAG, "failed to fetch image for og", e);
                    continue;
                }
            } finally {
                img_offset = m.end();
            }
        }

    }
    if (og.mDescription == null)
        og.mDescription = raw_description;
    return og;
}

From source file:com.jesjimher.bicipalma.MapaActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapa);/*from   w ww .jav a 2  s.c o m*/

    // Activar zoom
    GoogleMap mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapfragment))
            .getMap();
    //        mapa.setBuiltInZoomControls(true);
    mapa.setMyLocationEnabled(true);

    // Si el mapa no est en Palma o similar, ponerlo en pza espaa
    CameraPosition c = mapa.getCameraPosition();
    Location actual = new Location("");
    actual.setLatitude(c.target.latitude);
    actual.setLongitude(c.target.longitude);
    Location pe = new Location("");
    pe.setLatitude(PZAESPANYA.latitude);
    pe.setLongitude(PZAESPANYA.longitude);
    if (actual.distanceTo(pe) >= 5000)
        mapa.moveCamera(CameraUpdateFactory.newLatLng(PZAESPANYA));

    Intent i = getIntent();
    //        GeoPoint point=null;
    if (i.hasExtra("estaciones")) {
        estaciones = i.getExtras().getParcelableArrayList("estaciones");

        for (Estacion e : estaciones) {
            LevelListDrawable d = (LevelListDrawable) getResources().getDrawable(R.drawable.estado_variable);
            d.setLevel(e.getBicisLibres() + 1);
            BitmapDrawable bd = (BitmapDrawable) d.getCurrent();
            Bitmap b = bd.getBitmap();
            Bitmap petit = Bitmap.createScaledBitmap(b, b.getWidth() / 2, b.getHeight() / 2, false);
            String mensaje = String.format("%s: %d, %s: %d", getResources().getString(R.string.lbicislibres),
                    e.getBicisLibres(), getResources().getString(R.string.lanclajeslibres),
                    e.getAnclajesLibres());
            mapa.addMarker(new MarkerOptions()
                    .position(new LatLng(e.getLoc().getLatitude(), e.getLoc().getLongitude()))
                    .title(e.getNombre()).snippet(mensaje).icon(BitmapDescriptorFactory.fromBitmap(petit)));
        }
        Double lat = i.getExtras().getDouble("latcentro");
        Double lon = i.getExtras().getDouble("longcentro");
        mapa.moveCamera(CameraUpdateFactory.zoomTo(16));
        mapa.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lon)));
    }
}

From source file:com.turkiyedenemeleri.chronometer.ForegroundService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent.getAction().equals(Constants.ACTION.STARTFOREGROUND_ACTION)) {

        PrefUtils mPreferences = new PrefUtils(this);
        long wakeUpTime = (mPreferences.getStartedTime(intent.getStringExtra("snavid")) + 1800) * 1000;
        /*//from  w w  w .j a  va  2  s .c  o m
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        Intent timerExpire = new Intent(this, TimerExpiredReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(this, 0, timerExpire, PendingIntent.FLAG_CANCEL_CURRENT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        am.setAlarmClock(new AlarmManager.AlarmClockInfo(wakeUpTime, sender), sender);
        } else {
        am.set(AlarmManager.RTC_WAKEUP, wakeUpTime, sender);
        }
        */
        Log.e("TAG", "4 bitince servisi durduracak, broadcast");

        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(Constants.ACTION.MAIN_ACTION);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        notificationIntent.putExtra("yeni", "yeni");
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        Log.e("TAG", "5 tklarsam ekran a");

        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

        Notification notification = new NotificationCompat.Builder(this).setContentTitle("Snav Devam Ediyor")
                .setTicker("Snav Devam Ediyor").setContentText("Snav Devam Ediyor")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingIntent)
                .setOngoing(true).build();

        startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, notification);
        Log.e("TAG", "6  Devam ediyor");

    } else if (intent.getAction().equals(Constants.ACTION.STOPFOREGROUND_ACTION)) {
        Log.i(LOG_TAG, "Received Stop Foreground Intent");

        Intent cancelIntent = new Intent(this, TimerExpiredReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(this, 0, cancelIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        am.cancel(sender);
        Log.e("TAG", "9  Receiver pta");

        stopForeground(true);
        stopSelf();

        Log.e("TAG", "10 Notif ptal");
    }
    return START_REDELIVER_INTENT;
}

From source file:at.flack.receiver.EMailReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();//from  ww w .ja v  a2s .  c o  m
    try {
        if (bundle.getString("type").equals("mail")) {
            sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
            if (!sharedPrefs.getBoolean("notification_mail", true))
                return;
            notify = sharedPrefs.getBoolean("notifications", true);
            vibrate = sharedPrefs.getBoolean("vibration", true);
            headsup = sharedPrefs.getBoolean("headsup", true);
            led_color = sharedPrefs.getInt("notification_light", -16776961);
            boolean all = sharedPrefs.getBoolean("all_mail", true);

            if (notify == false)
                return;

            NotificationCompat.Builder mBuilder = null;
            boolean use_profile_picture = false;
            Bitmap profile_picture = null;

            String origin_name = bundle.getString("senderName").equals("") ? bundle.getString("senderMail")
                    : bundle.getString("senderName");

            try {
                profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap(
                        ProfilePictureCache.getInstance(context).get(origin_name), 200, 200, false), 300);
                use_profile_picture = true;
            } catch (Exception e) {
                use_profile_picture = false;
            }

            Resources res = context.getResources();

            int lastIndex = bundle.getString("subject").lastIndexOf("=");
            if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(0, lastIndex))) {
                mBuilder = new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name)
                        .setColor(0xFFFF5722)
                        .setContentText(res.getString(R.string.sms_receiver_new_encrypted_mail))
                        .setAutoCancel(true);
                if (use_profile_picture && profile_picture != null) {
                    mBuilder = mBuilder.setLargeIcon(profile_picture);
                } else {
                    mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                            context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                }
            } else {

                if (bundle.getString("subject").charAt(0) == '%' && (bundle.getString("subject").length() == 10
                        || bundle.getString("subject").length() == 9)) {
                    if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) {
                        mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                                .setColor(0xFFFF5722)
                                .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                                .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true);
                        if (use_profile_picture && profile_picture != null) {
                            mBuilder = mBuilder.setLargeIcon(profile_picture);
                        } else {
                            mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                    context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                        }
                    } else {
                        return;
                    }
                } else if (bundle.getString("subject").charAt(0) == '%'
                        && bundle.getString("subject").length() >= 120
                        && bundle.getString("subject").length() < 125) {
                    if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) {
                        mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                                .setColor(0xFFFF5722)
                                .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                                .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true);
                        if (use_profile_picture && profile_picture != null) {
                            mBuilder = mBuilder.setLargeIcon(profile_picture);
                        } else {
                            mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                    context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                        }
                    } else {
                        return;
                    }
                } else if (all) { // normal message
                    mBuilder = new NotificationCompat.Builder(context)
                            .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name)
                            .setColor(0xFFFF5722).setContentText(bundle.getString("subject"))
                            .setAutoCancel(true).setStyle(
                                    new NotificationCompat.BigTextStyle().bigText(bundle.getString("subject")));

                    if (use_profile_picture && profile_picture != null) {
                        mBuilder = mBuilder.setLargeIcon(profile_picture);
                    } else {
                        mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                    }
                } else {
                    return;
                }
            }
            // }
            Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            mBuilder.setSound(alarmSound);
            mBuilder.setLights(led_color, 750, 4000);
            if (vibrate) {
                mBuilder.setVibrate(new long[] { 0, 100, 200, 300 });
            }

            Intent resultIntent = new Intent(context, MainActivity.class);
            resultIntent.putExtra("MAIL", bundle.getString("senderMail"));

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(1,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            if (Build.VERSION.SDK_INT >= 16 && headsup)
                mBuilder.setPriority(Notification.PRIORITY_HIGH);
            if (Build.VERSION.SDK_INT >= 21)
                mBuilder.setCategory(Notification.CATEGORY_MESSAGE);

            final NotificationManager mNotificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);

            if (!MainActivity.isOnTop)
                mNotificationManager.notify(9, mBuilder.build());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.sspai.dkjt.service.GenerateFrameService.java

@Override
public void startingImage(Bitmap screenshot) {
    // Create the large notification icon
    int imageWidth = screenshot.getWidth();
    int imageHeight = screenshot.getHeight();
    int iconSize = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight;

    // Check for if config is null, http://crashes.to/s/dd0857c8648
    Bitmap preview = Bitmap.createBitmap(shortSide, shortSide,
            screenshot.getConfig() == null ? Bitmap.Config.ARGB_8888 : screenshot.getConfig());
    Canvas c = new Canvas(preview);
    Paint paint = new Paint();
    ColorMatrix desat = new ColorMatrix();
    desat.setSaturation(0.25f);/*from   www .  j  a va2s . co  m*/
    paint.setColorFilter(new ColorMatrixColorFilter(desat));
    Matrix matrix = new Matrix();
    matrix.postTranslate((shortSide - imageWidth) / 2, (shortSide - imageHeight) / 2);
    c.drawBitmap(screenshot, matrix, paint);
    c.drawColor(0x40FFFFFF);

    Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);

    Intent nullIntent = new Intent(this, MainActivity.class);
    nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.screenshot_saving_ticker))
            .setContentTitle(resources.getString(R.string.screenshot_saving_title))
            .setSmallIcon(R.drawable.ic_actionbar_logo)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(preview))
            .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0))
            .setWhen(System.currentTimeMillis()).setProgress(0, 0, true).setLargeIcon(croppedIcon);

    Notification n = notificationBuilder.build();
    n.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(DFG_NOTIFICATION_ID, n);
}

From source file:com.alucas.snorlax.module.feature.gym.EjectNotification.java

private Notification createNotification(final int pokemonNumber, final String pokemonName, final String gymName,
        final Double gymLatitude, final Double gymLongitude) {
    final Uri posURI = Uri.parse("geo:" + gymLatitude + "," + gymLongitude + "?q=" + gymLatitude + ","
            + gymLongitude + "(" + gymName + ")");
    final Intent posIntent = new Intent(Intent.ACTION_VIEW, posURI).setPackage("com.google.android.apps.maps");
    final PendingIntent posPendingIntent = PendingIntent.getActivity(mPokemonGoContext, 0, posIntent, 0);

    return new NotificationCompat.Builder(mSnorlaxContext)
            .setSmallIcon(/*from   w w  w . ja v a2  s.  c  o  m*/
                    R.drawable.ic_eject)
            .setLargeIcon(Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(mResources,
                            Resource.getPokemonResourceId(mSnorlaxContext, mResources, pokemonNumber)),
                    Resource.getLargeIconWidth(mResources), Resource.getLargeIconHeight(mResources), false))
            .setContentTitle(mSnorlaxContext.getString(R.string.notification_gym_eject_title, pokemonName))
            .setContentText(mSnorlaxContext.getString(R.string.notification_gym_eject_content, gymName))
            .setColor(ContextCompat.getColor(mSnorlaxContext, R.color.red_700)).setAutoCancel(true)
            .setContentIntent(posPendingIntent).setVibrate(new long[] { 0, 1000 })
            .setPriority(Notification.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_ALARM).build();
}

From source file:it.polimi.spf.demo.couponing.provider.creation.CouponCreationFragment.java

/**
 * Method to set an show a cropped imaged.
 * @param resultCode//from w  ww .j  a v  a2 s . c om
 * @param result
 */
public void handleCrop(int resultCode, Intent result) {
    if (resultCode == Activity.RESULT_OK) {
        Uri uri = Crop.getOutput(result);
        mPhotoInput.setImageURI(uri);

        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(uri.getPath());
            Bitmap myBitmap = BitmapFactory.decodeStream(inputStream);
            myBitmap = Bitmap.createScaledBitmap(myBitmap, 130, 130, false);

            //                mContainer.setFieldValue(ProfileField.PHOTO, myBitmap);
            //                showPicture(myBitmap);
            mPhoto = myBitmap;
            this.mPhotoInput.setImageBitmap(myBitmap);
            this.mPhotoInput.invalidate();

        } catch (FileNotFoundException e) {
            Log.e(TAG, "handleCrop FileInputStream-file not found from uri.getpath", e);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    Log.e(TAG, "handleCrop closing input stream error", e);
                }
            }
        }
    } else if (resultCode == Crop.RESULT_ERROR) {
        Toast.makeText(this.getActivity(), Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
    }
}

From source file:org.chromium.chrome.browser.bookmarks.BookmarkItemRow.java

@Override
public void onLargeIconAvailable(Bitmap icon, int fallbackColor, boolean isFallbackColorDefault) {
    if (icon == null) {
        mIconGenerator.setBackgroundColor(fallbackColor);
        icon = mIconGenerator.generateIconForUrl(mUrl);
        mIconImageView.setImageDrawable(new BitmapDrawable(getResources(), icon));
    } else {/*  ww w . j  a  va2 s  .c  o  m*/
        RoundedBitmapDrawable roundedIcon = RoundedBitmapDrawableFactory.create(getResources(),
                Bitmap.createScaledBitmap(icon, mDisplayedIconSize, mDisplayedIconSize, false));
        roundedIcon.setCornerRadius(mCornerRadius);
        mIconImageView.setImageDrawable(roundedIcon);
    }
}

From source file:com.carlrice.reader.utils.UiUtils.java

static public Bitmap getScaledBitmap(byte[] iconBytes, int sizeInDp) {
    if (iconBytes != null && iconBytes.length > 0) {
        Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length);
        if (bitmap != null && bitmap.getWidth() != 0 && bitmap.getHeight() != 0) {
            int bitmapSizeInDip = UiUtils.dpToPixel(sizeInDp);
            if (bitmap.getHeight() != bitmapSizeInDip) {
                Bitmap tmp = bitmap;//from   www. j  a va2s  . c  o  m
                bitmap = Bitmap.createScaledBitmap(tmp, bitmapSizeInDip, bitmapSizeInDip, false);
                tmp.recycle();
            }

            return bitmap;
        }
    }

    return null;
}