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
相关文章
|
3月前
|
Android开发
定制Android关机界面
定制Android关机界面
29 0
|
23天前
|
XML Android开发 UED
💥Android UI设计新风尚!掌握Material Design精髓,让你的界面颜值爆表!🎨
【7月更文挑战第28天】随着移动应用市场的发展,用户对界面设计的要求不断提高。Material Design是由Google推出的设计语言,强调真实感、统一性和创新性,通过模拟纸张和墨水的物理属性创造沉浸式体验。它注重色彩、排版、图标和布局的一致性,确保跨设备的统一视觉风格。Android Studio提供了丰富的Material Design组件库,如按钮、卡片等,易于使用且美观。
56 1
|
1月前
|
XML Android开发 数据安全/隐私保护
使用RelativeLayout布局Android界面
使用RelativeLayout布局Android界面
|
2月前
|
编解码 安全 Android开发
探索iOS与Android开发的差异:从界面到性能
【6月更文挑战第10天】在移动应用开发的广阔天地中,iOS和Android两大平台各占山头,它们在设计理念、用户体验、性能优化等方面展现出独特的魅力。本文将深入探讨这两大系统在开发过程中的主要差异,从用户界面设计到性能调优,揭示各自背后的技术逻辑与创新策略,为开发者提供全面的视角和实用的开发指南。
|
2月前
|
XML Android开发 数据格式
【Android UI】使用RelativeLayout与TableLayout实现登录界面
【Android UI】使用RelativeLayout与TableLayout实现登录界面
39 5
|
1月前
|
Android开发 索引
Android流布局实现筛选界面
Android流布局实现筛选界面
27 0
|
3月前
|
物联网 测试技术 Android开发
构建未来:基于Android的智能物联网家居控制系统
【5月更文挑战第28天】 随着物联网(IoT)技术的不断演进,智能家居系统正变得越来越普遍。本文深入探讨了利用Android平台构建一个高效、可扩展的智能物联网家居控制系统。我们将分析系统架构、关键技术组件以及开发中的最佳实践,旨在为开发者提供一个清晰的指南,以实现设备之间的无缝通信和自动化控制。
|
3月前
|
安全 搜索推荐 物联网
构建未来:基于Android的智能物联网家居系统
【5月更文挑战第15天】 在快速发展的数字化时代,智能物联网(IoT)技术与移动操作系统的结合正在塑造未来家居的生活方式。特别是Android平台,以其开放性、灵活性和广泛的用户基础,成为智能家居创新的理想选择。本文将探讨如何利用Android系统构建一个高效、安全且易于扩展的智能家居控制系统,涵盖系统设计、关键技术实现以及可能面临的挑战。通过分析具体案例,我们旨在为开发者和企业提供一套可行的解决方案蓝图,以促进智能家居领域的进一步发展。
|
3月前
|
监控 物联网
LabVIEW开发基于物联网的多功能功率分析仪
LabVIEW开发基于物联网的多功能功率分析仪
38 2
|
3月前
|
传感器 机器学习/深度学习 算法
LabVIEW开发工业物联网状态监测
LabVIEW开发工业物联网状态监测
46 2

相关产品

  • 物联网平台