代码之家  ›  专栏  ›  技术社区  ›  Namratha

需要帮助解释谷歌Android摄像头应用程序代码

  •  0
  • Namratha  · 技术社区  · 16 年前

    下面的功能是谷歌相机应用程序代码的一部分。我不明白粗体字的逻辑。请帮忙。

    int seconds=intent.getintextra(mediastore.extra_duration_limit,0); mmaxvideodurationinms=1000*秒;

    mmediarecorder.setmaxduration(mmaxvideodurationinms);

    //此函数用于更新录制时间

    私有void updateRecordingTime()。{ 如果(!)我的日记顺序记录){ 返回; } long now=系统时钟.uptimemillis(); long delta=现在-mrecordingstarttime;

        // Starting a minute before reaching the max duration
        // limit, we'll countdown the remaining time instead.
        boolean countdownRemainingTime = (mMaxVideoDurationInMs != 0
                && delta >= mMaxVideoDurationInMs - 60000);
    
        long next_update_delay = 1000 - (delta % 1000);
        long seconds;
        if (countdownRemainingTime) {
            **delta = Math.max(0, mMaxVideoDurationInMs - delta);
            seconds = (delta + 999) / 1000;**
        } else {
            **seconds = delta / 1000; // round to nearest**
        }
    
        long minutes = seconds / 60;
        long hours = minutes / 60;
        long remainderMinutes = minutes - (hours * 60);
        long remainderSeconds = seconds - (minutes * 60);
    
        String secondsString = Long.toString(remainderSeconds);
        if (secondsString.length() < 2) {
            secondsString = "0" + secondsString;
        }
        String minutesString = Long.toString(remainderMinutes);
        if (minutesString.length() < 2) {
            minutesString = "0" + minutesString;
        }
        String text = minutesString + ":" + secondsString;
        if (hours > 0) {
            String hoursString = Long.toString(hours);
            if (hoursString.length() < 2) {
                hoursString = "0" + hoursString;
            }
            text = hoursString + ":" + text;
        }
        mRecordingTimeView.setText(text);
    
        if (mRecordingTimeCountsDown != countdownRemainingTime) {
            // Avoid setting the color on every update, do it only
            // when it needs changing.
            mRecordingTimeCountsDown = countdownRemainingTime;
    
            int color = getResources().getColor(countdownRemainingTime
                    ? R.color.recording_time_remaining_text
                    : R.color.recording_time_elapsed_text);
    
            mRecordingTimeView.setTextColor(color);
        }
    
        // Work around a limitation of the T-Mobile G1: The T-Mobile
        // hardware blitter can't pixel-accurately scale and clip at the
        // same time, and the SurfaceFlinger doesn't attempt to work around
        // this limitation. In order to avoid visual corruption we must
        // manually refresh the entire surface view when changing any
        // overlapping view's contents.
        mVideoPreview.invalidate();
        mHandler.sendEmptyMessageDelayed(
                UPDATE_RECORD_TIME, next_update_delay);
    }
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   mbafford    16 年前

    你指的是这些行吗?

    1.        delta = Math.max(0, mMaxVideoDurationInMs - delta);
    2.        seconds = (delta + 999) / 1000;
    

    3.        seconds = delta / 1000; // round to nearest
    

    很难说清楚,因为在你的问题中没有什么是大胆的(但是这些行前后的**让我觉得这就是你所指的)。

    delta 以毫秒为单位,其中 1000 一会儿。

    第1行: 确保显示0而不是负数

    第2行: 四舍五入到最接近的秒。自从 seconds 是一个整数,任何值 三角洲 1001 (1s 1ms)到 1999 (1s,999ms)将返回为 seconds = 2 .

    第3行: 只需删除ms部分,所以 delta = 1 收益率 0 但确实如此 delta = 999 .


    delta是指时间变化量中的“变化”。

    两者几乎相同,但当代码显示剩余秒数时,它选择向上取整,以便将剩余1.5秒(1500毫秒)显示为1秒。

    当它计算经过的秒数时,它向下舍入,这样,例如,经过的1.5秒(1500毫秒)将显示为1秒。

    因为秒是一个整数,所以任何浮点数的小数部分都将被切掉。所以:

    1500 / 1000 = 1.500
    (int)1.500 = 1
    

    当您添加999时,您有:

    (1500 + 999) / 1000 = 2499 / 1000 = 2.499
    (int)2.499 = 2