博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 下 JNI 开发
阅读量:4047 次
发布时间:2019-05-25

本文共 1256 字,大约阅读时间需要 4 分钟。

8.需要在setPressure方法中设置重画方法

 

    //重画

    //invalidate();只能在主线程中调用

    //postInvalidate();可以在子线程中调用

    postInvalidate();

 

9.解决图形向下移动bug,取绝对值

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();

 

 

 

10.锅炉爆炸后停止工作

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. 实现C语言端获取锅炉的压力值

  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();

 

 

 

  1. C代码

 

#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/

你可能感兴趣的文章
SSH框架总结(框架分析+环境搭建+实例源码下载)
查看>>
js弹窗插件
查看>>
自定义 select 下拉框 多选插件
查看>>
js获取url链接携带的参数值
查看>>
gdb 调试core dump
查看>>
gdb debug tips
查看>>
arm linux 生成火焰图
查看>>
linux和windows内存布局验证
查看>>
linux insmod error -1 required key invalid
查看>>
linux kconfig配置
查看>>
linux不同模块completion通信
查看>>
linux printf获得时间戳
查看>>
C语言位扩展
查看>>
linux irqdebug
查看>>
git 常用命令
查看>>
linux位操作API
查看>>
uboot.lds文件分析
查看>>
uboot start.s文件分析
查看>>
没有路由器的情况下,开发板,虚拟机Ubuntu,win10主机,三者也可以ping通
查看>>
本地服务方式搭建etcd集群
查看>>