Example usage for android.graphics Color alpha

List of usage examples for android.graphics Color alpha

Introduction

In this page you can find the example usage for android.graphics Color alpha.

Prototype

@IntRange(from = 0, to = 255)
public static int alpha(int color) 

Source Link

Document

Return the alpha component of a color int.

Usage

From source file:android.car.ui.provider.CarDrawerLayout.java

private void updateViewFaders() {
    if (!mHasInflated) {
        return;//from   w  w  w  .  j  a va2  s  . co m
    }

    float fadeProgress;
    if (mStartedOpen) {
        fadeProgress = mViewFaderInterpolator.getReverseInterpolation(onScreen());
    } else {
        fadeProgress = mViewFaderInterpolator.getForwardInterpolation(onScreen());
    }
    for (Iterator<ViewFaderHolder> it = mViewFaders.iterator(); it.hasNext();) {
        ViewFaderHolder viewFaderHolder = it.next();
        int startingColor = viewFaderHolder.startingColor;
        int endingColor = viewFaderHolder.endingColor;
        int alpha = weightedAverage(Color.alpha(startingColor), Color.alpha(endingColor), fadeProgress);
        int red = weightedAverage(Color.red(startingColor), Color.red(endingColor), fadeProgress);
        int green = weightedAverage(Color.green(startingColor), Color.green(endingColor), fadeProgress);
        int blue = weightedAverage(Color.blue(startingColor), Color.blue(endingColor), fadeProgress);
        viewFaderHolder.viewFader.setColor(alpha << 24 | red << 16 | green << 8 | blue);
    }
}

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap bright(Bitmap bmImage, int brightness) {
    Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig());

    for (int i = 0; i < bmImage.getWidth(); i++) {
        for (int j = 0; j < bmImage.getHeight(); j++) {
            int p = bmImage.getPixel(i, j);
            int r = Color.red(p);
            int g = Color.green(p);
            int b = Color.blue(p);
            int alpha = Color.alpha(p);

            r += brightness;//from ww  w .  j  a  va2 s  .c  om
            g += brightness;
            b += brightness;
            alpha += brightness;
            r = r < 0 ? 0 : (r > 255 ? 255 : r);
            g = g < 0 ? 0 : (g > 255 ? 255 : g);
            b = b < 0 ? 0 : (b > 255 ? 255 : b);
            alpha = alpha < 0 ? 0 : (alpha > 255 ? 255 : alpha);

            bmTemp.setPixel(i, j, Color.argb(alpha, r, g, b));
        }
    }

    return bmTemp;
}

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap tint(Bitmap bmImage, int degree) {
    Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig());

    double angle = (3.14159d * (double) degree) / 180.0d;
    int S = (int) (256.0d * Math.sin(angle));
    int C = (int) (256.0d * Math.cos(angle));

    for (int i = 0; i < bmImage.getWidth(); i++) {
        for (int j = 0; j < bmImage.getHeight(); j++) {
            int p = bmImage.getPixel(i, j);
            int r = Color.red(p);
            int g = Color.green(p);
            int b = Color.blue(p);
            // int alpha = Color.alpha(p);

            int RY = (70 * r - 59 * g - 11 * b) / 100;
            int BY = (-30 * r - 59 * g + 89 * b) / 100;
            int Y = (30 * r + 59 * g + 11 * b) / 100;
            int RYY = (S * BY + C * RY) / 256;
            int BYY = (C * BY - S * RY) / 256;
            int GYY = (-51 * RYY - 19 * BYY) / 100;
            r = Y + RYY;//from  w w  w . ja va  2s  .  c  o  m
            r = (r < 0) ? 0 : ((r > 255) ? 255 : r);
            g = Y + GYY;
            g = (g < 0) ? 0 : ((g > 255) ? 255 : g);
            b = Y + BYY;
            b = (b < 0) ? 0 : ((b > 255) ? 255 : b);
            bmTemp.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
        }
    }

    return bmTemp;
}

From source file:com.cosmicsubspace.nerdyaudio.visuals.PlayControlsView.java

