package com.example.nemophila;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import com.example.nemophila.resources.AccountsRest;
import java.util.HashMap;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
public class LoginActivity extends AppCompatActivity {
private Retrofit retrofit;
private AccountsRest AccountsRest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//通信の初期化
this.retrofit = new Retrofit.Builder()
.baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/nemophila/")
.addConverterFactory(JacksonConverterFactory.create())
.build();
this.AccountsRest = retrofit.create(AccountsRest.class);
setContentView(R.layout.activity_login);
findViewById(R.id.LoginButton).setOnClickListener((View.OnClickListener) this);
}
public void onClick(View v) {
// ビューのIDからボタンを取得
if (v.getId() == R.id.LoginButton) {
EditText edituid = (EditText) findViewById(R.id.editTextUserID);
String uid = edituid.getText().toString();
EditText editpw = (EditText) findViewById(R.id.editTextTextPassword);
String pw = editpw.getText().toString();
// 通信
Call<HashMap> call = AccountsRest.getAccounts();
call.enqueue (new Callback<HashMap>() {
@Override
public void onResponse(Call<HashMap> call, Response<HashMap> response) {
if (response.isSuccessful()) {
//System.out.println("通信成功:changeBelongsAndMaster");
} else {
//System.out.println("通信可能:changeBelongsAndMaster: " + response.code());
}
}
@Override
public void onFailure(Call<HashMap> call, Throwable t) {
//System.out.println("通信失敗:changeBelongsAndMaster");
}
});
}
}
}