Advertisement
rungene

Day 2 of Challenge

Jan 12th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.31 KB | None | 0 0
  1. //Manifest
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.     package="day2.rungene.com.puttextra2" >
  5.  
  6.     <application
  7.         android:allowBackup="true"
  8.         android:icon="@mipmap/ic_launcher"
  9.         android:label="@string/app_name"
  10.         android:supportsRtl="true"
  11.         android:theme="@style/AppTheme" >
  12.         <activity android:name=".Activity_One" >
  13.             <intent-filter>
  14.                 <action android:name="android.intent.action.MAIN" />
  15.  
  16.                 <category android:name="android.intent.category.LAUNCHER" />
  17.             </intent-filter>
  18.         </activity>
  19.         <activity android:name=".Activity_Two"></activity>
  20.     </application>
  21.  
  22. </manifest>
  23.  
  24. //Activity_One.Java
  25. package day2.rungene.com.puttextra2;
  26.  
  27. import android.content.Intent;
  28. import android.support.v7.app.AppCompatActivity;
  29. import android.os.Bundle;
  30. import android.view.View;
  31. import android.widget.Button;
  32. import android.widget.EditText;
  33. import android.widget.Toast;
  34.  
  35. public class Activity_One extends AppCompatActivity {
  36.  
  37.     private EditText etEmail;
  38.     private EditText etPass;
  39.     private Button btnA;
  40.  
  41.     @Override
  42.     protected void onCreate(Bundle savedInstanceState) {
  43.         super.onCreate(savedInstanceState);
  44.         setContentView(R.layout.activity__one);
  45.  
  46.         etEmail = (EditText) findViewById(R.id.etEmail);
  47.         etPass = (EditText) findViewById(R.id.etPass);
  48.  
  49.         btnA = (Button) findViewById(R.id.btnA);
  50.  
  51.         btnA.setOnClickListener(new View.OnClickListener() {
  52.             @Override
  53.             public void onClick(View view) {
  54.                 //validation
  55.                 String newEmail = etEmail.getText().toString();
  56.                 String newPass = etPass.getText().toString();
  57.  
  58.                 boolean samr = validEmail(newEmail);
  59.  
  60.                 if ((newEmail.equals("")|| newEmail.equals(null))
  61.                         || newPass.equals("") || newPass.equals(null)|| samr==false){
  62.                     Toast.makeText(getApplicationContext(),"Acces Denied" + newEmail,Toast.LENGTH_LONG).show();
  63.                 }else {
  64.                     if (newEmail.equals("samrr@yahoo.com") && newPass.equals("123")){
  65.  
  66.                         Intent intent = new Intent(Activity_One.this, Activity_Two.class);
  67.                         intent.putExtra("email", newEmail);
  68.                         intent.putExtra("pass", newPass);
  69.                         Activity_One.this.startActivity(intent);
  70.                     }else {
  71.                         Toast.makeText(getApplication(),"Emai or Password Incorrect", Toast.LENGTH_SHORT).show();
  72.                     }
  73.                 }
  74.             }
  75.  
  76.  
  77.         });
  78.     }
  79.     private boolean validEmail(String email) {
  80.         if (email.contains("@")){
  81.             return true;
  82.  
  83.         }else {
  84.             return false;
  85.         }
  86.     }
  87. }
  88.  
  89. //Activity_Two.Java
  90. import android.content.Intent;
  91. import android.os.Bundle;
  92. import android.support.v7.app.AppCompatActivity;
  93. import android.widget.TextView;
  94.  
  95. public class Activity_Two extends AppCompatActivity {
  96.  
  97.     private TextView tvEmail;
  98.     private TextView tvPass;
  99.  
  100.     @Override
  101.     protected void onCreate(Bundle savedInstanceState){
  102.         super.onCreate(savedInstanceState);
  103.         setContentView(R.layout.activity_two);
  104.  
  105.         tvEmail = (TextView) findViewById(R.id.tvEmail);
  106.         tvPass = (TextView) findViewById(R.id.tvPass);
  107.  
  108.         Intent getIntA = getIntent();
  109.         String getEmail = getIntA.getStringExtra("email");
  110.         String getPass = getIntA.getStringExtra("pass");
  111.  
  112.         String newEmail = tvEmail.getText().toString();
  113.         String newPass  = tvPass.getText().toString();
  114.  
  115.         tvEmail.setText(newEmail + " " + getEmail);
  116.         tvPass.setText(newPass + " "+getPass);
  117.     }
  118.  
  119. }
  120.  
  121. //activity_one.xml
  122. <?xml version="1.0" encoding="utf-8"?>
  123. <RelativeLayout
  124.     xmlns:android="http://schemas.android.com/apk/res/android"
  125.     xmlns:tools="http://schemas.android.com/tools"
  126.     android:id="@+id/activity__one"
  127.     android:layout_width="match_parent"
  128.     android:layout_height="match_parent"
  129.     android:paddingLeft="@dimen/activity_horizontal_margin"
  130.     android:paddingRight="@dimen/activity_horizontal_margin"
  131.     android:paddingTop="@dimen/activity_vertical_margin"
  132.     android:paddingBottom="@dimen/activity_vertical_margin"
  133.     tools:context="day2.rungene.com.puttextra2.Activity_One">
  134.  
  135.     <TextView
  136.         android:layout_width="match_parent"
  137.         android:layout_height="wrap_content"
  138.         android:text="LOGIN"
  139.         android:gravity="center_horizontal"
  140.         android:textSize="25dp"
  141.         android:textStyle="bold"
  142.         android:layout_marginTop="15dp"
  143.         android:id="@+id/textView"
  144.         />
  145.     <EditText
  146.         android:layout_width="match_parent"
  147.         android:layout_height="wrap_content"
  148.         android:id="@+id/etEmail"
  149.         android:hint="Enter ur email"
  150.         android:padding="10dp"
  151.         android:layout_marginTop="10dp"
  152.         android:backgroundTint="@color/colorAccent"
  153.         android:layout_below="@+id/textView"
  154.         />
  155.  
  156.     <EditText
  157.         android:layout_width="match_parent"
  158.         android:layout_height="wrap_content"
  159.         android:id="@+id/etPass"
  160.         android:hint="Enter ur pass"
  161.         android:padding="10dp"
  162.         android:layout_marginTop="10dp"
  163.         android:backgroundTint="@color/colorAccent"
  164.         android:layout_below="@+id/etEmail"
  165.         />
  166.     <Button
  167.         android:layout_width="match_parent"
  168.         android:layout_height="wrap_content"
  169.         android:id="@+id/btnA"
  170.         android:text="LOGIN"
  171.         android:layout_marginTop="10dp"
  172.         android:background="@color/colorPrimaryDark"
  173.         android:textColor="@color/white"
  174.         android:textStyle="bold"
  175.         android:layout_below="@+id/etPass"
  176.         />
  177.  
  178. </RelativeLayout>
  179.  
  180. //activity_two.xml
  181. <?xml version="1.0" encoding="utf-8"?>
  182. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  183.     android:layout_width="match_parent"
  184.     android:layout_height="match_parent"
  185.     xmlns:tools="http://schemas.android.com/tools"
  186.     android:paddingBottom="16dp"
  187.     android:paddingLeft="64dp"
  188.     android:paddingRight="64dp"
  189.     android:paddingTop="16dp"
  190.     tools:context="day2.rungene.com.puttextra2.Activity_Two">
  191.  
  192.     <TextView
  193.         android:layout_width="match_parent"
  194.         android:layout_height="wrap_content"
  195.         android:id="@+id/tvWelcom"
  196.         android:layout_marginTop="15dp"
  197.         android:text="Welcome Bro"
  198.         android:textStyle="bold"
  199.         android:textSize="20dp"
  200.         />
  201.  
  202.     <TextView
  203.         android:layout_width="match_parent"
  204.         android:layout_height="wrap_content"
  205.         android:id="@+id/tvEmail"
  206.         android:layout_marginTop="15dp"
  207.         android:text="Ur Email:"
  208.         android:textStyle="bold"
  209.         android:textSize="20dp"
  210.         android:layout_below="@+id/tvWelcom"
  211.         />
  212.     <TextView
  213.         android:layout_width="match_parent"
  214.         android:layout_height="wrap_content"
  215.         android:id="@+id/tvPass"
  216.         android:layout_marginTop="10dp"
  217.         android:text="Ur Password:"
  218.         android:textStyle="bold"
  219.         android:textSize="20dp"
  220.         android:layout_below="@+id/tvEmail"
  221.         />
  222.  
  223.  
  224. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement