功能算法

Android 连击实现


  // 数组长度表示要点击的次数
  long[] mHits = new long[3];
  
  public void onClick(View view) {
    		System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
    		mHits[mHits.length - 1] = SystemClock.uptimeMillis();
    		if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
    			Toast.makeText(this, "!!!", Toast.LENGTH_SHORT).show();
    		}
    	}

根据年月返回当月的总天数

   /**
     * 根据年月返回当月的总天数
     *
     * @param year
     * @param month
     * @return
     */
    public static int getMonthDay(int year, int month) {
        // 添加大小月月份并将其转换为list,方便之后的判断
        String[] months_big = {"1", "3", "5", "7", "8", "10", "12"};
        String[] months_little = {"4", "6", "9", "11"};

        final List<String> list_big = Arrays.asList(months_big);
        final List<String> list_little = Arrays.asList(months_little);

        // 判断大小月及是否闰年,用来确定"日"的数据
        if (list_big.contains(String.valueOf(month))) {
            return 31;
        } else if (list_little.contains(String.valueOf(month))) {
            return 30;
        } else {
            // 闰年
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                return 29;
            } else {
                return 28;
            }
        }
    }
原文地址:https://www.cnblogs.com/MillerKevin/p/12650260.html