zeev

more my task classes

Sep 28th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.46 KB | None | 0 0
  1. MainActivity.java
  2. ============================
  3.  
  4. import android.content.Context;
  5. import android.content.DialogInterface;
  6. import android.content.Intent;
  7. import android.support.v7.app.AlertDialog;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.os.Bundle;
  10. import android.view.LayoutInflater;
  11. import android.view.View;
  12. import android.widget.EditText;
  13. import android.widget.Toast;
  14.  
  15. public class MainActivity extends AppCompatActivity implements View.OnClickListener{
  16.     Context context;
  17.     EditText lUser,lPass;
  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.         lUser=(EditText)findViewById(R.id.userLogin);
  27.         lPass=(EditText)findViewById(R.id.userPass);
  28.         this.context=this;
  29.     }
  30.  
  31.     @Override
  32.     public void onClick(View view) {
  33.         switch (view.getId()){
  34.             case R.id.btnLogin:
  35.                 /*//                         Key                       Value
  36.                 if (!SharedPref.checkPass(lUser.getText().toString(),lPass.getText().toString(),this))
  37.                 {
  38.                     Toast.makeText(this, "Invalid user name or pass", Toast.LENGTH_LONG).show();
  39.                     return;
  40.                 }
  41.                 */
  42.  
  43.                 //check if user exists
  44.                 if (!SharedPref.checkUserExists(lUser.getText().toString(),context))
  45.                 {
  46.                     AlertDialog.Builder dlgNewUser = new AlertDialog.Builder(context);
  47.                     //dlgNewUser.setTitle("user does not exists");
  48.                     //dlgNewUser.setMessage("do you wish to create new user");
  49.                     //dlgNewUser.setView()   -> for inflater
  50.                     View myDlgView = LayoutInflater.from(context).inflate(R.layout.dialog_layout,null);
  51.                     dlgNewUser.setView(myDlgView);
  52.                     dlgNewUser.setPositiveButton("Create", new DialogInterface.OnClickListener() {
  53.                         @Override
  54.                         public void onClick(DialogInterface dialogInterface, int i) {
  55.                             startActivity(new Intent(context,Register.class));
  56.                             dialogInterface.dismiss();
  57.                         }
  58.                     });
  59.                     dlgNewUser.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  60.                         @Override
  61.                         public void onClick(DialogInterface dialogInterface, int i) {
  62.                             dialogInterface.dismiss();
  63.                         }
  64.                     });
  65.                     dlgNewUser.show();
  66.                 }
  67.                 else {
  68.                     Intent intent = new Intent(this, Tasks.class);
  69.                     //intent.putExtra("userName",lUser.getText().toString());
  70.                     intent.putExtra("userName", "zeev");
  71.                     startActivity(intent);
  72.                 }
  73.                 break;
  74.  
  75.             case R.id.btnRegister:
  76.                 startActivity(new Intent(this,Register.class));
  77.                 break;
  78.  
  79.             default:
  80.                 Toast.makeText(this, "Error in button", Toast.LENGTH_SHORT).show();
  81.         }
  82.     }
  83.  
  84.     private void checkLogin() {
  85.     }
  86. }
  87.  
  88.  
  89. dialog_layout.xml
  90. =======================
  91. <?xml version="1.0" encoding="utf-8"?>
  92. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  93.     android:orientation="vertical" android:layout_width="match_parent"
  94.     android:layout_height="wrap_content"
  95.     android:background="#000000">
  96.  
  97.     <TextView
  98.         android:layout_width="wrap_content"
  99.         android:layout_height="wrap_content"
  100.         android:text="User not exists !!!"
  101.         android:textColor="#ff0000"
  102.         android:textSize="22sp"
  103.         android:layout_marginBottom="20dp"
  104.         android:layout_gravity="center" />
  105.     <TextView
  106.         android:layout_width="match_parent"
  107.         android:layout_height="wrap_content"
  108.         android:text="User not found in the system"
  109.         android:textColor="#ffffff"
  110.         android:textSize="22sp"
  111.         android:layout_marginBottom="5dp"/>
  112.     <TextView
  113.         android:layout_width="match_parent"
  114.         android:layout_height="wrap_content"
  115.         android:text="do you wish to create a new one"
  116.         android:textColor="#ffffff"
  117.         android:textSize="22sp"/>
  118. </LinearLayout>
Add Comment
Please, Sign In to add comment