Search in sources :

Example 56 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class TypefaceTest method testUniformY.

@MediumTest
public void testUniformY() throws Exception {
    Paint p = new Paint();
    final int n = mFaces.length;
    for (int i = 1; i <= 36; i++) {
        p.setTextSize(i);
        float ascent = 0;
        float descent = 0;
        for (int j = 0; j < n; j++) {
            p.setTypeface(mFaces[j]);
            Paint.FontMetrics fm = p.getFontMetrics();
            if (j == 0) {
                ascent = fm.ascent;
                descent = fm.descent;
            } else {
                assertTrue("fontMetrics", fm.ascent == ascent);
                assertTrue("fontMetrics", fm.descent == descent);
            }
        }
    }
}
Also used : Paint(android.graphics.Paint) Paint(android.graphics.Paint) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 57 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class RemoteControlClient method scaleBitmapIfTooBig.

//===========================================================
// Internal utilities
/**
     * Scale a bitmap to fit the smallest dimension by uniformly scaling the incoming bitmap.
     * If the bitmap fits, then do nothing and return the original.
     *
     * @param bitmap
     * @param maxWidth
     * @param maxHeight
     * @return
     */
private Bitmap scaleBitmapIfTooBig(Bitmap bitmap, int maxWidth, int maxHeight) {
    if (bitmap != null) {
        final int width = bitmap.getWidth();
        final int height = bitmap.getHeight();
        if (width > maxWidth || height > maxHeight) {
            float scale = Math.min((float) maxWidth / width, (float) maxHeight / height);
            int newWidth = Math.round(scale * width);
            int newHeight = Math.round(scale * height);
            Bitmap.Config newConfig = bitmap.getConfig();
            if (newConfig == null) {
                newConfig = Bitmap.Config.ARGB_8888;
            }
            Bitmap outBitmap = Bitmap.createBitmap(newWidth, newHeight, newConfig);
            Canvas canvas = new Canvas(outBitmap);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setFilterBitmap(true);
            canvas.drawBitmap(bitmap, null, new RectF(0, 0, outBitmap.getWidth(), outBitmap.getHeight()), paint);
            bitmap = outBitmap;
        }
    }
    return bitmap;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 58 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class BaseStatusBar method toggleRecentsActivity.

protected void toggleRecentsActivity() {
    try {
        TaskDescription firstTask = RecentTasksLoader.getInstance(mContext).getFirstTask();
        Intent intent = new Intent(RecentsActivity.TOGGLE_RECENTS_INTENT);
        intent.setClassName("com.android.systemui", "com.android.systemui.recent.RecentsActivity");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        if (firstTask == null) {
            if (RecentsActivity.forceOpaqueBackground(mContext)) {
                ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext, R.anim.recents_launch_from_launcher_enter, R.anim.recents_launch_from_launcher_exit);
                mContext.startActivityAsUser(intent, opts.toBundle(), new UserHandle(UserHandle.USER_CURRENT));
            } else {
                // The correct window animation will be applied via the activity's style
                mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
            }
        } else {
            Bitmap first = firstTask.getThumbnail();
            final Resources res = mContext.getResources();
            float thumbWidth = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_width);
            float thumbHeight = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_height);
            if (first == null) {
                throw new RuntimeException("Recents thumbnail is null");
            }
            if (first.getWidth() != thumbWidth || first.getHeight() != thumbHeight) {
                first = Bitmap.createScaledBitmap(first, (int) thumbWidth, (int) thumbHeight, true);
                if (first == null) {
                    throw new RuntimeException("Recents thumbnail is null");
                }
            }
            DisplayMetrics dm = new DisplayMetrics();
            mDisplay.getMetrics(dm);
            // calculate it here, but consider moving it elsewhere
            // first, determine which orientation you're in.
            // todo: move the system_bar layouts to sw600dp ?
            final Configuration config = res.getConfiguration();
            int x, y;
            if (config.orientation == Configuration.ORIENTATION_PORTRAIT) {
                float appLabelLeftMargin = res.getDimensionPixelSize(R.dimen.status_bar_recents_app_label_left_margin);
                float appLabelWidth = res.getDimensionPixelSize(R.dimen.status_bar_recents_app_label_width);
                float thumbLeftMargin = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_left_margin);
                float thumbBgPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_bg_padding);
                float width = appLabelLeftMargin + +appLabelWidth + thumbLeftMargin + thumbWidth + 2 * thumbBgPadding;
                x = (int) ((dm.widthPixels - width) / 2f + appLabelLeftMargin + appLabelWidth + thumbBgPadding + thumbLeftMargin);
                y = (int) (dm.heightPixels - res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_height) - thumbBgPadding);
                if (mLayoutDirection == View.LAYOUT_DIRECTION_RTL) {
                    x = dm.widthPixels - x - res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_width);
                }
            } else {
                // if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                float thumbTopMargin = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_top_margin);
                float thumbBgPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_bg_padding);
                float textPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_text_description_padding);
                float labelTextSize = res.getDimensionPixelSize(R.dimen.status_bar_recents_app_label_text_size);
                Paint p = new Paint();
                p.setTextSize(labelTextSize);
                float labelTextHeight = p.getFontMetricsInt().bottom - p.getFontMetricsInt().top;
                float descriptionTextSize = res.getDimensionPixelSize(R.dimen.status_bar_recents_app_description_text_size);
                p.setTextSize(descriptionTextSize);
                float descriptionTextHeight = p.getFontMetricsInt().bottom - p.getFontMetricsInt().top;
                float statusBarHeight = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
                float recentsItemTopPadding = statusBarHeight;
                float height = thumbTopMargin + thumbHeight + 2 * thumbBgPadding + textPadding + labelTextHeight + recentsItemTopPadding + textPadding + descriptionTextHeight;
                float recentsItemRightPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_item_padding);
                float recentsScrollViewRightPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_right_glow_margin);
                x = (int) (dm.widthPixels - res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_width) - thumbBgPadding - recentsItemRightPadding - recentsScrollViewRightPadding);
                y = (int) ((dm.heightPixels - statusBarHeight - height) / 2f + thumbTopMargin + recentsItemTopPadding + thumbBgPadding + statusBarHeight);
            }
            ActivityOptions opts = ActivityOptions.makeThumbnailScaleDownAnimation(getStatusBarView(), first, x, y, new ActivityOptions.OnAnimationStartedListener() {

                public void onAnimationStarted() {
                    Intent intent = new Intent(RecentsActivity.WINDOW_ANIMATION_START_INTENT);
                    intent.setPackage("com.android.systemui");
                    mContext.sendBroadcastAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
                }
            });
            intent.putExtra(RecentsActivity.WAITING_FOR_WINDOW_ANIMATION_PARAM, true);
            mContext.startActivityAsUser(intent, opts.toBundle(), new UserHandle(UserHandle.USER_CURRENT));
        }
        return;
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Failed to launch RecentAppsIntent", e);
    }
}
Also used : Configuration(android.content.res.Configuration) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Paint(android.graphics.Paint) DisplayMetrics(android.util.DisplayMetrics) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) TaskDescription(com.android.systemui.recent.TaskDescription) ActivityNotFoundException(android.content.ActivityNotFoundException) UserHandle(android.os.UserHandle) Resources(android.content.res.Resources) ActivityOptions(android.app.ActivityOptions)

