• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
戈瑾
博客园    首页    新随笔    联系   管理    订阅  订阅
体温上报APP——录入体温

继上次完成体温上报APP后,老师又提出了进一步的要求

1、要求增加用户注册功能,用户注册信息包括用户ID(学号)、用户名(姓名),手机号码,用户单位(班级),用户班级四项基本信息,用户第一次注册后,用户姓名不用每次输入 。

2、体温上报界面包括用户姓名(自动从注册信息获取)、测量时间(精确到年月日时分即可)、所在位置(自动获取)、测量体温(缺省值为36.2),特殊情况(见下图)五项内容。

 

 

 


登陆与注册在之前博客里发过,仔细不在赘述

登陆界面:

 

 

 注册界面:

 

录入体面与之前不同的是增加了特殊情况,可以进行多选和输入

AddActivity>java文件:

  1 package com.example.application;
  2 
  3 import java.util.ArrayList;
  4 import java.util.Calendar;
  5 import java.util.List;
  6 
  7 import androidx.appcompat.app.AppCompatActivity;
  8 
  9 import android.content.ContentValues;
 10 import android.content.Intent;
 11 import android.database.Cursor;
 12 import android.database.sqlite.SQLiteDatabase;
 13 import android.view.View;
 14 import android.widget.Button;
 15 import android.widget.CheckBox;
 16 import android.widget.EditText;
 17 import android.widget.ScrollView;
 18 import android.widget.TextView;
 19 import android.os.Bundle;
 20 import android.widget.Toast;
 21 
 22 import static com.example.application.Constants.TABLE_NAME;
 23 
 24 import com.baidu.location.BDAbstractLocationListener;
 25 import com.baidu.location.BDLocation;
 26 import com.baidu.location.LocationClient;
 27 import com.baidu.location.LocationClientOption;
 28 import com.baidu.mapapi.SDKInitializer;
 29 
 30 public class AddActivity extends AppCompatActivity {
 31     private DatabaseHelper myHelper;
 32     public SQLiteDatabase db;
 33     public ContentValues values;
 34     private TextView tv_date;
 35     private TextView tv_time;
 36     private EditText et_name;
 37     private EditText et_location;
 38     private EditText et_temperature;
 39     private CheckBox checkBox1;
 40     private CheckBox checkBox2;
 41     private CheckBox checkBox3;
 42     private CheckBox checkBox4;
 43     private CheckBox checkBox5;
 44     private EditText checkBox2_bj;
 45     private EditText checkBox3_bj;
 46     private EditText checkBox4_bj;
 47     private EditText checkBox5_bj;
 48 
 49     private TextView mTvShow;
 50     private Button bt_add;
 51     private Calendar cal;
 52     private String year;
 53     private String month;
 54     private String day;
 55     private String hour;
 56     private String minute;
 57     private String my_time_1;
 58     private String my_time_2;
 59     private String ID;
 60     private String phone;
 61     private String company;
 62     public LocationClient mLocationClient = null;
 63     private MyLocationListener myListener = new MyLocationListener();
 64 
 65     public class MyLocationListener extends BDAbstractLocationListener {
 66         @Override
 67         public void onReceiveLocation(BDLocation location){
 68             //此处的BDLocation为定位结果信息类,通过它的各种get方法可获取定位相关的全部结果
 69             //以下只列举部分获取地址相关的结果信息
 70             //更多结果信息获取说明,请参照类参考中BDLocation类中的说明
 71             String addr = location.getAddrStr();    //获取详细地址信息
 72             String country = location.getCountry();    //获取国家
 73             String province = location.getProvince();    //获取省份
 74             String city = location.getCity();    //获取城市
 75             String district = location.getDistrict();    //获取区县
 76             String street = location.getStreet();    //获取街道信息
 77             String town = location.getTown();
 78             //获取乡镇信息
 79             et_location=(EditText)findViewById(R.id.edit_text2);
 80             et_location.setText(country+province+city+district+town+street);
 81         }
 82     }
 83 
 84     protected void onCreate(Bundle savedInstanceState) {
 85         super.onCreate(savedInstanceState);
 86         //如果没有定位权限,动态请求用户允许使用该权限
 87         SDKInitializer.initialize(getApplicationContext());
 88         setContentView(R.layout.activity_add);
 89         //创建数据库
 90         myHelper = new DatabaseHelper(this);
 91         initdata();
 92         getTime();
 93     }
 94     //初始化
 95     private void initdata() {
 96         Intent intent=getIntent();
 97         bt_add=(Button)findViewById(R.id.add_data);
 98         tv_date = (TextView) findViewById(R.id.textView1);
 99         tv_time = (TextView) findViewById(R.id.textView2);
100         et_name=(EditText)findViewById(R.id.edit_text1) ;
101         et_name.setText(intent.getStringExtra("user_name"));
102         et_temperature=(EditText)findViewById(R.id.edit_text3) ;
103         checkBox1=(CheckBox)findViewById(R.id.check1);
104         checkBox2=(CheckBox)findViewById(R.id.check2);
105         checkBox3=(CheckBox)findViewById(R.id.check3);
106         checkBox4=(CheckBox)findViewById(R.id.check4);
107         checkBox5=(CheckBox)findViewById(R.id.check5);
108         checkBox2_bj=(EditText)findViewById(R.id.check2_bj) ;
109         checkBox3_bj=(EditText)findViewById(R.id.check3_bj) ;
110         checkBox4_bj=(EditText)findViewById(R.id.check4_bj) ;
111         checkBox5_bj=(EditText)findViewById(R.id.check5_bj) ;
112     }
113     //获取时间
114     private void getTime() {
115         cal = Calendar.getInstance();
116         year = String.valueOf(cal.get(Calendar.YEAR));
117         month = String.valueOf(cal.get(Calendar.MONTH)+ 1) ;
118         day = String.valueOf(cal.get(Calendar.DATE));
119         if (cal.get(Calendar.AM_PM) == 0) {
120             if (cal.get(Calendar.HOUR) < 10) {
121                 hour = "0" + cal.get(Calendar.HOUR);
122             } else {
123                 hour = String.valueOf(cal.get(Calendar.HOUR));
124             }
125         }
126         else {
127             hour = String.valueOf(cal.get(Calendar.HOUR) + 12);
128         }
129         if (cal.get(Calendar.MINUTE) < 10) {
130             minute = "0" + cal.get(Calendar.MINUTE);
131         } else {
132             minute = String.valueOf(cal.get(Calendar.MINUTE));
133         }
134         my_time_1 = year + "年" + month + "月" + day+"日";
135         my_time_2 = hour + ":" + minute;
136         tv_date.setText(my_time_1);
137         tv_time.setText(my_time_2);
138     }
139 
140     public void getAddress(View view)
141     {
142         mLocationClient = new LocationClient(getApplicationContext());
143         //声明LocationClient类
144         mLocationClient.registerLocationListener(myListener);
145         LocationClientOption option = new LocationClientOption();
146         option.setIsNeedAddress(true);
147         option.setNeedNewVersionRgc(true);
148         mLocationClient.setLocOption(option);
149         //注册监听函数
150         mLocationClient.start();
151     }
152 
153     public void insertData(View view)
154     {
155         //获取可读写的SQLiteDatabase对象
156         db = myHelper.getWritableDatabase();
157         //创建ContentValues对象
158         values = new ContentValues();
159         values.put("name",et_name.getText().toString());
160         values.put("date",tv_date.getText().toString());
161         values.put("time",tv_time.getText().toString());
162         values.put("location",et_location.getText().toString());
163         values.put("temperature",et_temperature.getText().toString());
164         //定义字符串变量来储存其他情况
165         StringBuffer str_bf=new StringBuffer();
166         StringBuffer str_tip=new StringBuffer();
167         if(checkBox1.isChecked()){
168             str_bf.append(checkBox1.getText().toString()+" ");
169             str_tip.append("");
170         }
171         if(checkBox2.isChecked()){
172             str_bf.append(checkBox2.getText().toString()+" ");
173             str_tip.append(checkBox2_bj.getText().toString()+" ");
174         }
175         if(checkBox3.isChecked()){
176             str_bf.append(checkBox3.getText().toString()+" ");
177             str_tip.append(checkBox3_bj.getText().toString()+" ");
178         }
179         if(checkBox4.isChecked()){
180             str_bf.append(checkBox4.getText().toString()+" ");
181             str_tip.append(checkBox4_bj.getText().toString()+" ");
182         }
183         if(checkBox5.isChecked()){
184             str_bf.append(checkBox5.getText().toString()+" ");
185             str_tip.append(checkBox5_bj.getText().toString()+" ");
186         }
187 
188         values.put("situation",str_bf.toString());
189         values.put("tip",str_tip.toString());
190         if(et_name.getText().toString().equals("")|| et_location.getText().toString().equals("")||et_temperature.getText().toString().equals("")||str_bf != null && "".equals(str_bf.toString())){
191             Toast.makeText(this,"请将信息填写完整",Toast.LENGTH_SHORT).show();
192         }else {
193             long flag = db.insert(TABLE_NAME, null, values);
194             Toast.makeText(this, "登记成功", Toast.LENGTH_LONG).show();
195         }
196 
197         Cursor cursor = db.query("TABLE_NAME_User", null, "name like ?", new String[]{et_name.getText().toString()}, null, null, null);//读取数据库所有信息
198         if(cursor.moveToFirst()){
199             do{
200                 ID=cursor.getString(cursor.getColumnIndex("ID"));
201                 phone=cursor.getString(cursor.getColumnIndex("phone"));
202                 company=cursor.getString(cursor.getColumnIndex("company"));
203             }while (cursor.moveToNext());
204         }
205         myHelper.add1(ID,et_name.getText().toString(),phone,company,tv_date.getText().toString(),tv_time.getText().toString(),et_location.getText().toString(),et_temperature.getText().toString(),str_bf.toString(),str_tip.toString());
206         cursor.close();
207         db.close();
208     }
209      public void showbj2(View view){
210          checkBox2_bj.setVisibility(View.VISIBLE);
211      }
212      public void showbj3(View view){
213          checkBox3_bj.setVisibility(View.VISIBLE);
214      }
215      public void showbj4(View view){
216          checkBox4_bj.setVisibility(View.VISIBLE);
217      }
218      public void showbj5(View view){
219          checkBox5_bj.setVisibility(View.VISIBLE);
220      }
221 }

 

 

 activity_add.xml文件:

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  3     xmlns:app="http://schemas.android.com/apk/res-auto"
  4     xmlns:tools="http://schemas.android.com/tools"
  5     android:orientation="vertical"
  6     android:layout_width="match_parent"
  7     android:layout_height="match_parent"
  8     android:background="@mipmap/bj3"
  9     tools:context=".AddActivity"
 10     >
 11     <LinearLayout
 12         android:layout_width="match_parent"
 13         android:layout_height="match_parent"
 14         android:orientation="vertical">
 15 
 16     <LinearLayout
 17         android:layout_width="wrap_content"
 18         android:layout_height="wrap_content"
 19         android:orientation="horizontal">
 20         <TextView
 21             android:layout_width="wrap_content"
 22             android:layout_height="wrap_content"
 23             android:text="  姓  名:"
 24             android:textSize="18sp" />
 25         <EditText
 26             android:id="@+id/edit_text1"
 27             android:layout_width="280sp"
 28             android:layout_height="wrap_content"
 29             android:hint="请填写姓名"
 30             android:maxLines="1"
 31             android:textColor="#000000"
 32             />
 33     </LinearLayout>
 34     <LinearLayout
 35         android:layout_width="wrap_content"
 36         android:layout_height="wrap_content"
 37         android:orientation="horizontal">
 38         <TextView
 39             android:layout_width="wrap_content"
 40             android:layout_height="wrap_content"
 41             android:text="  日  期:"
 42             android:textSize="18sp"/>
 43         <TextView
 44             android:id="@+id/textView1"
 45             android:layout_width="match_parent"
 46             android:layout_height="wrap_content"
 47             android:textColor="#000000"
 48             android:textSize="18sp"/>
 49     </LinearLayout>
 50     <LinearLayout
 51         android:layout_width="wrap_content"
 52         android:layout_height="wrap_content"
 53         android:orientation="horizontal">
 54         <TextView
 55             android:layout_width="wrap_content"
 56             android:layout_height="wrap_content"
 57             android:text="  时  间:"
 58             android:layout_marginTop="15dp"
 59             android:textSize="18sp"/>
 60         <TextView
 61             android:id="@+id/textView2"
 62             android:layout_width="match_parent"
 63             android:layout_height="wrap_content"
 64             android:textColor="#000000"
 65             android:layout_marginTop="15dp"
 66             android:textSize="18sp"/>
 67     </LinearLayout>
 68     <LinearLayout
 69         android:layout_width="wrap_content"
 70         android:layout_height="wrap_content"
 71         android:orientation="horizontal">
 72         <TextView
 73             android:layout_width="wrap_content"
 74             android:layout_height="wrap_content"
 75             android:text="  体  温:"
 76             android:textSize="18sp"/>
 77 
 78         <EditText
 79             android:id="@+id/edit_text3"
 80             android:layout_width="280sp"
 81             android:layout_height="wrap_content"
 82             android:drawableRight="@mipmap/wd1"
 83             android:text="36.2"
 84             android:maxLines="1" />
 85     </LinearLayout>
 86     <LinearLayout
 87         android:layout_width="wrap_content"
 88         android:layout_height="55dp"
 89         android:orientation="horizontal">
 90         <TextView
 91             android:layout_width="wrap_content"
 92             android:layout_height="wrap_content"
 93             android:text="  地  点:"
 94             android:textSize="18sp"/>
 95         <EditText
 96             android:id="@+id/edit_text2"
 97             android:layout_width="280sp"
 98             android:layout_height="60dp"
 99             android:onClick="getAddress"
