Last active
February 14, 2020 07:18
-
-
Save numanayhan/947cacdc993c25c69298782018ba94b9 to your computer and use it in GitHub Desktop.
Login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<shape | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="rectangle" > | |
<solid | |
android:color="#fff" > | |
</solid> | |
<stroke | |
android:width="1dp" | |
android:color="#e0e6f1" > | |
</stroke> | |
<padding | |
android:left="5dp" | |
android:top="5dp" | |
android:right="5dp" | |
android:bottom="5dp" > | |
</padding> | |
<corners | |
android:radius="3dp" > | |
</corners> | |
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
Button login,register,forgot; | |
EditText emailText,passwordText; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
emailText = (EditText)findViewById(R.id.email); | |
passwordText = (EditText)findViewById(R.id.password); | |
login = (Button)findViewById(R.id.login); | |
login.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
validate(); | |
} | |
}); | |
register = (Button)findViewById(R.id.register); | |
register.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent createAccount = new Intent(MainActivity.this,Register.class); | |
startActivity(createAccount); | |
} | |
}); | |
forgot = (Button)findViewById(R.id.forgot); | |
forgot.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent forgotAccount = new Intent(MainActivity.this,ForgotPassword.class); | |
startActivity(forgotAccount); | |
} | |
}); | |
} | |
public void validate(){ | |
String email = emailText.getText().toString().trim(); | |
String emailRegex = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; | |
String password = passwordText.getText().toString().trim(); | |
if (emailText.getText().toString().isEmpty()) { | |
Toast toast = Toast.makeText( this, R.string.please_enter_email, Toast.LENGTH_LONG); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); | |
emailText.requestFocus(); | |
} else if (email.matches("")) { | |
Toast toast = Toast.makeText( this, R.string.no_matches, Toast.LENGTH_LONG); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); | |
emailText.requestFocus(); | |
} else if (!email.matches(emailRegex)) { | |
Toast toast = Toast.makeText(this, R.string.no_matches, Toast.LENGTH_LONG); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); | |
emailText.requestFocus(); | |
} else if (passwordText.getText().toString().isEmpty()) { | |
Toast toast = Toast.makeText(this, R.string.please_enter_Password, Toast.LENGTH_LONG); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); | |
passwordText.requestFocus(); | |
} else if (password.matches("")) { | |
Toast toast = Toast.makeText(this, R.string.no_spaces_allowed, Toast.LENGTH_LONG); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); | |
passwordText.requestFocus(); | |
} else if (passwordText.getText().toString().length() < 5) { | |
Toast toast = Toast.makeText(this, R.string.required_minimum_three_characters, Toast.LENGTH_LONG); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); | |
passwordText.requestFocus(); | |
} else { | |
login(email,password); | |
} | |
} | |
private void login(String email,String password){ | |
Log.d(email, "login: email"); | |
Log.d(password, "login: password"); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<EditText | |
android:textColor="@color/colorAccent" | |
android:textStyle="normal" | |
android:hint="@string/e_posta" | |
android:textColorHint="@color/light_text" | |
android:layout_width="match_parent" | |
android:layout_marginLeft="30dp" | |
android:layout_marginRight="30dp" | |
android:background="@drawable/edit" | |
android:layout_height="50dp"> | |
</EditText> | |
<EditText | |
android:textColor="@color/colorAccent" | |
android:textStyle="normal" | |
android:hint="@string/password" | |
android:textColorHint="@color/light_text" | |
android:layout_width="match_parent" | |
android:layout_marginLeft="30dp" | |
android:layout_marginRight="30dp" | |
android:layout_marginTop="5dp" | |
android:background="@drawable/edit" | |
android:layout_height="50dp"> | |
</EditText> | |
<Button | |
android:id="@+id/login" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:background="@color/colorAccent" | |
android:layout_marginLeft="30dp" | |
android:textColor="@color/white" | |
android:layout_marginRight="30dp" | |
android:layout_marginTop="20dp" | |
android:textAlignment="center" | |
android:textAllCaps="true" | |
android:text="Giriş" | |
android:fontFamily="@font/roboto_medium" | |
/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment