Advertisement
Guest User

dorin v2

a guest
Mar 12th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.34 KB | None | 0 0
  1. /////////////////////////////////////////////////////////main activity//////////////////////////////////////////////////////////////
  2.  
  3. package com.example.dorinzrihen.loginapp;
  4.  
  5.         import android.app.Activity;
  6.         import android.content.Intent;
  7.         import android.content.SharedPreferences;
  8.         import android.support.v7.app.ActionBarActivity;
  9.         import android.os.Bundle;
  10.         import android.text.Editable;
  11.         import android.view.View;
  12.         import android.widget.EditText;
  13.         import android.widget.Toast;
  14.  
  15.         import junit.framework.Test;
  16.  
  17. public class MainActivity extends Activity {
  18.     public static final String DEFULT = "N/A" ;
  19.  
  20.     EditText user ;
  21.     EditText pass;
  22.  
  23.  
  24.     String password ;
  25.     String userName ;
  26.  
  27.     protected void onCreate(Bundle savedInstanceState) {
  28.         super.onCreate(savedInstanceState);
  29.         setContentView(R.layout.activity_main);
  30.  
  31.  
  32.         user =(EditText)findViewById(R.id.userName);
  33.         pass = (EditText)findViewById(R.id.pass);
  34.  
  35.         SharedPreferences prefs = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
  36.         userName = prefs.getString("user",DEFULT);
  37.         password = prefs.getString("password" , DEFULT);
  38.  
  39.     }
  40. //make the text from the xml remove
  41.     public void uName(View v)
  42.     {
  43.         user.setText(" ");
  44.     }
  45.     public void pas(View v)
  46.     {
  47.         pass.setText(" ");
  48.     }
  49.  
  50.  
  51.  
  52.  
  53.     //register function
  54.     public void btnR(View v)
  55.     {
  56.         Intent iRegister = new Intent(this,Register.class);
  57.         this.startActivity(iRegister);
  58.     }
  59.  
  60.  
  61. //check if the username and the password are similar
  62.     public void btnL(View v)
  63.     {
  64.         Toast.makeText(getApplicationContext(),user.getText().toString()+ userName  ,
  65.                 Toast.LENGTH_LONG).show();
  66.  
  67.         if((user.getText().toString().equals(userName)&&(pass.getText().toString().equals(password))))
  68.         {
  69.             Intent iLogin = new Intent (this,Login.class);
  70.             iLogin.putExtra("user",user.getText().toString());
  71.             this.startActivity(iLogin);
  72.         }
  73.         else
  74.         {
  75.             Toast.makeText(getApplicationContext(), "your username are not Exists",
  76.                     Toast.LENGTH_LONG).show();
  77.         }
  78.     }
  79.  
  80.  
  81. }
  82.  
  83.  
  84. ////////////////////////////////////////////////////////////reg///////////////////////////////////////////////////////////
  85.  
  86. package com.example.dorinzrihen.loginapp;
  87.  
  88. import android.app.Activity;
  89. import android.content.Intent;
  90. import android.content.SharedPreferences;
  91. import android.os.Bundle;
  92. import android.view.View;
  93. import android.widget.EditText;
  94. import android.widget.Toast;
  95.  
  96.  
  97. public class Register  extends Activity {
  98.         EditText user;
  99.         EditText pass;
  100.         EditText pass2;
  101. //set pointers
  102.         protected void onCreate(Bundle savedInstanceState)
  103.         {
  104.             super.onCreate(savedInstanceState);
  105.             setContentView(R.layout.activity_register);
  106.           user = (EditText) findViewById(R.id.user);
  107.            pass = (EditText) findViewById(R.id.password);
  108.            pass2 = (EditText) findViewById(R.id.password2);
  109.         }
  110.  
  111.     public void register(View v)
  112.     {
  113.        if(pass.getText().toString().equals(pass2.getText().toString()) )
  114.         {
  115.             SharedPreferences prefs = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
  116.             SharedPreferences.Editor editor = prefs.edit();
  117.             String userName = user.getText().toString();
  118.             String password = pass.getText().toString();
  119.             editor.putString("user", userName);
  120.             editor.putString("password" , password);
  121.             editor.commit();
  122.             Intent iMain = new Intent(this,MainActivity.class);
  123.  
  124.             Toast.makeText(getApplicationContext(), "You have successfully register ",
  125.                     Toast.LENGTH_LONG).show();
  126.             this.startActivity(iMain);
  127.  
  128.         }
  129.         //if the passwords not the same
  130.         else
  131.         {
  132.             Toast.makeText(getApplicationContext(), "passwords are not similar",
  133.                     Toast.LENGTH_LONG).show();
  134.         }
  135.     }
  136.     public void userDel(View v)
  137.     {
  138.         user.setText(" ");
  139.     }
  140.  
  141.     public void passDel(View v)
  142.     {
  143.         pass.setText(" ");
  144.     }
  145.  
  146.     public void pass2Del(View v)
  147.     {
  148.         pass2.setText(" ");
  149.     }
  150. //check if the passwords are the same and if they are shareprefernce to the password and to the username
  151.  
  152.     //the function to go back to the main activity
  153.     public void cencel(View v)
  154.     {
  155.         Intent iMain = new Intent(this,MainActivity.class);
  156.         this.startActivity(iMain);
  157.     }
  158. }
  159.  
  160. //////////////////////////////////////////////////////////////log in/////////////////////////////////////////////////////////
  161.  
  162.  
  163. package com.example.dorinzrihen.loginapp;
  164.  
  165. import android.app.Activity;
  166. import android.content.Intent;
  167. import android.content.SharedPreferences;
  168. import android.os.Bundle;
  169. import android.widget.EditText;
  170. import android.widget.TextView;
  171. import android.widget.Toast;
  172.  
  173. public class Login extends Activity
  174. {
  175.     TextView txtHello ;
  176.  
  177.  
  178.     String accName;
  179.  
  180.     protected void onCreate(Bundle savedInstanceState) {
  181.         super.onCreate(savedInstanceState);
  182.         setContentView(R.layout.activity_login);
  183.  
  184.  
  185.         SharedPreferences prefs = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
  186.         accName = prefs.getString("user",MainActivity.DEFULT);
  187.  
  188.  
  189.         Toast.makeText(getApplicationContext(),accName,
  190.                 Toast.LENGTH_LONG).show();
  191.  
  192. // the username + hello
  193.         txtHello = (TextView)findViewById(R.id.helloS);
  194.         txtHello.setText(" Hello " + accName);
  195.  
  196.  
  197.     }
  198.  
  199.  
  200.  
  201. //log out and delete the user name that e used
  202.     public void logout()
  203.     {
  204.         SharedPreferences prefs = getApplicationContext().getSharedPreferences("MyPref",MODE_PRIVATE);
  205.         SharedPreferences.Editor editor = prefs.edit();
  206.         editor.remove("user");
  207.         editor.commit();
  208.         Intent iMain = new Intent(this,MainActivity.class);
  209.         this.startActivity(iMain);
  210.     }
  211. }
  212.  
  213.  
  214. ////////////////////////////////////////////////////////////main activity xml//////////////////////////////////////////////////////
  215.  
  216. <LinearLayout
  217.     android:layout_width="match_parent"
  218.     android:layout_height="match_parent"
  219.     android:orientation="vertical"
  220.     android:gravity="center_vertical"
  221.     android:background="#3b00c4ff"
  222.     xmlns:android="http://schemas.android.com/apk/res/android" >
  223.  <LinearLayout
  224.      android:layout_width="match_parent"
  225.      android:layout_height="match_parent"
  226.      android:layout_weight="1"
  227.      android:orientation="vertical"
  228.      android:gravity="center">
  229.  
  230.      <TextView
  231.          android:layout_width="wrap_content"
  232.          android:layout_height="wrap_content"
  233.          android:text="Log in "
  234.          android:textSize="60sp"
  235.          android:textStyle="bold"
  236.          android:textColor="#b8ffffff"/>
  237.  
  238.      <TextView
  239.          android:layout_width="match_parent"
  240.          android:layout_height="wrap_content"
  241.          android:text="User name"
  242.          android:textSize="30sp"/>
  243.  
  244. <EditText
  245.     android:layout_width="match_parent"
  246.     android:layout_height="wrap_content"
  247.     android:textSize="30sp"
  248.     android:background="#849bf5ef"
  249.     android:id="@+id/userName"
  250.     android:onClick="uName"
  251.     />
  252.      <TextView
  253.          android:layout_width="match_parent"
  254.          android:layout_height="wrap_content"
  255.          android:text="Password"
  256.          android:textSize="30sp"
  257.          />
  258. <EditText
  259.     android:layout_width="match_parent"
  260.     android:layout_height="wrap_content"
  261.     android:textSize="30sp"
  262.     android:background="#849bf5ef"
  263.     android:id="@+id/pass"
  264.     android:inputType="textPassword"
  265.     android:onClick="pas"
  266.  
  267.     />
  268.  
  269.  
  270.  </LinearLayout>
  271.     <LinearLayout
  272.         android:layout_width="match_parent"
  273.         android:layout_height="match_parent"
  274.         android:layout_weight="1"
  275.         android:orientation="vertical"
  276.         >
  277.     <Button
  278.         android:layout_width="match_parent"
  279.         android:layout_height="wrap_content"
  280.         android:text="Log in"
  281.         android:textSize="30sp"
  282.         android:gravity="center"
  283.         android:id="@+id/btnLog"
  284.         android:onClick="btnL"/>
  285.         <Button
  286.             android:layout_width="match_parent"
  287.             android:layout_height="wrap_content"
  288.             android:text="Register"
  289.             android:textSize="30sp"
  290.             android:gravity="center"
  291.             android:id="@+id/btnReg"
  292.             android:onClick="btnR"/>
  293.  
  294.     </LinearLayout>
  295.  
  296. </LinearLayout>
  297.  
  298. //////////////////////////////////////////////////////////////////reg xml/////////////////////////////////////////////////////
  299.  
  300. <LinearLayout
  301.     android:layout_width="match_parent"
  302.     android:layout_height="match_parent"
  303.     android:orientation="vertical"
  304.     android:background="#3b00c4ff"
  305.     xmlns:android="http://schemas.android.com/apk/res/android" >
  306.  
  307.  
  308.     <LinearLayout
  309.         android:layout_width="match_parent"
  310.         android:layout_height="match_parent"
  311.         android:gravity="center"
  312.         android:layout_weight="1"
  313.         android:orientation="vertical"
  314.  
  315.         >
  316.         <TextView
  317.             android:layout_width="match_parent"
  318.             android:layout_height="wrap_content"
  319.             android:text="Username"
  320.             android:textSize="30sp"/>
  321.  
  322.         <EditText
  323.  
  324.             android:layout_width="match_parent"
  325.             android:layout_height="wrap_content"
  326.             android:textSize="30sp"
  327.             android:background="#849bf5ef"
  328.             android:id="@+id/user"
  329.             android:onClick="userDel"/>
  330.  
  331.  
  332.         <TextView
  333.             android:layout_width="match_parent"
  334.             android:layout_height="wrap_content"
  335.             android:text="Password"
  336.             android:textSize="30sp"/>
  337.  
  338.  
  339.         <EditText
  340.             android:layout_width="match_parent"
  341.             android:layout_height="wrap_content"
  342.             android:textSize="30sp"
  343.             android:background="#849bf5ef"
  344.             android:id="@+id/password"
  345.             android:inputType="textPassword"
  346.             android:onClick="passDel"/>
  347.  
  348.  
  349.         <TextView
  350.             android:layout_width="match_parent"
  351.             android:layout_height="wrap_content"
  352.             android:text="Confirm password"
  353.             android:textSize="30sp"/>
  354.  
  355.  
  356.         <EditText
  357.             android:layout_width="match_parent"
  358.             android:layout_height="wrap_content"
  359.  
  360.             android:textSize="30sp"
  361.             android:background="#849bf5ef"
  362.             android:id="@+id/password2"
  363.             android:inputType="textPassword"
  364.             android:onClick="pass2Del"/>
  365.  
  366.  
  367.     </LinearLayout>
  368.  
  369.     <LinearLayout
  370.         android:layout_width="match_parent"
  371.         android:layout_height="match_parent"
  372.         android:layout_weight="1"
  373.         android:orientation="vertical"
  374.         android:gravity="center">
  375.  
  376.         <Button
  377.             android:layout_width="match_parent"
  378.             android:layout_height="wrap_content"
  379.             android:text="Register me"
  380.             android:textSize="30sp"
  381.             android:id="@+id/reg"
  382.             android:onClick="register"/>
  383.         <Button
  384.             android:layout_width="match_parent"
  385.             android:layout_height="wrap_content"
  386.             android:text="Just Cancel"
  387.             android:textSize="30sp"
  388.             android:id="@+id/cen"
  389.             android:onClick="cencel"/>
  390.  
  391.     </LinearLayout>
  392. </LinearLayout>
  393.  
  394. //////////////////////////////////////////////////////////////log in xml/////////////////////////////////////////////////////////
  395.  
  396. <LinearLayout
  397.     android:layout_width="match_parent"
  398.     android:layout_height="match_parent"
  399.     android:orientation="vertical"
  400.     android:background="#3b00c4ff"
  401.     xmlns:android="http://schemas.android.com/apk/res/android" >
  402.  
  403. <TextView
  404.     android:layout_width="match_parent"
  405.     android:layout_height="wrap_content"
  406.     android:text="hello"
  407.     android:textSize="50sp"
  408.     android:id="@+id/helloS"
  409.     />
  410.  
  411.     <Button
  412.         android:layout_width="match_parent"
  413.         android:layout_height="wrap_content"
  414.         android:text="Log out"
  415.         android:textSize="30sp"
  416.         android:id="@+id/btnOut"
  417.         android:onClick="logout"/>
  418.  
  419.  
  420.     </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement