Answered Essay: 站 1111 5:01 Mobile Timetabler New appointment Delete appointmentis) Monday 12 noon, 3 hours, Fly a kite Tuesday No appointments, Wednes

If someone could just even provide code for the layout of each page to help get me started that would be a great step in the right direction. Someone commented on a previous post of this and said it would be too hard to make the full app in time, but i never specified a time period. I have been struggling with mobile application development and have asked my teacher numerous times for help just to be turned away so i’ll turn to this community and hopefully someone can help me. cheers everyone.

Project Settings

Your Android application should have the following settings:

Minimum SDK: API 19 Android 4.4
Application Name: Mobile Timetabler
Project Name: MobileTimetabler
For example, MobileTimetabler30078589
Package name: au.edu.vu.timetable
For example, au.edu.vu.timetable30078589

Your Mobile Timetabler application will do exactly what it sounds like. When the application first launches, it will display the days of the week Monday through to Friday, and underneath each day, it will display some details (which you will enter, and which will be saved into a simple SQLite database) about what classes / labs you have on that day.
When the application starts it should have two buttons which are displayed at the top of the screen:
– A button to create a New appointment, and – A button to Delete appointment(s).
Under this, in a LinearLayout inside a ScrollView, there should be 5 centred TextViews with the days of the week Monday through Friday.
Under each day should be the text for one or more appointments. If there are no appointments saved for that day then the text “No appointments.” is displayed.
An example of the MainActivity layout is shown below in figure 1 (Figures provided in this assignment are as sample only):

站 1111 5:01 Mobile Timetabler New appointment Delete appointmentis) Monday 12 noon, 3 hours, Fly a kite Tuesday No appointments, Wednesday 4am, 5 seconds, Wake up and look at the alarm clock Thursday No appointments, Friday 12:30pm, 1 hour, Meet John for lunch @ cafeteria.

When the user clicks the [New appointment] button, an “onClick” method is executed which creates a new Intent, and starts a new NewAppointmentActivity using that intent.
The NewAppointmentActivity layout has two buttons, one to [Create appointment] which triggers the creation of a new Appointment object which must be saved to the SQLite database, and a second [Back] button which simply finishes the NewAppointmentActivity and returns to the MainActivity.
Under these two buttons are 5 radio buttons with the text “Mon”, “Tue”, “Wed”, “Thur”, and “Fri” on them inside a horizontal RadioGroup. It also has TextViews which display the words “Time”, “Duration” and “Description”. Under each of these three TextViews are EditText views which allow the user to enter text for the time, duration and description of the appointment.

The layout of  NewAppointmentActivity is shown below:

Once the user clicks the New appointment button, the appointment must be saved in the database, and the NewAppointmentActivity finishes so we return to the MainActivity, which in both the onCreate and onResume methods calls another method called populateSchedule – which reads all the appointments from the database and puts them under the correct day for which they are scheduled. For example, after saving the above appointment, our new schedule is shown below in Figure 3.

If the user then clicks the [Delete appointment(s)] button the DeleteAppointmentActivity is executed. There are two ways that you can write the DeleteAppointmentActivity – a standard way.

DeleteAppointmentActivity – Standard Version

When a DeleteAppointmentActivity is launched, the database is queried for all saved appointments, and each appointment is displayed in a list of dynamically created checkboxes, one appointment per checkbox.

The id value from the database is retrieved (along with all other fields for each appointment), and the program sets the id value of the checkbox to be the id of the appointment. This way, the id value of each checked checkbox is the id value of the appointment we want to delete from the database.

A user can check some, all or none of the checkboxes and then click the [Delete selected] button, which will trigger deletion of the appointments from the database. This is achieved by creating a List of the checkbox id values where the checkbox is checked, and then passing that list to a deleteScheduleItems method which goes through each value in the list and deletes the record with that id from the database.

If the user clicks the [Back] button the activity finishes and we are returned to the MainActivity without making any changes to the database.
An example layout for the standard version of the DeleteAppointmentActivity is shown below in Figure 4:

After deleting the “fly a kite” appointment above, our appointment list in the MainActivity will now look like Figure 5, below:

