<file_sep># ConOrganiser

This is a basic project which will allow convention hosts to share their schedule of events with their attendees.

Currently this will only hold changes local but in future hopefully will be able to read from a database of events instead

<file_sep>package com.example.daniel.myapplication;

import android.content.Context;
import android.util.Log;

import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

/**
 * Created by Daniel on 28/03/2016.
 */
public class FileManager {
    private static ArrayList<Event>eventList = new ArrayList<Event>();

    public static void writeToFile(Event pEvent,Context pContext) {
        try {

            FileOutputStream fos = pContext.openFileOutput("userEvents", pContext.MODE_PRIVATE);
            ObjectOutputStream os = new ObjectOutputStream(fos);
            if(!eventList.contains(pEvent)) {
                eventList.add(pEvent);
            }

            for(int count=0;count < eventList.size();count++){
                   os.writeObject(eventList.get(count));
               }



            os.close();
            fos.close();
        }
        catch(Exception ex)
        {
            Log.w("exception writing out",ex.getMessage());
        }

    }

    public static void readFromFile(Context pContext){

        eventList.clear();
        boolean isRunning = true;

        try {
            FileInputStream fis = pContext.openFileInput("userEvents");


            ObjectInputStream is = new ObjectInputStream(fis);
            while(isRunning) {
                try {
                    Event event = (Event) is.readObject();
                    eventList.add(event);
                }
                catch(EOFException ex)
                {
                    isRunning = false;
                }
            }
            for(int count =0; count < eventList.size();count++){
                Log.d("read input","event " + count + " is " + eventList.get(count).eventName);
            }

            is.close();
            fis.close();
        }
        catch(Exception ex){
            Log.w("exception reading in",ex.getMessage());
        }
    }

}
<file_sep>package com.example.daniel.myapplication;

import android.app.ActionBar;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

/**
 * Created by Daniel on 25/03/2016.
 */
public class EventButton extends Button
{
    public Button button = this;
    public String eventHost;
    public String eventName;
    public Calendar eventDate;
    public Calendar backup;
    private LinearLayout screen;

    public EventButton(Context context, String pHost, String pName, Calendar pDate)
    {
        super(context);
        eventHost=pHost;
        eventName=pName;
        eventDate=pDate;
        setOnClick();



        this.setText(pName + "\n " + pHost);

    }

    public int getTimeDifference(){
        Calendar currentTime=Calendar.getInstance();
        int difference =0;

        int startHour = eventDate.get(eventDate.HOUR_OF_DAY);
        int currentHour = currentTime.get(currentTime.HOUR_OF_DAY);

        int startMinute = eventDate.get(eventDate.MINUTE);
        int currentMinute = currentTime.get(currentTime.MINUTE);

        int overallStart = (startHour *60) + startMinute;
        int overallCurrent = (currentHour * 60) + currentMinute;


        int overall = overallStart - overallCurrent;
        //Log.d("current Time", currentTime.toString());

        Toast.makeText(getContext(), "time until event " + eventName + " is " + overall + " minutes away", Toast.LENGTH_SHORT).show();


        return overall;
    }

    public boolean AddButtonToScreen(LinearLayout lineaerLayout1 , LinearLayout.LayoutParams lp){
        screen = lineaerLayout1;
        lineaerLayout1.addView(button, lp);
        return false;
    }

    public void RemoveButtonFromScreen(){
        if(screen != null){
            Log.d("screen removal", "the button has been removed");
            screen.removeView(button);
            screen = null;
        }
        else{
            Log.e("nothing to delete ","the specified variable does not exist");
        }

    }

    public boolean GetIsEventToday(){
        Calendar currentDate = Calendar.getInstance();

        int currentDay = currentDate.get(currentDate.DAY_OF_MONTH);
        int currentMonth = currentDate.get(currentDate.MONTH);
        int currentYear = currentDate.get(currentDate.YEAR);

        int eventDay = eventDate.get(eventDate.DAY_OF_MONTH);
        int eventMonth = eventDate.get(eventDate.MONTH);
        int eventYear = eventDate.get(eventDate.YEAR);

        if(currentYear == eventYear){
            if(currentMonth == eventMonth){
                if(currentDay == eventDay){
                    return true;
                }
            }
        }
        return false;
    }


    public void setOnClick() {
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                FileManager.writeToFile(new Event(eventHost,eventName,eventDate),getContext());

                FileManager.readFromFile(getContext());
              /*  int timeTilEvent =getTimeDifference();
                int day = eventDate.get(eventDate.DAY_OF_MONTH);
                int month=eventDate.get(eventDate.MONTH);
                int year=eventDate.get(eventDate.YEAR);
                int hour=eventDate.get(eventDate.HOUR_OF_DAY);
                int minute=eventDate.get(eventDate.MINUTE);
                String minutestring=""+ minute;

                if(minutestring.length()==1){
                    minutestring = "0"+minute;
                }


                if(timeTilEvent <= 15 && timeTilEvent > 0){
                    Log.d("timeTilEvent " , "there is " + timeTilEvent + " minutes until the event " + eventName);
                }
                else if(timeTilEvent <= -15  && GetIsEventToday() == true){
                    Toast.makeText(getContext(), "sorry you have missed the event " + eventName, Toast.LENGTH_SHORT).show();
                    Log.d("timeTilEvent", "you missed the event " + eventName);
                    RemoveButtonFromScreen();
                }


                String dateOutput= day + "/" + month +"/" + year + "\n " + hour + ":" + minutestring;
                Toast.makeText(getContext(), "speaker: " + eventHost + "\n topic: " + eventName + "\n date: " + dateOutput, Toast.LENGTH_SHORT).show();*/
            }

        });

    }
}
<file_sep>package com.example.daniel.myapplication;

import android.app.ActionBar;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class MainActivity extends AppCompatActivity {
static int count=0;

    EventButton[] buttons = new EventButton[5];
    public void createButton(){


        final Button button = new Button(this.getBaseContext());
        button.setText("push me");
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(getBaseContext(), "hello world, button " + count + " was pressed", Toast.LENGTH_LONG).show();
                createButton();
            }

        });
        count++;
        LinearLayout ll = (LinearLayout) findViewById(R.id.LinearLayout1);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ll.addView(button, lp);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);

        
        buttons[0]=new EventButton(this.getBaseContext(),"<NAME>","how to be awesome",new GregorianCalendar(2016,05,01,00,00));

        buttons[1]=new EventButton(this.getBaseContext(),"Kate","cosplay masquerade",new GregorianCalendar(2016,05,01,17,00));

        buttons[2]=new EventButton(this.getBaseContext(),"Stephan","how to make cool stuff",new GregorianCalendar(2016,04,31,13,30));


        buttons[3]=new EventButton(this.getBaseContext(),"Lisa","sewing for beginners",new GregorianCalendar(2016,04,31,15,30));

        buttons[4]=new EventButton(this.getBaseContext(),"kate","mandatory jam tart praising session",new GregorianCalendar(2016,04,31,12,00));
        //button.AddButtonToScreen();

        LinearLayout ll = (LinearLayout) findViewById(R.id.LinearLayout1);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        for(int count=0;count < buttons.length;count++){
            if(buttons[count] != null) {
                buttons[count].AddButtonToScreen(ll, lp);
            }
        }



        }
    }