Example 59 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class BaseStatusBar method prepareHaloNotification.

public void prepareHaloNotification(NotificationData.Entry entry, StatusBarNotification notification, boolean update) {
    Notification notif = notification.getNotification();
    // Get the remote view
    try {
        if (!update) {
            ViewGroup mainView = (ViewGroup) notif.contentView.apply(mContext, null, mOnClickHandler);
            if (mainView instanceof FrameLayout) {
                entry.haloContent = mainView.getChildAt(1);
                mainView.removeViewAt(1);
            } else {
                entry.haloContent = mainView;
            }
        } else {
            notif.contentView.reapply(mContext, entry.haloContent, mOnClickHandler);
        }
    } catch (Exception e) {
        // Non uniform content?
        android.util.Log.d("PARANOID", "   Non uniform content?");
    }
    // Construct the round icon
    final float haloSize = Settings.System.getFloat(mContext.getContentResolver(), Settings.System.HALO_SIZE, 1.0f);
    int iconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.halo_bubble_size) * haloSize);
    int smallIconSize = (int) (mContext.getResources().getDimensionPixelSize(R.dimen.status_bar_icon_size) * haloSize);
    int largeIconWidth = notif.largeIcon != null ? (int) (notif.largeIcon.getWidth() * haloSize) : 0;
    int largeIconHeight = notif.largeIcon != null ? (int) (notif.largeIcon.getHeight() * haloSize) : 0;
    Bitmap roundIcon = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(roundIcon);
    canvas.drawARGB(0, 0, 0, 0);
    // halo-bubble, we'll use that one and cut it round
    if (notif.largeIcon != null && largeIconWidth >= iconSize / 2) {
        Paint smoothingPaint = new Paint();
        smoothingPaint.setAntiAlias(true);
        smoothingPaint.setFilterBitmap(true);
        smoothingPaint.setDither(true);
        canvas.drawCircle(iconSize / 2, iconSize / 2, iconSize / 2.3f, smoothingPaint);
        smoothingPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        final int newWidth = iconSize;
        final int newHeight = iconSize * largeIconWidth / largeIconHeight;
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(notif.largeIcon, newWidth, newHeight, true);
        canvas.drawBitmap(scaledBitmap, null, new Rect(0, 0, iconSize, iconSize), smoothingPaint);
    } else {
        try {
            Drawable icon = StatusBarIconView.getIcon(mContext, new StatusBarIcon(notification.getPackageName(), notification.getUser(), notif.icon, notif.iconLevel, notif.number, notif.tickerText));
            if (icon == null)
                icon = mContext.getPackageManager().getApplicationIcon(notification.getPackageName());
            int margin = (iconSize - smallIconSize) / 2;
            icon.setBounds(margin, margin, iconSize - margin, iconSize - margin);
            icon.draw(canvas);
        } catch (Exception e) {
        // NameNotFoundException
        }
    }
    entry.roundIcon = roundIcon;
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Paint(android.graphics.Paint) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) FrameLayout(android.widget.FrameLayout) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon)