The MySQLiteHelper class creates our SQLite database.
The DATABASE_CREATE string must contain commands to create the table with the following schema:
COLUMN_ID – integer primary key autoincrement
COLUMN_DAY – integer not null
COLUMN_TIME – text not null
COLUMN_DURATION – text not null
COLUMN_DESCRIPTION – text not null

The database name should be appointments.db

The NewAppointmentActivity allows the user to select a day from a group of RadioButtons, and then enter text (as a String) for the time, duration and description.

If the [Create appointment] button is clicked the appointment is saved to the database. However, if the user opts to create a new appointment but has not entered any time, duration or description information (i.e. all three strings are empty) – then placeholder text is used for each field, which is specified as “”, “” and “” respectively. After saving the appointment the activity finishes and we are returned to the MainActivity.

If the [Back] button is pressed then the activity finishes without saving the appointment and we are again returned to the MainActivity.

站 1111 5:01 Mobile Timetabler New appointment Delete appointmentis) Monday 12 noon, 3 hours, Fly a kite Tuesday No appointments, Wednesday 4am, 5 seconds, Wake up and look at the alarm clock Thursday No appointments, Friday 12:30pm, 1 hour, Meet John for lunch @ cafeteria.

Expert Answer

 

MainActivity.java

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
    private List<AppointmentGroup> mGroupList;
    private AppointmentGroupAdapter mListAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //Log.d(this.getClass().getName(), "Create Start");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initResources();

        //Log.d(this.getClass().getName(), "Create End");
    }

    @Override
    public void onResume() {
        //Log.d(this.getClass().getName(), "Resume Start");

        super.onResume();

        getAllAppointments();
        mListAdapter.notifyDataSetChanged();

        //Log.d(this.getClass().getName(), "Resume End");
    }

    private void initResources() {
        mGroupList = new ArrayList<>();
        for (DayClass day : DayClass.values()) {
            mGroupList.add(new AppointmentGroup(day));
        }

        mListAdapter = new AppointmentGroupAdapter(this, R.layout.appointment_group_row, 0, mGroupList);
        final ListView listView = (ListView) findViewById(R.id.listViewMain);
        listView.setAdapter(mListAdapter);
    }

    private void getAllAppointments() {
        //Log.d(this.getClass().getName(), "getAllAppointments Start");
        AppointmentDataSource.getInstance().getAllGroupAppointments(mGroupList);
        //Log.d(this.getClass().getName(), "getAllAppointments End");
    }

    public void createNewAppointment(View view) {
        Intent intent = new Intent(this, NewAppointmentActivity.class);
        startActivity(intent);
    }

    public void deleteAppointment(View view) {
        Intent intent = new Intent(this, DeleteAppointmentActivity.class);
        startActivity(intent);
    }
}

================================================================================

Appointment.java

public class Appointment {
    private static final String DELIMITER = ", ";
    private static final String DEFAULT_TIME = "No time";
    private static final String DEFAULT_DURATION = "No duration";
    private static final String DEFAULT_DESCRIPTION = "No description";
    private int mId;
    private DayClass mDay;
    private String mTime;
    private String mDuration;
    private String mDescription;

    public int getId() {
        return mId;
    }

    public void setId(int id) {
        this.mId = id;
    }

    public DayClass getDay() {
        return mDay;
    }

    public void setDay(DayClass day) {
        this.mDay = day;
    }

    public String getTime() {
        return mTime;
    }

    public void setTime(String time) {
        if (time == null || time.isEmpty())
            this.mTime = DEFAULT_TIME;
        else
            this.mTime = time;
    }

    public String getDuration() {
        return mDuration;
    }

    public void setDuration(String duration) {
        if (duration == null || duration.isEmpty())
            this.mDuration = DEFAULT_DURATION;
        else
            this.mDuration = duration;
    }

    public String getDescription() {
        return mDescription;
    }

    public void setDescription(String description) {
        if (description == null || description.isEmpty())
            this.mDescription = DEFAULT_DESCRIPTION;
        else
            this.mDescription = description;
    }

    public boolean isValid() {
        if (mDay != null && mTime != null && mDuration != null) {
            if (!mTime.isEmpty() && !mDuration.isEmpty())
                return true;
        }

        return false;
    }

