Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"
- android:background="#ffffff">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:src="@drawable/logo_mysh"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical"
- android:gravity="center"
- android:layout_marginLeft="@dimen/edge"
- android:layout_marginRight="@dimen/edge">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/user_name"
- android:id="@+id/txtUser"/>
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/user_pass"
- android:id="@+id/txtPass"
- android:inputType="textPassword"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- android:layout_weight="1"
- android:layout_marginRight="@dimen/edge"
- android:layout_marginLeft="@dimen/edge"
- android:gravity="center">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnLogin"
- android:textSize="22sp"
- android:layout_margin="@dimen/edge"
- android:onClick="btnLogin"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnRegister"
- android:textSize="22sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnRegister"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="2dp"
- android:background="#000000"/>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- android:layout_weight="1">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnAr"
- android:textSize="16sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnAr"
- android:onClick="onClick"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnHE"
- android:textSize="16sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnHe"
- android:onClick="onClick"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnRu"
- android:textSize="16sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnRu"
- android:onClick="onClick"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnEn"
- android:textSize="16sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnEn"
- android:onClick="onClick"/>
- </LinearLayout>
- </LinearLayout>
- </LinearLayout>
- actyivity_registration.xml
- ==============================
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_margin="@dimen/edge"
- android:background="#ffffff">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_weight="1">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:src="@drawable/logo_mysh"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layout_weight="1"
- android:gravity="center">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/user_name"
- android:id="@+id/newUserName"/>
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/user_pass"
- android:id="@+id/newUserPass"/>
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/user_pass"
- android:id="@+id/newUserPassCheck"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- android:layout_weight="1"
- android:gravity="center">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textColor="#ffffff"
- android:background="#009fff"
- android:text="@string/btnLogin"
- android:textSize="22sp"
- android:id="@+id/btnNewUserReg"
- android:layout_weight="1"
- android:layout_margin="@dimen/edge"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textColor="#ffffff"
- android:background="#009fff"
- android:text="@string/btnCancel"
- android:textSize="22sp"
- android:id="@+id/btnCancel"
- android:layout_weight="1"
- android:layout_margin="@dimen/edge"/>
- </LinearLayout>
- </LinearLayout>
- UserAble.java
- ========================
- package com.example.teacher.mysmarthome;
- public interface UserAble {
- //check user if not exists - boolean
- //add user - void
- //delete user - void
- //update user - void
- //check user password -boolean
- boolean userExists(String userName);
- void addUser(String userName, String userPass);
- void deleteUser(String userName);
- void updateUser(String userName,String newUserPass);
- boolean checkUser(String userName,String userPass);
- }
- MainActivity.java
- =====================
- package com.example.teacher.mysmarthome;
- import android.content.Context;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- EditText txtUser,txtPass;
- Button btnRegister;
- Context context;
- private final String TEST_USER="zeev";
- private final String TEST_PASS="12345";
- SPusers myUsers;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer();
- myUsers = new SPusers(this);
- }
- private void setPointer() {
- context=this;
- txtUser=findViewById(R.id.txtUser);
- txtPass=findViewById(R.id.txtPass);
- btnRegister=findViewById(R.id.btnRegister);
- btnRegister.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- //create a new intent
- Intent intent=new Intent(context,Registration.class);
- startActivity(intent);
- //bad practice
- //startActivity(new Intent(context,Registration.class));
- }
- });
- }
- public void btnLogin(View view)
- {
- //Toast.makeText(this, "Hello my brother from another mother", Toast.LENGTH_LONG).show();
- String myUser=txtUser.getText().toString();
- String myPass=txtPass.getText().toString();
- //check if user exists...
- }
- @Override
- public void onClick(View view) {
- switch (view.getId())
- {
- case R.id.btnAr:
- Toast.makeText(context, "Arabic", Toast.LENGTH_SHORT).show();
- break;
- case R.id.btnEn:
- Toast.makeText(context, "English", Toast.LENGTH_SHORT).show();
- break;
- case R.id.btnHe:
- Toast.makeText(context, "Hebrew", Toast.LENGTH_SHORT).show();
- break;
- case R.id.btnRu:
- Toast.makeText(context, "Russion", Toast.LENGTH_SHORT).show();
- break;
- default:
- Toast.makeText(context, "WTF?!?!?!?", Toast.LENGTH_SHORT).show();
- break;
- }
- }
- }
- SPUsers.java
- ====================
- package com.example.teacher.mysmarthome;
- import android.content.Context;
- import android.content.SharedPreferences;
- import android.preference.PreferenceManager;
- import android.widget.Toast;
- public class SPusers implements UserAble {
- //our shared preferances (saving data to our device)
- SharedPreferences sp; //for reading
- SharedPreferences.Editor spe; //for writing
- Context context;
- public SPusers(Context context) {
- this.context=context;
- sp=context.getSharedPreferences("users",Context.MODE_PRIVATE);
- spe=sp.edit();
- }
- @Override
- public boolean userExists(String userName) {
- return sp.getString(userName,"-1").equals("-1");
- }
- @Override
- public void addUser(String userName, String userPass) {
- spe.putString(userName,userPass);
- spe.commit();
- //Toast.makeText(context, "WE GOT MIRA IN THE SYSTEM!!!", Toast.LENGTH_SHORT).show();
- }
- @Override
- public void deleteUser(String userName) {
- }
- @Override
- public void updateUser(String userName, String newUserPass) {
- }
- @Override
- public boolean checkUser(String userName, String userPass) {
- /*
- if (userExists(userName))
- {
- if (sp.getString(userName,"-1").equals(userPass))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- return false;
- */
- return sp.getString(userName,"-1").equals(userPass);
- }
- public String hatib(String userName)
- {
- return sp.getString(userName,"-1");
- }
- }
- Registration.java
- ========================
- package com.example.teacher.mysmarthome;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.Button;
- import android.widget.EditText;
- public class Registration extends AppCompatActivity {
- EditText txtUser,txtPass,txtPass2;
- Button btnRegister,btnCancel;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_registration);
- setPointer();
- }
- private void setPointer() {
- //class work, add pointers
- }
- private void registerUser()
- {
- //class work,
- //1. check if password larger then 3 symblos
- //2. check if passwords match
- //3. if user exists
- //4. add user
- //5. give error or successful
- //to close activity, use the command finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement