diff --git a/app/src/main/java/com/example/cosmosclient/views/SigninActivity.java b/app/src/main/java/com/example/cosmosclient/views/SigninActivity.java index de06c2c..b3e02fe 100644 --- a/app/src/main/java/com/example/cosmosclient/views/SigninActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/SigninActivity.java @@ -3,6 +3,8 @@ import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.view.View; import android.widget.Button; import android.widget.EditText; @@ -17,6 +19,9 @@ import retrofit2.converter.jackson.JacksonConverterFactory; public class SigninActivity extends AppCompatActivity { + private boolean uIdEnable; + private boolean pwEnable; + Button SigninButton; @Override protected void onCreate(Bundle savedInstanceState) { @@ -24,12 +29,19 @@ setContentView(R.layout.activity_signin); //各種IDを取得 - Button SigninButton = findViewById(R.id.SigninButton); + 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); + //ボタン無効化 + SigninButton.setEnabled(false); + + //TextWatcherで入力監視 + NameText.addTextChangedListener(new SigninActivity.GenericTextWatcher(NameText)); + PasswordText.addTextChangedListener(new SigninActivity.GenericTextWatcher(PasswordText)); + //retrofitの処理 final Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/") @@ -61,6 +73,7 @@ finish(); }else{ + //onFailureでキャッチできないエラーの処理 Toast.makeText(SigninActivity.this, "通信エラー",Toast.LENGTH_SHORT).show(); } @@ -98,4 +111,42 @@ } }); } + private class GenericTextWatcher implements TextWatcher{ + private View view; + + private GenericTextWatcher(View view){ + this.view = view; + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count,int after){/*記述不要*/}; + @Override + public void onTextChanged(CharSequence s, int start, int before, int count){/*記述不要*/}; + + @Override + public void afterTextChanged(Editable s){ + switch(view.getId()) { + case R.id.NameText: + if (s.length() > 0) { + uIdEnable = true; + } else { + uIdEnable = false; + } + break; + case R.id.PasswordText: + if(s.length()>5){ + pwEnable=true; + }else{ + pwEnable=false; + } + break; + } + //ボタン有効&無効 + if(uIdEnable && pwEnable ){ + SigninButton.setEnabled(true); + }else{ + SigninButton.setEnabled(false); + } + } + } }