    public String toString() {
        return mTime + DELIMITER + mDuration + DELIMITER + mDescription;
    }
}

=================================================================================

AppointmentAdapter.java

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class AppointmentAdapter extends CustomAdapter<Appointment> implements OnCheckedChangeListener {
    private Map<Integer, Boolean> mCheckedList;

    public AppointmentAdapter(Context context, int resource, int textViewResourceId, List<Appointment> objects) {
        super(context, resource, textViewResourceId, objects);
        this.mCheckedList = new HashMap<>();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        CheckBox checkBox;
        Appointment appointment = getItem(position); // appointment is not null

        if (convertView == null) {
            view = mInflater.inflate(mResource, parent, false);
            //Log.d(this.getClass().getName(), "null convertView pos : " + position + " , app_id : " + appointment.getId());

            checkBox = (CheckBox) view.findViewById(mFieldId);
            view.setTag(checkBox);
            //Log.d(this.getClass().getName(), "checkBox pos : " + position + " , app_id : " + appointment.getId());
        }
        else {
            view = convertView;
            checkBox = (CheckBox) view.getTag();
            //Log.d(this.getClass().getName(), "convertView pos : " + position + " , app_id : " + appointment.getId());
        }
        checkBox.setText(appointment.toString());
        checkBox.setTag(appointment);
        //checkBox.setChecked(((ListView) parent).isItemChecked(position));
        Boolean isChecked = mCheckedList.get(appointment.getId());
        if (isChecked != null && isChecked) {
            checkBox.setChecked(true);
        } else {
            checkBox.setChecked(false);
        }

        checkBox.setOnCheckedChangeListener(this);
        return view;
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        try {
            Integer id = ((Appointment) buttonView.getTag()).getId();
            if (isChecked)
                mCheckedList.put(id, true);
            else
                mCheckedList.remove(id);
        } catch (NullPointerException e) {
            Log.e(this.getClass().getName(), "Null Pointer" );
        }
        buttonView.setChecked(isChecked);
    }

    Set<Integer> getCheckedList() {
        return mCheckedList.keySet();
    }
}

===============================================================================

AppointmentDataSource.java

import android.app.Application;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import java.util.List;
public class AppointmentDataSource extends Application {
    private static AppointmentDataSource mAppInstance;
    private volatile static MySQLiteHelper mHelperInstance;
    private SQLiteDatabase mDatabase;

    private static final String DELIMITER_1 = ", ";
    private static final String DELIMITER_2 = "', '";

    @Override
    public void onCreate() {
        //Log.d(this.getClass().getName(), "Create Start");

        super.onCreate();

        initResources();

        //Log.d(this.getClass().getName(), "Create End");
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        //Log.d(this.getClass().getName(), "Terminate");
        try {
            mDatabase.close();
            mHelperInstance.close();
        } catch (Exception e) {
            Log.d(this.getClass().getName(), "Terminate Exception");
        }
    }

    private void initResources() {
        mAppInstance = this;
        // DCL (Double Checking Locking) >= JDK 1.4
        if (mHelperInstance == null) {
            synchronized (MySQLiteHelper.class) {
                if (mHelperInstance == null) mHelperInstance = new MySQLiteHelper(getApplicationContext());
            }
        }
        mDatabase = mHelperInstance.getWritableDatabase();
    }

    public static AppointmentDataSource getInstance() {
        return mAppInstance;
    }

    public void open() {
        if (!mDatabase.isOpen()) mHelperInstance.onOpen(mDatabase);
    }

    private void insert1(Appointment appointment) {
        String sqlStr = "INSERT INTO " +
                MySQLiteHelper.TABLE_APPOINTMENTS + " (" +
                MySQLiteHelper.COLUMN_DAY_NAME + DELIMITER_1 +
                MySQLiteHelper.COLUMN_TIME_NAME + DELIMITER_1 +
                MySQLiteHelper.COLUMN_DURATION_NAME + DELIMITER_1 +
                MySQLiteHelper.COLUMN_DESCRIPTION_NAME + ") VALUES ('" +
                DayClass.toInteger(appointment.getDay()) + DELIMITER_2 +
                appointment.getTime() + DELIMITER_2 +
                appointment.getDuration() + DELIMITER_2 +
                appointment.getDescription() + "')";

        Log.d(this.getClass().getName(), sqlStr);
        Log.d(this.getClass().getName(), "insertAppointment End");
        mDatabase.execSQL(sqlStr);
    }

