package ypy.client;
import android.app.Activity;
import android.app.Service;
import android.content.DialogInterface;
import android.database.Cursor;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;
import android.os.Vibrator;
import android.provider.ContactsContract;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.TimeZone;
public class MainActivity extends AppCompatActivity {
private SoundPool sp;
private HashMap<Integer,Integer> spMap;
Handler handler1, handler2;
private ImageView rainImage;
private TextView currentTime, thresholdTime, red;
private Button setThreshold;
private EditText setHour, setMinute, setSecond;
private long isRain = 0;
private long threshold = 0;
private int redSensor = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
handler1.postDelayed(soundRunnable1, 100);
handler2.postDelayed(soundRunnable2, 1000);
setListenser();
}
private void init() {
rainImage = (ImageView)findViewById(R.id.rain_image);
currentTime = (TextView)findViewById(R.id.time_current);
thresholdTime = (TextView)findViewById(R.id.time_threadhold);
red = (TextView)findViewById(R.id.red);
setThreshold = (Button)findViewById(R.id.set_threshold);
sp = new SoundPool(2, AudioManager.STREAM_MUSIC,0);
spMap = new HashMap<Integer,Integer>();
spMap.put(1, sp.load(this,R.raw.notice, 1));
handler1 = new Handler();
handler2 = new Handler();
}
private void setListenser() {
setThreshold.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LayoutInflater factory = LayoutInflater.from(MainActivity.this);
View dialogView = factory.inflate(R.layout.dialog_layout, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("修改阈值");
builder.setView(dialogView);
setHour = (EditText) dialogView.findViewById(R.id.dialogHour);;
setMinute = (EditText) dialogView.findViewById(R.id.dialogMinute);
setSecond = (EditText) dialogView.findViewById(R.id.dialogSecond);
builder.setNegativeButton("放弃修改", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setPositiveButton("保存修改", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String time1 = setHour.getText().toString()+":"+setMinute.getText().toString()+":" +setSecond.getText().toString();
String[] my1 =time1.split(":");
int hour1 =Integer.parseInt(my1[0]);
int min1 =Integer.parseInt(my1[1]);
int sec1 =Integer.parseInt(my1[2]);
final int temp =(hour1*3600+min1*60+sec1) *1000;
Runnable set_threshold= new Runnable() {
@Override
public void run() {
String baseURL = "http://172.18.71.17:8080/IoT/set/threshold/";
String threshold = temp+"";
try{
String url = baseURL + threshold;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = new DefaultHttpClient().execute(httpGet);
} catch (Exception e) {
e.printStackTrace();
}
}
};
new Thread(set_threshold).start();
Toast.makeText(MainActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
}
});
builder.create();
builder.show();
}
});
}
public void playSounds(int sound, int number){
AudioManager am = (AudioManager)this.getSystemService(this.AUDIO_SERVICE);
float audioMaxVolumn = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float audioCurrentVolumn = am.getStreamVolume(AudioManager.STREAM_MUSIC);
float volumnRatio = audioCurrentVolumn/audioMaxVolumn;
sp.play(spMap.get(sound), volumnRatio, volumnRatio, 1, number, 1);
}
Runnable getTask= new Runnable() { //返回下雨时长、阈值、红外情况
@Override
public void run() {
String baseURL = "http://172.18.71.17:8080/IoT/get";
String result= "";
String TAG= "get";
try {
HttpGet httpGet= new HttpGet(baseURL);
HttpResponse httpResponse= new DefaultHttpClient().execute(httpGet);
result = EntityUtils.toString(httpResponse.getEntity(),"UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
Message msg = new Message();
Bundle data = new Bundle();
data.putString("value", result);
msg.setData(data);
get_handler.sendMessage(msg);
}
};
Handler get_handler= new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
Bundle data = msg.getData();
String val = data.getString("value");
String TAG = "json";
try{
JSONArray array= new JSONObject(val).getJSONArray("data");
for (int i = 0; i < array.length(); ++i) {
JSONObject temp = array.getJSONObject(i);
isRain = Integer.parseInt(temp.get("rain").toString());
redSensor = Integer.parseInt(temp.getString("redsensor").toString());
threshold = Integer.parseInt(temp.getString("threshold").toString());
}
if (isRain > 0) {
rainImage.setImageResource(R.mipmap.rain);
} else {
rainImage.setImageResource(R.mipmap.sun);
}
if (redSensor > 0) {
red.setText("红外预警");
} else {
red.setText("");
}
currentTime.setText(timeParse(isRain));
thresholdTime.setText(timeParse(threshold));
}
catch (Exception e) {
Log.i(TAG, e.toString());
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
案例说明:基于物联网开发平台,结合农业物联网和视频监控技术,实现一个物联网农业的应用案例,实现一到两项传感数据获取、监控或者控制。完成一个可执行、演示的系统。 技能集:IAR单片机编程,嵌入式linux QT编程,网站,数据库,Android应用程序开发等等 具体功能: 智能报警子系统 (1) 系统可以灵活的设置各个温室不同环境参数的上下阀值。一旦超出阀值,系统可以根据配置,通过手机短信、系统消息等方式提醒相应管理者。 (2) 报警提醒内容可根据模板灵活设置,根据不同客户需求可以设置不同的提醒内容,最大程度满足客户个性化需求。 (3) 可以根据报警记录查看关联的温室设备,更加及时、快速远程控制温室设备,高效处理温室环境问题。 (4) 可及时发现不正常状态设备,通过短信或系统消息及时提醒管理者,保证系统稳定运行。
资源推荐
资源详情
资源评论
收起资源包目录
农业物联网技术平台开发.zip (94个子文件)
IoT-master
IoT(后台)
.classpath 5KB
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.jdt.core.prefs 430B
.jsdtscope 639B
org.eclipse.wst.validation.prefs 50B
org.eclipse.wst.common.component 734B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.m2e.core.prefs 90B
pom.xml 3KB
src
main
resources
iot-servlet.xml 2KB
jdbc.properties 293B
java
com
IoT
DAO
DAO.java 3KB
model
model.java 524B
raintime.java 676B
Controller
setRequest.java 1KB
getRequest.java 995B
webapp
WEB-INF
web.xml 670B
index.jsp 57B
target
classes
iot-servlet.xml 2KB
jdbc.properties 293B
com
IoT
DAO
DAO$1.class 1KB
DAO$2.class 1KB
DAO.class 2KB
DAO$3.class 1KB
model
model.class 861B
raintime.class 614B
Controller
getRequest.class 1KB
setRequest.class 1KB
m2e-wtp
web-resources
META-INF
MANIFEST.MF 115B
maven
com.IoT
IoT
pom.properties 198B
pom.xml 3KB
.project 1KB
IoT_SENSOR
widget.ui 976B
include
node_config.h 2KB
libwsncomm.h 3KB
rain.ui 4KB
lib
libwsncomm.so 20KB
pic
Thumbs.db 10KB
human.png 91KB
rainUmbrella.png 26KB
safe.png 41KB
sun.png 33KB
widget.cpp 499B
IOT_SENSOR.pro.user 13KB
rain.h 1KB
secure.h 1KB
secure.cpp 7KB
main.cpp 227B
rain.cpp 6KB
IOT_SENSOR.pro 846B
res.qrc 201B
secure.ui 4KB
widget.h 510B
IoT(手机端)
gradle.properties 872B
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 239B
app
src
androidTest
java
ypy
client
ApplicationTest.java 353B
test
java
ypy
client
ExampleUnitTest.java 317B
main
java
ypy
client
Utils.java 628B
MainActivity.java 10KB
res
mipmap-xxhdpi
logo.png 17KB
rain.png 24KB
sun.png 17KB
ic_launcher.png 8KB
mipmap-hdpi
ic_launcher.png 3KB
mipmap-mdpi
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher.png 10KB
mipmap-xhdpi
ic_launcher.png 5KB
values-w820dp
dimens.xml 364B
values
dimens.xml 216B
colors.xml 254B
strings.xml 78B
styles.xml 394B
layout
activity_main.xml 3KB
dialog_layout.xml 2KB
raw
notice.wav 358KB
AndroidManifest.xml 880B
proguard-rules.pro 662B
build.gradle 674B
.gitignore 8B
gradlew.bat 2KB
build.gradle 521B
.idea
.name 6B
runConfigurations.xml 564B
misc.xml 3KB
compiler.xml 686B
modules.xml 349B
gradle.xml 739B
encodings.xml 159B
copyright
profiles_settings.xml 76B
settings.gradle 16B
gradlew 5KB
.gitignore 105B
共 94 条
- 1
资源评论
博士僧小星
- 粉丝: 1713
- 资源: 5876
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功