100             android:hint="点击获取您的位置"
101             android:textColor="#000000"
102             android:minLines="2"
103             />
104     </LinearLayout>
105     <TextView
106         android:layout_width="wrap_content"
107         android:layout_height="wrap_content"
108         android:layout_marginTop="10dp"
109         android:text="  特殊情况(可多选,如有其他需报告的情况请说明)"
110         android:layout_marginBottom="10dp"
111         android:textSize="18sp"/>
112     <!--定义一个垂直线性布局-->
113     <LinearLayout
114         android:layout_gravity="center_horizontal"
115         android:orientation="vertical"
116         android:layout_width="wrap_content"
117         android:layout_height="wrap_content">
118         <!--定义五个复选框-->
119         <CheckBox
120             android:id="@+id/check1"
121             android:layout_width="wrap_content"
122             android:layout_height="wrap_content"
123             android:textSize="17sp"
124             android:text="无"/>
125         <CheckBox
126             android:id="@+id/check2"
127             android:layout_width="wrap_content"
128             android:layout_height="wrap_content"
129             android:textSize="17sp"
130             android:onClick="showbj2"
131             android:text="2020年12月27日至今去过或现在居住在中高风险地区"/>
132         <EditText
133             android:id="@+id/check2_bj"
134             android:layout_width="match_parent"
135             android:layout_height="wrap_content"
136             android:textSize="15sp"
137             android:visibility="gone"
138             android:textColor="#000000"
139             android:hint="按照公布的中高风险地区地域名称,对应填写"/>
140         <CheckBox
141             android:id="@+id/check3"
142             android:layout_width="wrap_content"
143             android:layout_height="wrap_content"
144             android:textSize="17sp"
145             android:onClick="showbj3"
146             android:text="本人或家人正在集中隔离"/>
147         <EditText
148             android:id="@+id/check3_bj"
149             android:layout_width="match_parent"
150             android:layout_height="wrap_content"
151             android:textSize="15sp"
152             android:visibility="gone"
153             android:textColor="#000000"
154             android:hint="请填写原因"/>
155         <CheckBox
156             android:id="@+id/check4"
157             android:layout_width="wrap_content"
158             android:layout_height="wrap_content"
159             android:textSize="17sp"
160             android:onClick="showbj4"
161             android:text="今日居住地异动"/>
162         <EditText
163             android:id="@+id/check4_bj"
164             android:layout_width="match_parent"
165             android:layout_height="wrap_content"
166             android:textSize="15sp"
167             android:textColor="#000000"
168             android:visibility="gone"
169             android:hint="请说明情况"/>
170         <CheckBox
171             android:id="@+id/check5"
172             android:layout_width="wrap_content"
173             android:layout_height="wrap_content"
174             android:textSize="17sp"
175             android:onClick="showbj5"
176             android:text="其他情况"/>
177         <EditText
178             android:id="@+id/check5_bj"
179             android:layout_width="match_parent"
180             android:layout_height="wrap_content"
181             android:textSize="15sp"
182             android:visibility="gone"
183             android:textColor="#000000"
184             android:hint="请说明情况"/>
185     </LinearLayout>
186 
187     <Button
188         android:id="@+id/add_data"
189         android:layout_width="match_parent"
190         android:layout_height="wrap_content"
191         android:background="#328359"
192         android:onClick="insertData"
193         android:text="登  记"
194         android:textColor="#F2F2F2"
195         android:layout_marginTop="10dp"
196         android:textSize="18sp" />
197     </LinearLayout>
198 </ScrollView>

