Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Utl.java
- ===================
- public class Utl {
- public static boolean checkUser(String userName,String userPass,String myUser,String myPass)
- {
- return (userName.equals(myUser) && userPass.equals(myPass));
- }
- }
- LoginActivity.java
- ============================
- public class LoginActivity extends AppCompatActivity {
- final String TAG="LoginScreen";
- EditText txtUser,txtPass;
- Button btnLogin;
- TextView txtLogo;
- final String USER_NAME="Firas",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);
- 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);
- 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" );
- }
- }
- });
- }
- }
- activity_main.xml
- ==========================
- <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>
- strings.xml
- =====================
- <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="btnLogin">Login</string>
- </resources>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement