Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.login.thinkpad.login;
- import android.app.Dialog;
- import android.content.Intent;
- import android.os.Handler;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.Window;
- import android.widget.Button;
- import android.widget.DialerFilter;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- EditText username;
- EditText password;
- Button login;
- Button signin;
- // For Dialog.
- //custom dialog
- EditText Setname;
- EditText SetUserName;
- EditText SetPassword;
- Button Create;
- Button cancel_action;
- public static String SetUser;
- public static String SetPass;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- username = (EditText)findViewById(R.id.username);
- password = (EditText)findViewById(R.id.password);
- login = (Button)findViewById(R.id.Login);
- signin = (Button)findViewById(R.id.Create);
- signin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final Dialog dialog = new Dialog(MainActivity.this);
- dialog.setTitle("Set info");
- dialog.setContentView(R.layout.custom);
- dialog.show();
- Setname = (EditText)dialog.findViewById(R.id.Setname);
- SetUserName = (EditText)dialog.findViewById(R.id.SetUserName);
- SetPassword = (EditText)dialog.findViewById(R.id.SetPassword);
- Create = (Button)dialog.findViewById(R.id.Create);
- cancel_action = (Button)dialog.findViewById(R.id.cancel_action);
- //set username
- //Check if SetUser and SetPass are entered,
- Create.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- SetUser = SetUserName.getText().toString();
- SetPass = SetPassword.getText().toString();
- if (SetUser.isEmpty() || SetPass.isEmpty()){
- Toast.makeText(getApplicationContext(),"you should set username and password", Toast.LENGTH_LONG).show();
- }else {
- dialog.cancel();
- }
- }
- });
- }
- });
- login.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- String mUserName = username.getText().toString();
- String mPassword = password.getText().toString();
- if (mPassword.isEmpty()||mUserName.isEmpty()){
- Toast.makeText(getApplicationContext(),"Please fill out username password", Toast.LENGTH_LONG).show();
- }else if (!mUserName.equals(SetUser)|| !mPassword.equals(SetPass)){
- Toast.makeText(getApplicationContext(),"Username and Password are not matched. Please Sign Up", Toast.LENGTH_LONG).show();
- }
- else{
- Toast.makeText(getApplicationContext(), "Please wait...", Toast.LENGTH_SHORT).show();
- final Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- //Do something after 100ms
- Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
- intent.putExtra("SpeicalKey", true);
- startActivity(intent);
- }
- }, 3000);
- }
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- // Make a new calss and name it (SecondActivity). Copy paste the following code.
- package com.login.thinkpad.login;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.widget.TextView;
- /**
- * Created by Ahmed Mostfa on Oct30.
- */
- public class SecondActivity extends AppCompatActivity {
- TextView youLoginIn;
- @Override
- protected void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.second_activity);
- youLoginIn = (TextView)findViewById(R.id.youLogined);
- Intent intent = getIntent();
- intent.getStringExtra("SpeicalKey");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement