hayannn / Power-J

2022-2 모바일응용 팀프로젝트
0 stars 0 forks source link

My 화면 - 성취도 기능 구현 완료(11/27) #8

Open hayannn opened 1 year ago

hayannn commented 1 year ago

my 화면의 성취도 버튼을 클릭했을 시에 나오는 성취도 그래프 부분 구현을 완료했습니다. [참고]

  1. 바로 이전 이슈 내용을 모두 공유 프로젝트에 연동한다.
  2. AchieveActivity.java를 삭제 한 후, 이 이슈의 과정을 진행한다.

https://user-images.githubusercontent.com/102213509/204100353-6baad9da-5881-4edc-99dc-036d9e7a3be5.mp4

hayannn commented 1 year ago

파일 구성 형태 image image

hayannn commented 1 year ago

build.gradle(:app)


plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.pjsetting"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
}
hayannn commented 1 year ago

settings.gradle


pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io"}
    }
}
rootProject.name = "pjsetting"
include ':app'
hayannn commented 1 year ago

그 다음 추가 방법 image

hayannn commented 1 year ago

image

hayannn commented 1 year ago

BarChartActivity.java


package com.example.pjsetting;

import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.utils.ColorTemplate;

import java.util.ArrayList;

public class BarChartActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bar_chart);

        BarChart barChart = findViewById(R.id.barChart);

        //샘플 데이터
        ArrayList<BarEntry> visitors = new ArrayList<>();
        visitors.add(new BarEntry(1, 10));
        visitors.add(new BarEntry(2, 20));
        visitors.add(new BarEntry(3, 30));
        visitors.add(new BarEntry(4, 40));
        visitors.add(new BarEntry(5, 50));

        BarDataSet barDataSet = new BarDataSet(visitors, "카테고리별 성취도");
        barDataSet.setColors(ColorTemplate.MATERIAL_COLORS);
        barDataSet.setValueTextColor(Color.BLACK);
        barDataSet.setValueTextSize(16f);

        BarData barData = new BarData(barDataSet);

        barChart.setFitBars(true);
        barChart.setData(barData);
        barChart.getDescription().setText("성취율(단위 : %)");
        barChart.getDescription().setTextSize(11f);
        barChart.animateY(2000);
    }
}
hayannn commented 1 year ago

activity_bar_chart.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"
    tools:context=".BarChartActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:layout_marginBottom="10dp">

        <TextView
            android:gravity="center"
            android:background="#FFFFFF"
            android:padding="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="카테고리별 성취도 확인 및 비교하기"
            android:textSize="20dp"
            android:textColor="#000000"
            android:textStyle="bold"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:layout_marginBottom="10dp">

        <TextView
            android:background="#FFFFFF"
            android:padding="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="                      운동(건강)    공부       취미생활   생활습관     기타"
            android:textSize="13dp"
            android:textColor="#000000"
            android:textStyle="bold"/>

    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="-50dp"
        android:padding="30dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <com.github.mikephil.charting.charts.BarChart
        android:layout_marginTop="-10dp"
        android:id="@+id/barChart"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    </LinearLayout>
</LinearLayout>
hayannn commented 1 year ago

기존 내용에서 수정 사항이 있어, 지금부터 올리는 파일은 바로 이전 이슈(알림 설정 관련)의 파일명을 보시고 해당되는 코드를 다시 붙여넣어 주시기 바랍니다.

hayannn commented 1 year ago

MainActivity.java


