Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 058473c7 authored by Rohit Yengisetty's avatar Rohit Yengisetty
Browse files

Constrain logo bounds within the picker for caller-info provider

Change-Id: I9017f6bd9a3b28e4c60d67acd030960e61f9be89
Issue-Id: CYNGNOS-2844
(cherry picked from commit 9fb1a7b0)
parent 1eec8c6e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -15,4 +15,6 @@
    <dimen name="coachmark_hint_text">14sp</dimen>
    <dimen name="coachmark_touch_padding">14sp</dimen>

    <dimen name="callerinfo_provider_picker_logo_width">98dp</dimen>
    <dimen name="callerinfo_provider_picker_logo_height">20dp</dimen>
</resources>
 No newline at end of file
+7 −3
Original line number Diff line number Diff line
@@ -144,8 +144,12 @@ public class CallerInfoProviderPicker {
            subText = Html.fromHtml(text);
        }

        int logoWidth = context.getResources().getDimensionPixelSize(
                R.dimen.callerinfo_provider_picker_logo_width);
        int logoHeight = context.getResources().getDimensionPixelSize(
                R.dimen.callerinfo_provider_picker_logo_height);
        Bitmap logo = ImageUtils.drawableToBitmap(info.getBrandLogo());

        Bitmap scaledLogo = ImageUtils.scaleBitmapToTarget(logo, logoHeight, logoWidth);
        int resId = info.hasProperty(ProviderInfo.PROPERTY_SUPPORTS_SPAM) ?
                R.string.callerinfo_provider_auth_desc :
                R.string.callerinfo_provider_auth_desc_no_spam;
@@ -158,8 +162,8 @@ public class CallerInfoProviderPicker {
            nudge.setSubhead(subText.toString());
        }

        if (logo != null) {
            nudge.setTitleImage(logo);
        if (scaledLogo != null) {
            nudge.setTitleImage(scaledLogo);
        }

        Intent enableIntent = buildEnableIntent(context, component, info, metricsReason);
+12 −17
Original line number Diff line number Diff line
@@ -77,10 +77,9 @@ public class ImageUtils {

    /**
     * Scale bitmap to the defined bounds. The bitmap will be scaled while maintaining the
     * aspect ratio and center-cropped(vertically and horizontally) if it exceeds the
     * defined bounds.
     * aspect ratio
     */
    public static Bitmap scaleAndCropBitmapToTarget(Bitmap bitmap, int targetHeight,
    public static Bitmap scaleBitmapToTarget(Bitmap bitmap, int targetHeight,
            int targetWidth) {
        if (bitmap == null) {
            return bitmap;
@@ -89,25 +88,23 @@ public class ImageUtils {
        int bitmapHeight = bitmap.getHeight();
        int bitmapWidth = bitmap.getWidth();

        int deltaWidth = targetWidth - bitmapWidth;
        int deltaHeight = targetHeight - bitmapHeight;
        int deltaWidth = Math.abs(targetWidth - bitmapWidth);
        int deltaHeight = Math.abs(targetHeight - bitmapHeight);

        // nothing to do if src bitmap is bigger than or equal to the target
        if (deltaWidth <= 0 && deltaHeight <= 0)
        // nothing to do if one of the dimensions doesn't change as the aspect ratio
        // needs to be preserved
        if (deltaWidth == 0 || deltaHeight == 0)
            return bitmap;

        // scale bitmap along the dimension that is lacking the greatest
        float scale = Math.max( ((float)targetWidth) / bitmapWidth,
        // scale bitmap to fit target bounds
        float scale = Math.min( ((float)targetWidth) / bitmapWidth,
                ((float)targetHeight) / bitmapHeight);

        // calculate the new bitmap dimensions
        int newHeight = (int) Math.ceil(bitmapHeight * scale);
        int newWidth = (int) Math.ceil(bitmapWidth * scale);
        int newHeight = (int) Math.floor(bitmapHeight * scale);
        int newWidth = (int) Math.floor(bitmapWidth * scale);
        Bitmap scaledBitmap =  Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);

        // center the bitmap vertically and horizontally
        int startX = Math.max(0, (newWidth - targetWidth) / 2);
        int startY = Math.max(0, (newHeight - targetHeight) / 2);
        if (DEBUG) {
            Log.i(TAG, "bitmapWidth : " + bitmapWidth);
            Log.i(TAG, "bitmapHeight : " + bitmapHeight);
@@ -115,11 +112,9 @@ public class ImageUtils {
            Log.i(TAG, "deltaHeight : " + deltaHeight);
            Log.i(TAG, "newWidth : " + newWidth);
            Log.i(TAG, "newHeight : " + newHeight);
            Log.i(TAG, "startX : " + startX);
            Log.i(TAG, "startY : " + startY);
        }

        return Bitmap.createBitmap(scaledBitmap, startX, startY, targetWidth, targetHeight);
        return scaledBitmap;
    }

    /**