diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..f68b55e --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +lessonClient \ No newline at end of file diff --git a/.idea/codeStyles b/.idea/codeStyles new file mode 100644 index 0000000..e2e415d --- /dev/null +++ b/.idea/codeStyles @@ -0,0 +1,119 @@ + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..141522e --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..0897082 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8978d23 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/other.xml b/.idea/other.xml new file mode 100644 index 0000000..b45a6e0 --- /dev/null +++ b/.idea/other.xml @@ -0,0 +1,340 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..7178c9a --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,47 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.example.lessonClient" + compileSdk = 34 + + defaultConfig { + applicationId = "com.example.lessonClient" + minSdk = 30 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.activity) + implementation(libs.constraintlayout) + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.espresso.core) + implementation("com.squareup.retrofit2:retrofit:2.9.0") + implementation("com.squareup.retrofit2:converter-moshi:2.9.0") + implementation("com.squareup.retrofit2:converter-jackson:2.5.0") + implementation("com.squareup.retrofit2:converter-scalars:2.1.0") +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/lessonClient/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/lessonClient/ExampleInstrumentedTest.java new file mode 100644 index 0000000..b4906bb --- /dev/null +++ b/app/src/androidTest/java/com/example/lessonClient/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.lessonClient; + +import android.content.Context; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.lesson", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..45fd48e --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/lessonClient/models/Account.java b/app/src/main/java/com/example/lessonClient/models/Account.java new file mode 100644 index 0000000..6521a30 --- /dev/null +++ b/app/src/main/java/com/example/lessonClient/models/Account.java @@ -0,0 +1,28 @@ +package com.example.lessonClient.models; + +public class Account { + private String account_id; + private String password; + + public Account(String aid, String pass) { + account_id = aid; + password = pass; + } + + public String getAccount_id() { + return account_id; + } + + public void setAccount_id(String account_id) { + this.account_id = account_id; + } + + public void setPassword(String p) { + password = p; + } + + public String getPassword() { + return password; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/lessonClient/rest/AccountsRest.java b/app/src/main/java/com/example/lessonClient/rest/AccountsRest.java new file mode 100644 index 0000000..243e6bd --- /dev/null +++ b/app/src/main/java/com/example/lessonClient/rest/AccountsRest.java @@ -0,0 +1,44 @@ +package com.example.lessonClient.rest; + +import com.example.lessonClient.models.Account; +import java.util.Set; +import retrofit2.Call; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.GET; +import retrofit2.http.POST; +import retrofit2.http.PUT; +import retrofit2.http.Path; +import retrofit2.http.Query; + +public interface AccountsRest { + // 全体のアカウント一覧 + @GET("accounts") + Call> getAccounts( + ); + + // サインアップ + @FormUrlEncoded + @POST("accounts") + Call signup( + @Field("account_id") String account_id, + @Field("password") String password + ); + + //指定されたアカウント情報を返す + @GET("accounts/{account_id}") + Call getAccountInfo( + @Path("account_id") String account_id, + @Query("password") String password + ); + + // パスワード変更 + @FormUrlEncoded + @PUT("accounts/{account_id}/password") + Call changePW( + @Path("account_id") String account_id, + @Field("new_password") String new_password, + @Field("old_password") String old_password + ); + +} diff --git a/app/src/main/java/com/example/lessonClient/views/AccountListActivity.java b/app/src/main/java/com/example/lessonClient/views/AccountListActivity.java new file mode 100644 index 0000000..4869be6 --- /dev/null +++ b/app/src/main/java/com/example/lessonClient/views/AccountListActivity.java @@ -0,0 +1,55 @@ +package com.example.lessonClient.views; + +import android.os.Bundle; + +import android.widget.TextView; +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import com.example.lessonClient.R; +import com.example.lessonClient.rest.AccountsRest; +import java.util.Set; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + +public class AccountListActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_account_list); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + //通信の初期化 + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://10.0.2.2:8080/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + AccountsRest accountsRest = retrofit.create(AccountsRest.class); + Call> call = accountsRest.getAccounts(); + call.enqueue(new Callback>() { + + @Override + public void onResponse(Call> call, Response> response) { + + ((TextView) findViewById(R.id.accounts)).setText(response.body().toString()); + + } + + @Override + public void onFailure(Call> call, Throwable t) { + ((TextView) findViewById(R.id.accounts)).setText("通信失敗"); + } + }); + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/lessonClient/views/SettingsActivity.java b/app/src/main/java/com/example/lessonClient/views/SettingsActivity.java new file mode 100644 index 0000000..fbb5fec --- /dev/null +++ b/app/src/main/java/com/example/lessonClient/views/SettingsActivity.java @@ -0,0 +1,94 @@ +package com.example.lessonClient.views; + +import android.content.Intent; +import android.os.Bundle; + +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import com.example.lessonClient.R; +import com.example.lessonClient.rest.AccountsRest; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + +public class SettingsActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_settings); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + String str_account_id = getIntent().getStringExtra("account_id"); + ((TextView) findViewById(R.id.account_id)).setText(str_account_id); + + //通信の初期化 + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://10.0.2.2:8080/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + AccountsRest accountsRest = retrofit.create(AccountsRest.class); + + // listボタンを押してlist画面に遷移 + Button button_list = (Button) findViewById(R.id.List); + button_list.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(SettingsActivity.this, AccountListActivity.class); + startActivity(intent); + } + }); + + // changeボタンを押してメッセージ表示 + Button button_change = (Button) findViewById(R.id.change); + + button_change.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + + EditText pw = (EditText) findViewById(R.id.password); + String oldpass = pw.getText().toString().trim(); + EditText newpw = (EditText) findViewById(R.id.newpassword); + String newpass = newpw.getText().toString().trim(); + + + Call call = accountsRest.changePW(str_account_id, newpass, oldpass); + call.enqueue(new Callback() { + + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + ((TextView) findViewById(R.id.message)).setText("パスワードが変更されました"); + } else { + ((TextView) findViewById(R.id.message)).setText("パスワードが違います"); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + ((TextView) findViewById(R.id.message)).setText("Failure"); + } + }); + + + } + + + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/lessonClient/views/SignUpActivity.java b/app/src/main/java/com/example/lessonClient/views/SignUpActivity.java new file mode 100644 index 0000000..85a7dd8 --- /dev/null +++ b/app/src/main/java/com/example/lessonClient/views/SignUpActivity.java @@ -0,0 +1,69 @@ +package com.example.lessonClient.views; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.EditText; +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import com.example.lessonClient.R; +import com.example.lessonClient.rest.AccountsRest; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + +public class SignUpActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_sign_up); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + //通信の初期化 + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://10.0.2.2:8080/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + AccountsRest accountsRest = retrofit.create(AccountsRest.class); + + //ボタンを押してlogin画面に遷移 + Button button_register = (Button) findViewById(R.id.Registerbutton); + button_register.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + EditText editid = (EditText) findViewById(R.id.Username); + String account_id = editid.getText().toString().trim(); + EditText editpw = (EditText) findViewById(R.id.Password); + String password = editpw.getText().toString().trim(); + Call call = accountsRest.signup(account_id, password); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + Intent intent = new Intent(SignUpActivity.this, SettingsActivity.class); + intent.putExtra("account_id", account_id); + startActivity(intent); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("!!!"); + } + }); + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..4fdacf0 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..5c25c11 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_account_list.xml b/app/src/main/res/layout/activity_account_list.xml new file mode 100644 index 0000000..1b54b2d --- /dev/null +++ b/app/src/main/res/layout/activity_account_list.xml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 0000000..d77ef64 --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,118 @@ + + + + + + + + + +