2016-08-14 41 views
0

您好我經歷模擬watch.In的onDraw方法的樣品我碰到這個邏輯任何一個可以模擬手錶樣品中解釋手錶面對這種邏輯的Android

@Override 
    public void onDraw(Canvas canvas, Rect bounds) { 
     mTime.setToNow(); 

     // Draw the background. 
     if (isInAmbientMode()) { 
      canvas.drawColor(Color.BLACK); 
     } else { 
      canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint); 
     } 

     // Find the center. Ignore the window insets so that, on round watches with a 
     // "chin", the watch face is centered on the entire screen, not just the usable 
     // portion. 
     float centerX = bounds.width()/2f; 
     float centerY = bounds.height()/2f; 

     float secRot = (mTime.second/30f) * (float) Math.PI; 
     int minutes = mTime.minute; 
     float minRot = minutes/30f * (float) Math.PI; 
     float hrRot = ((mTime.hour + (minutes/60f))/6f) * (float) Math.PI; 

     float secLength = centerX - 20; 
     float minLength = centerX - 40; 
     float hrLength = centerX - 80; 

     if (!mAmbient) { 
      float secX = (float) Math.sin(secRot) * secLength; 
      float secY = (float) -Math.cos(secRot) * secLength; 
      canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, mHandPaint); 
     } 

     float minX = (float) Math.sin(minRot) * minLength; 
     float minY = (float) -Math.cos(minRot) * minLength; 
     canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, mHandPaint); 

     float hrX = (float) Math.sin(hrRot) * hrLength; 
     float hrY = (float) -Math.cos(hrRot) * hrLength; 
     canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, mHandPaint); 
    } 

我不理解什麼是確切的含義這些線

float secRot = (mTime.second/30f) * (float) Math.PI; 
    int minutes = mTime.minute; 
    float minRot = minutes/30f * (float) Math.PI; 
    float hrRot = ((mTime.hour + (minutes/60f))/6f) * (float) Math.PI; 

回答

0

它似乎是試圖計算每個手的旋轉角度。它正在獨立移動秒針和分針,但也依賴於分鐘來移動時針。在「12點30分」的時針將在12點和1點之間。

+0

是的,它只計算旋轉,但爲什麼除以30,我試圖找出? –

相關問題