Android安卓实战项目(4)---提供给阿尔兹海默症患者的APP(源码在文末)

Android安卓实战项目(4)—提供给阿尔兹海默症患者的APP(源码在文末)

一.项目运行介绍

1.大致浏览

(1)开机界面

Android安卓实战项目(4)---提供给阿尔兹海默症患者的APP(源码在文末)_第1张图片

(2)主界面

Android安卓实战项目(4)---提供给阿尔兹海默症患者的APP(源码在文末)_第2张图片

(3)Read Instructions界面

Android安卓实战项目(4)---提供给阿尔兹海默症患者的APP(源码在文末)_第3张图片

(4)Proceed for Test界面

Android安卓实战项目(4)---提供给阿尔兹海默症患者的APP(源码在文末)_第4张图片

(5)Exercise your Memory界面

2.功能介绍

(1)功能一

开机动画

(2)功能二

主页面实现四个分页面的大体框架

(3)功能三

Read Instructions(阅读说明):给使用者一个使用说明

(4)功能四

Proceed for Test(测试):出一些简单的题目进行测试

(5)功能五

Exercise your Memory(记忆功能测试):

(6)功能六

只写了一个跳转网页的控件

二.具体实现

(1)功能一

开机动画

只是一个简单的跳转页面

Instructions.java
package com.example.alzheimersdetector;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class Instructions extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_instructions);
    }

    public void home(View view) {
        Intent homeIntent = new Intent(Instructions.this, Home.class);
        startActivity(homeIntent);
    }
}

(2)功能二

主页面实现四个分页面的大体框架

Home.java
package com.example.alzheimersdetector;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class Home extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_home);
    }
    public void inst(View view) {
        Intent i = new Intent(Home.this, Instructions.class);
        startActivity(i);
    }
    public void test(View view) {
        Intent i = new Intent(Home.this, Test.class);
        startActivity(i);
    }
    public void play(View view) {
        Intent i = new Intent(Home.this, Exercise.class);
        startActivity(i);
    }
    public void site(View view) {
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.alz.org/in/dementia-alzheimers-en.asp"));
        startActivity(i);
    }
}

(3)功能三

Read Instructions(阅读说明):给使用者一个使用说明

Test.java
package com.example.alzheimersdetector;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class Test extends AppCompatActivity {

    RadioButton rd1,rd2,rd3,rd4;
    RadioGroup rd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_test);

        rd1 = findViewById(R.id.rd1);
        rd2 = findViewById(R.id.rd2);
        rd3 = findViewById(R.id.rd3);
        rd4 = findViewById(R.id.rd4);
        rd = findViewById(R.id.rd);

        rd1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Test.this,"You`r Wrong!",Toast.LENGTH_SHORT).show();
            }
        });

        rd2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Test.this,"You`r Wrong!",Toast.LENGTH_SHORT).show();
            }
        });

        rd3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Test.this,"Correct!",Toast.LENGTH_SHORT).show();
            }
        });

        rd4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Test.this,"You`r Wrong!",Toast.LENGTH_SHORT).show();
            }
        });
    }
    public void test2(View view) {
        Intent homeIntent = new Intent(Test.this, Test2.class);
        startActivity(homeIntent);
    }
}

(4)功能四

Proceed for Test(测试):出一些简单的题目进行测试

Test2.java
package com.example.alzheimersdetector;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.TimePicker;

public class Test2 extends AppCompatActivity {

    TextView result1;
    TimePicker timePickerclock;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_test2);

        result1 = findViewById(R.id.settime);
        timePickerclock = findViewById(R.id.tp1);
        timePickerclock.setIs24HourView(true);

        timePickerclock.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
            @Override
            public void onTimeChanged(TimePicker view, int i, int i1) {
                result1.setText("Time: " + i + ":" + i1);
            }
        });
    }
    public void test3(View view) {
        Intent homeIntent = new Intent(Test2.this, Test3.class);
        startActivity(homeIntent);
    }
}

(5)功能五

Exercise your Memory(记忆功能测试):

package com.example.alzheimersdetector;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class Test3 extends AppCompatActivity {

    RadioButton rdb1,rdb2;
    RadioGroup rdg1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_test3);

        rdg1 = findViewById(R.id.rdg1);
        rdb1 = findViewById(R.id.rdb1);
        rdb2 = findViewById(R.id.rdb2);

        rdb1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Test3.this,"Correct!",Toast.LENGTH_SHORT).show();
            }
        });

        rdb2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Test3.this,"You`r Wrong!",Toast.LENGTH_SHORT).show();
            }
        });
    }
    public void test4(View view) {
        Intent homeIntent = new Intent(Test3.this, Test4.class);
        startActivity(homeIntent);
    }
}

题目的话,另外写一个类

