내 arduino에서 블루투스를 통해 색상을 읽고 내 전화 화면에 해당 색상을 표시하는 사용자 정의보기를 만들려고합니다. 나는 지속적으로 arduino에서 데이터를 읽도록 만든 스레드를 통해 블루투스 장치의 색상을 successfuly 읽을 수 있습니다. 나는 또한 그 색이 변경된 경우 루프에서 실행중인 다른 스레드보고 가지고하고있는 경우, 이에 따라 글로벌 변수 chosenColor 변경 :Android Repainting Rectangle White로 채우기
while(true){
int newColor = device.activeSensorColor;
if(chosenColor != newColor){
chosenColor = newColor;
invalidater.post(invalidating);
}
}
이 이런 짓을 한 후를,이 UI에 처리기를 사용 thread가 무효화를 호출한다(); 양식을 다시 그립니다. 다음 무효는 항상 호출됩니다 :
@Override
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawRect(bounds, boxPaint);
samplePaint.setColor(chosenColor);
canvas.drawRect(colorSample, samplePaint);
canvas.drawText(buttonText, (width - height)/2 + height, height/2, textPaint);
canvas.drawRect(sampleBorder, borderPaint);
}
그리고 이것은 상자의 색상을 반드시 흰색으로 설정합니다. 나는 이것을 몇 시간 동안 알아 내려고 노력해 왔지만, 무언가를 시도 할 때마다 arduino에서 어떤 색상이 선택 되든 샘플 사각형의 색상은 흰색이됩니다. 누구 아이디어있어? 감사.