微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.graphics.drawable.ShapeDrawable.ShaderFactory的实例源码

项目:MyCalendar    文件FloatingActionButtonLibrary.java   
private Drawable createInnerstrokesDrawable(final int color,float strokeWidth) {
  if (!mstrokeVisible) {
    return new ColorDrawable(Color.TRANSPARENT);
  }

  ShapeDrawable shapeDrawable = new ShapeDrawable(new ovalShape());

  final int bottomstrokeColor = darkenColor(color);
  final int bottomstrokeColorHalfTransparent = halfTransparent(bottomstrokeColor);
  final int topstrokeColor = lightenColor(color);
  final int topstrokeColorHalfTransparent = halfTransparent(topstrokeColor);

  final Paint paint = shapeDrawable.getPaint();
  paint.setAntiAlias(true);
  paint.setstrokeWidth(strokeWidth);
  paint.setStyle(Style.stroke);
  shapeDrawable.setShaderFactory(new ShaderFactory() {
    @Override
    public Shader resize(int width,int height) {
      return new LinearGradient(width / 2,width / 2,height,new int[] { topstrokeColor,topstrokeColorHalfTransparent,color,bottomstrokeColorHalfTransparent,bottomstrokeColor },new float[] { 0f,0.2f,0.5f,0.8f,1f },TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:TestChat    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,float strokeWidth) {
        if (!mstrokeVisible) {
                return new ColorDrawable(Color.TRANSPARENT);
        }

        ShapeDrawable shapeDrawable = new ShapeDrawable(new ovalShape());

        final int bottomstrokeColor = darkenColor(color);
        final int bottomstrokeColorHalfTransparent = halfTransparent(bottomstrokeColor);
        final int topstrokeColor = lightenColor(color);
        final int topstrokeColorHalfTransparent = halfTransparent(topstrokeColor);

        final Paint paint = shapeDrawable.getPaint();
        paint.setAntiAlias(true);
        paint.setstrokeWidth(strokeWidth);
        paint.setStyle(Style.stroke);
        shapeDrawable.setShaderFactory(new ShaderFactory() {
                @Override
                public Shader resize(int width,int height) {
                        return new LinearGradient(width / 2,new int[]{topstrokeColor,bottomstrokeColor},new float[]{0f,1f},TileMode.CLAMP
                        );
                }
        });

        return shapeDrawable;
}
项目:boohee_v5.6    文件DayView.java   
private static Drawable generateCircleDrawable(final int color) {
    ShapeDrawable drawable = new ShapeDrawable(new ovalShape());
    drawable.setShaderFactory(new ShaderFactory() {
        public Shader resize(int width,int height) {
            return new LinearGradient(0.0f,0.0f,TileMode.REPEAT);
        }
    });
    return drawable;
}
项目:IIFYM    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:FlowGeek    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:mvpChat    文件FloatingActionButton.java   
/**
 * 创建内层drawable
 *
 * @param color
 * @param strokeWidth
 * @return
 */
private Drawable createInnerstrokesDrawable(final int color,float strokeWidth) {
    //不描边的话直接返回一个颜色为透明的drawable
    if (!mstrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }
    //圆 drawable
    ShapeDrawable shapeDrawable = new ShapeDrawable(new ovalShape());

    final int bottomstrokeColor = darkenColor(color);//这个暗颜色
    final int bottomstrokeColorHalfTransparent = halfTransparent(bottomstrokeColor);//比bottomstrokeColor透明一半
    final int topstrokeColor = lightenColor(color);//这个亮颜色
    final int topstrokeColorHalfTransparent = halfTransparent(topstrokeColor);//比topstrokeColor透明一半

    final Paint paint = shapeDrawable.getPaint();
    paint.setAntiAlias(true);//锯齿
    paint.setstrokeWidth(strokeWidth);//描边宽度
    paint.setStyle(Style.stroke);//描边
    //draws a linear gradient
    shapeDrawable.setShaderFactory(new ShaderFactory() {
        @Override
        public Shader resize(int width,int height) {
            return new LinearGradient(width / 2,TileMode.CLAMP
            );
        }
    });

    return shapeDrawable;
}
项目:Carbonizr    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:android-chat-ui    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:shadowsocks_android    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:android-floating-action-button-master    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:Studddinv2_android    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,float strokeWidth) {
    if (!mstrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }

    ShapeDrawable shapeDrawable = new ShapeDrawable(new ovalShape());

    final int bottomstrokeColor = darkenColor(color);
    final int bottomstrokeColorHalfTransparent = halfTransparent(bottomstrokeColor);
    final int topstrokeColor = lightenColor(color);
    final int topstrokeColorHalfTransparent = halfTransparent(topstrokeColor);

    final Paint paint = shapeDrawable.getPaint();
    paint.setAntiAlias(true);
    paint.setstrokeWidth(strokeWidth);
    paint.setStyle(Style.stroke);
    shapeDrawable.setShaderFactory(new ShaderFactory() {
        @Override
        public Shader resize(int width,TileMode.CLAMP
            );
        }
    });

    return shapeDrawable;
}
项目:mobile-manager-for-cloudflare    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:sophia    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:bhammer-android-old    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
            );
        }
    });

    return shapeDrawable;
}
项目:PARLA    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:CustomTema    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:Movie-lol-android    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
            );
        }
    });

    return shapeDrawable;
}
项目:BMap    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:android_gisapp    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(
        final int color,float strokeWidth)
{
    if (!mstrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }

    ShapeDrawable shapeDrawable = new ShapeDrawable(new ovalShape());

    final int bottomstrokeColor = darkenColor(color);
    final int bottomstrokeColorHalfTransparent = halfTransparent(bottomstrokeColor);
    final int topstrokeColor = lightenColor(color);
    final int topstrokeColorHalfTransparent = halfTransparent(topstrokeColor);

    final Paint paint = shapeDrawable.getPaint();
    paint.setAntiAlias(true);
    paint.setstrokeWidth(strokeWidth);
    paint.setStyle(Style.stroke);
    shapeDrawable.setShaderFactory(
            new ShaderFactory()
            {
                @Override
                public Shader resize(
                        int width,int height)
                {
                    return new LinearGradient(
                            width / 2,new int[] {
                            topstrokeColor,new float[] {0f,TileMode.CLAMP);
                }
            });

    return shapeDrawable;
}
项目:android-floating-action-button    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:CareerStack    文件FloatingActionButton.java   
private Drawable createInnerstrokesDrawable(final int color,TileMode.CLAMP
      );
    }
  });

  return shapeDrawable;
}
项目:grouptuity    文件StyleTemplate.java   
protected void preprocess()
{
    if(!(topLefTradius==topRighTradius && bottomLefTradius==bottomrighTradius && topLefTradius==bottomLefTradius))
    {
        shapeDrawable = new ShapeDrawable(new RoundRectShape(new float[]{topLefTradius,topLefTradius,topRighTradius,bottomLefTradius,bottomrighTradius,bottomrighTradius},null,null));
        shapeDrawable.setShaderFactory(new ShaderFactory(){public Shader resize(int width,int height){return new LinearGradient(0,primaryColor,secondaryColor,Shader.TileMode.CLAMP);}});
        innerPaint = null;
        borderPaint = null;
    }
    else
    {
        shapeDrawable = null;

        borderPaint = new Paint();
        borderPaint.setAntiAlias(true);
        borderPaint.setStyle(Style.stroke);
        borderPaint.setstrokeWidth(borderThickness);
        borderPaint.setColor((borderThickness==0)?Color.TRANSPARENT:borderColor);

        innerPaint = new Paint();
        innerPaint.setAntiAlias(true);
        if(!innerGradient)
            innerPaint.setColor(primaryColor);

        if(shadowColor!=0)
        {
            innerPaint.setShadowLayer(shadowRadius,shadowDX,shadowDY,shadowColor);
        }

        if(!circularSides && topLefTradius > 0)
        {
            leftPadding = (int)(topLefTradius*0.75);
            topPadding = (int)(topLefTradius*0.75);
            rightPadding = (int)(topLefTradius*0.75);
            bottomPadding = (int)(topLefTradius*0.75);
        }
    }

    leftPadding += leftContraction;
    topPadding += topContraction;
    rightPadding += rightContraction;
    bottomPadding += bottomContraction;
}
项目:grouptuity    文件StyleTemplate.java   
private void apply(final ViewTemplate<?,?> vt,boolean forced)
{
    if(oldWidth!=vt.getWidth() || oldHeight!=vt.getHeight() || forced)
    {
        oldWidth = vt.getMeasuredWidth();
        oldHeight = vt.getMeasuredHeight();

        if(circularSides)
        {
            int rectangleRadius = vt.getHeight()/2;
            topLefTradius = rectangleRadius;
            topRighTradius = rectangleRadius;
            bottomLefTradius = rectangleRadius;
            bottomrighTradius = rectangleRadius;
            leftPadding = rectangleRadius+leftContraction;
            rightPadding = rectangleRadius+rightContraction;
        }

        if(shapeDrawable!=null)
            shapeDrawable.setBounds(leftContraction,topContraction,vt.getMeasuredWidth()-rightContraction,vt.getMeasuredHeight()-bottomContraction);
    }

    vt.setPadding(leftPadding,topPadding,rightPadding,bottomPadding-bottomPaddingCompensationPixels);

    if(innerGradient)
    {
        if(shapeDrawable==null)
            innerPaint.setShader(new LinearGradient(0,vt.getMeasuredHeight(),Shader.TileMode.CLAMP));
        else if(gradientSizingLL!=null)
        {
            shapeDrawable.setShaderFactory(new ShaderFactory()
            {
                public Shader resize(int width,int height)
                {
                    int startPos = 0;
                    for(int i=0; i<gradientSizingLL.getChildCount(); i++)
                    {
                        View v = gradientSizingLL.getChildAt(i);
                        if(v.equals(vt) || v.equals(vt.getParent()))
                            break;
                        else
                            startPos += v.getMeasuredHeight();
                    }

                    final double fullSpan = gradientSizingLL.getHeight();
                    final int startA = (primaryColor >> 24) & 0xFF;
                    final int endA = (secondaryColor >> 24) & 0xFF;
                    final int startR = (primaryColor >> 16) & 0xFF;
                    final int endR = (secondaryColor >> 16) & 0xFF;
                    final int startG = (primaryColor >> 8) & 0xFF;
                    final int endG = (secondaryColor >> 8) & 0xFF;
                    final int startB = (primaryColor >> 0) & 0xFF;
                    final int endB = (secondaryColor >> 0) & 0xFF;
                    final int actualA1 = (int)(startA + (endA-startA)*startPos/fullSpan);
                    final int actualA2 = (int)(startA + (endA-startA)*(startPos+vt.getHeight())/fullSpan);
                    final int actualR1 = (int)(startR + (endR-startR)*startPos/fullSpan);
                    final int actualR2 = (int)(startR + (endR-startR)*(startPos+vt.getHeight())/fullSpan);
                    final int actualG1 = (int)(startG + (endG-startG)*startPos/fullSpan);
                    final int actualG2 = (int)(startG + (endG-startG)*(startPos+vt.getHeight())/fullSpan);
                    final int actualB1 = (int)(startB + (endB-startB)*startPos/fullSpan);
                    final int actualB2 = (int)(startB + (endB-startB)*(startPos+vt.getHeight())/fullSpan);

                    return new LinearGradient(0,vt.getHeight(),Color.argb(actualA1,actualR1,actualG1,actualB1),Color.argb(actualA2,actualR2,actualG2,actualB2),Shader.TileMode.CLAMP);
                }
            });
        }
    }

    vt.applyStyle();
    vt.requestLayout();
    vt.invalidate();
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。