2021年3月5日:
今天完成了老师星期四布置的阶段一测试,主要添加了登录和注册功能以及在填报界面添加了填报人员的一些特殊情况,例如一些变动以及其他情况,当然,今天还看了一眼ssm项目的实战视频,了解了vue框架的一些基本概念和操作,今日的代码完成如下:
主要的MainActivity:
package com.example.myapplication;
import android.Manifest;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import java.util.Date;
public class MainActivity extends Activity {
private shujuku shuju;
public LocationClient myLocationClient = null;
public MyLocationListener myLocationListener;
private static final String TAG = "MainActivity";
private long exitTime = 0;
private TextView text;
private TextView add;
private TextView name;
private EditText tiwen;
public SQLiteDatabase db;
private CheckBox c1,c2,c3,c4,c5;
private EditText e1,e2,e3,e4;
public static String str="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
shuju=new shujuku(this,"tiwenapp.db",null,1);
db=shuju.getReadableDatabase();
havePermission();
registerMyLocationListener();
c1=(CheckBox)findViewById(R.id.c1);
c2=(CheckBox)findViewById(R.id.c2);
c3=(CheckBox)findViewById(R.id.c3);
c4=(CheckBox)findViewById(R.id.c4);
c5=(CheckBox)findViewById(R.id.c5);
e1=(EditText)findViewById(R.id.e1);
e2=(EditText)findViewById(R.id.e2);
e3=(EditText)findViewById(R.id.e3);
e4=(EditText)findViewById(R.id.e4);
text=( TextView)findViewById(R.id.date);
add=(TextView)findViewById(R.id.address);
name=(TextView)findViewById(R.id.name);
Bundle b=getIntent().getExtras();
String n=b.getString("name");
name.setText(n);
tiwen=(EditText)findViewById(R.id.tiwen);
c1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
str+="无";
}
}
});
c2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
str+="特殊情况1:"+e1.getText().toString()+" ";
}
}
});
c3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
str+="特殊情况2:"+e2.getText().toString()+" ";
}
}
});
c4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
str+="特殊情况3:"+e3.getText().toString()+" ";
}
}
});
c5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
str+="特殊情况4:"+e4.getText().toString()+" ";
}
}
});
text.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Date date = new Date();
String time = date.toLocaleString();
text.setText(time);
}
});
}
private void havePermission() {
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED||
ActivityCompat.checkSelfPermission(MainActivity.this,Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(MainActivity.this,new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
},100);
}
}
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
Log.d(TAG, "onRequestPermissionsResult: requestcode"+requestCode
+" "+permissions.toString()
+" "+grantResults[0]
);
if (grantResults[0]!=0){
Toast.makeText(this, "要开启权限才能用软件哦,不然无法让您更好的体验", Toast.LENGTH_SHORT).show();
this.finish();
}
}
public void showLocation(View view) {
startActivityForResult(new Intent(MainActivity.this, ShowLocationActivity.class),0x78);
}
public void tibia(View view) {
String min=name.getText().toString();
String ti=tiwen.getText().toString();
String time=text.getText().toString();
String address=add.getText().toString();
insertdata(db,min,ti,time,address,str);
Intent intent = new Intent();
intent.setClass(MainActivity.this,Tijiao.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
private void insertdata(SQLiteDatabase bd,String name,String ti,String time,String address,String specail){
ContentValues v=new ContentValues();
v.put("name",name);
v.put("tiwen",ti);
v.put("date",time);
v.put("address",address);
v.put("special",specail);
bd.insert("app",null,v);
}
protected void onDestroy() {
super.onDestroy();
if(shuju!=null){
shuju.close();
}
}
private void getLocation(){
LocationClientOption option = new LocationClientOption();
option.setScanSpan(1000);
option.setOpenGps(true);
option.setLocationNotify(true);
option.setLocationMode(LocationClientOption.LocationMode.Device_Sensors);
option.setIgnoreKillProcess(false);
option.SetIgnoreCacheException(false);
option.setEnableSimulateGps(false);
option.setIsNeedAddress(true);
option.setIsNeedLocationDescribe(true);
option.setIsNeedLocationPoiList(true);
myLocationClient.setLocOption(option);
myLocationClient.start();
}
public class MyLocationListener extends BDAbstractLocationListener {
public void onReceiveLocation(BDLocation location) {
MyLocationInfo.address = location.getAddrStr();
MyLocationInfo.poiList = location.getPoiList();
}
}
private void registerMyLocationListener() {
myLocationClient = new LocationClient(getApplicationContext());
myLocationListener = new MyLocationListener();
myLocationClient.registerLocationListener(myLocationListener);
getLocation();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if(requestCode==0x11 && resultCode==0x11){
Bundle bundle=data.getExtras();
String date=bundle.getString("data");
text.setText(date);
}
if(requestCode==0x78 && resultCode==0x78){
Bundle bundle=data.getExtras();
String date=bundle.getString("address");
add.setText(date);
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
exit();
return true;
}
return super.onKeyDown(keyCode, event);
}
public void exit() {
if ((System.currentTimeMillis() - exitTime) > 2000) {
Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else {
finish();
System.exit(0);
}
}
}
明天打算做一做老师布置的体温计测软件的第二阶段。