Exercise.java
package com.example.alzheimersdetector;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.Arrays;
import java.util.Collections;

public class Exercise extends AppCompatActivity {

    TextView t1, t2;
    ImageView i1, i2, i3, i4, i5, i6, i7 ,i8, i9, i10, i11, i12;
    Integer[] cardsArray = {101, 102, 103, 104, 105, 106, 201, 202, 203, 204, 205, 206};
    int Aries, Taurus, Gemini, Cancer, Leo, Virgo, Libra, Scorpio, Sagittarius, Capricorn, Aquarius, Pisces;
    int firstCard, secondCard;
    int clickedFirst, clickedSecond;
    int cardNumber = 1;
    int turn = 1;
    int playerPoints = 0, cpuPoints = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_exercise);

        t1 = (TextView) findViewById(R.id.t1);
        t2 = (TextView) findViewById(R.id.t2);

        i1 = (ImageView) findViewById(R.id.i1);
        i2 = (ImageView) findViewById(R.id.i2);
        i3 = (ImageView) findViewById(R.id.i3);
        i4 = (ImageView) findViewById(R.id.i4);
        i5 = (ImageView) findViewById(R.id.i5);
        i6 = (ImageView) findViewById(R.id.i6);
        i7 = (ImageView) findViewById(R.id.i7);
        i8 = (ImageView) findViewById(R.id.i8);
        i9 = (ImageView) findViewById(R.id.i9);
        i10 = (ImageView) findViewById(R.id.i10);
        i11 = (ImageView) findViewById(R.id.i11);
        i12 = (ImageView) findViewById(R.id.i12);

        i1.setTag("0");
        i2.setTag("1");
        i3.setTag("2");
        i4.setTag("3");
        i5.setTag("4");
        i6.setTag("5");
        i7.setTag("6");
        i8.setTag("7");
        i9.setTag("8");
        i10.setTag("9");
        i11.setTag("10");
        i12.setTag("11");

        frontOfCardsResources();
        Collections.shuffle(Arrays.asList(cardsArray));

        //t2.setTextColor(Color.GRAY);

        i1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i1, theCard);
            }
        });
        i2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i2, theCard);
            }
        });
        i3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i3, theCard);
            }
        });
        i4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i4, theCard);
            }
        });
        i5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i5, theCard);
            }
        });
        i6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i6, theCard);
            }
        });
        i7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i7, theCard);
            }
        });
        i8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i8, theCard);
            }
        });
        i9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i9, theCard);
            }
        });
        i10.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i10, theCard);
            }
        });
        i11.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i11, theCard);
            }
        });
        i12.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int theCard = Integer.parseInt((String) v.getTag());
                doStuff(i12, theCard);
            }
        });
    }
    private void doStuff(ImageView iv, int card){
        if (cardsArray[card] == 101){
            iv.setImageResource(Aries);
        }else if (cardsArray[card] == 102){
            iv.setImageResource(Taurus);
        }else if (cardsArray[card] == 103){
            iv.setImageResource(Gemini);
        }else if (cardsArray[card] == 104){
            iv.setImageResource(Cancer);
        }else if (cardsArray[card] == 105){
            iv.setImageResource(Leo);
        }else if (cardsArray[card] == 106){
            iv.setImageResource(Virgo);
        }else if (cardsArray[card] == 201){
            iv.setImageResource(Libra);
        }else if (cardsArray[card] == 202){
            iv.setImageResource(Scorpio);
        }else if (cardsArray[card] == 203){
            iv.setImageResource(Sagittarius);
        }else if (cardsArray[card] == 204){
            iv.setImageResource(Capricorn);
        }else if (cardsArray[card] == 205){
            iv.setImageResource(Aquarius);
        }else if (cardsArray[card] == 206){
            iv.setImageResource(Pisces);
        }
        if (cardNumber == 1){
            firstCard = cardsArray[card];
            if (firstCard > 200){
                firstCard = firstCard - 100;
            }
            cardNumber = 2;
            clickedFirst = card;

            iv.setEnabled(false);
        }else if (cardNumber == 2){
            secondCard = cardsArray[card];
            if (secondCard > 200){
                secondCard = secondCard - 100;
            }
            cardNumber = 1;
            clickedSecond = card;

            i1.setEnabled(false);
            i2.setEnabled(false);
            i3.setEnabled(false);
            i4.setEnabled(false);
            i5.setEnabled(false);
            i6.setEnabled(false);
            i7.setEnabled(false);
            i8.setEnabled(false);
            i9.setEnabled(false);
            i10.setEnabled(false);
            i11.setEnabled(false);
            i12.setEnabled(false);

            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    calculate();
                }
            }, 1000);
        }
    }
    private void calculate(){
        if (firstCard == secondCard){
            if (clickedFirst == 0){
                i1.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 1){
                i2.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 2){
                i3.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 3){
                i4.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 4){
                i5.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 5){
                i6.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 6){
                i7.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 7){
                i8.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 8){
                i9.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 9){
                i10.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 10){
                i11.setVisibility(View.INVISIBLE);
            }else if (clickedFirst == 11){
                i12.setVisibility(View.INVISIBLE);
            }

            if (clickedSecond == 0){
                i1.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 1){
                i2.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 2){
                i3.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 3){
                i4.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 4){
                i5.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 5){
                i6.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 6){
                i7.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 7){
                i8.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 8){
                i9.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 9){
                i10.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 10){
                i11.setVisibility(View.INVISIBLE);
            }else if (clickedSecond == 11){
                i12.setVisibility(View.INVISIBLE);
            }

            /*if (turn == 1){
                playerPoints++;
                t1.setText("P1: " + playerPoints);
            }else if (turn == 2){
                cpuPoints++;
                t2.setText("P2: " + cpuPoints);
            }*/
        } else {
            i1.setImageResource(R.drawable.imageback);
            i2.setImageResource(R.drawable.imageback);
            i3.setImageResource(R.drawable.imageback);
            i4.setImageResource(R.drawable.imageback);
            i5.setImageResource(R.drawable.imageback);
            i6.setImageResource(R.drawable.imageback);
            i7.setImageResource(R.drawable.imageback);
            i8.setImageResource(R.drawable.imageback);
            i9.setImageResource(R.drawable.imageback);
            i10.setImageResource(R.drawable.imageback);
            i11.setImageResource(R.drawable.imageback);
            i12.setImageResource(R.drawable.imageback);

            /*if (turn == 1){
                turn = 2;
                t1.setTextColor(Color.GRAY);
                t2.setTextColor(Color.BLACK);
            }else if (turn == 2){
                turn = 1;
                t2.setTextColor(Color.GRAY);
                t1.setTextColor(Color.BLACK);
            }*/
        }

        i1.setEnabled(true);
        i2.setEnabled(true);
        i3.setEnabled(true);
        i4.setEnabled(true);
        i5.setEnabled(true);
        i6.setEnabled(true);
        i7.setEnabled(true);
        i8.setEnabled(true);
        i9.setEnabled(true);
        i10.setEnabled(true);
        i11.setEnabled(true);
        i12.setEnabled(true);

        checkEnd();
    }

    private void checkEnd(){
        if (i1.getVisibility() == View.INVISIBLE && i2.getVisibility() == View.INVISIBLE && i3.getVisibility() == View.INVISIBLE && i4.getVisibility() == View.INVISIBLE && i5.getVisibility() == View.INVISIBLE && i6.getVisibility() == View.INVISIBLE && i7.getVisibility() == View.INVISIBLE && i8.getVisibility() == View.INVISIBLE && i9.getVisibility() == View.INVISIBLE && i10.getVisibility() == View.INVISIBLE && i11.getVisibility() == View.INVISIBLE && i12.getVisibility() == View.INVISIBLE){
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Exercise.this);
            alertDialogBuilder.setMessage("YOU PLAYED WELL !").setCancelable(false).setPositiveButton("PLAY AGAIN", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent i = new Intent(getApplicationContext(), Exercise.class);
                    startActivity(i);
                    finish();
                }
            }).setNegativeButton("EXIT", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    }
    private void frontOfCardsResources(){
        Aries = R.drawable.image101;
        Taurus = R.drawable.image102;
        Gemini = R.drawable.image103;
        Cancer = R.drawable.image104;
        Leo = R.drawable.image105;
        Virgo = R.drawable.image106;
        Libra = R.drawable.image201;
        Scorpio = R.drawable.image202;
        Sagittarius = R.drawable.image203;
        Capricorn = R.drawable.image204;
        Aquarius = R.drawable.image205;
        Pisces = R.drawable.image206;
    }
}

(6)功能六

只写了一个跳转网页的控件

Test4.java
package com.example.alzheimersdetector;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class Test4 extends AppCompatActivity {

    RadioButton rdc1,rdc2;
    RadioGroup rdg2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_test4);

        rdg2 = findViewById(R.id.rdg2);
        rdc1 = findViewById(R.id.rdc1);
        rdc2 = findViewById(R.id.rdc2);

        rdc1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Test4.this,"Correct!",Toast.LENGTH_SHORT).show();
            }
        });

        rdc2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Test4.this,"You`r Wrong!",Toast.LENGTH_SHORT).show();
            }
        });
    }
}

三.项目源码

记得点赞!!!

链接:https://pan.baidu.com/s/1H25QMDI9PxmSi8sF00gXaA?pwd=jynl
提取码:jynl

你可能感兴趣的:(开源项目,android)