안드로이드 스튜디오

[안드로이드 스튜디오] GCS 앱 만들기 - 전체소스

yangcotton 2023. 8. 30. 14:20

 

MainActivity.java 

package com.example.gcs;

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

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;

import org.xmlpull.v1.XmlPullParser;

public class MainActivity extends AppCompatActivity {

    TextView item1 ,item2, item3;
    TextView result1 ,result2, result3;
    TextView sum,state;

    String[] subSeekList1 = new AddContent().subSeekBarList1;
    String[] subSeekList2 = new AddContent().subSeekBarList2;
    String[] subSeekList3 = new AddContent().subSeekBarList3;

    private int total=0;
    private int total1;
    private int total2;
    private int total3;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        item1 = findViewById(R.id.txtItem1); // txtItem1
        result1 = findViewById(R.id.result1); // result1
        item2 = findViewById(R.id.txtItem2); // txtItem2
        result2 = findViewById(R.id.result2); // result2
        item3 = findViewById(R.id.txtItem3); // txtItem3
        result3 = findViewById(R.id.result3); // result3
        sum = findViewById(R.id.sum); // sum
        state = findViewById(R.id.state); // state

        SeekBar seek1 = findViewById(R.id.seekBar1);
        SeekBar seek2 = findViewById(R.id.seekBar2);
        SeekBar seek3 = findViewById(R.id.seekBar3);
        
        //  seekBar1
        seek1.setMax(subSeekList1.length-1);
        seek1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                for (int i=0; i<subSeekList1.length; i++){
                    if (progress == i){
                        result1.setText(subSeekList1[i]);
                    }
                }

                total1 = progress+1;
                total2 = seek2.getProgress()+1;
                total3 = seek3.getProgress()+1;
                totalState();
            }


            public void onStartTrackingTouch(SeekBar arg0) {
                // TODO Auto-generated method stub
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }
        });

        //  seekBar2
        seek2.setMax(subSeekList2.length-1);
        seek2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                for (int i=0; i<subSeekList2.length; i++){
                    if (progress == i){
                        result2.setText(subSeekList2[i]);
                    }
                }

                total1 = seek1.getProgress()+1;
                total2 = progress+1;
                total3 = seek3.getProgress()+1;
                totalState();

            }

            public void onStartTrackingTouch(SeekBar arg0) {
                // TODO Auto-generated method stub
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }
        });

        //  seekBar3
        seek3.setMax(subSeekList3.length-1);
        seek3.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                for (int i=0; i<subSeekList3.length; i++){
                    if (progress == i){
                        result3.setText(subSeekList3[i]);
                    }
                }
                total1 = seek1.getProgress()+1;
                total2 = seek2.getProgress()+1;
                total3 = progress+1;
                totalState();

            }

            public void onStartTrackingTouch(SeekBar arg0) {
                // TODO Auto-generated method stub
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }
        });

        //초기화 버튼
        Button btn = (Button)findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SeekBar seek1 = findViewById(R.id.seekBar1);
                SeekBar seek2 = findViewById(R.id.seekBar2);
                SeekBar seek3 = findViewById(R.id.seekBar3);
                seek1.setProgress(0);
                seek2.setProgress(0);
                seek3.setProgress(0);
                sum.setText("총점 : 기본 3점");
                state.setText("총점에 따른 상태");

            }
        });

        //다른 페이지로 이동 버튼
        Button moveAddPage = (Button) findViewById(R.id.moveAddPage);
        moveAddPage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(),AddNewList.class);
                startActivity(intent);
            }
        });
    }

    //총합
    private void totalState() {
        total = total1+total2+total3;
        sum.setText("총점 : " + total);
        if (total == 15){
            state.setText("정상 : alert");
        }else if ( 13 <= total&&total <= 14){
            state.setText("기면상태 : drowsy");
        }else if (8<= total&& total <= 12){
            state.setText("혼미 :stupor");
        }else if (4<= total&& total <= 7){
            state.setText("반혼수상태 :semicoma");
        }else{
            state.setText("혼수상태 : coma");
        }
    }
}

 

activity_main.xml

<?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">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="600dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/txtItem1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="7dp"
                    android:text="눈뜨기 기능 "
                    android:textSize="21sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/result1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/seekBar1"
                    android:layout_gravity="center_horizontal"
                    android:text="눈뜨기 기능 선택"
                    android:textSize="18sp" />

                <SeekBar
                    android:id="@+id/seekBar1"
                    style="@style/Widget.AppCompat.SeekBar.Discrete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txtItem1"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="5dp"
                    android:progressBackgroundTint="#77CFF2"
                    android:progressTint="#41C0F2"
                    android:thumbTint="#0D8BD9" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">


                <TextView
                    android:id="@+id/txtItem2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="10dp"
                    android:text="언어기능"
                    android:textSize="21sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/result2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/seekBar2"
                    android:layout_gravity="center_horizontal"
                    android:text="언어기능 선택"
                    android:textSize="18sp" />

                <SeekBar
                    android:id="@+id/seekBar2"
                    style="@style/Widget.AppCompat.SeekBar.Discrete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txtItem2"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="5dp"
                    android:progressBackgroundTint="#77CFF2"
                    android:progressTint="#41C0F2"
                    android:thumbTint="#0D8BD9" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/txtItem3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="7dp"
                    android:text="운동기능 "
                    android:textSize="21sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/result3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/seekBar3"
                    android:layout_gravity="center_horizontal"
                    android:text="운동 선택"
                    android:textSize="18sp" />

                <SeekBar
                    android:id="@+id/seekBar3"
                    style="@style/Widget.AppCompat.SeekBar.Discrete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txtItem3"
                    android:layout_alignParentLeft="true"
                    android:layout_marginLeft="5dp"
                    android:progressBackgroundTint="#77CFF2"
                    android:progressTint="#41C0F2"
                    android:thumbTint="#0D8BD9" />
            </LinearLayout>

            <TextView
                android:id="@+id/delete1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:layout_marginTop="20dp"
                android:text="1.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="2.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="3.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="4.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="5.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="6.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="7.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete8"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="8.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="9.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete10"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="10.스크롤 및 목록삭제 확인 리스트"
                android:textSize="27sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete11"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="11.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete12"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="12.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete13"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="13.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/delete14"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D6F3D5"
                android:gravity="center"
                android:text="14.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/delete15"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="#EDC8C8"
                android:text="15.스크롤 및 목록삭제 확인 리스트"
                android:textSize="28sp"
                android:textStyle="bold" />

        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/sum"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="총점 : 기본 3점"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/state"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="총점에 따른 상태"
            android:textSize="18sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">


        <Button
        android:id="@+id/save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="#D2FA2D2D"
        android:text="저장"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />

        <Button
            android:id="@+id/load"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="#D2FA2D2D"
            android:text="불러오기"
            android:textColor="#FFFFFF"
            android:textSize="20sp"
            android:textStyle="bold" />
    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#BDE3F2"
        android:text="초기화"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1"
        android:layout_margin="5dp"
        />
    <Button
        android:id="@+id/moveAddPage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#77CFF2"
        android:text="목록 추가"
        android:textSize="19sp"
        android:textStyle="bold"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:layout_margin="5dp"
        />
    </LinearLayout >

