package com.yujinoh.register;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends AppCompatActivity {
EditText editEmail;
EditText editPassword;
EditText editPassword2;
Button btnRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editEmail = findViewById(R.id.editEmail);
editPassword = findViewById(R.id.editPassword);
editPassword2 = findViewById(R.id.editPassword2);
btnRegister = findViewById(R.id.btnRegister);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 1. ์
๋ ฅ์ฌํญ๋ค์ ๋ชจ๋ ๊ฐ์ ธ์จ๋ค
String email = editEmail.getText().toString().trim();
String password = editPassword.getText().toString().trim();
String password2 = editPassword2.getText().toString().trim();
// 2. ํ์ํญ๋ชฉ ์ฒดํฌ
if (email.isEmpty() || password.isEmpty() || password2.isEmpty()){
Snackbar.make(btnRegister,"ํ์ํญ๋ชฉ์
๋๋ค. ๋ชจ๋ ์
๋ ฅํ์ธ์.",Snackbar.LENGTH_SHORT).show();
return;
}
// 3. ์ด๋ฉ์ผ ํ์์ด ๋ง๋์ง ์ฒดํฌ
if (email.contains("@") == false){
Snackbar.make(btnRegister,"์ด๋ฉ์ผ์ ์ ๋๋ก ์
๋ ฅํ์ธ์.",Snackbar.LENGTH_SHORT).show();
return;
}
// 4. ๋ง์ฝ์ ๋น๋ฒ ๊ธธ์ด ์ ์ฝ์ด ์๋ค๋ฉด,
if (password.length() < 4 || password.length() > 12){
Snackbar.make(btnRegister,"๋น๋ฐ๋ฒํธ ๊ธธ์ด๋ฅผ ํ์ธํ์ธ์.",Snackbar.LENGTH_SHORT).show();
return;
}
// 5. ๋น๋ฐ๋ฒํธ๊ฐ ๋น๋ฐ๋ฒํธ ํ์ธ๊ณผ ๊ฐ์์ง ํ์ธํ๋ค
if (password.equals(password2) == false) {
Snackbar.make(btnRegister,"๋น๋ฐ๋ฒํธ๊ฐ ์ผ์นํ์ง ์์ต๋๋ค.",Snackbar.LENGTH_SHORT).show();
return;
}
// ์๋ฐํ ์กํฐ๋นํฐ๋ฅผ ๋์ด๋ค
Intent intent = new Intent(MainActivity.this, AvataActivity.class);
// ์ธํ
ํธ ๋ฐ์ดํฐ ๋ค์์ผ๋ก ๋๊ธฐ๊ธฐ
// intent.putExtra("email", email);
startActivity(intent);
// ์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์ฑ ๋ด ์ ์ฅ์์ ์ ์ฅํ๋ ๋ฐฉ๋ฒ
SharedPreferences sp = getSharedPreferences("avata_app",MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("email",email);
editor.commit();
// ๋ฐฑ๋ฒํผ ๋๋ฌ๋ ๋ค์ ๋์์ค์ง ๋ชปํ๊ฒ ํ๊ธฐ
finish();
}
});
}
}
package com.yujinoh.register;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.snackbar.Snackbar;
public class AvataActivity extends AppCompatActivity {
ImageView imgAvata;
Button btnRabbit;
Button btnTurtle;
Button button;
String email;
// ์ ์ ๊ฐ ์๋ฐํ๋ฅผ ์ ํํ๋ฉด, ์ ํํ ์๋ฐํ๊ฐ ๋ฌด์์ธ์ง ์ ์ฅํ๋ ์ฉ๋์ด๋ค.
// 0 : ์๋ฌด๊ฒ๋ ์ ํ ์ํ ๊ฒ์ด๋ค, 1 : ํ ๋ผ, 2 : ๊ฑฐ๋ถ์ด
int imageType = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_avata);
// ์ ์ธํ
ํธ๋ก๋ถํฐ ์ด๋ฉ์ผ ๋ฐ๊ธฐ
// email = getIntent().getStringExtra("email");
imgAvata = findViewById(R.id.imgAvata);
btnRabbit = findViewById(R.id.btnRabbit);
btnTurtle = findViewById(R.id.btnTurtle);
button = findViewById(R.id.button);
btnRabbit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imgAvata.setImageResource(R.drawable.rabbit);
imageType = 1;
}
});
btnTurtle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imgAvata.setImageResource(R.drawable.turtle);
imageType = 2;
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (imageType == 0) {
Snackbar.make(button, "์๋ฐํ๋ฅผ ์ ํํ์ธ์.", Snackbar.LENGTH_SHORT).show();
return;
}
// ์๋ฌํธ ๋ค์ด์ผ๋ก๊ทธ๋ฅผ ๋์ด๋ค.
showAlertDialog();
}
});
}
private void showAlertDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(AvataActivity.this);
builder.setCancelable(false);
builder.setTitle("ํ์๊ฐ์
์๋ฃ");
builder.setMessage("์๋ฃํ์๊ฒ ์ต๋๊น?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Yes ๋ฒํผ์ ๋๋ ์ ๋์ ์ฒ๋ฆฌ
Intent intent = new Intent(AvataActivity.this, WelcomeActivity.class);
// ์ธํ
ํธ ๋ฐ์ดํฐ ๋ค์์ผ๋ก ๋๊ธฐ๊ธฐ
// intent.putExtra("email", email);
startActivity(intent);
// ๋ฐฑ๋ฒํผ ๋๋ฌ๋ ๋ค์ ๋์์ค์ง ๋ชปํ๊ฒ ํ๊ธฐ
finish();
}
});
builder.setNegativeButton("No", null);
builder.show();
}
}
package com.yujinoh.register;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class WelcomeActivity extends AppCompatActivity {
TextView textWel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
textWel = findViewById(R.id.textWel);
// ์ ์ธํ
ํธ๋ก๋ถํฐ ์ด๋ฉ์ผ ๋ฐ๊ธฐ
// String email = getIntent().getStringExtra("email");
// ์ฑ ๋ด ์ ์ฅ์์ ์ ์ฅ๋ ์ด๋ฉ์ผ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์จ๋ค
SharedPreferences sp = getSharedPreferences("avata_app", MODE_PRIVATE);
String email = sp.getString("email","");
textWel.setText(email+"๋\n"+"ํ์๊ฐ์
์ ์ถํํฉ๋๋ค");
}
}