    private void insert2(Appointment appointment) {
        ContentValues values = new ContentValues();
        values.put(MySQLiteHelper.COLUMN_DAY_NAME, DayClass.toInteger(appointment.getDay()));
        values.put(MySQLiteHelper.COLUMN_TIME_NAME, appointment.getTime());
        values.put(MySQLiteHelper.COLUMN_DURATION_NAME, appointment.getDuration());
        values.put(MySQLiteHelper.COLUMN_DESCRIPTION_NAME, appointment.getDescription());
        mDatabase.insert(MySQLiteHelper.TABLE_APPOINTMENTS, null, values);
    }

    public void insertAppointment(Appointment appointment) {
        //Log.d(this.getClass().getName(), "insertAppointment Start");

        insert2(appointment);
    }

    private void delete1(String list) {
        String sqlStr = "DELETE FROM " +
                MySQLiteHelper.TABLE_APPOINTMENTS + " WHERE " +
                MySQLiteHelper.COLUMN_ID_NAME + " IN (" +
                list + ")";
        Log.d(this.getClass().getName(), sqlStr);
        mDatabase.execSQL(sqlStr);
    }

    private void delete2(String list) {
        String sqlStr = MySQLiteHelper.COLUMN_ID_NAME + " IN (" + list + ")";
        //Log.d(this.getClass().getName(), sqlStr);

        mDatabase.delete(MySQLiteHelper.TABLE_APPOINTMENTS, sqlStr, null);
    }
    public void deleteAppointment(String list) {
        if (!list.isEmpty()) {
            delete2(list);
        }

        //Log.d(this.getClass().getName(), "deleteAppointment End");
    }

