当前位置: 首页>>代码示例>>Java>>正文


Java PaintDrawable.setShape方法代码示例

本文整理汇总了Java中android.graphics.drawable.PaintDrawable.setShape方法的典型用法代码示例。如果您正苦于以下问题:Java PaintDrawable.setShape方法的具体用法?Java PaintDrawable.setShape怎么用?Java PaintDrawable.setShape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.drawable.PaintDrawable的用法示例。


在下文中一共展示了PaintDrawable.setShape方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
public static Drawable drawable(final int[] colorBoxes, final float[] position, final GradientAngle gradientAngle) {
    ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            AngleCoordinate ac = AngleCoordinate.getAngleCoordinate(gradientAngle, width, height);
            LinearGradient linearGradient = new LinearGradient(ac.x1, ac.y1, ac.x2, ac.y2,
                    colorBoxes,
                    position,
                    Shader.TileMode.REPEAT);
            return linearGradient;
        }
    };
    PaintDrawable paint = new PaintDrawable();
    paint.setShape(new RectShape());
    paint.setShaderFactory(shaderFactory);
    return paint;
}
 
开发者ID:akshay2211,项目名称:Ariana,代码行数:18,代码来源:Ariana.java

示例2: createDrawableFrom

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
private Drawable createDrawableFrom(ShapeDrawable.ShaderFactory sf) {
    PaintDrawable p = new PaintDrawable();
    p.setShape(new RectShape());
    p.setShaderFactory(sf);

    return p;
}
 
开发者ID:alxgrk,项目名称:BlendedBackground,代码行数:8,代码来源:Gradient.java

示例3: getColorScala

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
public PaintDrawable getColorScala() {
    ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(width, height, 0, 0,
                    new int[]{
                            getResources().getColor(R.color.altitude_0_100),
                            getResources().getColor(R.color.altitude_100_300),
                            getResources().getColor(R.color.altitude_300_500),
                            getResources().getColor(R.color.altitude_500_1000),
                            getResources().getColor(R.color.altitude_1000_1500),
                            getResources().getColor(R.color.altitude_1500_2000),
                            getResources().getColor(R.color.altitude_2000_2500),
                            getResources().getColor(R.color.altitude_more_than_2500)},
                    new float[]{
                            0, 0.07f, 0.14f, 0.28f, 0.42f, 0.56f, 0.7f, 0.84f},
                    Shader.TileMode.REPEAT);
            return linearGradient;
        }
    };

    PaintDrawable paint = new PaintDrawable();
    paint.setShape(new RectShape());
    paint.setShaderFactory(shaderFactory);

    return paint;
}
 
开发者ID:santiago-hollmann,项目名称:igcparser,代码行数:28,代码来源:FlightPreviewActivity.java

示例4: makeCubicGradientScrimDrawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtil.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}
 
开发者ID:htqqdd,项目名称:music_player,代码行数:64,代码来源:ScrimUtil.java

