Java Code Examples for android.graphics.Shader.TileMode#MIRROR

The following examples show how to use android.graphics.Shader.TileMode#MIRROR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoundedImageView.java    From letv with Apache License 2.0 5 votes vote down vote up
private static TileMode parseTileMode(int tileMode) {
    switch (tileMode) {
        case 0:
            return TileMode.CLAMP;
        case 1:
            return TileMode.REPEAT;
        case 2:
            return TileMode.MIRROR;
        default:
            return null;
    }
}
 
Example 2
Source File: SlideView.java    From SpecialAlarmClock with Apache License 2.0 5 votes vote down vote up
public SlideView(Context context, AttributeSet attrs) {
    super(context, attrs);
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaxVelocity = configuration.getScaledMaximumFlingVelocity();
    mInterpolator = new AccelerateDecelerateInterpolator();
    mDensity = getResources().getDisplayMetrics().density;
    setClickable(true);
    setFocusable(true);
    setFocusableInTouchMode(true);

    TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.SlideView);
    mText = typeArray.getString(R.styleable.SlideView_maskText);
    mTextSize = typeArray.getDimensionPixelSize(R.styleable.SlideView_maskTextSize, R.dimen.mask_text_size);
    mTextLeft = typeArray.getDimensionPixelSize(R.styleable.SlideView_maskTextMarginLeft, R.dimen.mask_text_margin_left);
    mTextTop = typeArray.getDimensionPixelSize(R.styleable.SlideView_maskTextMarginTop, R.dimen.mask_text_margin_top);

    mSlider = typeArray.getResourceId(R.styleable.SlideView_slider, R.mipmap.app_icon);
    mSliderLeft = typeArray.getDimensionPixelSize(R.styleable.SlideView_sliderMarginLeft, R.dimen.slider_margin_left);
    mSliderTop = typeArray.getDimensionPixelSize(R.styleable.SlideView_sliderMarginTop, R.dimen.slider_margin_top);
    mSliderBitmap = BitmapFactory.decodeResource(getResources(), mSlider);
    mSliderRect = new Rect(mSliderLeft, mSliderTop, mSliderLeft + mSliderBitmap.getWidth(), mSliderTop + mSliderBitmap.getHeight());

    mSlidableLength = typeArray.getDimensionPixelSize(R.styleable.SlideView_slidableLength, R.dimen.slidable_length);
    mEffectiveLength = typeArray.getDimensionPixelSize(R.styleable.SlideView_effectiveLength,
            R.dimen.effective_length);
    mEffectiveVelocity = typeArray.getDimensionPixelSize(R.styleable.SlideView_effectiveVelocity,
            R.dimen.effective_velocity);
    typeArray.recycle();

    mGradientColors = new int[]{Color.argb(255, 120, 120, 120), Color.argb(255, 120, 120, 120), Color.argb(255, 255, 255, 255)};
    mGradient = new LinearGradient(0, 0, 100 * mDensity, 0, mGradientColors, new float[]{0, 0.7f, 1}, TileMode.MIRROR);
    mGradientIndex = 0;
    mPaint = new Paint();
    mMatrix = new Matrix();
    mPaint.setTextSize(mTextSize);
    mHandler.sendEmptyMessageDelayed(MSG_REDRAW, DRAW_INTERVAL);
}
 
Example 3
Source File: ImageTools.java    From android-tv-launcher with MIT License 5 votes vote down vote up
/**
 * 倒影图片
 * @param originalBitmap
 * @return
 */
public static Bitmap createReflectedImage(Bitmap originalBitmap) {
    final int reflectionGap = 4;
    int width = originalBitmap.getWidth();
    int height = originalBitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(originalBitmap, 0,
            height / 2, width, height / 2, matrix, false);
    Bitmap withReflectionBitmap = Bitmap.createBitmap(width, (height
            + height / 2 + reflectionGap), Config.ARGB_8888);
    Canvas canvas = new Canvas(withReflectionBitmap);
    canvas.drawBitmap(originalBitmap, 0, 0, null);
    Paint defaultPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
    canvas.drawBitmap(reflectionBitmap, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0,
            originalBitmap.getHeight(), 0,
            withReflectionBitmap.getHeight(), 0x70ffffff, 0x00ffffff,
            TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

    canvas.drawRect(0, height, width, withReflectionBitmap.getHeight(),
            paint);

    return withReflectionBitmap;
}
 
Example 4
Source File: BitmapUtils.java    From Cangol-appcore with Apache License 2.0 5 votes vote down vote up
/**
 * 创建倒影
 *
 * @param originalImage
 * @return
 */
public static Bitmap createReflectedImage(Bitmap originalImage) {
    final int reflectionGap = 4;  //倒影和原图片间的距离
    final int width = originalImage.getWidth();
    final int height = originalImage.getHeight();

    final Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    //倒影部分
    final Bitmap reflectionImage = Bitmap.createBitmap(originalImage,
            0, height / 2, width, height / 2, matrix, false);
    //要返回的倒影图片
    final Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
            (height + height / 2), Config.ARGB_8888);

    final Canvas canvas = new Canvas(bitmapWithReflection);
    //画原来的图片
    canvas.drawBitmap(originalImage, 0, 0, null);

    final Paint defaultPaint = new Paint();
    //倒影和原图片间的距离
    canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
    //画倒影部分
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    final Paint paint = new Paint();
    final LinearGradient shader = new LinearGradient(0, originalImage.getHeight(),
            0, bitmapWithReflection.getHeight() + reflectionGap,
            0x70ffffff, 0x00ffffff,
            TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
    return bitmapWithReflection;
}