Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Manifest
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="day2.rungene.com.puttextra2" >
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:supportsRtl="true"
- android:theme="@style/AppTheme" >
- <activity android:name=".Activity_One" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name=".Activity_Two"></activity>
- </application>
- </manifest>
- //Activity_One.Java
- package day2.rungene.com.puttextra2;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class Activity_One extends AppCompatActivity {
- private EditText etEmail;
- private EditText etPass;
- private Button btnA;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity__one);
- etEmail = (EditText) findViewById(R.id.etEmail);
- etPass = (EditText) findViewById(R.id.etPass);
- btnA = (Button) findViewById(R.id.btnA);
- btnA.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- //validation
- String newEmail = etEmail.getText().toString();
- String newPass = etPass.getText().toString();
- boolean samr = validEmail(newEmail);
- if ((newEmail.equals("")|| newEmail.equals(null))
- || newPass.equals("") || newPass.equals(null)|| samr==false){
- Toast.makeText(getApplicationContext(),"Acces Denied" + newEmail,Toast.LENGTH_LONG).show();
- }else {
- if (newEmail.equals("samrr@yahoo.com") && newPass.equals("123")){
- Intent intent = new Intent(Activity_One.this, Activity_Two.class);
- intent.putExtra("email", newEmail);
- intent.putExtra("pass", newPass);
- Activity_One.this.startActivity(intent);
- }else {
- Toast.makeText(getApplication(),"Emai or Password Incorrect", Toast.LENGTH_SHORT).show();
- }
- }
- }
- });
- }
- private boolean validEmail(String email) {
- if (email.contains("@")){
- return true;
- }else {
- return false;
- }
- }
- }
- //Activity_Two.Java
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.widget.TextView;
- public class Activity_Two extends AppCompatActivity {
- private TextView tvEmail;
- private TextView tvPass;
- @Override
- protected void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_two);
- tvEmail = (TextView) findViewById(R.id.tvEmail);
- tvPass = (TextView) findViewById(R.id.tvPass);
- Intent getIntA = getIntent();
- String getEmail = getIntA.getStringExtra("email");
- String getPass = getIntA.getStringExtra("pass");
- String newEmail = tvEmail.getText().toString();
- String newPass = tvPass.getText().toString();
- tvEmail.setText(newEmail + " " + getEmail);
- tvPass.setText(newPass + " "+getPass);
- }
- }
- //activity_one.xml
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/activity__one"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- tools:context="day2.rungene.com.puttextra2.Activity_One">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="LOGIN"
- android:gravity="center_horizontal"
- android:textSize="25dp"
- android:textStyle="bold"
- android:layout_marginTop="15dp"
- android:id="@+id/textView"
- />
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/etEmail"
- android:hint="Enter ur email"
- android:padding="10dp"
- android:layout_marginTop="10dp"
- android:backgroundTint="@color/colorAccent"
- android:layout_below="@+id/textView"
- />
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/etPass"
- android:hint="Enter ur pass"
- android:padding="10dp"
- android:layout_marginTop="10dp"
- android:backgroundTint="@color/colorAccent"
- android:layout_below="@+id/etEmail"
- />
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/btnA"
- android:text="LOGIN"
- android:layout_marginTop="10dp"
- android:background="@color/colorPrimaryDark"
- android:textColor="@color/white"
- android:textStyle="bold"
- android:layout_below="@+id/etPass"
- />
- </RelativeLayout>
- //activity_two.xml
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- xmlns:tools="http://schemas.android.com/tools"
- android:paddingBottom="16dp"
- android:paddingLeft="64dp"
- android:paddingRight="64dp"
- android:paddingTop="16dp"
- tools:context="day2.rungene.com.puttextra2.Activity_Two">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/tvWelcom"
- android:layout_marginTop="15dp"
- android:text="Welcome Bro"
- android:textStyle="bold"
- android:textSize="20dp"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/tvEmail"
- android:layout_marginTop="15dp"
- android:text="Ur Email:"
- android:textStyle="bold"
- android:textSize="20dp"
- android:layout_below="@+id/tvWelcom"
- />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/tvPass"
- android:layout_marginTop="10dp"
- android:text="Ur Password:"
- android:textStyle="bold"
- android:textSize="20dp"
- android:layout_below="@+id/tvEmail"
- />
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement