Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////Main Activity Java/////////////////////////
- package com.mordekicloud.yuli.myapp1980;
- 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 yuli.mordek on 3/26/2016.
- */
- public class MainActivity extends Activity
- {
- EditText txtUserName;
- EditText txtPassword;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- txtUserName = (EditText) findViewById(R.id.txtUser1);
- txtPassword = (EditText) findViewById(R.id.txtPass1);
- if (CheckUser()) {
- SharedPreferences
- pref = getApplicationContext().getSharedPreferences("Pref", MODE_PRIVATE);
- Intent loggedIntent = new Intent(this, Daf3.class);
- loggedIntent.putExtra("userPut", pref.getString("Logged In", "Error"));
- this.startActivity(loggedIntent);
- }
- }
- private boolean CheckUser ()
- {
- SharedPreferences
- pref = getApplicationContext().getSharedPreferences("user", MODE_PRIVATE);
- String userName = pref.getString("Logged In", "Error");
- return (!userName.equals("Error"));
- }
- public void btnLogIn(View v) {
- SharedPreferences pref =
- getApplicationContext().getSharedPreferences("user", MODE_PRIVATE);
- String logUserName = txtUserName.getText().toString().toLowerCase();
- String logPassword = txtPassword.getText().toString();
- String logPasswordConf = pref.getString(logUserName, "Error");
- if (logUserName.isEmpty() || logPassword.isEmpty()) {
- Toast.makeText(this, "Ther is one or more fields empty", Toast.LENGTH_LONG).show();
- return;
- }
- else if (!pref.contains(logUserName) || !logPassword.equals(logPasswordConf)) {
- Toast.makeText(this, "Invald user name or password", Toast.LENGTH_LONG).show();
- return;
- }
- else {
- SharedPreferences.Editor editor = pref.edit();
- editor.putString("Logged", logUserName).commit();
- Toast.makeText(this, "You logged successfuly", Toast.LENGTH_SHORT).show();
- Intent loggedIntent = new Intent(this, Daf3.class);
- loggedIntent.putExtra("userPut", pref.getString("Logged", "Error"));
- this.startActivity(loggedIntent);
- }
- }
- public void btnSingUp (View v)
- {
- Intent singIntent = new Intent(this, Daf2.class);
- this.startActivity(singIntent);
- }
- }
- //////////////////////////////////////////Java Daf2//////////////////////////////
- package com.mordekicloud.yuli.myapp1980;
- 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 yuli.mordek on 3/26/2016.
- */
- public class Daf2 extends Activity
- {
- EditText txtUserName;
- EditText txtPassword;
- EditText txtComfPass;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.daf2);
- txtUserName=(EditText)findViewById(R.id.UserName);
- txtPassword=(EditText)findViewById(R.id.Password);
- txtComfPass=(EditText)findViewById(R.id.ConfPass);
- }
- public void btnCancel (View v)
- {
- Intent cancelIntent=new Intent(this, MainActivity.class);
- this.startActivity(cancelIntent);
- }
- public void btnEnter(View v)
- {
- SharedPreferences
- pref=getApplicationContext().getSharedPreferences("user",MODE_PRIVATE);
- SharedPreferences.Editor editor=pref.edit();
- String UserName=txtUserName.getText().toString().toLowerCase();
- String Password=txtPassword.getText().toString().toLowerCase();
- String ConfPass=txtComfPass.getText().toString().toLowerCase();
- if (UserName.isEmpty() || Password.isEmpty() || ConfPass.isEmpty())
- {
- Toast.makeText(this, "You must fill all fields", Toast.LENGTH_LONG).show();
- return;
- }
- else if(pref.contains(UserName))
- {
- Toast.makeText(this,"User you exists",Toast.LENGTH_SHORT).show();
- return;
- }
- else if (!Password.equals(ConfPass))
- {
- Toast.makeText(this, "Password is not correct", Toast.LENGTH_LONG).show();
- return;
- }
- Toast.makeText(this, "You registreted successful", Toast.LENGTH_SHORT).show();
- editor.putString(UserName, Password).commit();
- Intent singIntent = new Intent(this,MainActivity.class);
- this.startActivity(singIntent);
- }
- }
- ///////////////////////////////////////Java Daf3////////////////////////////////////
- package com.mordekicloud.yuli.myapp1980;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.ListView;
- import android.widget.TextView;
- import java.util.ArrayList;
- import java.util.Map;
- /**
- * Created by yuli.mordek on 3/26/2016.
- */
- public class Daf3 extends Activity
- {
- private TextView txtUser1;
- private ListView myTaskList;
- private Context context=this;
- private ArrayList<String> myTaskArrayList=new ArrayList<String>();
- private NewAdapter adapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.daf3);
- txtUser1=(TextView)findViewById(R.id.Msg);
- txtUser1.setText("Helllooo... !! "+getIntent().getStringExtra("userPut"));
- myTaskList=(ListView)findViewById(R.id.myListTv);
- String loggedUser=getIntent().getStringExtra("userPut");
- }
- public void onResume()
- {
- super.onResume();
- String loggedUser=getIntent().getStringExtra("userPut");
- SharedPreferences
- pref=getApplicationContext().getSharedPreferences(loggedUser, MODE_PRIVATE);
- Map<String,?> tasks=pref.getAll();
- for(Map.Entry<String,?> singleTask:tasks.entrySet())
- {
- myTaskArrayList.add(singleTask.getKey());
- }
- NewAdapter adapter =new NewAdapter(context, loggedUser);
- myTaskList.setAdapter(adapter);
- }
- public void btnOut(View v)
- {
- SharedPreferences
- pref=getApplicationContext().getSharedPreferences("user",MODE_PRIVATE);
- SharedPreferences.Editor editor=pref.edit();
- editor.remove("Logged").commit();
- Intent outIntent=new Intent(this,MainActivity.class);
- this.startActivity(outIntent);
- finish();
- }
- public void btnTask(View v)
- {
- Intent i=new Intent(this,Daf4.class);
- //addTaskIntent.putExtra("putUserTask",getIntent().getStringExtra("userPut"));
- startActivity(i);
- finish();
- }
- }
- ////////////////////////////////Daf4 Java/////////////////////////////////////
- package com.mordekicloud.yuli.myapp1980;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.text.InputType;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.widget.Switch;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.util.zip.Inflater;
- public class Daf4 extends AppCompatActivity {
- private String myText="";
- private TextView txt;
- protected static ListView myList;
- private Context context=this;
- private String myUser;
- private NewAdapter myTask;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.daf4);
- txt=(TextView)findViewById(R.id.text);
- myList=(ListView)findViewById(R.id.myListTv);
- myUser=getIntent().getStringExtra("putUser");
- txt.setText("Hello "+myUser);
- refresh();
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
- MenuInflater inflater=getMenuInflater();
- inflater.inflate(R.menu.menu, menu);
- return super.onCreateOptionsMenu(menu);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.AddTask:
- btnAddtask();
- dlgAddTask();
- Toast.makeText(this, myText, Toast.LENGTH_SHORT).show();
- break;
- case R.id.Logout:
- btnLogout();
- Toast.makeText(this, "Logout", Toast.LENGTH_SHORT).show();
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- public void refresh()
- {
- myTask=new NewAdapter(context,myUser);
- myList.setAdapter(myTask);
- }
- public void btnAddtask()
- {
- AlertDialog.Builder builder=new AlertDialog.Builder(this);
- builder.setTitle("Enter new task");
- final EditText input=new EditText(this);
- input.setInputType(InputType.TYPE_CLASS_TEXT);
- builder.setView(input);
- builder.setPositiveButton("Add Task", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- myText = input.getText().toString();
- UtlShared myPref = new UtlShared(context, myUser);
- myPref.newTask(myText);
- refresh();
- }
- });
- builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- });
- builder.show();
- }
- public void btnLogout()
- {
- SharedPreferences
- pref=getApplicationContext().getSharedPreferences("myPref",MODE_PRIVATE);
- SharedPreferences.Editor editor=pref.edit();
- editor.remove("userLogged").commit();
- Intent iMain=new Intent(this,MainActivity.class);
- this.startActivity(iMain);
- finish();
- }
- private void dlgAddTask()
- {
- AlertDialog.Builder builder=new AlertDialog.Builder(this);
- builder.setTitle("Input new task");
- final EditText input = new EditText(this);
- input.setInputType(InputType.TYPE_CLASS_TEXT);
- builder.setPositiveButton("Add task", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- myText = input.getText().toString();
- Toast.makeText(Daf4.this, "Hello " + myText + "The Cizar!! ", Toast.LENGTH_SHORT).show();
- }
- });
- builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- });
- builder.show();
- }
- }
- ///////////////////////NewAdapter//////////////////////
- package com.mordekicloud.yuli.myapp1980;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.graphics.Color;
- import android.media.Image;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.ImageButton;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.util.ArrayList;
- /**
- * Created by yuli.mordek on 3/26/2016.
- */
- public class NewAdapter extends BaseAdapter
- {
- Context context;
- String userName;
- ArrayList<UtlShared>userTasks;
- public NewAdapter(Context context, String userName)
- {
- this.context=context;
- this.userName=userName;
- UtlShared myPref=new UtlShared(context,userName);
- userTasks=myPref.getAllTasks();
- }
- @Override
- public int getCount()
- {
- return userTasks.size();
- }
- @Override
- public Object getItem(int position)
- {
- return null;
- }
- @Override
- public long getItemId(int position)
- {
- return 0;
- }
- @Override
- public View getView(final int position, View convertView, ViewGroup parent)
- {
- LinearLayout myLayout=new LinearLayout(context);
- myLayout.setOrientation(LinearLayout.HORIZONTAL);
- ImageButton delete=new ImageButton(context);
- // delete.setBackgroundResource(R.drawable.trash);
- final TextView taskName = new TextView(context);
- taskName.setText(userTasks.get(position).taskName);
- taskName.setTextSize(30);
- //myLayout.setTextColor(userTask.get(position).taskDone.equals(true)?
- // Color.GREEN:Color.RED);
- myLayout.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- AlertDialog.Builder builder=new AlertDialog.Builder(context);
- builder.setTitle(userTasks.get(position).taskDone.equals(true) ?
- "Are you sure the task isn't completed ?" : "Are you sure the task is completed ?");
- builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- UtlShared myPref = new UtlShared(context, userName);
- myPref.doneTask(userTasks.get(position).taskName, userTasks.get(position).taskDone.equals(true) ? false : true);
- }
- });
- // builder.setIcon(android.R.drawable.ic_menu_help);
- builder.show();
- }
- });
- delete.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- AlertDialog.Builder builder=new AlertDialog.Builder(context);
- builder.setTitle("Are you sure to delete task?");
- builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- UtlShared myPref = new UtlShared(context, userName);
- myPref.removeTask(userTasks.get(position).taskName);
- }
- });
- // builder.setIcon(android.R.drawable.ic_delete);
- builder.show();
- }
- });
- myLayout.addView(delete);
- myLayout.addView(taskName);
- return myLayout;
- }
- }
- /////////////////Utlshared///////////////////////////
- package com.mordekicloud.yuli.myapp1980;
- import android.content.Context;
- import android.content.Entity;
- import android.content.SharedPreferences;
- import android.os.DropBoxManager;
- import java.security.KeyStore;
- import java.util.ArrayList;
- import java.util.Map;
- /**
- * Created by yuli.mordek on 3/26/2016.
- */
- public class UtlShared
- {
- private Context context;
- private SharedPreferences userPref;
- private SharedPreferences.Editor editor;
- public String taskName;
- public Boolean taskDone;
- private String userName;
- private NewAdapter myTask;
- private ArrayList<UtlShared>taskList;
- public UtlShared(String taskName, Boolean taskDone)
- {
- this.taskName=taskName;
- this.taskDone=taskDone;
- }
- public UtlShared(Context context, String userName)
- {
- this.context=context;
- this.userName=userName;
- userPref=context.getSharedPreferences(userName, Context.MODE_PRIVATE);
- editor=userPref.edit();
- taskList=new ArrayList<UtlShared>();
- getTasks();
- }
- public void newTask(String taskName)
- {
- editor.putString(taskName,"0");
- editor.commit();
- taskList.add(new UtlShared(taskName, false));
- }
- public void removeTask(String taskName)
- {
- editor.remove(taskName);
- editor.commit();
- taskList.remove(taskName);
- refresh();
- }
- public void doneTask(String taskName, boolean taskDone)
- {
- editor.putString(taskName,taskDone?"1":"0");
- editor.commit();
- taskList.remove(taskName);
- taskList.add(new UtlShared(taskName, taskDone));
- refresh();
- }
- public void getTasks()
- {
- Map<String,?>tasks=userPref.getAll();
- for (Map.Entry<String,?> singleTask:tasks.entrySet())
- {
- taskList.add(new UtlShared(singleTask.getKey(),singleTask.getValue().equals("1")));
- }
- }
- public ArrayList<UtlShared>getAllTasks()
- {
- return taskList;
- }
- public void refresh()
- {
- myTask=new NewAdapter(context,userName);
- //Entry.myList.setAdapter(myTask);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement