Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //strings
- -------------------
- <resources>
- <string name="app_name">MyLogin</string>
- <string name="myLogo">LOGO</string>
- <string name="hintUserName">Enter user name...</string>
- <string name="hintPassword">Enter user password...</string>
- <string name="hintChecked">password checked</string>
- <string name="btnLogin">Login</string>
- <string name="msgLogo">Hello Esra !!!</string>
- <string name="newUser">New User</string>
- <string name="btnRegister">Register</string>
- <string name="btnCanel">Cancel</string>
- </resources>
- ----------------------------
- //logInActivity
- ---------------------------
- package com.example.android.loginapp;
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Color;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- public class LoginActivity extends AppCompatActivity {
- final String TAG="LoginScreen";
- EditText txtUser,txtPass;
- Button btnLogin;
- TextView txtLogo;
- final String USER_NAME="Esra",USER_PASS="12345";
- Context context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- setPointer();
- }
- private void setPointer()
- {
- this.context=this;
- txtUser=(EditText) findViewById(R.id.txtUser);
- txtPass=(EditText)findViewById(R.id.txtPass);
- txtLogo=(TextView)findViewById(R.id.txtLogo);
- txtLogo.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- Toast.makeText(context, context.getResources().getString(R.string.msgLogo), Toast.LENGTH_SHORT).show();
- return true;
- }
- });
- final int orgHintColor=txtLogo.getCurrentHintTextColor();
- btnLogin=(Button)findViewById(R.id.btnLogin);
- btnLogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View roni) {
- String userName=txtUser.getText().toString();
- String userPass=txtPass.getText().toString();
- //validation for user name
- if (userName.length()<1)
- {
- txtUser.setText("");
- txtUser.setHintTextColor(Color.RED);
- return;
- }
- if (userPass.length()<1)
- {
- txtPass.setText("");
- txtPass.setHintTextColor(Color.RED);
- return;
- }
- //check user
- if (Utl.checkUser(userName,userPass,USER_NAME,USER_PASS))
- {
- //user is correct -true
- /*
- Toast.makeText(context, "Hello my Master", Toast.LENGTH_SHORT).show();
- txtPass.setText("");
- txtPass.setHintTextColor(orgHintColor);
- txtUser.setText("");
- txtUser.setHintTextColor(orgHintColor);
- */
- //move now to second screen - which is our main screen
- Intent myIntent = new Intent(context,TaskActivity.class);
- myIntent.putExtra("userName",USER_NAME);
- startActivity(myIntent);
- finish();
- Log.i(TAG, "onClick: User OK");
- }
- else
- {
- //user is incorrect -false
- txtPass.setText("");
- Toast.makeText(context, "You are not allowed!!", Toast.LENGTH_LONG).show();
- Log.e(TAG, "onClick: Incorrect User" );
- }
- }
- });
- }
- }
- ------------------
- //registerActivity
- ------------------
- package com.example.android.loginapp;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.Button;
- import android.widget.EditText;
- public class RegisterActivity extends AppCompatActivity {
- EditText txtUser,txtPass,txtCheckPass;
- Button btnReg,btnCancel;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- setPointer();
- }
- private void setPointer()
- {
- txtUser=(EditText)findViewById(R.id.txtUserReg);
- txtPass=(EditText)findViewById(R.id.txtPassReg);
- txtCheckPass=(EditText)findViewById(R.id.txtCheckPass);
- btnReg=(Button)findViewById(R.id.btnReg);
- btnCancel=(Button)findViewById(R.id.btnCancel);
- }
- }
- -----------------------
- //taskActivity
- -----------------------
- package com.example.android.loginapp;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.TextView;
- import android.widget.Toast;
- public class TaskActivity extends AppCompatActivity {
- TaskActivity context;
- TextView txtLogo;
- boolean isBackPressed=false;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_task);
- setPointer();
- getExtra();
- }
- private void setPointer()
- {
- this.context=this;
- txtLogo=(TextView)findViewById(R.id.txtHello);
- }
- private void getExtra()
- {
- String myData = getIntent().getStringExtra("userName");
- txtLogo.setText("Hello "+myData);
- Toast.makeText(context, "user "+myData+" is loged in...", Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onBackPressed() {
- if (!isBackPressed)
- {
- isBackPressed=true;
- Toast.makeText(context, "Press again to exit", Toast.LENGTH_SHORT).show();
- }
- else
- {
- finish();
- }
- }
- }
- -------------------------------
- //Utl
- --------------------------
- package com.example.android.loginapp;
- /**
- * Created by Android on 09/01/2017.
- */
- public class Utl {
- public static boolean checkUser(String userName, String userPass, String myUser, String myPass) {
- return (userName.equals(myUser) && userPass.equals(myPass));
- }
- }
- ------------------------------------
- //UtlShared
- ---------------------------------------
- package com.example.android.loginapp;
- import android.content.SharedPreferences;
- /**
- * Created by Android on 09/01/2017.
- */
- public class UtlShared {
- SharedPreferences userPref;
- SharedPreferences.Editor editor;
- publi
- }
- --------------------------------
- //activity_login
- ----------------------------
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <!-- my logo layout -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_weight="1"
- >
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="@string/myLogo"
- android:textSize="90sp"
- android:gravity="center"
- android:id="@+id/txtLogo"
- />
- </LinearLayout>
- <!-- my Edit text box -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_weight="1">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:hint="@string/hintUserName"
- android:textSize="25sp"
- android:layout_weight="1"
- android:id="@+id/txtUser"/>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="5px"
- android:orientation="vertical"
- android:background="#000"/>
- <EditText
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:hint="@string/hintPassword"
- android:textSize="25sp"
- android:inputType="numberPassword"
- android:layout_weight="1"
- android:id="@+id/txtPass"
- />
- </LinearLayout>
- <!-- my Login Button -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_weight="1">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnLogin"
- android:textSize="26sp"
- android:id="@+id/btnLogin"/>
- </LinearLayout>
- </LinearLayout>
- ---------------------------------
- //activity_register
- --------------------------------
- <LinearLayout android:orientation="vertical"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <LinearLayout
- android:layout_height="match_parent"
- android:layout_width="match_parent"
- android:orientation="vertical"
- android:layout_weight="1">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="@string/newUser"
- android:textSize="@dimen/regttl"
- android:gravity="center"
- />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:hint="@string/hintUserName"
- android:textSize="@dimen/regEditText"
- android:id="@+id/txtUserReg"/>
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:hint="@string/hintPassword"
- android:textSize="@dimen/regEditText"
- android:id="@+id/txtPassReg"/>
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:hint="@string/hintChecked"
- android:textSize="@dimen/regEditText"
- android:id="@+id/txtCheckPass"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="horizontal"
- android:layout_gravity="center">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="@color/btnbg"
- android:textColor="@color/btnText"
- android:text="@string/btnRegister"
- android:layout_margin="@dimen/btnMargin"
- android:id="@+id/btnReg"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="@color/btnbg"
- android:textColor="@color/btnText"
- android:text="@string/btnCanel"
- android:layout_margin="@dimen/btnMargin"
- android:id="@+id/btnCancel"/>
- </LinearLayout>
- </LinearLayout>
- --------------------------------
- //activity_task
- -----------------------------
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="32sp"
- android:text="place holder"
- android:gravity="center"
- android:layout_marginTop="15dp"
- android:id="@+id/txtHello"/>
- </LinearLayout>
- ------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement