如何在Android Watch Face中模拟模拟秒表?

时间:2018-11-03 01:43:39

标签: android-wear-2.0 watch-face-api

我正在使用Android Wear OS开发一款逼真的计时表。我已经有秒针手表运转良好,并且秒针已停下。当我点击手表时,我希望我的计时器指针从零开始,但实际上是从秒针开始。

我的问题是:如何为我的计时码表旋转应用偏移值,以对实际秒数进行打折,并且指针从0位置开始?

这是实际行为:

enter image description here

以下是旋转小秒针的代码:

private float getSecondsRotation() {
            final float seconds =
                    (mCalendar.get(Calendar.SECOND) + mCalendar.get(Calendar.MILLISECOND) / 1000f);
            return seconds * 6f;
        }

是否可以通过该方法传递shift参数并从结果中扣除?

1 个答案:

答案 0 :(得分:0)

我实际上并没有尝试运行此代码,但希望它能使您了解如何解决问题。

// True when the chronograph is running, false otherwise
private boolean isChronographRunning = false;

// The second when the chronograph is started
private float secondOffset = 0f;

// Called when the user taps on the watch face
private void startChronograph() {
    isChronographRunning = true;
    secondOffset = mCalendar.get(Calendar.SECOND) + mCalendar.get(Calendar.MILLISECOND) / 1000f;
}

// Called from your draw loop if(isChronographRunning)
private float getChronographRotation() {
    float currentSecond = mCalendar.get(Calendar.SECOND) + mCalendar.get(Calendar.MILLISECOND) / 1000f;
    float chronographSecond = currentSecond - secondOffset;
    return chronographSecond * 6f;
}