</LinearLayout >

 

 

AddNewList.java

package com.example.gcs;


import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

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

import java.util.ArrayList;

public class AddNewList extends AppCompatActivity {
    TextView content;
    ArrayList<String> items;
    ArrayAdapter<String> adapter;
    ListView listView;
    Button moveMainPage;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_new_list);

        content = (TextView) findViewById(R.id.content);
        //데이터 준비
        items = new ArrayList<String>();

        // 어댑터 생성
        adapter = new ArrayAdapter<String>(AddNewList.this,
                android.R.layout.simple_list_item_single_choice, items);

        // 어댑터 설정
        listView = (ListView) findViewById(R.id.listView);
        listView.setAdapter(adapter);
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // 하나의 항목만 선택할 수 있도록 설정

        //대분류 제목
        EditText addTitle = (EditText) findViewById(R.id.addTitle);
        String text = addTitle.getText().toString();        // EditText에 입력된 문자열값을 얻기

        /**
         * ADD, DELETE 버튼 클릭 시 실행되는 메소드
         */

        Button btnAdd = (Button) findViewById(R.id.btnAdd);
        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditText ed = (EditText) findViewById(R.id.newitem);
                String text = ed.getText().toString();        // EditText에 입력된 문자열값을 얻기
                if (!text.isEmpty()) {                        // 입력된 text 문자열이 비어있지 않으면
                    items.add(text);                          // items 리스트에 입력된 문자열 추가
                    ed.setText("");                           // EditText 입력란 초기화
                    adapter.notifyDataSetChanged();           // 리스트 목록 갱신
                }
            }
        });

        Button btnDelete = (Button) findViewById(R.id.btnDelete);
        btnDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int pos = listView.getCheckedItemPosition(); // 현재 선택된 항목의 첨자(위치값) 얻기
                if (pos != ListView.INVALID_POSITION) {      // 선택된 항목이 있으면
                    items.remove(pos);                       // items 리스트에서 해당 위치의 요소 제거
                    listView.clearChoices();                 // 선택 해제
                    adapter.notifyDataSetChanged();
                    // 어답터와 연결된 원본데이터의 값이 변경된을 알려 리스트뷰 목록 갱신
                }
            }
        });

        moveMainPage = (Button) findViewById(R.id.moveMainPage);
        moveMainPage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                startActivity(intent);
            }
        });
    }
}

 

add_new_list.xml

<?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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".AddNewList">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/moveMainPage"
            android:layout_gravity="right"
            android:text="취소"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="이동한 페이지"
            android:textSize="40dp"
            android:id="@+id/content"/>
    </LinearLayout>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:id="@+id/addTitle"
        android:hint="대분류 제목을 적으시오"
        android:focusable="true"
        android:focusableInTouchMode="true"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="소분류를 추가 하세요"
        android:textSize="20dp"
        android:id="@+id/content2"/>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/newitem"
            android:focusable="true"
            android:focusableInTouchMode="true"
            />
        <Button
            android:text="추가"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:id="@+id/btnAdd"
            />

        <Button
            android:text="삭제"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:id="@+id/btnDelete"
            />
    </LinearLayout>
    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1" />

</LinearLayout>

 

 

AddContent.java

package com.example.gcs;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;

public class AddContent extends AppCompatActivity {
    String[] subSeekBarList1 = {"1점:눈뜨지 않음(none)", "2점:통증에 의해(to pain)", "3점:음성에 의해(to speech)", "4점:자발적으로(spontaneous)" };
    String[] subSeekBarList2 = {"1점:발어하지 않음(orientated)", "2점:이해불가능한 소리(confused converstation)"
            , "3점:언어 혼란(inappropriate words)", "4점:대화 혼란(incomprehensible sounds)", "5점:지남력 양호(none)(기관절개,삽관시 : T)" };

    String[] subSeekBarList3 = {"1점:전허 움직이지 않음(obey commands)", "2점:사지신전 반응(localize pain)"
            ,"3점:이상굴곡 반응(withdraws)", "4점:회피굴곡 반응(abnormal flexion)", "5점:통증부위 인식가능(extension)", "6점:명령에 따른다(none)" };
}