コード例 #1
0
 /**
  * 画进度等待界面
  *
  * @param canvas
  */
 private void drawProgressPrepare(Canvas canvas) {
   if (type != TYPE_PREPARE && oldType != TYPE_PREPARE) {
     return; // 如果与自己不相关就返回
   }
   drawType = false;
   // 画背景色
   if (!option.isProgressCenterLucency()) {
     canvas.drawCircle(width / 2, height / 2, radius, progressCenterPaint);
   }
   // 画背景图
   if (!option.isProgressCenterLucency() && option.getBtnProgressCenterImage() > 0) {
     canvas.drawBitmap(
         createBitmap(
             BitmapFactory.decodeResource(getResources(), option.getBtnProgressCenterImage()),
             radius * 2,
             radius * 2,
             radius),
         width / 2 - radius,
         height / 2 - radius,
         null);
   }
   progressPaint.setStrokeWidth(option.getBtnProgressWidth() * radius);
   progressBgPaint.setStrokeWidth(option.getBtnProgressWidth() * radius);
   canvas.drawCircle(width / 2, height / 2, radius, progressBgPaint);
   RectF rectF =
       new RectF(width / 2 - radius, height / 2 - radius, width / 2 + radius, height / 2 + radius);
   if (type == TYPE_PREPARE && oldType != TYPE_PREPARE) {
     int r = 0;
     if (width > height) {
       r = (int) (height * 0.4);
     } else {
       r = (int) (width * 0.4);
     }
     if (radius < r) {
       radius += (r * 0.1);
     } else {
       radius = r;
       oldType = type;
     }
     // invalidate();
   } else if (type == TYPE_PREPARE && oldType == TYPE_PREPARE) {
     if (index < maxIndex) {
       canvas.drawArc(rectF, -90, 360 * index * 0.01f, false, progressPaint);
       index++;
       // invalidate();
     } else { // prepareIndex
       canvas.drawArc(rectF, prepareIndex - 90, 360 * index * 0.01f, false, progressPaint);
       prepareIndex += 5;
       if (prepareIndex > 360) {
         prepareIndex = 0;
       }
       // invalidate();
     }
     isEnd = false;
   } else if (type == TYPE_LOADING && oldType == TYPE_PREPARE) {
     if (!isEnd && index > 0) {
       canvas.drawArc(rectF, prepareIndex - 90, 360 * index * 0.01f, false, progressPaint);
       if (prepareIndex > 285) {
         prepareIndex += 360 * 0.01f;
         index--;
       } else {
         prepareIndex += 5;
         if (prepareIndex > 360) {
           prepareIndex = 0;
         }
       }
       // invalidate();
     }
     if (index <= 0) {
       isEnd = true;
       drawType = true;
       index = 0;
     }
   } else if (oldType == TYPE_PREPARE) {
     canvas.drawArc(rectF, prepareIndex - 90, 360 * index * 0.01f, false, progressPaint);
     prepareIndex += 5;
     if (prepareIndex > 360) {
       prepareIndex = 0;
     }
     int r = 0;
     if (width > height) {
       r = (int) (height * 0.4);
     } else {
       r = (int) (width * 0.4);
     }
     if (radius > 0) {
       radius -= (r * 0.1);
     } else {
       radius = 0;
       // oldType = type;
       index = 0;
     }
     // invalidate();
   }
   invalidate();
 }
コード例 #2
0
 /**
  * 绘制进度界面
  *
  * @param canvas
  */
 private void drawProgress(Canvas canvas) {
   if (type != TYPE_LOADING & oldType != TYPE_LOADING) {
     return; // 如果与自己不相关就返回
   }
   drawType = false;
   // 画背景色
   if (!option.isProgressCenterLucency()) {
     canvas.drawCircle(width / 2, height / 2, radius, progressCenterPaint);
   }
   // 画背景图
   if (!option.isProgressCenterLucency() && option.getBtnProgressCenterImage() > 0) {
     canvas.drawBitmap(
         createBitmap(
             BitmapFactory.decodeResource(getResources(), option.getBtnProgressCenterImage()),
             radius * 2,
             radius * 2,
             radius),
         width / 2 - radius,
         height / 2 - radius,
         null);
   }
   progressPaint.setStrokeWidth(option.getBtnProgressWidth() * radius);
   progressBgPaint.setStrokeWidth(option.getBtnProgressWidth() * radius);
   canvas.drawCircle(width / 2, height / 2, radius, progressBgPaint);
   RectF rectF =
       new RectF(width / 2 - radius, height / 2 - radius, width / 2 + radius, height / 2 + radius);
   if (type == TYPE_LOADING && oldType != TYPE_LOADING && oldType != TYPE_PREPARE) {
     int r = 0;
     if (width > height) {
       r = (int) (height * 0.4);
     } else {
       r = (int) (width * 0.4);
     }
     if (radius < r) {
       radius += (r * 0.1);
     } else {
       radius = r;
       oldType = type;
     }
     // invalidate();
   } else if (type == TYPE_LOADING && (oldType == TYPE_LOADING || oldType == TYPE_PREPARE)) {
     oldType = type;
     isEnd = false;
     if (allNum <= 0 || proNum <= 0) {
       return;
     } else {
       //				if(Math.abs(proNum - proIndex) < allNum / 100){
       //					proIndex = proNum;
       //				}
       canvas.drawArc(rectF, -90, 360 * proIndex / allNum, false, progressPaint);
       String text = ((int) (proIndex / allNum * 100)) + "%";
       // 画字
       if (text != null && text.length() > 0 && option.isShowPercent()) {
         int textSize;
         textSize = (int) (radius * 2 * 0.3);
         if (textSize * text.length() > (radius * 2)) {
           textSize = (int) ((radius * 2) / text.length() * 0.8);
         }
         progressTextPaint.setTextSize(textSize);
         FontMetrics fm = progressTextPaint.getFontMetrics();
         float textY = -fm.descent + (fm.descent - fm.ascent) / 2;
         canvas.drawText(text, width / 2, height / 2 + textY, progressTextPaint);
       }
       if (proIndex < proNum) {
         proIndex += allNum * 0.01;
         if (Math.abs(proNum - proIndex) < allNum * 0.01) {
           proIndex = proNum;
         }
       } else if (proIndex > proNum) {
         proIndex -= proNum * 0.01;
         if (Math.abs(proNum - proIndex) < allNum * 0.01) {
           proIndex = proNum;
         }
       } else {
         return;
       }
     }
   } else if (oldType == TYPE_LOADING) {
     canvas.drawArc(rectF, -90, 360 * proIndex / allNum, false, progressPaint);
     if (!isEnd) {
       int r = 0;
       if (width > height) {
         r = (int) (height * 0.4);
       } else {
         r = (int) (width * 0.4);
       }
       if (radius > 0) {
         radius -= (r * 0.1);
       } else {
         radius = 0;
         index = 0;
         isEnd = true;
       }
     } else {
       drawType = true;
     }
     // invalidate();
   }
   invalidate();
 }