package com.example.cosmosclient.views; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.example.cosmosclient.R; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; public class SigninActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_signin); //各種IDを取得 Button SigninButton = findViewById(R.id.SigninButton); Button SignupButton = findViewById(R.id.SignupButton); final EditText NameText = findViewById(R.id.NameText); final EditText PasswordText = findViewById(R.id.PasswordText); Button ForgotPasswordButton = findViewById(R.id.ForgotPasswordButton); //retrofitの処理 final Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/") .addConverterFactory(JacksonConverterFactory.create()) .build(); //interfaceから実装を取得 final Signin signin = retrofit.create(Signin.class); //Sign inボタンの処理 SigninButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Intent intent = new Intent(getApplication(), GroupList.class); Call<login> call = signin.loginList(NameText.getText().toString(), PasswordText.getText().toString()); call.enqueue(new Callback<login>() { //成功時 @Override public void onResponse(Call<login> call, Response<login> response) { if (response.isSuccessful()) { login result = response.body(); Intent intent = new Intent(getApplication(), GroupList.class); //intent.putExtra("UserInfomation",result); Toast.makeText(SigninActivity.this, "ログインしました", Toast.LENGTH_SHORT).show(); startActivity(intent); finish(); } } //失敗時 @Override public void onFailure(Call<login> call, Throwable t) { //t.printStackTrace(); Toast.makeText(SigninActivity.this, "ユーザIDもしくはパスワードが間違っています",Toast.LENGTH_SHORT).show(); } }); } }); //サインアップ画面への遷移処理 SignupButton.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ Intent intent = new Intent(getApplication(), SignupActivity.class); startActivity(intent); finish(); } }); //パスワード再登録画面への遷移処理 ForgotPasswordButton.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ Intent intent = new Intent(getApplication(), ForgotPasswordActivity.class); startActivity(intent); //finish(); } }); } }