- Add the Codota plugin to your IDE and get smart completions
private void myMethod () {FileOutputStream f =
File file;new FileOutputStream(file)
String name;new FileOutputStream(name)
File file;new FileOutputStream(file, true)
- Smart code suggestions by Codota
}
/** * 修改数值 * * @param number 新值 */ public void setNumber(long number) { setNumber(number, false); }
/** * 切换当前状态 */ public void trigger() { if (isActivated) { if (!notAllowedCancel) { deactivateAndTallyDown(); } } else { activateAndPlusOne(); } }
@Override protected void onDraw(Canvas canvas) { drawGraph(canvas); drawNumber(canvas); }
graphColor = textColor = Color.parseColor("#888888"); animateColor = Color.parseColor("#ca5f5f"); textSize = sp2px(14); isActivated = false; animateDuration = 300L; distance = dp2px(3); graphStrokeWidth = dp2px(3); textStrokeWidth = dp2px(2); graphTextHeightRatio = 1.3f; autoMeasureMaxTextWidth = true; gravity = GRAVITY_CENTER; } else { TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LikeView); try { number = ta.getInt(R.styleable.LikeView_number, 0); textColor = ta.getColor(R.styleable.LikeView_textColor, Color.parseColor("#888888")); animateColor = ta.getColor(R.styleable.LikeView_animateColor, Color.parseColor("#ca5f5f")); textSize = ta.getDimensionPixelSize(R.styleable.LikeView_textSize, sp2px(14)); isActivated = ta.getBoolean(R.styleable.LikeView_isActivated, false); autoMeasureMaxTextWidth = ta.getBoolean(R.styleable.LikeView_autoMeasureMaxWidth, true); notAllowedCancel = ta.getBoolean(R.styleable.LikeView_notAllowedCancel, false); animateDuration = ta.getInt(R.styleable.LikeView_animateDuration, 300); distance = ta.getDimensionPixelSize(R.styleable.LikeView_distance, dp2px(3)); graphStrokeWidth = ta.getDimensionPixelSize(R.styleable.LikeView_graphStrokeWidth, dp2px(3)); textStrokeWidth = ta.getDimensionPixelSize(R.styleable.LikeView_textStrokeWidth, dp2px(2)); graphTextHeightRatio = ta.getFloat(R.styleable.LikeView_graphTextHeightRatio, 1.3f); gravity = ta.getInteger(R.styleable.LikeView_gravity,GRAVITY_CENTER);
final SSEntity entity = ssEntities.get(position); holder.like.setActivated(entity.isLike); holder.like.setNumber(entity.likeNum); holder.like.setCallback(new LikeView.SimpleCallback() { @Override public void activate(LikeView view) { holder.comment.setNumber(entity.commentNum); holder.comment.setGraphAdapter(CommentPathAdapter.getInstance()); holder.comment.setCallback(new LikeView.SimpleCallback(){ @Override public boolean onClick(LikeView view) {
/** * 取消激活并且给数组减1 */ public void deactivateAndTallyDown() { add(-1); deactivate(); }
/** * 修改数值 * * @param number 新值 * @param animate 是否启用动画 */ public void setNumber(long number, boolean animate) { if (animate) { add(number - this.number); } else { this.number = number; postInvalidate(); } }
/** * 画图形 */ private void drawGraph(Canvas canvas) { canvas.save(); canvas.translate(graphStartX, graphStartY); canvas.clipPath(graphPath); float radial = (float) (graphLength * Math.sqrt(2) / 2f); if (!isGraphAnimateRunning) {//如果不是动画中,就直接绘画 if (isActivated) { //绘制激活状态 canvas.drawCircle(graphLength / 2, graphLength / 2, radial, animatePaint); } else { //绘制图形 canvas.drawPath(graphPath, graphPaint); } } else { //是动画中就要按比例绘画 //修改外圈图形比例 drawGraphPathByScale(canvas, 1 - graphAnimateScale); //修改内圈圆形比例 canvas.drawCircle(graphLength / 2, graphLength / 2, radial * graphAnimateScale, animatePaint); } canvas.restore(); }