protected int rampColor(int colorA, int colorB, float ramp) {
    //Log2.log(1,this,"Ramping color..."+colorA+" | "+colorB+" | "+ramp);
    return Color.argb(Math.round(Color.alpha(colorA) * ramp + Color.alpha(colorB) * (1.0f - ramp)),
            Math.round(Color.red(colorA) * ramp + Color.red(colorB) * (1.0f - ramp)),
            Math.round(Color.green(colorA) * ramp + Color.green(colorB) * (1.0f - ramp)),
            Math.round(Color.blue(colorA) * ramp + Color.blue(colorB) * (1.0f - ramp)));

}

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap mozac(Bitmap bmImage, int level) {
    Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig());

    for (int i = 0; i < bmImage.getWidth(); i += level) {
        for (int j = 0; j < bmImage.getHeight(); j += level) {
            int p = 0;
            int r = 0;
            int g = 0;
            int b = 0;

            // compute neighboring area index
            int kx_start = i - level;
            int kx_end = i + level;
            int ky_start = j - level;
            int ky_end = j + level;

            // filter out boundary index
            kx_start = Math.max(0, kx_start);
            kx_end = Math.min(bmImage.getWidth() - 1, kx_end);
            ky_start = Math.max(0, ky_start);
            ky_end = Math.min(bmImage.getHeight() - 1, ky_end);

            // summing and averaging color value within the neighboring area
            for (int ki = kx_start; ki <= kx_end; ki++) {
                for (int kj = ky_start; kj <= ky_end; kj++) {
                    p = bmImage.getPixel(ki, kj);
                    r += Color.red(p);
                    g += Color.green(p);
                    b += Color.blue(p);
                }/*from w ww.j a  va 2 s  .co  m*/
            }

            int n = (kx_end - kx_start + 1) * (ky_end - ky_start + 1);
            r /= n;
            g /= n;
            b /= n;

            // copy color value to each pixel on neighboring area
            for (int kx = kx_start; kx <= kx_end; kx++) {
                for (int ky = ky_start; ky <= ky_end; ky++) {
                    bmTemp.setPixel(kx, ky, Color.argb(Color.alpha(p), r, g, b));
                }
            }

        } // /for(j)
    } // /for(i)

    return bmTemp;
}

From source file:com.rks.musicx.misc.utils.Helper.java

@ColorInt
public static int setColorAlpha(@ColorInt int color, @FloatRange(from = 0.0D, to = 1.0D) float alpha) {
    int alpha2 = Math.round((float) Color.alpha(color) * alpha);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha2, red, green, blue);
}

From source file:net.rossharper.coloredtablayout.TabLayout.java

static int lerpColor(int startColor, int endColor, float fraction) {

    return Color.argb((int) lerp(Color.alpha(startColor), Color.alpha(endColor), fraction),
            (int) lerp(Color.red(startColor), Color.red(endColor), fraction),
            (int) lerp(Color.green(startColor), Color.green(endColor), fraction),
            (int) lerp(Color.blue(startColor), Color.blue(endColor), fraction));
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

private View getView(List<AppEntry> list, int position) {
    View convertView = View.inflate(this, R.layout.icon, null);

    final AppEntry entry = list.get(position);
    final SharedPreferences pref = U.getSharedPreferences(this);

    ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    ImageView imageView2 = (ImageView) convertView.findViewById(R.id.shortcut_icon);
    imageView.setImageDrawable(entry.getIcon(this));
    imageView2.setBackgroundColor(// w w w . j  av a 2s. c  o m
            pref.getInt("accent_color", getResources().getInteger(R.integer.translucent_white)));

    String taskbarPosition = U.getTaskbarPosition(this);
    if (pref.getBoolean("shortcut_icon", true)) {
        boolean shouldShowShortcutIcon;
        if (taskbarPosition.contains("vertical"))
            shouldShowShortcutIcon = position >= list.size() - numOfPinnedApps;
        else
            shouldShowShortcutIcon = position < numOfPinnedApps;

        if (shouldShowShortcutIcon)
            imageView2.setVisibility(View.VISIBLE);
    }

    if (taskbarPosition.equals("bottom_right") || taskbarPosition.equals("top_right")) {
        imageView.setRotationY(180);
        imageView2.setRotationY(180);
    }

    FrameLayout layout = (FrameLayout) convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> U.launchApp(TaskbarService.this, entry.getPackageName(),
            entry.getComponentName(), entry.getUserId(TaskbarService.this), null, true, false));

    layout.setOnLongClickListener(view -> {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        openContextMenu(entry, location);
        return true;
    });

    layout.setOnGenericMotionListener((view, motionEvent) -> {
        int action = motionEvent.getAction();

        if (action == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(entry, location);
        }

        if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
            view.setBackgroundColor(0);

        return false;
    });

    if (pref.getBoolean("visual_feedback", true)) {
        layout.setOnHoverListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
                int accentColor = U.getAccentColor(TaskbarService.this);
                accentColor = ColorUtils.setAlphaComponent(accentColor, Color.alpha(accentColor) / 2);
                v.setBackgroundColor(accentColor);
            }

            if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
                v.setBackgroundColor(0);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(TaskbarService.this, PointerIcon.TYPE_DEFAULT));

            return false;
        });

        layout.setOnTouchListener((v, event) -> {
            v.setAlpha(
                    event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                            ? 0.5f
                            : 1);
            return false;
        });
    }

    return convertView;
}

From source file:com.alexcruz.papuhwalls.MainActivity.java

public static int tint(int color, double factor) {
    int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    return Color.argb(a, Math.max((int) (r * factor), 0), Math.max((int) (g * factor), 0),
            Math.max((int) (b * factor), 0));
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static int adjustColorAlpha(final int color, final float factor) {
    int alpha = Math.round(Color.alpha(color) * factor);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha, red, green, blue);
}