示例5: getPaintDrawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
public static PaintDrawable getPaintDrawable(int startX, int endX) {
  PaintDrawable drawable = new PaintDrawable();
  drawable.setShape(new RectShape());
  drawable.setShaderFactory(getShaderFactory(startX, endX));
  return drawable;
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:7,代码来源:QuranDisplayHelper.java

示例6: makeCubicGradientScrimDrawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
/**
 * This helper method creates a 'nice' scrim or background protection for layering text over
 * an image. This non-linear scrim is less noticable than a linear or constant one.
 *
 * Borrowed from github.com/romannurik/muzei
 *
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        double x = i * 1f / (numStops - 1);
        double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
        stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:55,代码来源:UIUtils.java

示例7: getCubicGradient

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
public static Drawable getCubicGradient(int baseColor, int gravity) {
    PaintDrawable drawable = new PaintDrawable();
    drawable.setShape(new RectShape());
    setCubicGradient(drawable, baseColor, gravity);
    return drawable;
}
 
开发者ID:gnosygnu,项目名称:xowa_android,代码行数:7,代码来源:GradientUtil.java

示例8: makeCubicGradientScrimDrawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(@ColorInt int baseColor,
                                                      int numStops,
                                                      int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtils.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = ColorUtils.modifyAlpha(baseColor, (int) (alpha * opacity));
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:
            x0 = 1;
            x1 = 0;
            break;
        case Gravity.RIGHT:
            x0 = 0;
            x1 = 1;
            break;
        default:
            x0 = 0;
            x1 = 0;
            break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            y0 = 1;
            y1 = 0;
            break;
        case Gravity.BOTTOM:
            y0 = 0;
            y1 = 1;
            break;
        default:
            y0 = 0;
            y1 = 0;
            break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
 
开发者ID:liulinbo,项目名称:Amumu,代码行数:70,代码来源:ScrimUtil.java

示例9: makeCubicGradientScrimDrawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
       /* float opacity = MathUtil.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);*/
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}
 
开发者ID:glassLake,项目名称:DialogUtils,代码行数:65,代码来源:ScrimUtil.java

示例10: makeCubicGradientScrimDrawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtil.constrain(0, 1, FloatMath.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
 
开发者ID:chrislacy,项目名称:AndroidLiveWallpaperHelloWorld,代码行数:53,代码来源:ScrimUtil.java

示例11: makeCubicGradientScrimDrawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.START:
            x0 = 1;
            x1 = 0;
            break;
        case Gravity.END:
            x0 = 0;
            x1 = 1;
            break;
        default:
            x0 = 0;
            x1 = 0;
            break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            y0 = 1;
            y1 = 0;
            break;
        case Gravity.BOTTOM:
            y0 = 0;
            y1 = 1;
            break;
        default:
            y0 = 0;
            y1 = 0;
            break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
        }
    });

    return paintDrawable;
}
 
开发者ID:plusCubed,项目名称:anticipate,代码行数:70,代码来源:ScrimUtil.java

示例12: makeCubicGradientScrimDrawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);

        float opacity = (float) Math.max(0, Math.min(1, Math.pow(x, 3)));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
 
开发者ID:imojiengineering,项目名称:imoji-android-sdk-ui,代码行数:54,代码来源:ScrimUtil.java

示例13: makeCubicGradientScrimDrawable

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
/**
 * This helper method creates a 'nice' scrim or background protection for layering text over an
 * image. This non-linear scrim is less noticable than a linear or constant one.
 * <p/>
 * Borrowed from github.com/romannurik/muzei
 * <p/>
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See <a
 * href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops,
        int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        double x = i * 1f / (numStops - 1);
        double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
        stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        //noinspection RtlHardcoded
        case Gravity.LEFT:
            x0 = 1;
            x1 = 0;
            break;
        //noinspection RtlHardcoded
        case Gravity.RIGHT:
            x0 = 0;
            x1 = 1;
            break;
        default:
            x0 = 0;
            x1 = 0;
            break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            y0 = 1;
            y1 = 0;
            break;
        case Gravity.BOTTOM:
            y0 = 0;
            y1 = 1;
            break;
        default:
            y0 = 0;
            y1 = 0;
            break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
 
开发者ID:google,项目名称:iosched,代码行数:75,代码来源:UIUtils.java

示例14: getPowerGradient

import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
public static Drawable getPowerGradient(@ColorRes int baseColor, int gravity) {
    PaintDrawable drawable = new PaintDrawable();
    drawable.setShape(new RectShape());
    setPowerGradient(drawable, ContextCompat.getColor(WikipediaApp.getInstance(), baseColor), gravity);
    return drawable;
}
 
开发者ID:wikimedia,项目名称:apps-android-wikipedia,代码行数:7,代码来源:GradientUtil.java


注:本文中的android.graphics.drawable.PaintDrawable.setShape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。