| | package com.example.cosmosclient.views; |
---|
| | |
---|
| | import android.annotation.SuppressLint; |
---|
| | import android.content.Intent; |
---|
| | import android.graphics.Bitmap; |
---|
| | import android.media.Image; |
---|
| | import android.net.Uri; |
---|
| | import android.support.v7.app.AppCompatActivity; |
---|
| | import android.os.Bundle; |
---|
| | import android.text.Editable; |
---|
| | import android.text.TextWatcher; |
---|
| | import android.util.Log; |
---|
| | import android.view.View; |
---|
| | import android.widget.Button; |
---|
| | import android.widget.EditText; |
---|
| | import android.widget.ImageView; |
---|
| | import android.widget.Toast; |
---|
| | |
---|
| | import com.example.cosmosclient.R; |
---|
| | import com.example.cosmosclient.app.Cosmos; |
---|
| | import com.example.cosmosclient.entities.SignupResponse; |
---|
| | import com.example.cosmosclient.resources.UsersRest; |
---|
| | import com.theartofdev.edmodo.cropper.CropImage; |
---|
| | import com.theartofdev.edmodo.cropper.CropImageView; |
---|
| | |
---|
| | |
---|
| | import retrofit2.Call; |
---|
| | import retrofit2.Callback; |
---|
| |
---|
| | private boolean nameEnable; |
---|
| | private boolean pwEnable; |
---|
| | private boolean cpwEnable; |
---|
| | private Button MakeAccountButton; |
---|
| | private ImageView iconChoice; |
---|
| | private static final int REQUEST_GALLERY = 1000; |
---|
| | private static final int REQUEST_CROP = 1001; |
---|
| | |
---|
| | @Override |
---|
| | protected void onCreate(Bundle savedInstanceState) { |
---|
| | super.onCreate(savedInstanceState); |
---|
| |
---|
| | MakeAccountButton = findViewById(R.id.MakeAccountButton); |
---|
| | final EditText NameText = findViewById(R.id.NameText); |
---|
| | final EditText PasswordText = findViewById(R.id.PasswordText); |
---|
| | final EditText ConfirmPasswordText = findViewById(R.id.ConfirmPasswordText); |
---|
| | iconChoice = findViewById(R.id.choiceImage); |
---|
| | |
---|
| | // |
---|
| | // //入力欄監視 |
---|
| | // NameText.addTextChangedListener(new GenericTextWatcher(NameText)); |
---|
| | // PasswordText.addTextChangedListener(new GenericTextWatcher(PasswordText)); |
---|
| |
---|
| | // //アカウント登録ボタン無効化 |
---|
| | // MakeAccountButton.setEnabled(false); |
---|
| | |
---|
| | //Make Accountボタンの処理 |
---|
| | MakeAccountButton.setOnClickListener(new View.OnClickListener(){ |
---|
| | MakeAccountButton.setOnClickListener(new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View v){ |
---|
| | public void onClick(View v) { |
---|
| | String pw = PasswordText.getText().toString(); |
---|
| | String confirmPw = ConfirmPasswordText.getText().toString(); |
---|
| | |
---|
| | //パスワードと確認パスワードが一致していない際の処理 |
---|
| | if(!pw.equals(confirmPw)){ |
---|
| | if (!pw.equals(confirmPw)) { |
---|
| | PasswordText.setError("入力されたパスワードが一致しません"); |
---|
| | ConfirmPasswordText.setError("入力されたパスワードが一致しません"); |
---|
| | return; |
---|
| | } |
---|
| | |
---|
| | //API呼び出しのための値入力 |
---|
| | Call<SignupResponse> call = signupService.createUser(NameText.getText().toString(), |
---|
| | PasswordText.getText().toString(),"https://yumenavi.info/live/2018/photo/k/s015980019.jpg"); |
---|
| | PasswordText.getText().toString(), "https://yumenavi.info/live/2018/photo/k/s015980019.jpg"); |
---|
| | |
---|
| | //サーバからデータ受け取り |
---|
| | call.enqueue(new Callback<SignupResponse>() { |
---|
| | //成功時 |
---|
| |
---|
| | public void onResponse(Call<SignupResponse> call, Response<SignupResponse> response) { |
---|
| | if (response.isSuccessful()) { |
---|
| | SignupResponse result = response.body(); |
---|
| | |
---|
| | Cosmos app = (Cosmos)getApplication(); |
---|
| | Cosmos app = (Cosmos) getApplication(); |
---|
| | app.setToken(result.token); |
---|
| | |
---|
| | Intent intent = new Intent(getApplication(), GroupListActivity.class); |
---|
| | |
---|
| |
---|
| | // System.out.println(result.pw); |
---|
| | |
---|
| | startActivity(intent); |
---|
| | Toast.makeText(SignupActivity.this, |
---|
| | "アカウントを作成しました",Toast.LENGTH_SHORT); |
---|
| | "アカウントを作成しました", Toast.LENGTH_SHORT); |
---|
| | finish(); |
---|
| | |
---|
| | }else{ |
---|
| | } else { |
---|
| | //onFailureでキャッチできないエラー用 |
---|
| | Toast.makeText(SignupActivity.this, |
---|
| | "アカウント作成失敗",Toast.LENGTH_SHORT); |
---|
| | "アカウント作成失敗", Toast.LENGTH_SHORT); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | //失敗時 |
---|
| | @Override |
---|
| | public void onFailure(Call<SignupResponse> call, Throwable t) { |
---|
| | t.printStackTrace(); |
---|
| | Toast.makeText(SignupActivity.this, |
---|
| | "アカウント作成失敗",Toast.LENGTH_SHORT); |
---|
| | "アカウント作成失敗", Toast.LENGTH_SHORT); |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | //サインイン画面への遷移処理 |
---|
| | LoginButton.setOnClickListener(new View.OnClickListener(){ |
---|
| | LoginButton.setOnClickListener(new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View v){ |
---|
| | Intent intent = new Intent(getApplication(),SigninActivity.class); |
---|
| | public void onClick(View v) { |
---|
| | Intent intent = new Intent(getApplication(), SigninActivity.class); |
---|
| | startActivity(intent); |
---|
| | finish(); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | //アイコン選択 |
---|
| | iconChoice.setOnClickListener(new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view) { |
---|
| | // Intent intent = new Intent(); |
---|
| | // intent.setType("image/*"); |
---|
| | // intent.setAction(Intent.ACTION_GET_CONTENT); |
---|
| | // startActivityForResult(intent, REQUEST_GALLERY); |
---|
| | CropImage.activity() |
---|
| | .setAspectRatio(1,1) |
---|
| | .setGuidelines(CropImageView.Guidelines.ON) |
---|
| | .start(SignupActivity.this); |
---|
| | |
---|
| | |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
---|
| | // |
---|
| | // //アルバムの結果をここで受け、oginotihiroへ渡します。 |
---|
| | // if (requestCode == REQUEST_GALLERY && resultCode == RESULT_OK) { |
---|
| | // try { |
---|
| | // //アルバムで選ばれたファイル(original_uri)を取得して、oginotihiroへ渡します |
---|
| | // Uri original_uri = data.getData(); |
---|
| | // Intent intent = new Intent(this, oginotihiro.class); |
---|
| | // intent.putExtra("original_uri",original_uri.toString()); |
---|
| | // startActivityForResult(intent, REQUEST_CROP); |
---|
| | // } catch (Exception e) { |
---|
| | // } |
---|
| | // } |
---|
| | // |
---|
| | // //oginotihiroからの結果(saved_uri)をここで受けとります。 |
---|
| | // if (requestCode == REQUEST_CROP && resultCode == RESULT_OK) { |
---|
| | // Bundle bundle = data.getExtras(); |
---|
| | // Uri saved_uri = (Uri)bundle.get("saved_uri"); |
---|
| | // //saved_uriが、クロップされた写真の保存先のパスになります。 |
---|
| | // Log.d("saved_uri",saved_uri+""); |
---|
| | // |
---|
| | // iconChoice.setImageURI(saved_uri); |
---|
| | //// } |
---|
| | // switch (requestCode) { |
---|
| | // case REQUEST_GALLERY: |
---|
| | // if (resultCode != RESULT_OK) return; |
---|
| | // Uri uri = data.getData(); // 選ばれた写真のUri |
---|
| | // Intent intent = new Intent("com.android.camera.action.CROP"); |
---|
| | // intent.setData(uri); |
---|
| | // intent.putExtra("outputX", 200); |
---|
| | // intent.putExtra("outputY", 200); |
---|
| | // intent.putExtra("aspectX", 1); |
---|
| | // intent.putExtra("aspectY", 1); |
---|
| | // intent.putExtra("scale", true); |
---|
| | // intent.putExtra("return-data", true); |
---|
| | // startActivityForResult(intent, REQUEST_CROP); |
---|
| | // break; |
---|
| | // case REQUEST_CROP: |
---|
| | // if (resultCode != RESULT_OK) return; |
---|
| | // Bitmap bitmap = data.getExtras().getParcelable("data"); |
---|
| | // iconChoice.setImageBitmap(bitmap); |
---|
| | // //Bitmap bitmap = data.getExtras().getParcelable("data"); |
---|
| | // } |
---|
| | if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { |
---|
| | CropImage.ActivityResult result = CropImage.getActivityResult(data); |
---|
| | if (resultCode == RESULT_OK) { |
---|
| | Uri resultUri = result.getUri(); |
---|
| | iconChoice.setImageURI(resultUri); |
---|
| | } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { |
---|
| | Exception error = result.getError(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |
---|
| | } |
---|
| | |
---|
| | //入力欄監視処理内容 |
---|
| | private class GenericTextWatcher implements TextWatcher{ |
---|
| |
---|
| | |