Advertisement
Guest User

LoginScreen

a guest
Mar 25th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.10 KB | None | 0 0
  1. MainActiviy.java
  2. ======================
  3. package com.example.teacher.mysmarthome;
  4.  
  5. import android.content.Context;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  14.     EditText txtUser,txtPass;
  15.     Button btnRegister;
  16.     Context context;
  17.     private final String TEST_USER="zeev";
  18.     private final String TEST_PASS="12345";
  19.  
  20.     @Override
  21.     protected void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.activity_main);
  24.         setPointer();
  25.     }
  26.  
  27.     private void setPointer() {
  28.         context=this;
  29.         txtUser=findViewById(R.id.txtUser);
  30.         txtPass=findViewById(R.id.txtPass);
  31.         btnRegister=findViewById(R.id.btnRegister);
  32.         btnRegister.setOnClickListener(new View.OnClickListener() {
  33.             @Override
  34.             public void onClick(View view) {
  35.                 Toast.makeText(context, "Dude, please register", Toast.LENGTH_LONG).show();
  36.             }
  37.         });
  38.     }
  39.  
  40.     public void btnLogin(View view)
  41.     {
  42.         //Toast.makeText(this, "Hello my brother from another mother", Toast.LENGTH_LONG).show();
  43.         String myUser=txtUser.getText().toString();
  44.         String myPass=txtPass.getText().toString();
  45.         // TEST_USER==myUser - will not work, we need equals....
  46.     }
  47.  
  48.     @Override
  49.     public void onClick(View view) {
  50.         switch (view.getId())
  51.         {
  52.             case R.id.btnAr:
  53.                 Toast.makeText(context, "Arabic", Toast.LENGTH_SHORT).show();
  54.                 break;
  55.  
  56.             case R.id.btnEn:
  57.                 Toast.makeText(context, "English", Toast.LENGTH_SHORT).show();
  58.                 break;
  59.  
  60.             case R.id.btnHe:
  61.                 Toast.makeText(context, "Hebrew", Toast.LENGTH_SHORT).show();
  62.                 break;
  63.  
  64.             case R.id.btnRu:
  65.                 Toast.makeText(context, "Russion", Toast.LENGTH_SHORT).show();
  66.                 break;
  67.  
  68.             default:
  69.                 Toast.makeText(context, "WTF?!?!?!?", Toast.LENGTH_SHORT).show();
  70.                 break;
  71.         }
  72.     }
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79. activity_main.xml
  80. ======================
  81. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  82.     android:layout_width="match_parent"
  83.     android:layout_height="match_parent"
  84.     android:orientation="vertical"
  85.     android:background="#ffffff">
  86.     <LinearLayout
  87.         android:layout_width="match_parent"
  88.         android:layout_height="match_parent"
  89.         android:layout_weight="1"
  90.         android:orientation="vertical">
  91.         <ImageView
  92.             android:layout_width="match_parent"
  93.             android:layout_height="match_parent"
  94.             android:src="@drawable/logo_mysh"/>
  95.     </LinearLayout>
  96.     <LinearLayout
  97.         android:layout_width="match_parent"
  98.         android:layout_height="match_parent"
  99.         android:layout_weight="1"
  100.         android:orientation="vertical"
  101.         android:gravity="center"
  102.         android:layout_marginLeft="@dimen/edge"
  103.         android:layout_marginRight="@dimen/edge">
  104.         <EditText
  105.             android:layout_width="match_parent"
  106.             android:layout_height="wrap_content"
  107.             android:hint="@string/user_name"
  108.             android:id="@+id/txtUser"/>
  109.         <EditText
  110.             android:layout_width="match_parent"
  111.             android:layout_height="wrap_content"
  112.             android:hint="@string/user_pass"
  113.             android:id="@+id/txtPass"
  114.             android:inputType="textPassword"/>
  115.     </LinearLayout>
  116.     <LinearLayout
  117.         android:layout_width="match_parent"
  118.         android:layout_height="match_parent"
  119.         android:layout_weight="1"
  120.         android:orientation="vertical">
  121.         <LinearLayout
  122.             android:layout_width="match_parent"
  123.             android:layout_height="match_parent"
  124.             android:orientation="horizontal"
  125.             android:layout_weight="1"
  126.             android:layout_marginRight="@dimen/edge"
  127.             android:layout_marginLeft="@dimen/edge"
  128.             android:gravity="center">
  129.             <Button
  130.                 android:layout_width="match_parent"
  131.                 android:layout_height="wrap_content"
  132.                 android:layout_weight="1"
  133.                 android:background="#009fff"
  134.                 android:textColor="#ffffff"
  135.                 android:text="@string/btnLogin"
  136.                 android:textSize="22sp"
  137.                 android:layout_margin="@dimen/edge"
  138.                 android:onClick="btnLogin"/>
  139.             <Button
  140.                 android:layout_width="match_parent"
  141.                 android:layout_height="wrap_content"
  142.                 android:layout_weight="1"
  143.                 android:background="#009fff"
  144.                 android:textColor="#ffffff"
  145.                 android:text="@string/btnRegister"
  146.                 android:textSize="22sp"
  147.                 android:layout_margin="@dimen/edge"
  148.                 android:id="@+id/btnRegister"/>
  149.         </LinearLayout>
  150.         <LinearLayout
  151.             android:layout_width="match_parent"
  152.             android:layout_height="2dp"
  153.             android:background="#000000"/>
  154.         <LinearLayout
  155.             android:layout_width="match_parent"
  156.             android:layout_height="match_parent"
  157.             android:orientation="horizontal"
  158.             android:layout_weight="1">
  159.             <Button
  160.                 android:layout_width="match_parent"
  161.                 android:layout_height="wrap_content"
  162.                 android:layout_weight="1"
  163.                 android:background="#009fff"
  164.                 android:textColor="#ffffff"
  165.                 android:text="@string/btnAr"
  166.                 android:textSize="16sp"
  167.                 android:layout_margin="@dimen/edge"
  168.                 android:id="@+id/btnAr"
  169.                 android:onClick="onClick"/>
  170.             <Button
  171.                 android:layout_width="match_parent"
  172.                 android:layout_height="wrap_content"
  173.                 android:layout_weight="1"
  174.                 android:background="#009fff"
  175.                 android:textColor="#ffffff"
  176.                 android:text="@string/btnHE"
  177.                 android:textSize="16sp"
  178.                 android:layout_margin="@dimen/edge"
  179.                 android:id="@+id/btnHe"
  180.                 android:onClick="onClick"/>
  181.             <Button
  182.                 android:layout_width="match_parent"
  183.                 android:layout_height="wrap_content"
  184.                 android:layout_weight="1"
  185.                 android:background="#009fff"
  186.                 android:textColor="#ffffff"
  187.                 android:text="@string/btnRu"
  188.                 android:textSize="16sp"
  189.                 android:layout_margin="@dimen/edge"
  190.                 android:id="@+id/btnRu"
  191.                 android:onClick="onClick"/>
  192.             <Button
  193.                 android:layout_width="match_parent"
  194.                 android:layout_height="wrap_content"
  195.                 android:layout_weight="1"
  196.                 android:background="#009fff"
  197.                 android:textColor="#ffffff"
  198.                 android:text="@string/btnEn"
  199.                 android:textSize="16sp"
  200.                 android:layout_margin="@dimen/edge"
  201.                 android:id="@+id/btnEn"
  202.                 android:onClick="onClick"/>
  203.         </LinearLayout>
  204.     </LinearLayout>
  205. </LinearLayout>
  206.  
  207.  
  208.  
  209. strings.xml
  210. ===================
  211. <resources>
  212.     <string name="app_name">MySmartHome</string>
  213.     <string name="user_name">Enter user ID...</string>
  214.     <string name="user_pass">Enter user password...</string>
  215.     <string name="btnLogin">Login</string>
  216.     <string name="btnRegister">Register</string>
  217.     <string name="btnHE">עברית</string>
  218.     <string name="btnRu">Rus</string>
  219.     <string name="btnEn">Eng</string>
  220.     <string name="btnAr">Arabic</string>
  221. </resources>
  222.  
  223.  
  224. dim.xml
  225. =============
  226. <?xml version="1.0" encoding="utf-8"?>
  227. <resources>
  228.     <dimen name="edge">16dp</dimen>
  229. </resources>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement