HIS1.2版本开发(健康智库APP开发)

项目简介

这是一个大学小组项目,目的是开发一款app实现健康智库的建立,目前只是有个雏形阶段,其中有很多不足,也有很多功能没有实现,目前实现了:本地注册、登录、记住密码、注销等基础功能,涉及数据库的只是由于本人还未学习到,所以暂时搁置。
下面为项目目录
java部分
对应xml文件

采用一一对应的形式进行

登录页面

package com.example.his12;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import android.view.View.OnClickListener;
import com.bumptech.glide.Glide;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;
import com.example.his12.tool.MD5;

public class MainActivity extends Activity {

    public int pwdresetFlag=0;
private Button mlogin,mfoegetpassword,mregist;
private EditText mEtUserName,mEtPassword;
private ImageView M1p;
private CheckBox mRememberCheck;
    private SharedPreferences login_sp;
    private String userNameValue,passwordValue;
    private View loginView;                           //登录
    private View loginSuccessView;
    private TextView loginSuccessShow;
    private TextView mChangepwdText;
    private UserDataManager mUserDataManager;         //用户数据管理类




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//通过id找到相应的控件
        mEtUserName = (EditText) findViewById(R.id.account);
        mEtPassword = (EditText) findViewById(R.id.password);
        mregist = (Button) findViewById(R.id.btn_regist);
        mlogin = (Button) findViewById(R.id.btn_login);
        loginView = findViewById(R.id.view);
        loginSuccessView = findViewById(R.id.login_success_view);
        loginSuccessShow = (TextView) findViewById(R.id.login_success_show);

        mChangepwdText = (TextView) findViewById(R.id.login_text_change_pwd);

        mRememberCheck = (CheckBox) findViewById(R.id.Login_Remember);

        login_sp = getSharedPreferences("userInfo", 0);
        String name = login_sp.getString("USER_NAME", "");
        String pwd = login_sp.getString("PASSWORD", "");
        boolean choseRemember = login_sp.getBoolean("mRememberCheck", false);
        boolean choseAutoLogin = login_sp.getBoolean("mAutologinCheck", false);
        //如果上次选了记住密码,那进入登录页面也自动勾选记住密码,并填上用户名和密码
        if (choseRemember) {
            mEtUserName.setText(name);
            mEtPassword.setText(pwd);
            mRememberCheck.setChecked(true);
        }

        mregist.setOnClickListener(mListener);                      //采用OnClickListener方法设置不同按钮按下之后的监听事件
        mlogin.setOnClickListener(mListener);
        mChangepwdText.setOnClickListener(mListener);