    private Appointment cursorToAppointment(Cursor cursor, Appointment appointment) {
        if (appointment == null) appointment = new Appointment();

        appointment.setId(cursor.getInt(cursor.getColumnIndexOrThrow(MySQLiteHelper.COLUMN_ID_NAME)));
        appointment.setDay(DayClass.fromInteger(Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(MySQLiteHelper.COLUMN_DAY_NAME)))));
        appointment.setTime(cursor.getString(cursor.getColumnIndexOrThrow(MySQLiteHelper.COLUMN_TIME_NAME)));
        appointment.setDuration(cursor.getString(cursor.getColumnIndexOrThrow(MySQLiteHelper.COLUMN_DURATION_NAME)));
        appointment.setDescription(cursor.getString(cursor.getColumnIndexOrThrow(MySQLiteHelper.COLUMN_DESCRIPTION_NAME)));

        return appointment;
    }

    public void getAllGroupAppointments(List<AppointmentGroup> groupList) {
        //Log.d(this.getClass().getName(), "getAllGroupAppointments Start");
        for (AppointmentGroup group : groupList) {
            group.clear();
        }

        // Read-Only SQLiteDatabase doesn't need to be closed. See Android API
        SQLiteDatabase db = mHelperInstance.getReadableDatabase();
        Cursor cursor = db.query(MySQLiteHelper.TABLE_APPOINTMENTS, null, null, null, null, null, MySQLiteHelper.ORDER_CONDITION);
        Appointment appointment = null;
        while (cursor.moveToNext()) {
            appointment = cursorToAppointment(cursor, appointment);

            DayClass day = appointment.getDay();
            if (day != null) {
                AppointmentGroup group = groupList.get(DayClass.toInteger(day));
                if (group != null && group.add(appointment)) appointment = null;
            }
        }
        cursor.close();
        //Log.d(this.getClass().getName(), "getAllGroupAppointments End");
    }

    public void getAllAppointments(List<Appointment> appointmentList) {
        //Log.d(this.getClass().getName(), "getAllAppointments Start");
        // Read-Only SQLiteDatabase doesn't need to be closed. See Android API
        SQLiteDatabase db = mHelperInstance.getReadableDatabase();
        Cursor cursor = db.query(MySQLiteHelper.TABLE_APPOINTMENTS, null, null, null, null, null, MySQLiteHelper.ORDER_CONDITION);
        while (cursor.moveToNext()) {
            Appointment appointment = cursorToAppointment(cursor, null);
            if (appointment.getDay() != null && appointmentList != null) appointmentList.add(appointment);
        }
        cursor.close();
        //Log.d(this.getClass().getName(), appointmentList.toString());
        //Log.d(this.getClass().getName(), "getAllAppointments End");
    }

    private final class MySQLiteHelper extends SQLiteOpenHelper {
        private static final String TABLE_APPOINTMENTS = "appointments";
        private static final String COLUMN_ID_NAME = "id";
        private static final String COLUMN_DAY_NAME = "app_day";
        private static final String COLUMN_TIME_NAME = "app_time";
        private static final String COLUMN_DURATION_NAME = "duration";
        private static final String COLUMN_DESCRIPTION_NAME = "description";

        private static final String COLUMN_ID = "integer primary key";
        private static final String COLUMN_DAY = "integer not null";
        private static final String COLUMN_TIME = "text not null";
        private static final String COLUMN_DURATION = "text not null";
        private static final String COLUMN_DESCRIPTION = "text not null";

        private static final String DATABASE_NAME = "timetable.db";
        private static final String DATABASE_CREATE = "CREATE TABLE ";
        private static final String ORDER_CONDITION = "app_day, app_time, id";
        private static final int DATABASE_VERSION = 1;

        private MySQLiteHelper(final Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            String sqlStr = DATABASE_CREATE +
                    TABLE_APPOINTMENTS + " (" +
                    COLUMN_ID_NAME + " " + COLUMN_ID + ", " +
                    COLUMN_DAY_NAME + " " + COLUMN_DAY + ", " +
                    COLUMN_TIME_NAME + " " + COLUMN_TIME + ", " +
                    COLUMN_DURATION_NAME + " " + COLUMN_DURATION + ", " +
                    COLUMN_DESCRIPTION_NAME + " " + COLUMN_DESCRIPTION + ")";
            db.execSQL(sqlStr);

            //Log.d(this.getClass().getName(), sqlStr);
            //Log.d(this.getClass().getName(), "Create End");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            String sqlStr = "DROP TABLE IF EXISTS " + TABLE_APPOINTMENTS;
            db.execSQL(sqlStr);
            onCreate(db);

            //Log.d(this.getClass().getName(), sqlStr);
            //Log.d(this.getClass().getName(), "Upgrade End");
        }
    }
}

================================================================================

AppointmentGroup.java

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class AppointmentGroup {
    private DayClass mDay;
    private List<Appointment> mList;

    AppointmentGroup(final DayClass day) {
        this.mDay = day;
        mList = new ArrayList<>();
    }

    public String getDayName() {
        switch (mDay) {
            case MONDAY:
                return "Monday";
            case TUESDAY:
                return "Tuesday";
            case WEDNESDAY:
                return "Wednesday";
            case THURSDAY:
                return "Thursday";
            case FRIDAY:
                return "Friday";
            default:
                return "Unknown Day";
        }
    }

    public boolean add(Appointment appointment) {
        //if (!mList.isEmpty()) {
            for (Appointment element : mList) {
                if (appointment.getId() == element.getId())
                    return false;
            }
        //}
        mList.add(appointment);
        return true;
    }

    public void clear() {
        mList.clear();
    }

    public String getSchedules() {
        if (mList.isEmpty()) {
            return "No appointments";
        }

        StringBuilder sb = new StringBuilder("");
        Iterator<Appointment> iterator = mList.iterator();
        boolean initialLoop = true;
        while (iterator.hasNext()) {
            Appointment appointment = iterator.next();

            if (initialLoop) initialLoop = false;
            else sb.append("n");
            sb.append(appointment.toString());
        }

        return sb.toString();
    }
}

===================================================================================

