Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.app0811.mytodo;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends Activity
- {
- SharedPreferences myPref;
- SharedPreferences.Editor editor;
- private EditText userName;
- private EditText passWord;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPoints();
- }
- private void setPoints()
- {
- myPref = getApplicationContext().getSharedPreferences(Register.myPrefs,MODE_PRIVATE);
- editor =myPref.edit();
- userName = (EditText)findViewById(R.id.inUser);
- passWord = (EditText)findViewById(R.id.inPass);
- }
- private void chkUser()
- {
- String userInput = userName.getText().toString();
- String passInput = passWord.getText().toString();
- if(userInput.trim().equals("") || passInput.trim().equals(""))
- {
- Toast.makeText(this,"Error, please fill all the fields",Toast.LENGTH_SHORT).show();
- }
- else if(!myPref.contains(userInput) || !passInput.equals(myPref.getString(userInput,passInput)))
- {
- Toast.makeText(this,"Error, wrong username or password!",Toast.LENGTH_SHORT).show();
- }
- else
- {
- Intent logMe = new Intent(this,Logged.class);
- this.startActivity(logMe);
- }
- }
- }
- =========================================================================================================================
- =============================register
- package com.example.app0811.mytodo;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- /**
- * Created by app0811 on 16/03/2016.
- */
- public class Register extends Activity
- {
- public final static String myPrefs = "myPref";//shared prefrences xml file name
- SharedPreferences myPref;
- SharedPreferences.Editor editor;
- private EditText userInput;
- private EditText passInput;
- private EditText rePassInput;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- setPoints();
- }
- private void setPoints()
- {
- myPref = getApplicationContext().getSharedPreferences(myPrefs,MODE_PRIVATE);
- editor =myPref.edit();
- userInput = (EditText)findViewById(R.id.setUser);
- passInput = (EditText)findViewById(R.id.setPass);
- rePassInput = (EditText)findViewById(R.id.confPass);
- }
- private void chkReg()
- {
- String userName = userInput.getText().toString();
- String passWord = passInput.getText().toString();
- String checkPass = rePassInput.getText().toString();
- if(userName.trim().length()<=0 || passWord.trim().length()<=0 || checkPass.trim().length()<=0)
- {
- Toast.makeText(this, "Error, please fill all the fields", Toast.LENGTH_SHORT).show();
- }
- else if(!checkPass.equals(passWord))
- {
- Toast.makeText(this, "Error, Password do not match!", Toast.LENGTH_SHORT).show();
- }
- else if(userName.equals(myPref.contains(userName)))
- {
- Toast.makeText(this, "Error, this user allready exists", Toast.LENGTH_SHORT).show();
- }
- else
- {
- editor.putString(userName, passWord);
- editor.commit();
- Intent mainInt = new Intent(this,MainActivity.class);
- this.startActivity(mainInt);
- finish();
- }
- }
- public void btnReg(View v)
- {
- chkReg();
- }
- public void btnCncle(View v)
- {
- Intent cnclInten = new Intent (this,MainActivity.class);
- this.startActivity(cnclInten);
- finish();
- }
- }
- ==============================================================================================
- ====================================logged
- package com.example.app0811.mytodo;
- import android.app.Activity;
- import android.os.Bundle;
- /**
- * Created by app0811 on 16/03/2016.
- */
- public class Logged extends Activity
- {
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_logged);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement