Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MainActivity.java
- ============================
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity implements View.OnClickListener{
- Context context;
- EditText lUser,lPass;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer();
- }
- private void setPointer() {
- lUser=(EditText)findViewById(R.id.userLogin);
- lPass=(EditText)findViewById(R.id.userPass);
- this.context=this;
- }
- @Override
- public void onClick(View view) {
- switch (view.getId()){
- case R.id.btnLogin:
- /*// Key Value
- if (!SharedPref.checkPass(lUser.getText().toString(),lPass.getText().toString(),this))
- {
- Toast.makeText(this, "Invalid user name or pass", Toast.LENGTH_LONG).show();
- return;
- }
- */
- //check if user exists
- if (!SharedPref.checkUserExists(lUser.getText().toString(),context))
- {
- AlertDialog.Builder dlgNewUser = new AlertDialog.Builder(context);
- //dlgNewUser.setTitle("user does not exists");
- //dlgNewUser.setMessage("do you wish to create new user");
- //dlgNewUser.setView() -> for inflater
- View myDlgView = LayoutInflater.from(context).inflate(R.layout.dialog_layout,null);
- dlgNewUser.setView(myDlgView);
- dlgNewUser.setPositiveButton("Create", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- startActivity(new Intent(context,Register.class));
- dialogInterface.dismiss();
- }
- });
- dlgNewUser.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- }
- });
- dlgNewUser.show();
- }
- else {
- Intent intent = new Intent(this, Tasks.class);
- //intent.putExtra("userName",lUser.getText().toString());
- intent.putExtra("userName", "zeev");
- startActivity(intent);
- }
- break;
- case R.id.btnRegister:
- startActivity(new Intent(this,Register.class));
- break;
- default:
- Toast.makeText(this, "Error in button", Toast.LENGTH_SHORT).show();
- }
- }
- private void checkLogin() {
- }
- }
- dialog_layout.xml
- =======================
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#000000">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="User not exists !!!"
- android:textColor="#ff0000"
- android:textSize="22sp"
- android:layout_marginBottom="20dp"
- android:layout_gravity="center" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="User not found in the system"
- android:textColor="#ffffff"
- android:textSize="22sp"
- android:layout_marginBottom="5dp"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="do you wish to create a new one"
- android:textColor="#ffffff"
- android:textSize="22sp"/>
- </LinearLayout>
Add Comment
Please, Sign In to add comment