Example 60 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class RecentsScrollViewPerformanceHelper method drawCallback.

public void drawCallback(Canvas canvas, int left, int right, int top, int bottom, int scrollX, int scrollY, float topFadingEdgeStrength, float bottomFadingEdgeStrength, float leftFadingEdgeStrength, float rightFadingEdgeStrength, int mPaddingTop) {
    if ((mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) || USE_DARK_FADE_IN_HW_ACCELERATED_MODE) {
        if (mFadePaint == null) {
            mFadePaint = new Paint();
            mFadeMatrix = new Matrix();
            // use use a height of 1, and then wack the matrix each time we
            // actually use it.
            mFade = new LinearGradient(0, 0, 0, 1, 0xCC000000, 0, Shader.TileMode.CLAMP);
            // PULL OUT THIS CONSTANT
            mFadePaint.setShader(mFade);
        }
        // draw the fade effect
        boolean drawTop = false;
        boolean drawBottom = false;
        boolean drawLeft = false;
        boolean drawRight = false;
        float topFadeStrength = 0.0f;
        float bottomFadeStrength = 0.0f;
        float leftFadeStrength = 0.0f;
        float rightFadeStrength = 0.0f;
        final float fadeHeight = mFadingEdgeLength;
        int length = (int) fadeHeight;
        // overlapping fades produce odd-looking artifacts
        if (mIsVertical && (top + length > bottom - length)) {
            length = (bottom - top) / 2;
        }
        // also clip horizontal fades if necessary
        if (!mIsVertical && (left + length > right - length)) {
            length = (right - left) / 2;
        }
        if (mIsVertical) {
            topFadeStrength = Math.max(0.0f, Math.min(1.0f, topFadingEdgeStrength));
            drawTop = topFadeStrength * fadeHeight > 1.0f;
            bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, bottomFadingEdgeStrength));
            drawBottom = bottomFadeStrength * fadeHeight > 1.0f;
        }
        if (!mIsVertical) {
            leftFadeStrength = Math.max(0.0f, Math.min(1.0f, leftFadingEdgeStrength));
            drawLeft = leftFadeStrength * fadeHeight > 1.0f;
            rightFadeStrength = Math.max(0.0f, Math.min(1.0f, rightFadingEdgeStrength));
            drawRight = rightFadeStrength * fadeHeight > 1.0f;
        }
        if (drawTop) {
            mFadeMatrix.setScale(1, fadeHeight * topFadeStrength);
            mFadeMatrix.postTranslate(left, top);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(left, top, right, top + length, mFadePaint);
            if (mBlackPaint == null) {
                // Draw under the status bar at the top
                mBlackPaint = new Paint();
                mBlackPaint.setColor(0xFF000000);
            }
            canvas.drawRect(left, top - mPaddingTop, right, top, mBlackPaint);
        }
        if (drawBottom) {
            mFadeMatrix.setScale(1, fadeHeight * bottomFadeStrength);
            mFadeMatrix.postRotate(180);
            mFadeMatrix.postTranslate(left, bottom);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(left, bottom - length, right, bottom, mFadePaint);
        }
        if (drawLeft) {
            mFadeMatrix.setScale(1, fadeHeight * leftFadeStrength);
            mFadeMatrix.postRotate(-90);
            mFadeMatrix.postTranslate(left, top);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(left, top, left + length, bottom, mFadePaint);
        }
        if (drawRight) {
            mFadeMatrix.setScale(1, fadeHeight * rightFadeStrength);
            mFadeMatrix.postRotate(90);
            mFadeMatrix.postTranslate(right, top);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(right - length, top, right, bottom, mFadePaint);
        }
    }
}
Also used : LinearGradient(android.graphics.LinearGradient) Matrix(android.graphics.Matrix) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)3611 Canvas (android.graphics.Canvas)815 Bitmap (android.graphics.Bitmap)735 RectF (android.graphics.RectF)484 Rect (android.graphics.Rect)400 Path (android.graphics.Path)281 TextPaint (android.text.TextPaint)269 PorterDuffXfermode (android.graphics.PorterDuffXfermode)232 Matrix (android.graphics.Matrix)173 SuppressLint (android.annotation.SuppressLint)148 Point (android.graphics.Point)147 TypedArray (android.content.res.TypedArray)134 BitmapShader (android.graphics.BitmapShader)117 View (android.view.View)103 Drawable (android.graphics.drawable.Drawable)99 BitmapDrawable (android.graphics.drawable.BitmapDrawable)92 ColorMatrix (android.graphics.ColorMatrix)76 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)66 Resources (android.content.res.Resources)65 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)57