本文共 1256 字,大约阅读时间需要 4 分钟。
//重画
//invalidate();只能在主线程中调用
//postInvalidate();可以在子线程中调用
postInvalidate();
new Thread(){
public void run() {
while (true) {
SystemClock.sleep(1000);
Random random = new Random();
int pressure= random.nextInt() % 210;
myPressureView.setPressure(Math.abs(pressure));
}
};
}.start();
new Thread(){
public void run() {
while (true) {
SystemClock.sleep(1000);
Random random = new Random();
int pressure= Math.abs(random.nextInt() % 210);
myPressureView.setPressure(pressure);
if(pressure >200){
break;
}
}
};
}.start();
1.native代码
/**
* 从C端获取一个压力值
* @return
*/
public native int getPressure();
{
java.lang.System.loadLibrary("PressureDemo");
}
new Thread(){
public void run() {
while (true) {
SystemClock.sleep(1000);
// Random random = new Random();
int pressure= getPressure();//Math.abs(random.nextInt() % 250);
myPressureView.setPressure(pressure);
if(pressure >200){
break;
}
}
};
}.start();
#include "com_atguigu_pressuredemo_MainActivity.h"
#include<stdio.h>
#include<stdlib.h>
/**模拟-得到锅炉的压力值
范围:0~250
*/
int getPressure()
{
return rand()%250;
}
JNIEXPORT jint JNICALL Java_com_atguigu_pressuredemo_MainActivity_getPressure
(JNIEnv *env, jobject obj){
return getPressure();
}
转载地址:http://wluci.baihongyu.com/