package com.example.pjsetting;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button btn_achieve;
    private Button btn_setting1;
    private Button btn_setting2;
    private Button btn_setting3;
    private Button btn_setting4;

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

        Button btn_achieve = (Button) findViewById(R.id.btn_achieve);

        btn_achieve.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, BarChartActivity.class);
                startActivity(intent);
            }
        });

        Button btn_setting1 = (Button) findViewById(R.id.btn_setting1);
        btn_setting1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                final PopupMenu popupMenu = new PopupMenu(getApplicationContext(),view);
                getMenuInflater().inflate(R.menu.popup,popupMenu.getMenu());
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        if (menuItem.getItemId() == R.id.action_menu1){
                            Intent intent = new Intent(MainActivity.this, SettingActivity.class);
                            startActivity(intent);
                        }else if (menuItem.getItemId() == R.id.action_menu2){
                            Intent intent = new Intent(MainActivity.this, Setting2Activity.class);
                            startActivity(intent);
                        }else if (menuItem.getItemId() == R.id.action_menu3){
                            Intent intent = new Intent(MainActivity.this, Setting3Activity.class);
                            startActivity(intent);
                        }else if (menuItem.getItemId() == R.id.action_menu4){
                            Intent intent = new Intent(MainActivity.this, Setting4Activity.class);
                            startActivity(intent);
                        }else {
                            Intent intent = new Intent(MainActivity.this, Setting5Activity.class);
                            startActivity(intent);
                        }

                        return false;
                    }
                });
                popupMenu.show();
            }
        });

        Button btn_setting2 = (Button) findViewById(R.id.btn_setting2);

        btn_setting2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, ConnectRoutineActivity.class);
            startActivity(intent);
            }
        });

        Button btn_setting3 = (Button) findViewById(R.id.btn_setting3);

        btn_setting3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, SuggestionActivity.class);
                startActivity(intent);
            }
        });

    }
}
hayannn commented 1 year ago

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="wrap_content"
    android:orientation="vertical"
    tools:context=".MainActivity">

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

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

        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center">
            <TextView
                android:layout_width="100dp"
                android:layout_height="30dp"
                android:text="내정보"
                android:textSize="23sp"
                android:layout_marginTop="11dp"
                android:layout_marginLeft="22dp"
                android:layout_marginBottom="21dp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center">
                <TextView
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:text="이하얀"
                android:textSize="20dp"
                android:layout_marginLeft="150dp" />
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="50dp"
                    android:text="수정"/>
            </LinearLayout>
            <TextView
                android:layout_width="350dp"
                android:layout_height="30dp"
                android:text="  여자 / 22세 / dlgkdis801@naver.com"
                android:textSize="20dp"
                android:layout_marginTop="11dp"
                android:layout_marginBottom="21dp"/>

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center">
                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="470dp">

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

                        <Button
                            android:id="@+id/btn_achieve"
                            android:layout_width="match_parent"
                            android:layout_height="90dp"
                            android:text="성취도 보기"
                            android:textSize="18dp"
                            android:textColor="#000000"
                            android:backgroundTint="#FFFFFF"/>

                        <Button
                            android:id="@+id/btn_setting1"
                            android:layout_width="match_parent"
                            android:layout_height="90dp"
                            android:text="알림 설정"
                            android:textSize="18dp"
                            android:textColor="#000000"
                            android:backgroundTint="#FFFFFF"/>

                        <Button
                            android:id="@+id/btn_setting3"
                            android:layout_width="match_parent"
                            android:layout_height="90dp"
                            android:text="연관루틴 추천보기"
                            android:textSize="18dp"
                            android:textColor="#000000"
                            android:backgroundTint="#FFFFFF"/>

                        <Button
                            android:id="@+id/btn_setting2"
                            android:layout_width="match_parent"
                            android:layout_height="90dp"
                            android:text="카테고리별 다양한 루틴 배워보기"
                            android:textSize="18dp"
                            android:textColor="#000000"
                            android:backgroundTint="#FFFFFF"/>
                    </LinearLayout>
                </ScrollView>
            </LinearLayout>

    </LinearLayout>

    </LinearLayout>

</LinearLayout>
hayannn commented 1 year ago

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.pjsetting">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Pjsetting"
        tools:targetApi="31">
        <activity
            android:name=".BarChartActivity"
            android:exported="false" />
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SettingActivity" />
        <activity android:name=".Setting2Activity" />
        <activity android:name=".Setting3Activity" />
        <activity android:name=".Setting4Activity" />
        <activity android:name=".Setting5Activity" />
        <activity android:name=".ConnectRoutineActivity" />
        <activity android:name=".SuggestionActivity" />
    </application>

</manifest>