        if (mUserDataManager == null) {
            mUserDataManager = new UserDataManager(this);
            mUserDataManager.openDataBase();                              //建立本地数据库
        }
    }

        OnClickListener mListener = new OnClickListener() {                  //不同按钮按下的监听事件选择
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.btn_regist:                            //登录界面的注册按钮
                        Intent intent_Login_to_Register = new Intent(MainActivity.this,registered.class) ;    //切换Login Activity至User Activity
                        startActivity(intent_Login_to_Register);
                        finish();
                        break;
                    case R.id.btn_login:                              //登录界面的登录按钮
                        login();
                        break;
                    case R.id.login_text_change_pwd:
                        Intent intent=new Intent(MainActivity.this,resetpwd.class);
                        startActivity(intent);
                        finish();
                        break;
                }
            }
        };


        public void login() {                                              //登录按钮监听事件
            if (isUserNameAndPwdValid()) {
                String userName = mEtUserName.getText().toString().trim();    //获取当前输入的用户名和密码信息
                String userPwd = mEtPassword.getText().toString().trim();
                SharedPreferences.Editor editor =login_sp.edit();
                int result=mUserDataManager.findUserByNameAndPwd(userName, userPwd);
                if(result==1){                                             //返回1说明用户名和密码均正确
                    //保存用户名和密码
                    editor.putString("USER_NAME", userName);
                    editor.putString("PASSWORD", userPwd);

                    //是否记住密码
                    if(mRememberCheck.isChecked()){
                        editor.putBoolean("mRememberCheck", true);
                    }else{
                        editor.putBoolean("mRememberCheck", false);
                    }
                    editor.commit();

                    Intent intent = new Intent(MainActivity.this,MainActivity2.class) ;    //切换Login Activity至User Activity
                    startActivity(intent);
                    finish();
                    Toast.makeText(this, getString(R.string.login_success),Toast.LENGTH_SHORT).show();//登录成功提示
                }else if(result==0){
                    Toast.makeText(this, getString(R.string.login_fail),Toast.LENGTH_SHORT).show();  //登录失败提示
                }
            }
        }
      
        protected void onResume() {
            if (mUserDataManager == null) {
                mUserDataManager = new UserDataManager(this);
                mUserDataManager.openDataBase();
            }
            super.onResume();
        }

        protected void onDestroy() {
            super.onDestroy();
        }

        protected void onPause() {
            if (mUserDataManager != null) {
                mUserDataManager.closeDataBase();
                mUserDataManager = null;
            }
            super.onPause();
        }
        
    public boolean isUserNameAndPwdValid(){
        if (mEtUserName.getText().toString().trim().equals("")) {
            Toast.makeText(this, getString(R.string.account_empty),
                    Toast.LENGTH_SHORT).show();
            return false;
        } else if (mEtPassword.getText().toString().trim().equals("")) {
            Toast.makeText(this, getString(R.string.pwd_empty),
                    Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }
    }
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<RelativeLayout
    android:id="@+id/view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/ip0.1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

android:background="@drawable/cover"
        android:scaleType="fitXY"
        />

    <LinearLayout
        android:id="@+id/a"
        android:layout_width="410dp"
        android:layout_height="200dp"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="20dp">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="欢迎使用健康智库"
            android:gravity="center"
            android:textSize="30sp"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/b"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="vertical"
        android:layout_below="@+id/a">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="登录(≧∇≦)/"
            android:textSize="25sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/c"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:paddingTop="30dp"
        android:paddingRight="30dp"
        android:paddingLeft="30dp"
        android:orientation="vertical"
        android:layout_below="@+id/b">


        <EditText
            android:id="@+id/account"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:padding="15dp"
            android:hint="账号:"
            android:inputType="textPersonName"
            android:layout_marginBottom="15dp"
            android:maxLines="1"
            android:textColor="@color/black"
            android:textSize="25sp"
            android:background="@drawable/borderblack"
            >
        </EditText>


        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:padding="15dp"
            android:hint="密码:"
            android:textColor="@color/black"
            android:textSize="25sp"
            android:layout_marginTop="5dp"
            android:inputType="textPassword"
            android:maxLines="1"
            android:background="@drawable/borderblack"
            >
        </EditText>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >
            <CheckBox
                android:id="@+id/Login_Remember"
                android:layout_width="100dp"
                android:layout_height="20dp"
                android:text="记住密码"
                android:layout_marginTop="3dp"
                android:layout_gravity="center_vertical"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:checked="false"
                android:textSize="15dp" />
            <TextView
                android:layout_width="100dp"
                android:layout_height="20dp"
                android:text="修改密码"
                android:id="@+id/login_text_change_pwd"
                android:layout_marginTop="3dp"
                android:gravity="center"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:textSize="15dp"
                android:clickable="true"
                android:layout_gravity="center_vertical"
                />

        </LinearLayout>

    </LinearLayout>
    <LinearLayout
        android:id="@+id/d"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:layout_below="@+id/c"
        >

        <Button
            android:id="@+id/btn_forgetpassword"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:background="@drawable/touch_back"
            android:text="忘记密码"
            android:textSize="15sp" />

        <Button
            android:id="@+id/btn_regist"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_marginLeft="10sp"
            android:text="注册"
            android:onClick="resetpwd"
            android:textSize="15sp"
            android:background="@drawable/touch_back"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/d"
        android:layout_marginTop="30dp"
        android:layout_alignParentRight="true">
        <Button
            android:id="@+id/btn_login"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_gravity="right"
            android:drawableLeft="@mipmap/arrowright"
            android:text="进入"
            android:onClick="finish_login"
            android:textSize="18sp"
            android:background="@drawable/touch_back"
            android:layout_below="@+id/d"
            />

    </LinearLayout>
</RelativeLayout>
    <RelativeLayout
        android:id="@+id/login_success_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginLeft="15.0px"
        android:layout_marginRight="15.0px"
        android:layout_marginTop="62.0px"
        android:background="#ff3f3f3f"
        android:paddingBottom="10.0px"
        android:paddingTop="21.0px"
        android:visibility="gone" >

        <TextView
            android:id="@+id/login_success_show"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textColor="#ff3f3f3f"
            android:textSize="20.0dip" />
    </RelativeLayout>

</RelativeLayout>


登录界面

主界面

package com.example.his12;
import android.app.Activity;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.example.his12.MainActivity;
import com.bumptech.glide.Glide;

public class MainActivity2 extends AppCompatActivity {
private TextView mTV,mTV2;
private Button b,b1,b2,b3,b4;
private LinearLayout t1;
private ImageView tr1,tr2;
private CheckBox r1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
/文字下划线
        mTV=findViewById(R.id.textView1);
        mTV.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //添加下划线
        mTV.getPaint().setAntiAlias(true);//去除锯齿

        /

        mTV.setSelected(true);
        mTV2=findViewById(R.id.textView2);
        mTV2.setSelected(true);
//button部分

        b=findViewById(R.id.btn_1textview);
        b1=findViewById(R.id.btn_1textview1);
        b2=findViewById(R.id.btn_1textview2);
        b3=findViewById(R.id.btn_1textview3);
        b4=findViewById(R.id.acmb);
        r1=findViewById(R.id.Login_Remember);
        setListers();
/第三方图片导入
        tr1=findViewById(R.id.ip1);
        tr2=findViewById(R.id.ip2);
      Glide.with(this).load("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1434777225,597782379&fm=26&gp=0.jpg").into(tr1);
      Glide.with(this).load("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2956162865,3627735717&fm=26&gp=0.jpg").into(tr2);
}

private  void  setListers(){
        OnClick onClick=new OnClick();
    b.setOnClickListener(onClick);
    b1.setOnClickListener(onClick);
    b2.setOnClickListener(onClick);
    b3.setOnClickListener(onClick);
    b4.setOnClickListener(onClick);

}
private class OnClick implements View.OnClickListener{

    @Override
    public void onClick(View v) {
        Intent intent=null;
        switch (v.getId()){
            case R.id.btn_1textview:
                intent=new Intent(MainActivity2.this,Epidemic_prevention_and_control.class);
                break;
            case R.id.btn_1textview1:
                intent=new Intent(MainActivity2.this,Auxiliary_plate.class);
                break;
            case R.id.btn_1textview2:
                intent=new Intent(MainActivity2.this,Online_medicial.class);
                break;
            case R.id.btn_1textview3:
                intent=new Intent(MainActivity2.this,Person_center.class);
                break;
            case R.id.acmb:
              //5  r1.setChecked(false);
                intent=new Intent(MainActivity2.this,MainActivity.class);


            break;
        }
        startActivity(intent);
    }
}
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/R1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="vertical"
        android:gravity="right">
<ImageView
    android:id="@+id/ip1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY">
</ImageView>
        <Button
            android:id="@+id/acmb"
            android:layout_width="60dp"
            android:layout_height="35dp"
            android:background="@drawable/touch_back2"
            android:text="注销"
            android:textColor="#fff"
            android:textSize="13sp"
            android:layout_alignParentRight="true" />
        <TextView

            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:gravity="center"
            android:text="欢迎您的使用"
            android:textColor="#fff"
            android:textSize="20sp"
             />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            >
            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/borderblack"
                android:ellipsize="marquee"
                android:marqueeRepeatLimit="marquee_forever"
                android:singleLine="true"
                android:text="温馨提示,本APP正处于研发阶段,多有不足,还请担待!!!"
                android:textColor="@color/black"
                android:textSize="15sp"
                />
        </LinearLayout>
    </RelativeLayout>
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:id="@+id/ip2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        >
    </ImageView>
    <LinearLayout
        android:id="@+id/L2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        //第一列
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="225dp"
                android:gravity="center">

                <Button
                    android:id="@+id/btn_1textview"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:background="@drawable/touch_back"
                    android:text="疫情\n防控"
                    android:textSize="50dp"
                    android:onClick="showToast"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="225dp"
                android:gravity="center">

                <Button
                    android:id="@+id/btn_1textview1"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:background="@drawable/touch_back"
                    android:text="问卷\n调查"
                    android:textSize="50dp"></Button>
            </LinearLayout>
        </LinearLayout>
        //第二列

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="225dp"
                android:gravity="center">
                <Button
                    android:id="@+id/btn_1textview2"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:background="@drawable/touch_back"
                    android:text="线上\n医疗"
                    android:textSize="50dp"></Button>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="225dp"
                android:gravity="center">
                <Button
                    android:id="@+id/btn_1textview3"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:background="@drawable/touch_back"
                    android:text="个人\n中心"
                    android:textSize="50dp"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>
</LinearLayout>

这里图片是从网上搜索所以该界面不显示

疫情防控界面

package com.example.his12;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.annotation.RequiresApi;
import android.graphics.Bitmap;
import android.os.Build;
import android.view.KeyEvent;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;

import android.webkit.WebViewClient;

public class Epidemic_prevention_and_control extends AppCompatActivity {
private Button Epacb;
private WebView webview;
private static int account=1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_epidemic_prevention_and_control);
        Epacb=findViewById(R.id.back_button2);
        setLister();
        init();
    }
    private void setLister(){

        OnClick onClick=new OnClick();
       Epacb.setOnClickListener(onClick);

    }
    private class OnClick implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Intent intent=null;
            switch (v.getId()){
                case R.id.back_button2:
                    intent=new Intent(Epidemic_prevention_and_control.this,MainActivity2.class);
                    break;
            }
            startActivity(intent);
        }
    }
    private void init() {

        webview= (WebView) findViewById(R.id.webview2);
        //使用JAvascript语言
        webview.getSettings().setJavaScriptEnabled(true);
        //使用app打开网页
        webview.setWebViewClient(new Epidemic_prevention_and_control.MyWebViewClient());
        //设置网页组件功能
        webview.setWebChromeClient(new Epidemic_prevention_and_control.MyWebChromeClient());

//s        WebView1.loadUrl("https://m.baidu.com");
        //设置链接
        webview.loadUrl("http://sousuo.gov.cn/s.htm?t=govall&q=%E7%96%AB%E6%83%85");

    }
    class MyWebViewClient extends WebViewClient {
        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(request.getUrl().toString());
            return true;
        }
        //在进入页面前的操作,这里为弹出alert框口。
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

            if(account++ == 1){
              //  webview.loadUrl("javascript:alert('友情提示:账号为学号,密码为出生年月日,eg:账号:201607881 密码:19980101')");
            }}
        //页面结束后发生的操作
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }
    }
    class MyWebChromeClient extends WebChromeClient {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
        }
        //更改页面标题
        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            setTitle(title);
        }
    }
    //设置后退键为返回上一步的操作
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_BACK &&webview.canGoBack()){
            webview.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Epidemic_prevention_and_control">
    <RelativeLayout
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/back_button2"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:background="@drawable/blue_direction_left"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="50sp"
            android:text="疫情防控"
            android:textSize="30sp"
            android:gravity="center"/>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/title">
        <WebView
            android:id="@+id/webview2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"></WebView>
    </RelativeLayout>



</RelativeLayout>

引入中国人民共和国中央人民政府疫情防控的官方界面

问卷调查

package com.example.his12;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.widget.Button;
import android.app.Activity;
import android.net.http.SslError;
import android.os.Bundle;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Auxiliary_plate extends AppCompatActivity {
private Button b5,btn_Analysis;
private WebView WebView1;
private static int account=1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auxiliary_plate);

        b5=findViewById(R.id.back_button5);
btn_Analysis=findViewById(R.id.btn_analysis);
        setLister();

        b5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(Auxiliary_plate.this,MainActivity2.class);
                startActivity(intent);
            }
        });
        init();
    }

    private void setLister(){

        OnClick onClick=new OnClick();
        b5.setOnClickListener(onClick);
        btn_Analysis.setOnClickListener(onClick);
    }
    private class OnClick implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Intent intent=null;
            switch (v.getId()){
                case R.id.back_button5:
                    intent=new Intent(Auxiliary_plate.this,MainActivity2.class);
                    break;
                case R.id.btn_analysis:
                    intent=new Intent(Auxiliary_plate.this,Analysis.class);
                    break;

            }
            startActivity(intent);
        }
    }
    private void init() {

        WebView1= (WebView) findViewById(R.id.webview1);
        //使用JAvascript语言
        WebView1.getSettings().setJavaScriptEnabled(true);
        //使用app打开网页
        WebView1.setWebViewClient(new MyWebViewClient());
        //设置网页组件功能
        WebView1.setWebChromeClient(new MyWebChromeClient());

//        WebView1.loadUrl("https://m.baidu.com");
        //设置链接
        WebView1.loadUrl("https://www.wenjuan.com/s/UZBZJvMvUv/#《问卷标题》,快来参与吧。【问卷网提供支持】");

    }
    class MyWebViewClient extends WebViewClient {
        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(request.getUrl().toString());
            return true;
        }
        //在进入页面前的操作,这里为弹出alert框口。
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

            if(account++ == 1){
             //   WebView1.loadUrl("javascript:alert('友情提示:账号为学号,密码为出生年月日,eg:账号:201607881 密码:19980101')");
            }}
        //页面结束后发生的操作
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }
    }
    class MyWebChromeClient extends WebChromeClient {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
        }
        //更改页面标题
        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            setTitle(title);
        }
    }
    //设置后退键为返回上一步的操作
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_BACK &&WebView1.canGoBack()){
            WebView1.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".Auxiliary_plate"
    android:gravity="right">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/back_button5"
        android:layout_width="60dp"
        android:layout_height="50dp"
        android:background="@drawable/touch_back_blue_direction"

        />
    <TextView

        android:layout_width="match_parent"
        android:layout_height="50sp"
        android:text="调查问卷"
        android:textSize="30sp"
        android:gravity="center"/>
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="10dp">
    <RelativeLayout
        android:id="@+id/screen1"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <WebView
            android:id="@+id/webview1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp">
        </WebView>
    </RelativeLayout>
    <RelativeLayout
        android:id="@+id/screen2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/screen1"
        android:layout_alignParentRight="true">
        <Button
            android:id="@+id/btn_analysis"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="30dp"
            android:text="数据分析"
            android:textSize="30sp"
            android:gravity="center">
        </Button>
    </RelativeLayout>

</RelativeLayout>
</LinearLayout>

引入问卷网的问卷

注册

package com.example.his12;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.Toast;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.example.his12.tool.MD5;
public class registered extends AppCompatActivity {

    //private Button rbb,rbb1;
    private EditText mAccount;                        //用户名编辑
    private EditText mPwd;                            //密码编辑
    private EditText mPwdCheck;                       //密码编辑
    private Button mSureButton;                       //确定按钮
    private Button mCancelButton;                     //取消按钮
    private UserDataManager mUserDataManager;         //用户数据管理类
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registered);

        mAccount = (EditText) findViewById(R.id.et_user_name);
        mPwd = (EditText) findViewById(R.id.et_psw);
        mPwdCheck = (EditText) findViewById(R.id.et_psw_again);
        mCancelButton=findViewById(R.id.button1);
        mSureButton = (Button) findViewById(R.id.btn_register);
        mSureButton.setOnClickListener(m_register_Listener);      //注册界面两个按钮的监听事件
        mCancelButton.setOnClickListener(m_register_Listener);

        if (mUserDataManager == null) {
            mUserDataManager = new UserDataManager(this);
            mUserDataManager.openDataBase();                              //建立本地数据库
        }
    }
    View.OnClickListener m_register_Listener = new View.OnClickListener() {    //不同按钮按下的监听事件选择
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_register:                       //确认按钮的监听事件
                    register_check();
                    break;
                case R.id.button1:                     //取消按钮的监听事件,由注册界面返回登录界面
                    Intent intent_registered_to_MainActivity = new Intent(registered.this,MainActivity.class) ;    //切换User Activity至Login Activity
                    startActivity(intent_registered_to_MainActivity);
                    finish();
                    break;
            }
        }
    };
    public void register_check() {                                //确认按钮的监听事件
        if (isUserNameAndPwdValid()) {
            String userName = mAccount.getText().toString().trim();
            String userPwd = mPwd.getText().toString().trim();
            String userPwdCheck = mPwdCheck.getText().toString().trim();
            //检查用户是否存在
            int count = mUserDataManager.findUserByName(userName);
            //用户已经存在时返回,给出提示文字
            if (count > 0) {
                Toast.makeText(this, getString(R.string.name_already_exist), Toast.LENGTH_SHORT).show();
                return;
            }
            if (userPwd.equals(userPwdCheck) == false) {     //两次密码输入不一样
                Toast.makeText(this, getString(R.string.pwd_not_the_same), Toast.LENGTH_SHORT).show();
                return;
            } else {
                UserData mUser = new UserData(userName, userPwd);
                mUserDataManager.openDataBase();
                long flag = mUserDataManager.insertUserData(mUser); //新建用户信息
                if (flag == -1) {
                    Toast.makeText(this, getString(R.string.register_fail), Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(this, getString(R.string.register_success), Toast.LENGTH_SHORT).show();
                    Intent intent_registered_to_MainActivity = new Intent(registered.this, MainActivity.class);    //切换User Activity至Login Activity
                    startActivity(intent_registered_to_MainActivity);
                    finish();
                }
            }
        }
    }

    public boolean isUserNameAndPwdValid() {
        if (mAccount.getText().toString().trim().equals("")) {
            Toast.makeText(this, getString(R.string.account_empty),
                    Toast.LENGTH_SHORT).show();
            return false;
        } else if (mPwd.getText().toString().trim().equals("")) {
            Toast.makeText(this, getString(R.string.pwd_empty),
                    Toast.LENGTH_SHORT).show();
            return false;
        }else if(mPwdCheck.getText().toString().trim().equals("")) {
            Toast.makeText(this, getString(R.string.pwd_check_empty),
                    Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }

    }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
   >
  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
      <TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="注册"
          android:gravity="center"
          android:textSize="30sp"/>
      <Button
          android:id="@+id/button1"
          android:layout_width="50dp"
          android:layout_height="50dp"
          android:background="@drawable/blue_direction_left"/>
  </RelativeLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="150dp">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="15dp"/>
    </LinearLayout>

    <EditText
        android:id="@+id/et_user_name"
        android:layout_width="fill_parent"
        android:layout_height="48dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp"
        android:layout_marginTop="100dp"
        android:ems="10"
        android:background="@drawable/borderblack"
        android:drawableLeft="@drawable/arrowright"
        android:drawablePadding="10dp"
        android:gravity="center_vertical"
        android:hint="请输入用户名"
        android:paddingLeft="8dp"
        android:singleLine="true"
        android:textColor="#000000"
        android:textColorHint="#a3a3a3"
        android:textSize="14sp"/>
    <EditText
        android:id="@+id/et_psw"
        android:layout_width="fill_parent"
        android:layout_gravity="center_horizontal"
        android:layout_height="48dp"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/borderblack"
        android:drawableLeft="@drawable/arrowright"
        android:drawablePadding="10dp"
        android:ems="10"
        android:hint="请输入密码"
        android:inputType="textPassword"
        android:paddingLeft="8dp"
        android:singleLine="true"
        android:textColor="#000000"
        android:textColorHint="#a3a3a3"
        android:textSize="14sp"/>
    <EditText
        android:id="@+id/et_psw_again"
        android:layout_width="fill_parent"
        android:layout_height="48dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/borderblack"
        android:drawableLeft="@drawable/arrowright"
        android:drawablePadding="10dp"
        android:ems="10"
        android:hint="请再次输入密码"
        android:inputType="textPassword"
        android:paddingLeft="8dp"
        android:singleLine="true"
        android:textColor="#000000"
        android:textColorHint="#a3a3a3"
        android:textSize="14sp"/>
    <Button
        android:id="@+id/btn_register"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp"
        android:layout_marginTop="15dp"
        android:background="@drawable/cicle"
        android:text="注 册"
        android:textColor="@android:color/white"
        android:textSize="18sp"/>
</LinearLayout>

在这里插入图片描述

修改密码

package com.example.his12;

import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.os.Bundle;

public class resetpwd extends AppCompatActivity {
    private Button mButton1;
    private EditText mAccount;                        //用户名编辑
    private EditText mPwd_old;                        //密码编辑
    private EditText mPwd_new;                        //密码编辑
    private EditText mPwdCheck;                       //密码编辑
    private Button mSureButton;                       //确定按钮
    private Button mCancelButton;                     //取消按钮
    private UserDataManager mUserDataManager;         //用户数据管理类
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_resetpwd);
        mAccount = (EditText) findViewById(R.id.resetpwd_edit_name);
        mPwd_old = (EditText) findViewById(R.id.resetpwd_edit_pwd_old);
        mPwd_new = (EditText) findViewById(R.id.resetpwd_edit_pwd_new);
        mPwdCheck = (EditText) findViewById(R.id.resetpwd_edit_pwd_check);
        mButton1=(Button)findViewById(R.id.button1);
        mSureButton = (Button) findViewById(R.id.resetpwd_btn_sure);
        mCancelButton = (Button) findViewById(R.id.resetpwd_btn_cancel);

        mSureButton.setOnClickListener(m_resetpwd_Listener);      //注册界面两个按钮的监听事件
        mCancelButton.setOnClickListener(m_resetpwd_Listener);
        mButton1.setOnClickListener(m_resetpwd_Listener);
        if (mUserDataManager == null) {
            mUserDataManager = new UserDataManager(this);
            mUserDataManager.openDataBase();                              //建立本地数据库
        }
    }
    View.OnClickListener m_resetpwd_Listener = new View.OnClickListener() {    //不同按钮按下的监听事件选择
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.resetpwd_btn_sure:                       //确认按钮的监听事件
                    resetpwd_check();
                    break;
                case R.id.button1:
                    Intent intent_resetpwd_to_MainActivity1=new Intent(resetpwd.this,MainActivity.class);
                case R.id.resetpwd_btn_cancel:                     //取消按钮的监听事件,由注册界面返回登录界面
                    Intent intent_resetpwd_to_MainActivity2 = new Intent(resetpwd.this,MainActivity.class) ;    //切换Resetpwd Activity至Login Activity
                    startActivity(intent_resetpwd_to_MainActivity2);
                    finish();
                    break;
            }
        }
    };
    public void resetpwd_check() {                                //确认按钮的监听事件
        if (isUserNameAndPwdValid()) {
            String userName = mAccount.getText().toString().trim();
            String userPwd_old = mPwd_old.getText().toString().trim();
            String userPwd_new = mPwd_new.getText().toString().trim();
            String userPwdCheck = mPwdCheck.getText().toString().trim();
            int result=mUserDataManager.findUserByNameAndPwd(userName, userPwd_old);
            if(result==1){                                             //返回1说明用户名和密码均正确,继续后续操作
                if(userPwd_new.equals(userPwdCheck)==false){           //两次密码输入不一样
                    Toast.makeText(this, getString(R.string.pwd_not_the_same),Toast.LENGTH_SHORT).show();
                    return ;
                } else {
                    UserData mUser = new UserData(userName, userPwd_new);
                    mUserDataManager.openDataBase();
                    boolean flag = mUserDataManager.updateUserData(mUser);
                    if (flag == false) {
                        Toast.makeText(this, getString(R.string.resetpwd_fail),Toast.LENGTH_SHORT).show();
                    }else{
                        Toast.makeText(this, getString(R.string.resetpwd_success),Toast.LENGTH_SHORT).show();
                        mUser.pwdresetFlag=1;
                        Intent intent_resetpwd_to_MainActivity = new Intent(resetpwd.this,MainActivity.class) ;    //切换User Activity至Login Activity
                        startActivity(intent_resetpwd_to_MainActivity);
                        finish();
                    }
                }
            }else if(result==0){                                       //返回0说明用户名和密码不匹配,重新输入
                Toast.makeText(this, getString(R.string.pwd_not_fit_user),Toast.LENGTH_SHORT).show();
                return;
            }
        }
    }
    public boolean isUserNameAndPwdValid() {
        String userName = mAccount.getText().toString().trim();
        //检查用户是否存在
        int count=mUserDataManager.findUserByName(userName);
        //用户不存在时返回,给出提示文字
        if(count<=0){
            Toast.makeText(this, getString(R.string.name_not_exist),Toast.LENGTH_SHORT).show();
            return false;
        }
        if (mAccount.getText().toString().trim().equals("")) {
            Toast.makeText(this, getString(R.string.account_empty),Toast.LENGTH_SHORT).show();
            return false;
        } else if (mPwd_old.getText().toString().trim().equals("")) {
            Toast.makeText(this, getString(R.string.pwd_empty),Toast.LENGTH_SHORT).show();
            return false;
        } else if (mPwd_new.getText().toString().trim().equals("")) {
            Toast.makeText(this, getString(R.string.pwd_new_empty),Toast.LENGTH_SHORT).show();
            return false;
        }else if(mPwdCheck.getText().toString().trim().equals("")) {
            Toast.makeText(this, getString(R.string.pwd_check_empty),Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }

}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:weightSum="1">

    <RelativeLayout
        android:id="@+id/resetpwd_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="修改密码"
            android:gravity="center"
            android:textSize="30sp"
            />
        <Button
            android:id="@+id/button1"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/blue_direction_left"/>
      <ImageView
            android:id="@+id/resetpwd_imageview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"

            android:background="@drawable/cover"
            android:scaleType="fitXY"
            />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:paddingTop="200dp">

            <EditText
                android:id="@+id/resetpwd_edit_name"
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:layout_alignStart="@+id/resetpwd_edit_pwd_new"

                android:layout_alignLeft="@+id/resetpwd_edit_pwd_new"
                android:layout_alignEnd="@+id/resetpwd_edit_pwd_new"
                android:layout_alignRight="@+id/resetpwd_edit_pwd_new"
                android:layout_alignParentTop="true"
                android:background="@drawable/borderblack"
                android:drawableLeft="@android:drawable/ic_menu_myplaces"
                android:ems="10"
                android:hint="请输入您的用户名"
                android:inputType="textPersonName" />

            <!--

           <EditText android:id="@+id/edt_operator_name" style="@style/syncEditText"
               android:hint="@string/hint_operator_name" />
           <ImageView android:id="@+id/syncOperatorImg" style="@style/syncImageView"
               android:layout_alignLeft="@+id/edt_operator_name"
               android:layout_alignTop="@+id/edt_operator_name"
               android:layout_alignBottom="@+id/edt_operator_name" android:src="@drawable/sync_operator" />
       -->

            <EditText
                android:id="@+id/resetpwd_edit_pwd_old"
                android:layout_width="fill_parent"
                android:layout_height="60dp"
                android:layout_marginTop="10dp"
                android:layout_below="@+id/resetpwd_edit_name"
                android:layout_alignStart="@+id/resetpwd_edit_name"
                android:layout_alignLeft="@+id/resetpwd_edit_name"
                android:layout_alignEnd="@+id/resetpwd_edit_name"
                android:layout_alignRight="@+id/resetpwd_edit_name"
                android:drawableLeft="@android:drawable/ic_lock_idle_lock"
                android:background="@drawable/borderblack"
                android:ems="10"
                android:hint="请输入您的旧密码"
                android:inputType="textPassword" />

            <Button
                android:id="@+id/resetpwd_btn_cancel"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/resetpwd_btn_sure"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="20dp"
                android:background="#f71818"
                android:onClick="not_to_reset"
                android:text="取消"
                android:textSize="20dp" />

            <EditText
                android:id="@+id/resetpwd_edit_pwd_new"
                android:layout_width="fill_parent"
                android:layout_height="60dp"
                android:layout_marginTop="10dp"
                android:layout_below="@+id/resetpwd_edit_pwd_old"
                android:layout_centerHorizontal="true"
                android:drawableLeft="@android:drawable/ic_lock_idle_lock"
                android:background="@drawable/borderblack"
                android:ems="10"
                android:hint="请确认您的新密码"
                android:inputType="textPassword" />
            <EditText
                android:id="@+id/resetpwd_edit_pwd_check"
                android:layout_marginTop="10dp"
                android:layout_width="fill_parent"
                android:layout_height="60dp"
                android:layout_below="@+id/resetpwd_edit_pwd_new"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"
                android:drawableLeft="@android:drawable/ic_lock_idle_lock"
                android:background="@drawable/borderblack"
                android:ems="10"
                android:hint="请输入您的新密码"
                android:inputType="textPassword" />

            <Button
                android:id="@+id/resetpwd_btn_sure"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/resetpwd_edit_pwd_new"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="92dp"
                android:background="#1cf718"
                android:onClick="sure_to_reset"
                android:text="确定"
                android:textSize="20dp" />


        </RelativeLayout>


    </RelativeLayout>

</RelativeLayout>

在这里插入图片描述

用户数据库

package com.example.his12;

public class UserData {private String userName;                  //用户名
    private String userPwd;                   //用户密码
    private int userId;                       //用户ID号
    public int pwdresetFlag=0;
    //获取用户名
    public String getUserName() {             //获取用户名
        return userName;
    }
    //设置用户名
    public void setUserName(String userName) {  //输入用户名
        this.userName = userName;
    }
    //获取用户密码
    public String getUserPwd() {                //获取用户密码
        return userPwd;
    }
    //设置用户密码
    public void setUserPwd(String userPwd) {     //输入用户密码
        this.userPwd = userPwd;
    }
    //获取用户id
    public int getUserId() {                   //获取用户ID号
        return userId;
    }
    //设置用户id
    public void setUserId(int userId) {       //设置用户ID号
        this.userId = userId;
    }
    public UserData(String userName, String userPwd) {  //这里只采用用户名和密码
        super();
        this.userName = userName;
        this.userPwd = userPwd;
    }

}

数据库管理

package com.example.his12;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class UserDataManager {  //用户数据管理类
    //一些宏定义和声明
    private static final String TAG = "UserDataManager";
    private static final String DB_NAME = "user_data";
    private static final String TABLE_NAME = "users";
    public static final String ID = "_id";
    public static final String USER_NAME = "user_name";
    public static final String USER_PWD = "user_pwd";
    //    public static final String SILENT = "silent";
//    public static final String VIBRATE = "vibrate";
    private static final int DB_VERSION = 2;
    private Context mContext = null;

    //创建用户book表
    private static final String DB_CREATE = "CREATE TABLE " + TABLE_NAME + " ("
            + ID + " integer primary key," + USER_NAME + " varchar,"
            + USER_PWD + " varchar" + ");";

    private SQLiteDatabase mSQLiteDatabase = null;
    private DataBaseManagementHelper mDatabaseHelper = null;


    //DataBaseManagementHelper继承自SQLiteOpenHelper
    private static class DataBaseManagementHelper extends SQLiteOpenHelper {

        DataBaseManagementHelper(Context context) {
            super(context, DB_NAME, null, DB_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            Log.i(TAG,"db.getVersion()="+db.getVersion());
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME + ";");
            db.execSQL(DB_CREATE);
            Log.i(TAG, "db.execSQL(DB_CREATE)");
            Log.e(TAG, DB_CREATE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.i(TAG, "DataBaseManagementHelper onUpgrade");
            onCreate(db);
        }
    }

    public  UserDataManager(Context context) {
        mContext = context;
        Log.i(TAG, "UserDataManager construction!");
    }
    //打开数据库
    public void openDataBase() throws SQLException {
        mDatabaseHelper = new DataBaseManagementHelper(mContext);
        mSQLiteDatabase = mDatabaseHelper.getWritableDatabase();
    }
    //关闭数据库
    public void closeDataBase() throws SQLException {
        mDatabaseHelper.close();
    }
    //添加新用户,即注册
    public long insertUserData(UserData userData) {
        String userName=userData.getUserName();
        String userPwd=userData.getUserPwd();
        ContentValues values = new ContentValues();
        values.put(USER_NAME, userName);
        values.put(USER_PWD, userPwd);
        return mSQLiteDatabase.insert(TABLE_NAME, ID, values);
    }
    //更新用户信息,如修改密码
    public boolean updateUserData(UserData userData) {
        //int id = userData.getUserId();
        String userName = userData.getUserName();
        String userPwd = userData.getUserPwd();
        ContentValues values = new ContentValues();
        values.put(USER_NAME, userName);
        values.put(USER_PWD, userPwd);
        return mSQLiteDatabase.update(TABLE_NAME, values,null, null) > 0;
        //return mSQLiteDatabase.update(TABLE_NAME, values, ID + "=" + id, null) > 0;
    }
    //
    public Cursor fetchUserData(int id) throws SQLException {
        Cursor mCursor = mSQLiteDatabase.query(false, TABLE_NAME, null, ID
                + "=" + id, null, null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }
    //
    public Cursor fetchAllUserDatas() {
        return mSQLiteDatabase.query(TABLE_NAME, null, null, null, null, null,
                null);
    }
    //根据id删除用户
    public boolean deleteUserData(int id) {
        return mSQLiteDatabase.delete(TABLE_NAME, ID + "=" + id, null) > 0;
    }
    //根据用户名注销
    public boolean deleteUserDatabyname(String name) {
        return mSQLiteDatabase.delete(TABLE_NAME, USER_NAME + "=" + name, null) > 0;
    }
    //删除所有用户
    public boolean deleteAllUserDatas() {
        return mSQLiteDatabase.delete(TABLE_NAME, null, null) > 0;
    }

    //
    public String getStringByColumnName(String columnName, int id) {
        Cursor mCursor = fetchUserData(id);
        int columnIndex = mCursor.getColumnIndex(columnName);
        String columnValue = mCursor.getString(columnIndex);
        mCursor.close();
        return columnValue;
    }
    //
    public boolean updateUserDataById(String columnName, int id,
                                      String columnValue) {
        ContentValues values = new ContentValues();
        values.put(columnName, columnValue);
        return mSQLiteDatabase.update(TABLE_NAME, values, ID + "=" + id, null) > 0;
    }
    //根据用户名找用户,可以判断注册时用户名是否已经存在
    public int findUserByName(String userName){
        Log.i(TAG,"findUserByName , userName="+userName);
        int result=0;
     //   Cursor mCursor=mSQLiteDatabase.query(TABLE_NAME, null, USER_NAME+"="+userName, null, null, null, null);
        String sql = "Select * from users where user_name =?";
        Cursor mCursor = mSQLiteDatabase.rawQuery(sql,new String[]{userName});
        if(mCursor!=null){
            result=mCursor.getCount();
            mCursor.close();
            Log.i(TAG,"findUserByName , result="+result);
        }
        return result;
    }
    //根据用户名和密码找用户,用于登录
    public int findUserByNameAndPwd(String userName,String pwd){
        Log.i(TAG,"findUserByNameAndPwd");
        int result=0;
        String sql = "Select * from users where user_name=? and user_pwd=?";
        Cursor mCursor=mSQLiteDatabase.rawQuery(sql,new String[]{userName,pwd});
        //  Cursor mCursor=mSQLiteDatabase.query(TABLE_NAME, null, USER_NAME+"="+userName+" and "+USER_PWD+"="+pwd,
        //        null, null, null, null);
        if(mCursor!=null){
            result=mCursor.getCount();
            mCursor.close();
            Log.i(TAG,"findUserByNameAndPwd , result="+result);
        }
        return result;
    }
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值