안드로이드 개발 질문/답변
(글 수 45,052)
링크 사이트의 바이오리듬 예제 소스 인데요~
생년월일 입력시 바이오리듬 그래프를 출력해주는 예제 입니다.
막히는 부분은 아래쪽에 바이오리듬 사인그래프를 그리는 BioView 코드에서
오늘 날짜에 해당하는 3개의 y의 값 (mMaxType = 3; 신체지수, 감성지수, 지성지수의 값) 을 참조해서
그 값을 텍스트 뷰로 출력 되도록 하고 싶은데, (EX: 신체지수 : 39 감성지수 : 26 지성지수 : -25)
어떤 변수를 참조해야 할지를 몰라서 막히고 있습니다. (텍스트뷰로 출력하는 건 알고있습니다.)
도와주세요~~!
package ps.smanager.sentimental.common; import java.util.Date;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
public class Sen_BioView extends View {
/** 상수 */
private static final int mMaxDays = 30;
private static final int mMaxType = 3;
private static final long mTDV = (60*60*24*1000);
private static final double mPI = 3.14159;
private static final double mBioValues[] = { 23.0, 28.0, 33.0 };
private static final int mColors[] = { 0xff0000ff, 0xffff0000, 0xff006600 };
/** 멤버변수 */
private Paint mPaint;
private Rect mRect;
private double mStartDays;
private Date mBirthDate, mTodayDate;
public int ResultValue;
public Sen_BioView(Context context, AttributeSet attrs) {
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
mRect.top = 0;
mRect.bottom = getWidth();
mRect.left = 0;
mRect.right = getHeight();
/** 상수 */
private static final int mMaxDays = 30;
private static final int mMaxType = 3;
private static final long mTDV = (60*60*24*1000);
private static final double mPI = 3.14159;
private static final double mBioValues[] = { 23.0, 28.0, 33.0 };
private static final int mColors[] = { 0xff0000ff, 0xffff0000, 0xff006600 };
/** 멤버변수 */
private Paint mPaint;
private Rect mRect;
private double mStartDays;
private Date mBirthDate, mTodayDate;
public int ResultValue;
public Sen_BioView(Context context, AttributeSet attrs) {
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
mRect.top = 0;
mRect.bottom = getWidth();
mRect.left = 0;
mRect.right = getHeight();
mTodayDate = new Date();
Date startDate = new Date(mTodayDate.getYear(), mTodayDate.getMonth(), 1);
mStartDays = startDate.getTime()/mTDV;
mBirthDate = new Date();
mBirthDate.setYear(0);
}
public void setBirthDay(int year, int month, int day) {
mBirthDate.setYear(year);
mBirthDate.setMonth(month);
mBirthDate.setDate(day);
}
Date startDate = new Date(mTodayDate.getYear(), mTodayDate.getMonth(), 1);
mStartDays = startDate.getTime()/mTDV;
mBirthDate = new Date();
mBirthDate.setYear(0);
}
public void setBirthDay(int year, int month, int day) {
mBirthDate.setYear(year);
mBirthDate.setMonth(month);
mBirthDate.setDate(day);
}
@Override
protected void onDraw(Canvas canvas) {
int cellWidth = getWidth()/mMaxDays;
mRect.top = 0;
mRect.bottom = getWidth();
mRect.left = 0;
mRect.right = getHeight();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(0xFF999999);
protected void onDraw(Canvas canvas) {
int cellWidth = getWidth()/mMaxDays;
mRect.top = 0;
mRect.bottom = getWidth();
mRect.left = 0;
mRect.right = getHeight();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(0xFF999999);
int x = 0, y = 0, oldY = 0;
// 세로줄 출력
for (int i = 0; i <= mMaxDays; i++) {
x += cellWidth;
canvas.drawLine(x, mRect.top, x, mRect.bottom, mPaint);
}
// 가로줄 출력
canvas.drawLine(0, mRect.bottom/2, mRect.right, mRect.bottom/2, mPaint);
// 오늘 날짜 출력
mPaint.setColor(0xFFFFFF00);
mPaint.setStrokeWidth(2);
x = cellWidth * mTodayDate.getDate();
canvas.drawLine(x, mRect.top, x, mRect.bottom, mPaint);
// 바이오리듬 출력
if (mBirthDate.getYear() != 0) {
Log.e("LOG", "year:" + mBirthDate.getYear() +
"month:" + mBirthDate.getMonth() +
"day:" + mBirthDate.getDate());
double startDays = mStartDays;
double birthDays = mBirthDate.getTime()/mTDV;
for (int k = 0; k < mMaxType; k++) {
x = 0;
mPaint.setColor(mColors[k]);
mPaint.setStrokeWidth(2);
for (int i = 0; i <= mMaxDays; i++) {
double gab = birthDays - startDays;
double p = (int)(Math.sin((gab/mBioValues[k]) * 2.0 * mPI) * 100.0);
y = mRect.bottom/2 + (int)(p * ((mRect.bottom/2.0)/100.0));
if (i != 0)
canvas.drawLine(x, oldY, x + cellWidth, y, mPaint);
oldY = y;
startDays++;
x += cellWidth;
}
}
}
super.onDraw(canvas);
}
}
// 세로줄 출력
for (int i = 0; i <= mMaxDays; i++) {
x += cellWidth;
canvas.drawLine(x, mRect.top, x, mRect.bottom, mPaint);
}
// 가로줄 출력
canvas.drawLine(0, mRect.bottom/2, mRect.right, mRect.bottom/2, mPaint);
// 오늘 날짜 출력
mPaint.setColor(0xFFFFFF00);
mPaint.setStrokeWidth(2);
x = cellWidth * mTodayDate.getDate();
canvas.drawLine(x, mRect.top, x, mRect.bottom, mPaint);
// 바이오리듬 출력
if (mBirthDate.getYear() != 0) {
Log.e("LOG", "year:" + mBirthDate.getYear() +
"month:" + mBirthDate.getMonth() +
"day:" + mBirthDate.getDate());
double startDays = mStartDays;
double birthDays = mBirthDate.getTime()/mTDV;
for (int k = 0; k < mMaxType; k++) {
x = 0;
mPaint.setColor(mColors[k]);
mPaint.setStrokeWidth(2);
for (int i = 0; i <= mMaxDays; i++) {
double gab = birthDays - startDays;
double p = (int)(Math.sin((gab/mBioValues[k]) * 2.0 * mPI) * 100.0);
y = mRect.bottom/2 + (int)(p * ((mRect.bottom/2.0)/100.0));
if (i != 0)
canvas.drawLine(x, oldY, x + cellWidth, y, mPaint);
oldY = y;
startDays++;
x += cellWidth;
}
}
}
super.onDraw(canvas);
}
}