"JNI" Boiler pressure monitor

Source: Internet
Author: User

 Public classMainactivityextendsActivity {PrivateMyProgressBar PB; Static{system.loadlibrary ("Hello"); } @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); PB=(MyProgressBar) Findviewbyid (R.ID.PB); Pb.setmax (100); }    Public voidStart (View v) {NewThread () { Public voidrun () {startmonitor ();       };   }.start (); }    Public voidStop (View v) {stopmonitor (); }        Public native voidStartMonitor ();  Public native voidStopmonitor ();  Public voidShowintpressure)   {pb.setpressure (pressure); }}

 Public classMyProgressBarextendsView {Private intpressure; Private intMax;  PublicMyProgressBar (context context, AttributeSet attrs,intDefstyle) {        Super(context, attrs, Defstyle); //TODO auto-generated Constructor stub    }     PublicMyProgressBar (Context context, AttributeSet attrs) {Super(context, attrs); //TODO auto-generated Constructor stub    }     PublicMyProgressBar (Context context) {Super(context); //TODO auto-generated Constructor stub    }     Public voidSetpressure (intpressure) {         This. Pressure =pressure; //Invalidates the current view, if the current view is visible, then the OnDraw is called and can only be used in the main thread//invalidate ();postinvalidate (); }     Public voidSetmax (intmax) {         This. Max =Max; } @Overrideprotected voidOnDraw (canvas canvas) {Paint Paint=NewPaint (); if(Pressure < 50) {paint.setcolor (color.green); }        Else if(Pressure < 80) {Paint.setcolor (0xffff8800); }        Else{paint.setcolor (color.red); } canvas.drawrect (Ten + max-pressure, 30, 10 +max, paint); }}

#include <jni.h>#include<stdio.h>#include<stdlib.h>intgetpressure () {//... Monitoring voltage ... Operation to get pressure value    returnRAND ()%101;}intMonitor; Jniexportvoidjnicall java_com_itheima_monitor_mainactivity_startmonitor (jnienv*env, Jobject obj) {Monitor=1;  while(monitor) {//Get Boiler pressure        intpressure =getpressure (); //Jclass (*findclass) (jnienv*, const char*);Jclass clazz = (*env)->findclass (env,"com/itheima/monitor/mainactivity"); //Jmethodid (*getmethodid) (jnienv*, Jclass, const char*, const char*);Jmethodid Methodid = (*env)->getmethodid (env, Clazz,"Show","(I) V"); //void (*callvoidmethod) (jnienv*, Jobject, Jmethodid, ...);(*env)Callvoidmethod (env, obj, methodid, pressure); Sleep (1); }}jniexportvoidjnicall java_com_itheima_monitor_mainactivity_stopmonitor (jnienv*env, Jobject obj) {Monitor=0;}

Application.mk

App_abi: = Armeabi x86

Android.mk

Local_path: = $ (call my-dir) include $ (clear_vars) local_module    := hellolocal_src_files:=  Hello.cinclude $ (build_shared_library)

"JNI" Boiler pressure monitor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.