AppointmentGroupAdapter.java

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;
public class AppointmentGroupAdapter extends CustomAdapter<AppointmentGroup> {
    public AppointmentGroupAdapter(Context context, int resource, int textViewResourceId, List<AppointmentGroup> objects) {
        super(context, resource, textViewResourceId, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        TextView day;
        TextView detail;
        AppointmentGroup group = getItem(position); // group is not null

        if (convertView == null) {
            view = mInflater.inflate(mResource, parent, false);

            day = (TextView) view.findViewById(R.id.textViewGroupDay);
            detail = (TextView) view.findViewById(R.id.textViewGroupSchedule);
            view.setTag(new GroupViewHolder(day, detail));
        } else {
            view = convertView;
            GroupViewHolder holder = (GroupViewHolder) view.getTag();
            day = holder.day;
            detail = holder.detail;
        }

        if (day != null) day.setText(group.getDayName());
        if (detail != null) detail.setText(group.getSchedules());

        return view;
    }

    private final class GroupViewHolder {
        TextView day;
        TextView detail;

        GroupViewHolder(TextView day, TextView detail) {
            this.day = day;
            this.detail = detail;
        }
    }
}

============================================================================

CustomAdapter.java

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class CustomAdapter<T> extends BaseAdapter implements Filterable {
    protected List<T> mObjects;
    private final Object mLock = new Object();
    protected int mResource;
    private int mDropDownResource;
    protected int mFieldId = 0;
    private boolean mNotifyOnChange = true;
    private Context mContext;
    private ArrayList<T> mOriginalValues;
    private ArrayFilter mFilter;
    protected LayoutInflater mInflater;

    public CustomAdapter(Context context, int resource) {
        init(context, resource, 0, new ArrayList<T>());
    }

    public CustomAdapter(Context context, int resource, int textViewResourceId) {
        init(context, resource, textViewResourceId, new ArrayList<T>());
    }

    public CustomAdapter(Context context, int resource, T[] objects) {
        init(context, resource, 0, Arrays.asList(objects));
    }

    public CustomAdapter(Context context, int resource, int textViewResourceId, T[] objects) {
        init(context, resource, textViewResourceId, Arrays.asList(objects));
    }

    public CustomAdapter(Context context, int resource, List<T> objects) {
        init(context, resource, 0, objects);
    }

    public CustomAdapter(Context context, int resource, int textViewResourceId, List<T> objects) {
        init(context, resource, textViewResourceId, objects);
    }

    public void add(T object) {
        synchronized (mLock) {
            if (mOriginalValues != null) {
                mOriginalValues.add(object);
            } else {
                mObjects.add(object);
            }
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void addAll(Collection<? extends T> collection) {
        synchronized (mLock) {
            if (mOriginalValues != null) {
                mOriginalValues.addAll(collection);
            } else {
                mObjects.addAll(collection);
            }
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void addAll(T... items) {
        synchronized (mLock) {
            if (mOriginalValues != null) {
                Collections.addAll(mOriginalValues, items);
            } else {
                Collections.addAll(mObjects, items);
            }
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void insert(T object, int index) {
        synchronized (mLock) {
            if (mOriginalValues != null) {
                mOriginalValues.add(index, object);
            } else {
                mObjects.add(index, object);
            }
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void remove(T object) {
        synchronized (mLock) {
            if (mOriginalValues != null) {
                mOriginalValues.remove(object);
            } else {
                mObjects.remove(object);
            }
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void clear() {
        synchronized (mLock) {
            if (mOriginalValues != null) {
                mOriginalValues.clear();
            } else {
                mObjects.clear();
            }
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void sort(Comparator<? super T> comparator) {
        synchronized (mLock) {
            if (mOriginalValues != null) {
                Collections.sort(mOriginalValues, comparator);
            } else {
                Collections.sort(mObjects, comparator);
            }
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
        mNotifyOnChange = true;
    }

    public void setNotifyOnChange(boolean notifyOnChange) {
        mNotifyOnChange = notifyOnChange;
    }

    private void init(Context context, int resource, int textViewResourceId, List<T> objects) {
        mContext = context;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mResource = mDropDownResource = resource;
        mObjects = objects;
        mFieldId = textViewResourceId;
    }

    public Context getContext() {
        return mContext;
    }

    public int getCount() {
        return mObjects.size();
    }

    public T getItem(int position) {
        return mObjects.get(position);
    }

    public int getPosition(T item) {
        return mObjects.indexOf(item);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        return createViewFromResource(position, convertView, parent, mResource);
    }

    private View createViewFromResource(int position, View convertView, ViewGroup parent, int resource) {
        View view;
        TextView text;

        if (convertView == null) {
            view = mInflater.inflate(resource, parent, false);
        } else {
            view = convertView;
        }

        try {
            if (mFieldId == 0) {
                //  If no custom field is assigned, assume the whole resource is a TextView
                text = (TextView) view;
            } else {
                //  Otherwise, find the TextView field within the layout
                text = (TextView) view.findViewById(mFieldId);
            }
        } catch (ClassCastException e) {
            Log.e("CustomAdapter", "You must supply a resource ID for a TextView");
            throw new IllegalStateException("CustomAdapter requires the resource ID to be a TextView", e);
        }

        T item = getItem(position);
        if (item instanceof CharSequence) {
            text.setText((CharSequence) item);
        } else {
            text.setText(item.toString());
        }

        return view;
    }

    public void setDropDownViewResource(int resource) {
        this.mDropDownResource = resource;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        return createViewFromResource(position, convertView, parent, mDropDownResource);
    }

    public static ArrayAdapter<CharSequence> createFromResource(Context context, int textArrayResId, int textViewResId) {
        CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
        return new ArrayAdapter<>(context, textViewResId, strings);
    }

    public Filter getFilter() {
        if (mFilter == null) {
            mFilter = new ArrayFilter();
        }
        return mFilter;
    }

    private class ArrayFilter extends Filter {
        @Override
        protected FilterResults performFiltering(CharSequence prefix) {
            FilterResults results = new FilterResults();

            if (mOriginalValues == null) {
                synchronized (mLock) {
                    mOriginalValues = new ArrayList<>(mObjects);
                }
            }

            if (prefix == null || prefix.length() == 0) {
                ArrayList<T> list;
                synchronized (mLock) {
                    list = new ArrayList<>(mOriginalValues);
                }
                results.values = list;
                results.count = list.size();
            } else {
                String prefixString = prefix.toString().toLowerCase();

                ArrayList<T> values;
                synchronized (mLock) {
                    values = new ArrayList<>(mOriginalValues);
                }

                final int count = values.size();
                final ArrayList<T> newValues = new ArrayList<>();

                for (int i = 0; i < count; i++) {
                    final T value = values.get(i);
                    final String valueText = value.toString().toLowerCase();

                    // First match against the whole, non-splitted value
                    if (valueText.startsWith(prefixString)) {
                        newValues.add(value);
                    } else {
                        final String[] words = valueText.split(" ");
                        for (String word : words) {
                            if (word.startsWith(prefixString)) {
                                newValues.add(value);
                                break;
                            }
                        }
                    }
                }

                results.values = newValues;
                results.count = newValues.size();
            }

            return results;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            //noinspection unchecked
            mObjects = (List<T>) results.values;
            if (results.count > 0) {
                notifyDataSetChanged();
            } else {
                notifyDataSetInvalidated();
            }
        }
    }
}

=================================================================================

DayClass.java

import android.support.annotation.Nullable;
public enum DayClass {
    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY;//, SATURDAY, SUNDAY;

    @Nullable
    public static DayClass fromInteger(int day) {
        switch (day) {
            case 0:
                return MONDAY;
            case 1:
                return TUESDAY;
            case 2:
                return WEDNESDAY;
            case 3:
                return THURSDAY;
            case 4:
                return FRIDAY;
            //case 5:
            //    return SATURDAY;
            //case 6:
            //    return SUNDAY;
        }
        return null;
    }

    public static int toInteger(DayClass day) {
        switch (day) {
            case MONDAY:
                return 0;
            case TUESDAY:
                return 1;
            case WEDNESDAY:
                return 2;
            case THURSDAY:
                return 3;
            case FRIDAY:
                return 4;
            //case SATURDAY:
            //    return 5;
            //case SUNDAY:
            //    return 6;
        }
        return 7;
    }
}

=====================================================================================

DeleteAppointmentActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class DeleteAppointmentActivity extends AppCompatActivity {
    private List<Appointment> mAppointmentList;
    private AppointmentAdapter mListAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //Log.d(this.getClass().getName(), "Create Start");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_delete_appointment);

        initResources();

        //Log.d(this.getClass().getName(), "Create End");
    }

    @Override
    protected void onResume() {
        //Log.d(this.getClass().getName(), "Resume Start");

        super.onResume();

        getAllAppointments();
        mListAdapter.notifyDataSetChanged();

        //Log.d(this.getClass().getName(), "Resume End");
    }

    private void initResources() {
        mAppointmentList = new ArrayList<>();
        mListAdapter = new AppointmentAdapter(this, R.layout.appointment_row, R.id.checkboxAppointment, mAppointmentList);
        final ListView listView = (ListView) findViewById(R.id.listViewDelete);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setAdapter(mListAdapter);
    }

    public void onClickBack(View view) {
        finish();
    }

    public void onClickDelete(View view) {
        //Log.d(this.getClass().getName(), "Del Start");

        Set<Integer> checkedList = mListAdapter.getCheckedList();
        if (!checkedList.isEmpty()) {
            StringBuilder sb = new StringBuilder(checkedList.toString());
            String strCheckedIdList = sb.substring(1, sb.length() - 1);
            AppointmentDataSource.getInstance().deleteAppointment(strCheckedIdList);
            Toast.makeText(DeleteAppointmentActivity.this, "Appointment(s) deleted", Toast.LENGTH_SHORT).show();
            //Log.d(this.getClass().getName(), "Del End");
            finish();
        } else {
            Toast.makeText(DeleteAppointmentActivity.this, "Appointment(s) should be selected", Toast.LENGTH_SHORT).show();
            //Log.d(this.getClass().getName(), "Del End");
        }
    }

    public void getAllAppointments() {
        //Log.d(this.getClass().getName(), "getAllAppointments Start");
        AppointmentDataSource.getInstance().getAllAppointments(mAppointmentList);
        //Log.d(this.getClass().getName(), "getAllAppointments End");
    }
}

=================================================================================

NewAppointmentActivity.java

import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;
public class NewAppointmentActivity extends AppCompatActivity {
    private Appointment mAppointment;
    private RadioGroup mRadioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //Log.d(this.getClass().getName(), "Create Start");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_appointment);

        initResources();

        //Log.d(this.getClass().getName(), "Create End");
    }

    @Override
    public void onResume() {
        //Log.d(this.getClass().getName(), "Resume Start");

        super.onResume();

        //Log.d(this.getClass().getName(), "Resume End");
    }

    private void initResources() {
        mAppointment = new Appointment();
        mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup);
    }

    public void onClickBack(View view) {
        finish();
    }

    @Nullable
    private DayClass getSelectedDay() {
        switch (mRadioGroup.getCheckedRadioButtonId()) {
            case R.id.radioButton1:
                return DayClass.MONDAY;
            case R.id.radioButton2:
                return DayClass.TUESDAY;
            case R.id.radioButton3:
                return DayClass.WEDNESDAY;
            case R.id.radioButton4:
                return DayClass.THURSDAY;
            case R.id.radioButton5:
                return DayClass.FRIDAY;
            default:
                //Log.d(this.getClass().getName(), "Unknown RadioButton Clicked");
                return null;
        }
    }

    public void onClickCreate(View view) {
        //Log.d(this.getClass().getName(), "New Start");

        final EditText editTextTime = (EditText) findViewById(R.id.editTextTime);
        final EditText editTextDuration = (EditText) findViewById(R.id.editTextDuration);
        final EditText editTextDescription = (EditText) findViewById(R.id.editTextDescription);

        mAppointment.setId(0); // Dummy Value : 0
        mAppointment.setDay(getSelectedDay());
        mAppointment.setTime(editTextTime.getText().toString().trim());
        mAppointment.setDuration(editTextDuration.getText().toString().trim());
        mAppointment.setDescription(editTextDescription.getText().toString().trim());

        if (mAppointment.isValid()) {
            AppointmentDataSource.getInstance().insertAppointment(mAppointment);
            Toast.makeText(NewAppointmentActivity.this, "Appointment created", Toast.LENGTH_SHORT).show();
            //Log.d(this.getClass().getName(), "New End");
            finish();
        } else {
            Toast.makeText(NewAppointmentActivity.this, "Day should be selected", Toast.LENGTH_SHORT).show();
            //Log.d(this.getClass().getName(), "New End");
        }
    }
}
Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.