Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ActivityMain
- =============
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#f7fcff"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:gravity="center"
- android:text="Welcome, Login To The System"
- android:textColor="#ff8cd1"
- android:textSize="22sp" />
- <EditText
- android:id="@+id/etname"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:hint="User Name"
- android:textSize="22sp" />
- <EditText
- android:id="@+id/etPassword"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Password"
- android:inputType="textPassword"
- android:textSize="22sp" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Button
- android:id="@+id/btnlog"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="10dp"
- android:layout_weight="1"
- android:textColor="#ff8cd1"
- android:text="Login"
- android:textSize="18sp" />
- <Button
- android:id="@+id/btnreg"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="10dp"
- android:layout_weight="1"
- android:textColor="#00acff"
- android:text="Register"
- android:textSize="18sp" />
- <Button
- android:id="@+id/btnex"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="10dp"
- android:layout_weight="1"
- android:textColor="#ff8cd1"
- android:text="Exit"
- android:textSize="18sp" />
- </LinearLayout>
- <TextView
- android:id="@+id/tverr"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:gravity="center"
- android:textColor="#e5061d"
- android:textSize="22sp" />
- <TextView
- android:id="@+id/simple"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="15dp"
- android:gravity="center"
- android:text="If You Are A Teacher, \n Please Ask The Responsible \n Person, About The Register. \n \n POWERED BY: \n Anan Smnia \n(C)"
- android:textColor="#51aca9"
- android:textSize="22sp" />
- </LinearLayout>
- MainActivity.java
- =================
- package com.example.user.webtop;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.graphics.Color;
- 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.TextView;
- import android.widget.Toast;
- import android.app.AlertDialog;
- import android.content.DialogInterface;
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- private EditText etname;
- private EditText etpass;
- private TextView tve;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- connectToLayout();
- }
- private void connectToLayout() {
- etname = (EditText) findViewById(R.id.etname);
- etpass = (EditText) findViewById(R.id.etPassword);
- tve = (TextView) findViewById(R.id.tverr);
- findViewById(R.id.btnex).setOnClickListener(this);
- findViewById(R.id.btnlog).setOnClickListener(this);
- findViewById(R.id.btnreg).setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- String userName = etname.getText().toString();
- String password = etpass.getText().toString();
- if (v.getId() == R.id.btnex) {
- AlertDialog.Builder ad = new AlertDialog.Builder(this);
- ad.setTitle("Are You Sure To Exit ?");
- ad.setPositiveButton("Exit", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- moveTaskToBack(true);
- android.os.Process.killProcess(android.os.Process.myPid());
- System.exit(1);
- }
- });
- ad.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- ad.show();
- }
- if (v.getId() == R.id.btnlog) {
- tve.setText("");
- userName = etname.getText().toString();
- password = etpass.getText().toString();
- if (userName.length() == 0 || password.length() == 0) {
- tve.setText("Please Fill User Name And Password !");
- tve.setTextColor(Color.rgb(229, 6, 29));
- return;
- } else if (userName.length() > 0 && password.length() > 0) {
- if (isValid(userName, password)) {
- if (!isTeacher(userName, password)) {
- Intent i = new Intent(this, StudentActivity.class);
- i.putExtra("CurrentUser", userName);
- startActivity(i);
- etname.setText("");
- etpass.setText("");
- tve.setText("");
- } else if (isTeacher(userName, password)) {
- Intent i = new Intent(this, TeacherActivity.class);
- i.putExtra("CurrentUser", userName);
- startActivity(i);
- etname.setText("");
- etpass.setText("");
- tve.setText("");
- }
- } else {
- tve.setText("Wrong User Name Or Password !");
- tve.setTextColor(Color.rgb(229, 6, 29));
- }
- }
- }
- if (v.getId() == R.id.btnreg) {
- tve.setText("");
- userName = etname.getText().toString();
- password = etpass.getText().toString();
- if (userName.length() == 0 || password.length() == 0) {
- tve.setText("Please Fill User Name And Password !");
- tve.setTextColor(Color.rgb(229, 6, 29));
- return;
- }
- if (!isUserExist(userName)) {
- addNewUser(userName, password);
- tve.setText("User Was Added !");
- tve.setTextColor(Color.rgb(88, 168, 77));
- etname.setText("");
- etpass.setText("");
- } else {
- tve.setText("Error Adding The User " + userName + " !");
- tve.setTextColor(Color.rgb(229, 6, 29));
- }
- }
- }
- private boolean isTeacher(String userName, String password) {
- if (userName.substring(0, 1).equals("T") && password.substring(0, 2).equals("00") && password.substring(password.length() - 2).equals("00")) {
- return true;
- }
- return false;
- }
- private boolean isValid(String userName, String password) {
- SharedPreferences prefs = this.getSharedPreferences("myUsers", Context.MODE_PRIVATE);
- String savedPassword = prefs.getString(userName, "");
- return (savedPassword.equals(password));
- }
- private boolean addNewUser(String userName, String password) {
- SharedPreferences prefs = this.getSharedPreferences("myUsers", Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(userName, password);
- return editor.commit();
- }
- private boolean isUserExist(String userName) {
- SharedPreferences prefs = this.getSharedPreferences("myUsers", Context.MODE_PRIVATE);
- String savedPassword = prefs.getString(userName, "");
- return (!savedPassword.equals(""));
- }
- }
- person.class
- =============
- package com.example.user.webtop;
- /**
- * Created by user on 20/10/2017.
- */
- public class person {
- private String name;
- private String mark;
- public person(String name, String mark){
- this.name=name;
- this.mark=mark;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getMark() {
- return mark;
- }
- public void setMark(String mark) {
- this.mark = mark;
- }
- }
- personAdapter.class
- ====================
- package com.example.user.webtop;
- import android.content.Context;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.TextView;
- import java.util.List;
- /**
- * Created by user on 20/10/2017.
- */
- public class PersonAdapter extends BaseAdapter {
- private Context context;
- private List<person> personsList;
- public PersonAdapter(Context context, List<person> personsList){
- this.context=context;
- this.personsList=personsList;
- }
- @Override
- public int getCount() {
- return this.personsList.size();
- }
- @Override
- public Object getItem(int position) {
- return personsList.get(position);
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View myView = LayoutInflater.from(context).inflate(R.layout.studentshow, null);
- final person ps = personsList.get(position);
- ((TextView) myView.findViewById(R.id.StudentsesName)).setText(ps.getName());
- ((TextView) myView.findViewById(R.id.studentGrade)).setText(ps.getMark());
- return myView;
- }
- }
- StudentActiviy.java
- ===============
- package com.example.user.webtop;
- import android.content.Context;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.util.ArrayList;
- import java.util.List;
- public class StudentActivity extends AppCompatActivity implements View.OnClickListener {
- private TextView tvname;
- private TextView Clases;
- private String snames;
- private ListView lsvGrades;
- private Button btn;
- List<person> lst;
- Context context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_student);
- btn = (Button) findViewById(R.id.btnExist);
- tvname = (TextView) findViewById(R.id.Names);
- Clases = (TextView) findViewById(R.id.Classes);
- snames = getIntent().getStringExtra("CurrentUser");
- lsvGrades = (ListView) findViewById(R.id.lsvGrades);
- this.context = this;
- btn.setOnClickListener(this);
- tvname.setText(snames);
- lst = loadFromFile();
- PersonAdapter myAdapter = new PersonAdapter(context, lst);
- lsvGrades.setAdapter(myAdapter);
- }
- private List<person> loadFromFile() {
- SharedPreferences myfile = this.getSharedPreferences("MyPersons", Context.MODE_PRIVATE);
- Object[] keys = myfile.getAll().keySet().toArray();
- List<person> lst = new ArrayList<>();
- for (int i = 0; i < keys.length; i += 1) {
- String namesubject = (String) keys[i];
- String[] ss = namesubject.split("\\|");
- if (ss[1].equals(snames)) {
- lst.add(new person(ss[3], ss[2]));
- Clases.setText(ss[0]);
- }
- }
- return lst;
- }
- @Override
- public void onClick(View v) {
- this.finish();
- }
- }
- Activity_student.xml
- =====================
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <Button
- android:id="@+id/btnExist"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#00acff"
- android:text="Exit"
- android:textSize="22sp" />
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/Names"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:gravity="right"
- android:text="aaa"
- android:textColor="#ff8cd1"
- android:layout_marginTop="15dp"
- android:textSize="22sp" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:text=" "
- android:textColor="#ff8cd1"
- android:layout_marginTop="15dp"
- android:textSize="22sp" />
- <TextView
- android:id="@+id/Classes"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="left"
- android:text="aaa"
- android:textColor="#ff8cd1"
- android:layout_marginTop="15dp"
- android:textSize="22sp" />
- </LinearLayout>
- <ListView
- android:id="@+id/lsvGrades"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"> </ListView>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:textSize="22sp" />
- </LinearLayout>
- Teacher.class
- ==============
- package com.example.user.webtop;
- /**
- * Created by user on 19/10/2017.
- */
- public class Teacher {
- private String Subject;
- private String Clases;
- public Teacher(String Subject, String Clases) {
- this.Subject = Subject;
- this.Clases = Clases;
- }
- public String getSubject() {
- return Subject;
- }
- public String getClases() {
- return Clases;
- }
- public void setName(String Subject) {
- this.Subject = Subject;
- }
- public void setClases(String Clases) {
- this.Clases = Clases;
- }
- }
- TeacherAdapter.class
- ====================
- package com.example.user.webtop;
- import android.content.Context;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.TextView;
- import java.util.List;
- public class TeacherAdapter extends BaseAdapter {
- private Context context;
- private List<Teacher> TeachersList;
- public TeacherAdapter(List<Teacher> TeachersList, Context context) {
- this.TeachersList = TeachersList;
- this.context = context;
- }
- @Override
- public int getCount() {
- return this.TeachersList.size();
- }
- @Override
- public Object getItem(int position) {
- return TeachersList.get(position); }
- @Override
- public long getItemId(int position) {
- return 0;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View myView = LayoutInflater.from(context).inflate(R.layout.list_row_layout, null);
- final Teacher teacher = TeachersList.get(position);
- ((TextView) myView.findViewById(R.id.tvsubject)).setText(teacher.getSubject());
- ((TextView) myView.findViewById(R.id.tvclases)).setText(teacher.getClases());
- return myView;
- }
- }
- TeacherActivity.java
- ====================
- package com.example.user.webtop;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.util.ArrayList;
- import java.util.List;
- public class TeacherActivity extends AppCompatActivity implements View.OnClickListener {
- private TextView tvteachername;
- private String teachername;
- private EditText etٍNewSubject;
- private EditText etNewGrade;
- private Button btnAddItem;
- private Button btnExit;
- private ListView lsvTeachers;
- List<Teacher> lst;
- Context context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_teacher);
- tvteachername = (TextView) findViewById(R.id.tvteachername);
- teachername = getIntent().getStringExtra("CurrentUser");
- tvteachername.setText(teachername.substring(1, teachername.length()));
- this.context = this;
- etٍNewSubject = (EditText) findViewById(R.id.etٍNewSubject);
- etNewGrade = (EditText) findViewById(R.id.etNewGrade);
- btnAddItem = (Button) findViewById(R.id.btnAddTeacher);
- btnExit = (Button) findViewById(R.id.btnExit);
- lsvTeachers = (ListView) findViewById(R.id.lsvItems);
- btnAddItem.setOnClickListener(this);
- btnExit.setOnClickListener(this);
- lst = loadFromFile();
- TeacherAdapter myAdapter = new TeacherAdapter(lst, this);
- lsvTeachers.setAdapter(myAdapter);
- lsvTeachers.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
- final AlertDialog.Builder Dialoga = new AlertDialog.Builder(context);
- Dialoga.setTitle("U Want To Edit " + lst.get(position).getSubject() + " Subject, " + lst.get(position).getClases() + " Class Marks ?");
- Dialoga.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent i = new Intent(context, ClassActivity.class);
- i.putExtra("SubjectName", (String) lst.get(position).getSubject());
- i.putExtra("ClassName", (String) lst.get(position).getClases());
- i.putExtra("TeacherName", teachername);
- startActivity(i);
- lsvTeachers.setAdapter(new TeacherAdapter(lst, context));
- }
- });
- Dialoga.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- Dialoga.show();
- }
- });
- lsvTeachers.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
- @Override
- public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
- final String SubjectForRemove = (String) lst.get(position).getSubject();
- final String clasesForRemove = (String) lst.get(position).getClases();
- final AlertDialog.Builder Dialoga = new AlertDialog.Builder(context);
- Dialoga.setTitle("U Want To Delete The " + SubjectForRemove + " Subject, " + clasesForRemove + " Class ?");
- Dialoga.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- SharedPreferences myfile = context.getSharedPreferences("MyTeachers", Context.MODE_PRIVATE);
- myfile.edit().remove(teachername + "|" + SubjectForRemove + "|" + clasesForRemove).commit();
- lst = loadFromFile();
- lsvTeachers.setAdapter(new TeacherAdapter(lst, context));
- }
- });
- Dialoga.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- Dialoga.show();
- return false;
- }
- });
- }
- @Override
- public void onClick(View v) {
- if (v.getId() == R.id.btnAddTeacher) {
- String newSubjectName = etٍNewSubject.getText().toString();
- String newClassName = etNewGrade.getText().toString();
- if (!newSubjectName.isEmpty() && !newClassName.isEmpty()) {
- // add the item
- SharedPreferences myfile = this.getSharedPreferences("MyTeachers", Context.MODE_PRIVATE);
- String oldclassandsubject = myfile.getString(teachername + "|" + newSubjectName + "|" + newClassName, "");
- Object[] keys = myfile.getAll().keySet().toArray();
- int c = 0;
- for (int i = 0; i < keys.length; i += 1) {
- String namesubject = (String) keys[i];
- String[] ss = namesubject.split("\\|");
- if (oldclassandsubject.equals("") && (ss[1].toString().equals(newSubjectName) == false && ss[2].toString().equals(newClassName) == false) || (ss[1].toString().equals(newSubjectName) == true && ss[2].toString().equals(newClassName) == false) || (ss[1].toString().equals(newSubjectName) == false && ss[2].toString().equals(newClassName) == true)) {
- c++;
- }
- }
- if (keys.length == c)
- myfile.edit().putString(teachername + "|" + newSubjectName + "|" + newClassName, "1").commit();
- if (keys.length > c)
- Toast.makeText(this, "The Teacher Of The " + newSubjectName + ", Of " + newClassName + " Class, Found In The System!", Toast.LENGTH_LONG).show();
- // update the list
- lst = loadFromFile();
- lsvTeachers.setAdapter(new TeacherAdapter(lst, this));
- etٍNewSubject.setText("");
- etNewGrade.setText("");
- }
- }
- if (v.getId() == R.id.btnExit) {
- this.finish();
- }
- }
- private List<Teacher> loadFromFile() {
- SharedPreferences myfile = this.getSharedPreferences("MyTeachers", Context.MODE_PRIVATE);
- Object[] keys = myfile.getAll().keySet().toArray();
- List<Teacher> lst = new ArrayList<>();
- for (int i = 0; i < keys.length; i += 1) {
- String namesubject = (String) keys[i];
- String[] ss = namesubject.split("\\|");
- if (ss[0].equals(teachername)) {
- lst.add(new Teacher(ss[1], ss[2]));
- }
- }
- return lst;
- }
- }
- Activity_Teacher.xml
- ====================
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Button
- android:id="@+id/btnExit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#ff8cd1"
- android:text="Exit"
- android:textSize="22sp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/tvteachername"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:gravity="center"
- android:textColor="#00acff"
- android:textSize="22sp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <EditText
- android:id="@+id/etٍNewSubject"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:hint="Subject"
- android:textSize="22sp" />
- <EditText
- android:id="@+id/etNewGrade"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:inputType="number"
- android:hint="Class"
- android:textSize="22sp" />
- <Button
- android:id="@+id/btnAddTeacher"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:background="#ff8cd1"
- android:text="Add"
- android:textSize="22sp" />
- </LinearLayout>
- <ListView
- android:id="@+id/lsvItems"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:choiceMode="singleChoice"></ListView>
- </LinearLayout>
- ClassActivity.java
- ===================
- package com.example.user.webtop;
- 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.view.LayoutInflater;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.util.ArrayList;
- import java.util.List;
- public class ClassActivity extends AppCompatActivity implements View.OnClickListener {
- private String TeachersNames;
- private String SubjectsNames;
- private String ClasesNames;
- private TextView tvTeachers;
- private TextView tvSubjects;
- private TextView tvClaases;
- private EditText etٍNewStudent;
- private EditText etNewMark;
- private Button btnAddStudent;
- private Button btnExits;
- private Button btnpre;
- private ListView lsvPersons;
- List<person> lst;
- Context context;
- int c = 0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_class);
- tvTeachers = (TextView) findViewById(R.id.tvTeacherNames);
- tvSubjects = (TextView) findViewById(R.id.tvSubjectsesNames);
- tvClaases = (TextView) findViewById(R.id.tvClaasesNames);
- etٍNewStudent = (EditText) findViewById(R.id.etStudentName);
- etNewMark = (EditText) findViewById(R.id.etStudentMark);
- btnAddStudent = (Button) findViewById(R.id.btnAddStudent);
- btnExits = (Button) findViewById(R.id.btnExits);
- btnpre = (Button) findViewById(R.id.btnPrevius);
- lsvPersons = (ListView) findViewById(R.id.lsvStudents);
- lst = new ArrayList<>();
- this.context = this;
- TeachersNames = getIntent().getStringExtra("TeacherName");
- SubjectsNames = getIntent().getStringExtra("SubjectName");
- ClasesNames = getIntent().getStringExtra("ClassName");
- tvTeachers.setText(TeachersNames.substring(1, TeachersNames.length()));
- tvSubjects.setText(SubjectsNames);
- tvClaases.setText(ClasesNames);
- btnAddStudent.setOnClickListener(this);
- btnExits.setOnClickListener(this);
- btnpre.setOnClickListener(this);
- lst = loadFromFile();
- PersonAdapter pa = new PersonAdapter(context, lst);
- lsvPersons.setAdapter(pa);
- lsvPersons.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
- final AlertDialog.Builder myDialog = new AlertDialog.Builder(context);
- final View myView = LayoutInflater.from(context).inflate(R.layout.mark_update, null);
- myDialog.setView(myView);
- myDialog.setTitle("Update Mark");
- myDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- String inputDatas = ((EditText) myView.findViewById(R.id.etNewMark)).getText().toString();
- if (!inputDatas.isEmpty() && Integer.parseInt(inputDatas) > 19 && Integer.parseInt(inputDatas) <= 100) {
- int newMark = Integer.parseInt(inputDatas);
- String itemName = lst.get(position).getName();
- SharedPreferences myfiles = context.getSharedPreferences("MyPersons", Context.MODE_PRIVATE);
- if (!lst.get(position).getMark().equals("")) {
- Object[] keys = myfiles.getAll().keySet().toArray();
- for (int i = 0; i < keys.length; i += 1) {
- String personName = (String) keys[i];
- String[] ss = personName.split("\\|");
- if (ss[0].equals(ClasesNames) && ss[1].equals(itemName) && ss[3].equals(SubjectsNames) && ss[4].equals(TeachersNames) && !ss[2].equals("")) {
- myfiles.edit().remove(ClasesNames + "|" + itemName + "|" + ss[2] + "|" + SubjectsNames + "|" + TeachersNames).commit();
- myfiles.edit().putString(ClasesNames + "|" + itemName + "|" + inputDatas + "|" + SubjectsNames + "|" + TeachersNames, "1").commit();
- lst = loadFromFile();
- lsvPersons.setAdapter(new PersonAdapter(context, lst));
- }
- }
- }
- if (lst.get(position).getMark().equals("")) {
- myfiles.edit().putString((ClasesNames + "|" + itemName + "|" + inputDatas + "|" + SubjectsNames + "|" + TeachersNames), "1").commit();
- lst.remove(position);
- lst = loadFromFile();
- lsvPersons.setAdapter(new PersonAdapter(context, lst));
- }
- }
- lst = loadFromFile();
- lsvPersons.setAdapter(new PersonAdapter(context, lst));
- dialog.cancel();
- }
- });
- myDialog.show();
- }
- });
- lsvPersons.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
- @Override
- public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
- final String MarkForRemove = (String) lst.get(position).getMark();
- final String NameForRemove = (String) lst.get(position).getName();
- final android.support.v7.app.AlertDialog.Builder Dialoga = new android.support.v7.app.AlertDialog.Builder(context);
- Dialoga.setTitle("U Want To Delete The " + NameForRemove + " Student, " + MarkForRemove + " Mark ?");
- Dialoga.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- SharedPreferences myfile = context.getSharedPreferences("MyPersons", Context.MODE_PRIVATE);
- myfile.edit().remove(ClasesNames + "|" + lst.get(position).getName() + "|" + lst.get(position).getMark() + "|" + SubjectsNames + "|" + TeachersNames).commit();
- lst = loadFromFile();
- lsvPersons.setAdapter(new PersonAdapter(context, lst));
- }
- });
- Dialoga.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- Dialoga.show();
- return false;
- }
- });
- }
- @Override
- public void onClick(View v) {
- lst = loadFromFile();
- if (v.getId() == R.id.btnAddStudent) {
- lst = loadFromFile();
- boolean flag = false;
- String newPersonName = etٍNewStudent.getText().toString();
- String newPersonMark = etNewMark.getText().toString();
- if (!newPersonName.isEmpty() && !newPersonMark.isEmpty() && Integer.parseInt(newPersonMark) > 19 && Integer.parseInt(newPersonMark) <= 100) {
- SharedPreferences myfile = this.getSharedPreferences("MyPersons", Context.MODE_PRIVATE);
- String classnamemarksubjectteacher = myfile.getString(ClasesNames + "|" + newPersonName + "|" + newPersonMark + "|" + SubjectsNames + "|" + TeachersNames, "");
- SharedPreferences mf = context.getSharedPreferences("MyPersons", Context.MODE_PRIVATE);
- Object[] keys = mf.getAll().keySet().toArray();
- for (int i = 0; i < keys.length; i += 1) {
- String personName = (String) keys[i];
- String[] ss = personName.split("\\|");
- if (ss[1].equals(newPersonName) && !ss[0].equals(ClasesNames) && isUserFound(newPersonName)) {
- Toast.makeText(this, "The Student, " + newPersonName + " Is Avalibale In Another Class !", Toast.LENGTH_LONG).show();
- flag = true;
- } else if (ss[1].equals(newPersonName) && ss[0].equals(ClasesNames) && isUserFound(newPersonName) && isUserNotFoundInTheList(newPersonName)) {
- myfile.edit().putString(ClasesNames + "|" + newPersonName + "|" + newPersonMark + "|" + SubjectsNames + "|" + TeachersNames, "1").commit();
- flag = true;
- } else if (ss[1].equals(newPersonName) && ss[0].equals("") && isUserFound(newPersonName) && isUserNotFoundInTheList(newPersonName)) {
- myfile.edit().putString(ClasesNames + "|" + newPersonName + "|" + newPersonMark + "|" + SubjectsNames + "|" + TeachersNames, "1").commit();
- flag = true;
- }
- }
- if (isUserFound(newPersonName) && flag == false && isUserNotFoundInTheList(newPersonName)) {
- myfile.edit().putString(ClasesNames + "|" + newPersonName + "|" + newPersonMark + "|" + SubjectsNames + "|" + TeachersNames, "1").commit();
- flag = false;
- }
- if (!isUserFound(newPersonName))
- Toast.makeText(this, "The Student " + newPersonName + " Is Not Avalibale In The System, Or It's A Teacher Please Check It !", Toast.LENGTH_LONG).show();
- lst = loadFromFile();
- lsvPersons.setAdapter(new PersonAdapter(this, lst));
- etٍNewStudent.setText("");
- etNewMark.setText("");
- } else {
- Toast.makeText(this, "Some Thing Is Illegal, Please Check The Student Name And The Mark !", Toast.LENGTH_LONG).show();
- }
- }
- if (v.getId() == R.id.btnExits) {
- lst = loadFromFile();
- Intent i = new Intent(this, MainActivity.class);
- this.finish();
- startActivity(i);
- }
- if (v.getId() == R.id.btnPrevius) {
- lst = loadFromFile();
- this.finish();
- }
- }
- private boolean isUserFound(String userName) {
- SharedPreferences prefs = this.getSharedPreferences("myUsers", Context.MODE_PRIVATE);
- String savedPassword = prefs.getString(userName, "");
- if ((!savedPassword.equals("")) && isNotTeacher(userName))
- return true;
- return false;
- }
- private boolean isNotTeacher(String userName) {
- SharedPreferences prefs = this.getSharedPreferences("myUsers", Context.MODE_PRIVATE);
- String savedPassword = prefs.getString(userName, "");
- if (!userName.substring(0, 1).equals("T") || !savedPassword.substring(0, 2).equals("00") ||
- !savedPassword.substring(savedPassword.length() - 2).equals("00"))
- return true;
- return false;
- }
- private List<person> loadFromFile() {
- SharedPreferences myfile = this.getSharedPreferences("MyPersons", Context.MODE_PRIVATE);
- Object[] keys = myfile.getAll().keySet().toArray();
- List<person> lsts = new ArrayList<>();
- for (int i = 0; i < keys.length; i += 1) {
- String personName = (String) keys[i];
- String[] ss = personName.split("\\|");
- if (ss[0].equals(ClasesNames)) {
- if (ss[3].equals(SubjectsNames) && ss[4].equals(TeachersNames)) {
- lsts.add(new person(ss[1], ss[2]));
- }
- }
- }
- return lsts;
- }
- private boolean isUserNotFoundInTheList(String personname){
- for (int i = 0 ; i <lst.size(); i++){
- if (lst.get(i).getName().equals(personname)) return false;
- }
- return true;
- }
- }
- Activity_class.xml
- ===================
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#f7fcff"
- android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Button
- android:id="@+id/btnExits"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#ff8cd1"
- android:layout_weight="2"
- android:text="Exit"
- android:textSize="22sp" />
- <Button
- android:id="@+id/btnPrevius"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#00acff"
- android:layout_weight="2"
- android:text="Previous"
- android:textSize="22sp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/tvTeacherNames"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginTop="15dp"
- android:layout_weight="1"
- android:textColor="#ff8cd1"
- android:textSize="22sp" />
- <TextView
- android:id="@+id/tvSubjectsesNames"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginTop="15dp"
- android:layout_weight="1"
- android:textColor="#00acff"
- android:textSize="22sp" />
- <TextView
- android:id="@+id/tvClaasesNames"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginTop="15dp"
- android:layout_weight="1"
- android:textColor="#ff8cd1"
- android:textSize="22sp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <EditText
- android:id="@+id/etStudentName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:hint="Name"
- android:textSize="22sp" />
- <EditText
- android:id="@+id/etStudentMark"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="number"
- android:layout_weight="2"
- android:hint="Mark"
- android:textSize="22sp" />
- <Button
- android:id="@+id/btnAddStudent"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:background="#ff8cd1"
- android:text="Add"
- android:textSize="22sp" />
- </LinearLayout>
- <ListView
- android:id="@+id/lsvStudents"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:choiceMode="singleChoice"></ListView>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:textColor="#00acff"
- android:textSize="22sp" />
- </LinearLayout>
- list_row_layout.xml
- ===================
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#00acff"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/tvsubject"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:textColor="#FFFFFF"
- android:textSize="22sp" />
- <TextView
- android:id="@+id/tvclases"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:textColor="#FFFFFF"
- android:textSize="22sp" />
- </LinearLayout>
- mark_update.xml
- ================
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="match_parent">
- <EditText
- android:id="@+id/etNewMark"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Enter The New Mark"
- android:inputType="number"
- android:textSize="22sp" />
- </LinearLayout>
- studentshow.xml
- ===============
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#ff8cd1"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/StudentsesName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:textColor="#FFFFFF"
- android:textSize="22sp" />
- <TextView
- android:id="@+id/studentGrade"
- android:fontFamily="sans-serif-medium"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:textColor="#FFFFFF"
- android:textSize="22sp" />
- </LinearLayout>
- updatemarks.xml
- =================
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:hint="New Mark"
- android:textSize="22sp" />
- <Button
- android:id="@+id/etNewQuentity"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:hint="The New Mark"
- android:textColorHint="#00acff"
- android:textSize="22sp" />
- </LinearLayout>
Add Comment
Please, Sign In to add comment