• CountDownTimer


    package com.daoge.widget;
    
    import java.text.DecimalFormat;
    
    import android.os.CountDownTimer;
    import android.widget.TextView;
    
    public class DanceWageTimer extends CountDownTimer {
    
    	public static final int INTERVAL_ONE = 20;
    	public static final int INTERVAL_TWO = 40;
    
    	private TextView textView;
    	private float totalWage;
    	private int startNum = 0;//从多少开始累加
    	private int increased;//每次加多少
    	private int decimals;
    	private int decimalFlag = 0;//记录小数部分的累加
    	private long totalExecuteTime;
    	private long interval;
    	public DanceWageTimer(long millisInFuture, long countDownInterval) {
    		super(millisInFuture, countDownInterval);
    	}
    
    	public DanceWageTimer(long millisInFuture, long countDownInterval, TextView textView, float totalWage) {
    		super(millisInFuture, countDownInterval);
    		this.textView = textView;
    		this.totalWage = totalWage;
    		this.totalExecuteTime = millisInFuture;
    		this.interval = countDownInterval;
    		startNum = DanceWageTimer.getStartNum(totalWage);
    		decimals = (int) ((totalWage - getIntegerOfWage(totalWage)) * 100);
    		increased = DanceWageTimer.getIncreased(startNum);
    	}
    
    	@Override
    	public void onFinish() {
    		DecimalFormat decFormat = new DecimalFormat("##0.00");
    		String result = decFormat.format(totalWage);
    		textView.setText(result);
    	}
    
    	@Override
    	public void onTick(long arg0) {
    		startNum += increased;
    		if (decimalFlag < decimals) {
    			if (totalExecuteTime / interval < decimals) {
    				decimalFlag += 2;
    			} else {
    				decimalFlag++;
    			}
    		}
    		if (decimalFlag < 10) {
    			textView.setText(startNum + ".0" + decimalFlag);
    		} else {
    			textView.setText(startNum + "." + decimalFlag);
    		}
    
    	}
    
    	/**
    	 * @Title getTotalExecuteTime
    	 * @Description 得到总共执行的时间
    	 * @param totalWage
    	 * @return
    	 */
    	public static int getTotalExecuteTime(float totalWage, int interval) {
    		int wage = getIntegerOfWage(totalWage);
    		int startNum = getStartNum(totalWage);
    		int increased = getIncreased(startNum);
    		int result = (wage - startNum) / increased * interval;
    		return result;
    	}
    
    	/**
    	 * @Title getStartNum
    	 * @Description 得到从多少开始累加
    	 * @param totalWage
    	 * @return
    	 */
    	public static int getStartNum(float totalWage) {
    		int wage = getIntegerOfWage(totalWage);
    		if (wage / 10000 >= 1) {
    			return 10000;
    		} else if (wage / 1000 >= 1) {
    			return 1000;
    		} else if (wage / 100 >= 1) {
    			return 100;
    		} else if (wage / 10 >= 1) {
    			return 10;
    		} else {
    			return 0;
    		}
    	}
    
    	/**
    	 * @Title getIncreased
    	 * @Description 得到每次加多少
    	 * @param start
    	 * @return
    	 */
    	private static int getIncreased(int start) {
    		int increased = 0;
    		if (start >= 10000) {
    			increased = 1299;
    		} else if (start >= 1000) {
    			increased = 99;
    		} else if (start >= 100) {
    			increased = 7;
    		} else if (start >= 10) {
    			increased = 1;
    		} else {
    			increased = 1;
    		}
    		return increased;
    	}
    
    	public static int getIntegerOfWage(float totalWage) {
    		return (int) totalWage;
    	}
    
    }
    

      

  • 相关阅读:
    MongoDB配置多个ConfigDB的问题(笔记)
    Python访问PostGIS(建表、空间索引、分区表)
    Python访问MySQL数据库
    Python访问MongoDB数据库
    Mapnik读取PostGIS数据渲染图片
    Python批量处理CSV文件
    Spring Mongo配置多个Mongos
    hadoop2.2.0_hbase0.96_zookeeper3.4.5全分布式安装文档下载
    【Git】(1)---工作区、暂存区、版本库、远程仓库
    微信扫码支付功能(2)---用户扫码支付成功,微信异步回调商户接口
  • 原文地址:https://www.cnblogs.com/jiezzy/p/4282045.html
Copyright © 2020-2023  润新知