2016-08-14 7 views
0

안녕 아날로그 watch.In 된 onDraw 방법의 샘플을 통과 한 아날로그 시계 샘플에서 시계 얼굴의 논리를 설명 할 수 나는 정확한 의미가 무엇인지 내가 이해하지 못하는하고이 논리어느 한 안드로이드

@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으로 나눈 이유는 무엇입니까? –