Advertisement
Guest User

demo of class 18/8

a guest
Aug 18th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.37 KB | None | 0 0
  1. AndroidManifest
  2. =======================
  3.   <uses-permission android:name="android.permission.CALL_PHONE" />
  4.  
  5. MainActivity.java
  6. =====================
  7. public class MainActivity extends AppCompatActivity {
  8.  
  9.  
  10.     EditText txtUserName;
  11.     EditText txtUserPass;
  12.     TextView lblMsg;
  13.     final String MY_USER="zeev";
  14.     final String MY_PASS="12345";
  15.     private int totalTry=5;
  16.     Context context;
  17.  
  18.     @Override
  19.     protected void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.activity_main);
  22.         setPointer();
  23.     }
  24.  
  25.     private void setPointer()
  26.     {
  27.         context=this;
  28.         txtUserName=(EditText)findViewById(R.id.txtUserName);
  29.         txtUserPass=(EditText)findViewById(R.id.txtUserPassword);
  30.         lblMsg=(TextView)findViewById(R.id.lblMsg);
  31.     }
  32.  
  33.     public void btnClick(View view)
  34.     {
  35.         String getUser=txtUserName.getText().toString();
  36.         String getPass=txtUserPass.getText().toString();
  37.  
  38.         if (totalTry==0) {
  39.             Toast.makeText(MainActivity.this, "You are an idiot!!", Toast.LENGTH_SHORT).show();
  40.             return;
  41.         }
  42.  
  43.         if (getUser.equals(MY_USER) && getPass.equals(MY_PASS))
  44.         {
  45.             //lblMsg.setText("User loged...");
  46.             Intent myIntent = new Intent(this,Welcome.class);
  47.             startActivity(myIntent);
  48.             //startActivity(new Intent(this,Welcome.class));
  49.             finish();
  50.         }
  51.         else
  52.         {
  53.             totalTry--;
  54.             Toast.makeText(MainActivity.this, "you have "+totalTry+" times", Toast.LENGTH_LONG).show();
  55.  
  56.         }
  57.     }
  58.  
  59. }
  60.  
  61.  
  62.  
  63. activity_main.xml
  64. =====================
  65. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  66.     android:layout_width="match_parent"
  67.     android:layout_height="match_parent"
  68.     android:orientation="vertical"
  69.     android:background="@drawable/my_background">
  70.  
  71.     <LinearLayout
  72.         android:layout_width="match_parent"
  73.         android:layout_height="150dp"
  74.         android:orientation="vertical">
  75.  
  76.        <ImageView
  77.            android:layout_width="match_parent"
  78.            android:layout_height="wrap_content"
  79.            android:src="@drawable/google"/>
  80.     </LinearLayout>
  81.  
  82.     <LinearLayout
  83.         android:layout_width="match_parent"
  84.         android:layout_height="150dp"
  85.         android:orientation="vertical">
  86.  
  87.         <EditText
  88.             android:id="@+id/txtUserName"
  89.             android:layout_width="match_parent"
  90.             android:layout_height="wrap_content"
  91.             android:hint="Enter your name...."
  92.             android:inputType="text"
  93.             android:textSize="22sp" />
  94.  
  95.         <EditText
  96.             android:id="@+id/txtUserPassword"
  97.             android:layout_width="match_parent"
  98.             android:layout_height="wrap_content"
  99.             android:hint="Enter Password..."
  100.             android:inputType="textPassword"
  101.             android:textSize="22sp" />
  102.     </LinearLayout>
  103.  
  104.     <LinearLayout
  105.         android:layout_width="match_parent"
  106.         android:layout_height="70dp"
  107.         android:orientation="vertical">
  108.  
  109.         <Button
  110.             android:layout_width="match_parent"
  111.             android:layout_height="wrap_content"
  112.             android:text="Login"
  113.             android:background="#91E0FF"
  114.             android:textColor="#ffffff"
  115.             android:textSize="32sp"
  116.             android:onClick="btnClick"/>
  117.     </LinearLayout>
  118.  
  119.     <LinearLayout
  120.         android:layout_width="match_parent"
  121.         android:layout_height="match_parent"
  122.         android:orientation="vertical">
  123.         <TextView
  124.             android:layout_width="match_parent"
  125.             android:layout_height="match_parent"
  126.             android:textSize="32sp"
  127.             android:text="MY LOGIN SYSTEM V1"
  128.             android:gravity="center"
  129.             android:id="@+id/lblMsg"/>
  130.     </LinearLayout>
  131. </LinearLayout>
  132.  
  133.  
  134. Welcome.java
  135. =================
  136. public class Welcome extends Activity {
  137.     @Override
  138.     protected void onCreate(Bundle savedInstanceState) {
  139.         super.onCreate(savedInstanceState);
  140.         setContentView(R.layout.welcome);
  141.         //utlTest.showMsg(this);
  142.  
  143.         //create the number we want by String !!!!
  144.         String posted_by = "048772538";
  145.         //create string that is trimmed
  146.         String uri = "tel:" + posted_by.trim() ;
  147.         //create implicty intent of dial
  148.         Intent intent = new Intent(Intent.ACTION_DIAL);
  149.         //sending data to implicity intent
  150.         intent.setData(Uri.parse(uri));
  151.         //start the activity......
  152.         startActivity(intent);
  153.  
  154.     }
  155. }
  156.  
  157.  
  158. welcome.xml
  159. ====================
  160. <?xml version="1.0" encoding="utf-8"?>
  161. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  162.     android:orientation="vertical" android:layout_width="match_parent"
  163.     android:layout_height="match_parent"
  164.     android:background="@drawable/my_background">
  165.  
  166.     <TextView
  167.         android:layout_width="match_parent"
  168.         android:layout_height="match_parent"
  169.         android:text="WELCOME"
  170.         android:textSize="50sp"
  171.         android:gravity="center"
  172.         />
  173. </LinearLayout>
  174.  
  175.  
  176. utlTest.java
  177. ======================
  178. public class utlTest {
  179.  
  180.     public static void showMsg(Context context)
  181.     {
  182.         Toast.makeText(context, "Hello michal!!!", Toast.LENGTH_LONG).show();
  183.     }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement