Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面

简介: Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面

效果图:


image.png


自定义对话框布局:


7.png


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="350dp"
              android:layout_height="wrap_content"
              android:background="@android:color/white"
              android:orientation="vertical">
    <!--自定义对话框,线性布局水平方向-->
    <!--第一部分标题栏-->
    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#257CFF"
        android:gravity="center"
        android:paddingBottom="8dp"
        android:paddingTop="8dp"
        android:text="设置阈值"
        android:textColor="@android:color/white"
        android:textSize="18sp"/>
    <!--设置温度阈值-->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="温度阈值设置:"
        android:textColor="#6C6C6C"/>
    <!--设置阈值-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="center"
        android:orientation="horizontal">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:layout_weight="1">
            <TextView
                android:id="@+id/tv_tempValue"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="30"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="℃"
                />
        </LinearLayout>
        <SeekBar
            android:id="@+id/sb_temp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="4"
            android:max="60"
            android:progress="30"/>
    </LinearLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="5dp"
        android:text="数值范围 0-60℃"
        android:textColor="#6C6C6C"/>
    <!--分割线-->
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:background="#cccccc"></View>
    <!--设置湿度阈值-->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="湿度阈值设置:"
        android:textColor="#6C6C6C"/>
    <!--设置阈值-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="center"
        android:orientation="horizontal">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:layout_weight="1">
            <TextView
                android:id="@+id/tv_humiValue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:text="30"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="%RH"
                />
        </LinearLayout>
        <SeekBar
            android:id="@+id/sb_humi"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="4"
            android:max="100"
            android:progress="30"/>
    </LinearLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="5dp"
        android:text="数值范围 0-100%RH"
        android:textColor="#6C6C6C"/>
    <!--分割线-->
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:background="#cccccc"></View>
    <!--设置光照阈值-->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="光照阈值设置:"
        android:textColor="#6C6C6C"/>
    <!--设置阈值-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="center"
        android:orientation="horizontal">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:layout_weight="1">
            <TextView
                android:id="@+id/tv_lightValue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:text="3000"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Lx"/>
        </LinearLayout>
        <SeekBar
            android:id="@+id/sb_light"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="4"
            android:max="10000"
            android:progress="3000"/>
    </LinearLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="5dp"
        android:text="数值范围 0-10000Lx"
        android:textColor="#6C6C6C"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:background="#cccccc"></View>
    <!--确定,取消按钮-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:id="@+id/btn_confirm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:text="确定"
            android:textColor="#257CFF"/>
        <!--分割线-->
        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#cccccc"></View>
        <Button
            android:id="@+id/btn_cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:text="取消"
            android:textColor="#257CFF"/>
    </LinearLayout>
</LinearLayout>



自定义对话框实现类:

package com.newland.project3_3;
import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
/**
 * 设置阈值对话框
 */
public class SettingThresholdDialog extends Dialog {
    private TextView tvTempValue,tvHumiValue,tvLightValue;
    private Button btnCancel;
    private Button btnConfirm;
    private SeekBar sbTemp,sbHumi,sbLight;
    public SettingThresholdDialog(@NonNull Context context) {
        super(context,R.style.Dialog);
        //关联布局文件
        this.setContentView(R.layout.dialog_setting_threshold);
        //初始化组件
        initView();
        addListener();
    }
    private void initView() {
        sbTemp =  findViewById(R.id.sb_temp);
        sbHumi =  findViewById(R.id.sb_humi);
        sbLight =  findViewById(R.id.sb_light);
        tvTempValue = findViewById(R.id.tv_tempValue);
        tvHumiValue = findViewById(R.id.tv_humiValue);
        tvLightValue = findViewById(R.id.tv_lightValue);
        btnCancel = findViewById(R.id.btn_cancel);
        btnConfirm =  findViewById(R.id.btn_confirm);
    }
    private void addListener() {
        //温度SeekBar状态改变监听
        sbTemp.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                //SeekBar进度显示到TextView上
                tvTempValue.setText(String.valueOf(progress));
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        //湿度SeekBar状态改变监听
        sbHumi.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                //SeekBar进度显示到TextView上
                tvHumiValue.setText(String.valueOf(progress));
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        //光照SeekBar状态改变监听
        sbLight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                //SeekBar进度显示到TextView上
                tvLightValue.setText(String.valueOf(progress));
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        //设置确定点击事件
        btnConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //对话框消失
                SettingThresholdDialog.this.dismiss();
            }
        });
        //设置取消点击事件
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //对话框消失
                SettingThresholdDialog.this.dismiss();
            }
        });
    }
}



在主类中创建对话框并显示:


package com.newland.project3_3;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //创建对话框并显示
        SettingThresholdDialog dialog = new SettingThresholdDialog(this);
        dialog.show();
    }
}
相关实践学习
钉钉群中如何接收IoT温控器数据告警通知
本实验主要介绍如何将温控器设备以MQTT协议接入IoT物联网平台,通过云产品流转到函数计算FC,调用钉钉群机器人API,实时推送温湿度消息到钉钉群。
阿里云AIoT物联网开发实战
本课程将由物联网专家带你熟悉阿里云AIoT物联网领域全套云产品,7天轻松搭建基于Arduino的端到端物联网场景应用。 开始学习前,请先开通下方两个云产品,让学习更流畅: IoT物联网平台:https://iot.console.aliyun.com/ LinkWAN物联网络管理平台:https://linkwan.console.aliyun.com/service-open
相关文章
|
2月前
|
监控 安全 Android开发
【新手必读】Airtest测试Android手机常见的设置问题
【新手必读】Airtest测试Android手机常见的设置问题
|
6月前
|
数据库连接 数据库 Android开发
Android -- Room简化数据库设置图书案例
Android -- Room简化数据库设置图书案例
22 0
|
4月前
|
Android开发
Android Studio APP开发入门之对话框Dialog的讲解及使用(附源码 包括提醒对话框,日期对话框,时间对话框)
Android Studio APP开发入门之对话框Dialog的讲解及使用(附源码 包括提醒对话框,日期对话框,时间对话框)
35 0
|
5天前
|
存储 Java Android开发
Android系统 设置第三方应用为默认Launcher实现和原理分析
Android系统 设置第三方应用为默认Launcher实现和原理分析
18 0
|
1月前
|
Android开发
[Android]AlertDialog对话框
[Android]AlertDialog对话框
18 0
|
6月前
|
SQL 人工智能 移动开发
Android 遍历界面所有的View
本文讲述如何遍历获取页面中所有的view,并输出对应的id,textview文本内容,imageview实际大小及设置的图片大小。 可用于检测android应用中的大图。
|
2月前
|
Android开发 数据安全/隐私保护
【Android Studio】简单的QQ登录界面
【Android Studio】简单的QQ登录界面
|
3月前
|
网络安全 Android开发
2023安卓逆向 -- 抓包环境设置(Charles+Postern)
2023安卓逆向 -- 抓包环境设置(Charles+Postern)
33 0
|
4月前
|
传感器 人工智能 自动驾驶
【Android App】物联网实战项目之自动驾驶的智能小车(附源码和演示 超详细)
【Android App】物联网实战项目之自动驾驶的智能小车(附源码和演示 超详细)
99 0
|
4月前
|
传感器 物联网 Android开发
【Android App】物联网中指南针、计步器、感光器、陀螺仪的讲解及实战演示(附源码 超详细必看)
【Android App】物联网中指南针、计步器、感光器、陀螺仪的讲解及实战演示(附源码 超详细必看)
65 1

热门文章

最新文章

相关产品

  • 物联网平台