DatabaseHelper.java文件:

 1 package com.example.application;
 2 
 3 import android.content.Context;
 4 import android.database.Cursor;
 5 import android.database.sqlite.SQLiteDatabase;
 6 import android.database.sqlite.SQLiteOpenHelper;
 7 import android.util.Log;
 8 
 9 import androidx.annotation.Nullable;
10 
11 import java.util.ArrayList;
12 
13 
14 public class DatabaseHelper extends SQLiteOpenHelper {
15     private SQLiteDatabase db;
16     private static final String TAG="DatabaseHelper";
17     public DatabaseHelper(@Nullable Context context) {
18         super(context, Constants.DATABASE_NAME, null, Constants.VERSION_CODE);
19         db = getReadableDatabase();
20     }
21 
22     @Override
23     public void onCreate(SQLiteDatabase db) {
24         //创建时的回调
25         Log.d(TAG,"创建数据库...");
26         String sql="create table "+Constants.TABLE_NAME+" (id integer primary key autoincrement, name varchar,date varchar,time varchar,location varchar,temperature varchar,situation varchar,tip varchar)";
27         db.execSQL(sql);
28         db.execSQL("CREATE TABLE IF NOT EXISTS TABLE_NAME_User(" +
29                 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
30                 "ID TEXT," +"name TEXT,"+"phone TEXT,"+
31                 "company TEXT)");
32         /*String sql2="create table "+Constants.TABLE_NAME2+" (id integer primary key autoincrement, name varchar,ID varchar,phone varchar,company varchar,date varchar,time varchar,location varchar,temperature varchar,situation varchar,tip varchar)";
33         db.execSQL(sql2);*/
34         db.execSQL("CREATE TABLE IF NOT EXISTS ALL_information(" +
35                 "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
36                 "ID TEXT," +"name TEXT,"+"phone TEXT,"+ "company varchar,"+"date TEXT,"+"time TEXT,"+ "location varchar,"+"temperature varchar,"+"situation varchar,"+"tip TEXT)");
37     }
38 
39     @Override
40     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
41         //升级时的回调
42         Log.d(TAG,"升级数据库...");
43     }
44 
45     public void add(String ID,String name,String phone,String company){
46         db.execSQL("INSERT INTO TABLE_NAME_User (ID,name,phone,company) VALUES(?,?,?,?)",new Object[]{ID,name,phone,company});
47     }
48     public void add1(String ID,String name,String phone,String company,String date,String time,String location,String temperature,String situation,String tip){
49         db.execSQL("INSERT INTO ALL_information (ID,name,phone,company,date,time,location,temperature,situation,tip) VALUES(?,?,?,?,?,?,?,?,?,?)",new Object[]{ID,name,phone,company,date,time,location,temperature,situation,tip});
50     }
51     public void delete(String ID,String name,String phone,String company){
52         db.execSQL("DELETE FROM TABLE_NAME_User WHERE ID = AND name = AND phone = AND company ="+ID+name+phone+company);
53     }
54     public void updata(String phone){
55         db.execSQL("UPDATE TABLE_NAME_User SET phone = ?",new Object[]{phone});
56     }
57 
58 
59     public ArrayList<User> getAllData(){
60 
61         ArrayList<User> list = new ArrayList<User>();
62         Cursor cursor = db.query("TABLE_NAME_User",null,null,null,null,null,"name DESC");
63         while(cursor.moveToNext()){
64             String ID=cursor.getString(cursor.getColumnIndex("ID"));
65             String name = cursor.getString(cursor.getColumnIndex("name"));
66             String phone = cursor.getString(cursor.getColumnIndex("phone"));
67             String company = cursor.getString(cursor.getColumnIndex("company"));
68             list.add(new User(ID,name,phone,company));
69         }
70         return list;
71     }
72 }

界面效果(虚拟机上定位无法获取):

 

posted on 2021-03-05 01:09  戈瑾  阅读(598)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3