Calendar

Hey everyone, I was looking to make an application that incorporated many things into one, one of the things I’d like to add to my project is a calendar. I want to do things with this calendar, like add reminders/notifications to it, but I’m not even sure how to do the calendar.

I want to be able to connect to a calendar I guess online so that I don’t have to edit it every year with where the month starts and all. I would like for the calendar to be in a box form similar to this: http://www.timeanddate.com/calendar/

Then I want to add a notification table I guess or um system to it, so that you can input notifications like:
Doctor’s Appointment 9:00 am
And at whatever time you give it, a notification box will pop up just like the Reminders App and tell you that you have a Doctor’s Appointment!

If someone could please help me out with this I’d be grateful as I’m very new to Codea and not sure how I’d do this. If you could point me in the right dorection as far as a tutorial that goes over this or code that is already shared, I’d be thankful!

Speakmore

personally, I think that is like trying to make a car into a boat.

Codea is specifically designed for animation, refreshing the screen 60 times a second, unlike most programming languages which leave stuff on the screen until you move it.

Also, Codea doesn’t have built in UI controls or databases, and although people have built UI libraries, it still isn’t a good fit for Codea, IMHO.

@Ignatz what would be the language for it then?
I’d really like to do a game but I don’t know where I’d get the graphics because I’m not good with them on the computer.

I have a big project idea for a game, but between needing graphics and me not being able to code good, it won’t happen. :frowning:

@Speakmore Don’t give up! Take small steps and keep learning with your game idea as a goal.

Actually, I’ve found Codea completely well-suited to building small business apps. I’m using them in my work all the time, putting together small forms and doing little apps for effeciency studies, etc.

Codea is animation friendly, not animation limited.

But back to the original question: I’ve not seen a calendar control. It’s a gaping hole in my Cider controls, and something that I’m often wishing for. Guess I need to make one.

I didn’'t mean to put you off, Speakmore. It’s just that you don’t want something that might be a small part of the overall game, becoming a huge part of the overall work. And I think a calendar will be a lot of work if you aren’t experienced.

If possible, I suggest you start with a very simple version of your game, and work up from there as your skills grow.

The Calendar has nothing to do with the game I wanted to make.

I’m unfortunately fading away from going/attempting to make a game. I’ve wanted to make them for 6 years or so now, and I just started coding last year in VB for class, and Java now for this years class, but never really any games.
I made a blackjack game in VB, took me a bit, but it looks nice and was easy to make as far as coding and hardcoding.

Like I said, games need graphics, and I can’t make them let alone code yet.

If it makes you feel better, I think hardly anyone here can draw, but there are stacks of free pix on the Internet. And everyone starts off unable to code, too.

If you are keen, you can learn to code in a couple of months. I come from VB myself, and I find Codea way better and a lot more fun. I don’t think there’s an easier way to build mobile apps.

So don’t be put off, but I do suggest starting with something easier than a calendar.

I’m checking out the Reefwing tutorials, but it’s pretty much copy and paste whatever he does.

I’ve done some too, here, I guess it’s a question of which style suits you

http://coolcodea.wordpress.com/

Hang in there. It gets easier, and all of us started out feeling confused. I know I did.

I’ll check out your tutorials too!
I suggested folders a few weeks ago, so that I can seperate my projects accordingly, because I duplicate my tutorial projects when I add stuff.

Calendar would be cool. By the way, thanks to everybody for posting the encouraging words, it certainly is a steep hill to climb sometimes when you’re starting out, but my interest in creating some cool apps keeps me wanting to continue, and the encouragement from all of you is a big help as well. Thanks.

Hi @Speakmore. I threw this together so you can use it / modify it how you want. Use the arrows at the top of the calendar to go to the previous or next month. Codea may be mostly for animation/games, but it still can be used for anything else too.


supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function setup()
    d=os.date("*t")
    year=d.year
    month=d.month
    startMonth()
    dName={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
    days={31,28,31,30,31,30,31,31,30,31,30,31}
    mName={"January","February","March","April","May","June",
           "July","August","September","October","November","December"}
end

function draw()
    background(40, 40, 50)
    stroke(255)
    strokeWidth(2)
    for z=1,8 do
        line(120,z*100-30,960,z*100-30)
        line(z*120,70,z*120,670)
    end
    dayName()
    dayNumber()
    monthName()
end

function monthName()
    textMode(CENTER)
    fontSize(35)
    fill(0,255,0)
    text(string.format("%s  %d",mName[month],year),WIDTH/2,HEIGHT-40)
    text("<---",150,HEIGHT-40)    -- previous month
    text("--->",930,HEIGHT-40)    -- next month
end

function dayName()
    fill(0,0,255)
    textMode(CORNER)
    fontSize(20)
    for z=1,7 do
        text(dName[z],z*120+10,670)
    end
end

function dayNumber()
    fill(255,0,0)
    if year%4==0 then
        days[2]=29    -- leap yesr
    else
        days[2]=28    -- not leap year
    end
    c=0
    n=1
    for y=1,6 do
        for x=1,7 do
            c=c+1
            if c>=dNbr and n<=days[month] then
                text(n,x*120+5,740-y*100)
                n=n+1
            end
        end
    end
end

function startMonth()
    t=os.time{year=year,month=month,day=1}
    d=os.date("*t",t)
    dNbr=d.wday
end

function touched(t)
    if t.state==BEGAN and t.y>700 then
        if t.x<WIDTH/2 then
            month=month-1    -- show previous month
            if month<1 then
                month=12
                year=year-1
            end
        else
            month=month+1    -- show next month     
            if month>12 then
                month=1
                year=year+1
            end
        end
        startMonth()
    end   
end

@dave1707 Thanks so much for this!
Gonna see how you did it then test it out!

I’m going to also try and see if I can scale the calendar down to where I want it, thanks so much for the time you put into it!

@beyond - keep going, it gets easier. I have learned a number of programming languages, and i always felt like a complete idiot for the first few weeks or so.

I didn’t have anything better to do, so I thought I would expand on the calendar program I posted above. This version will allow you to input and save information for any day you select. Tap on a day and an input window will open. The keyboard will show so you can input data. Pressing RETURN will save the data and close the window. A white asterisk will show for that date so you know there’s data there. Selecting a date that has an asterisk will display the data that was saved without showing the keyboard. If you want to add data, tap the show keyboard button at the bottom of the calendar. The input window has a button to delete all the data for that date and one to close the window. The arrows at the top of the calendar allow you to select the previous or next month. The information is saved as local data, so the data is saved when the program is closed and restored when the program starts. I didn’t add any type of pop up reminder for the data.


supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function setup()
    dowTab={}    -- day of week table
    dataTab={}    -- data table
    showData=false
    saveData=false
    sel=vec2(0,0)
    d=os.date("*t")    --get current date
    currMonth=d.month
    currDay=d.day
    currYear=d.year
    year=currYear
    month=currMonth
    dName={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
    days={31,28,31,30,31,30,31,31,30,31,30,31}
    mName={"January","February","March","April","May","June",
           "July","August","September","October","November","December"}
    startMonth()
    d=listLocalData()    -- get saved data and build data table
    for a,b in pairs(d) do
        dataTab[b]=readLocalData(b)
    end
end

function draw()
    background(40, 40, 50)
    stroke(255)
    strokeWidth(2)
    for z=1,8 do
        line(120,z*100-30,960,z*100-30)
        line(z*120,70,z*120,670)
    end
    dayName()
    dayNumber()
    monthName()
    if showData then
        dataWindow()
    end
    if saveData then
        saveTable()
    end
end

function keyboard(k)
    if k==RETURN then
        dataTab[tabStr]=dataTab[tabStr].."\
"
        hideKeyboard()
        showData=false
        saveData=true
    elseif k==BACKSPACE then
        dataTab[tabStr]=string.sub(dataTab[tabStr],1,string.len(dataTab[tabStr])-1)
    else
        dataTab[tabStr]=dataTab[tabStr]..k
    end
end

function saveTable()
    saveData=false
    clearLocalData()    -- delete local data
    for a,b in pairs(dataTab) do    -- save data table information as local data
        saveLocalData(a,b)
    end    
end

function dataWindow()
    fill(0,0,0)
    rect(240,370,600,370) 
    fontSize(17)
    fill(255)
    textMode(CORNER)
    textWrapWidth(600)
    line(240,680,840,680)
    if dataTab[tabStr]~=nil then
        text(dataTab[tabStr],250,390)
    end
    fontSize(25)
    text("Show keyboard",450,30)
    str=string.format("%d%d",sel.x,sel.y)
    text(dowTab[str],400,700)
    fill(255,0,0)
    text("Delete",250,700)
    fill(0,255,0)
    text("Close",770,700)
end

function createTab()    -- day of week, month, day, year
    local d=dNbr
    c=0
    n=1
    for y=6,1,-1 do
        for x=1,7 do
            c=c+1
            str=string.format("%d%d",x,y)
            dowTab[str]=""
            if c>=dNbr and n<=days[month] then
                str1=string.format("%s   %s   %d   %d",dName[d],mName[month],n,year)
                d=d+1
                n=n+1
                if d>7 then
                    d=1
                end
                dowTab[str]=str1
            end
        end
    end
end

function monthName()
    textMode(CENTER)
    fontSize(35)
    fill(0,255,0)
    text(string.format("%s  %d",mName[month],year),WIDTH/2,HEIGHT-40)
    text("<---",150,730)    -- previous month
    text("--->",930,730)    -- next month
end

function dayName()
    fill(0,0,255)
    textMode(CORNER)
    fontSize(20)
    for z=1,7 do
        text(dName[z],z*120+10,670)
    end
end

function dayNumber()
    if year%4==0 then
        days[2]=29    -- leap yesr
    else
        days[2]=28    -- not leap year
    end
    
    -- show day number in calendar. current date in green
    c=0
    n=1
    for y=1,6 do
        for x=1,7 do
            c=c+1
            if c>=dNbr and n<=days[month] then
                if month==currMonth and n==currDay and year==currYear then
                    fill(0,255,0)
                else
                    fill(255,0,0)
                end
                text(n,x*120+5,740-y*100)
                n=n+1
            end
        end
    end
    
    -- check data table for info and show asterisk
    fill(255)
    fontSize(40)
    for y=1,6 do
        for x=1,7 do
            str=string.format("%04d%02d%d%d",year,month,x,y)
            if dataTab[str]~=nil and dataTab[str]~="" then
                text("*",x*120+55,790-(8-y)*100)
            end
        end
    end
end

function startMonth()
    t=os.time{year=year,month=month,day=1}
    d=os.date("*t",t)
    dNbr=d.wday
    createTab()
end

function touched(t)
    if t.state==BEGAN then
        if showData then
            if t.x>775 and t.x<850 and t.y>700 and t.y<800 then    -- close
                showData=false
                sel=vec2(0,0)
                hideKeyboard()
            end
            if t.x>250 and t.x<350 and t.y>700 and t.y<800 then    -- delete
                dataTab[tabStr]=nil
                showData=false
                sel=vec2(0,0)
                hideKeyboard()
                saveData=true
            end
            if t.x>450 and t.x<600 and t.y>20 and t.y<60 then    -- show keyboard
                showKeyboard()
            end
            return
        end
        if t.x>80 and t.x<180 and t.y>700 and t.y<760 then    -- show previous month
            showData=false
            sel=vec2(0,0)
            month=month-1
            if month<1 then
                month=12
                year=year-1
            end
            startMonth()
            return
        end
        if t.x>875 and t.x<975 and t.y>700 and t.y<760 then    -- show next month
            month=month+1    
            if month>12 then
                month=1
                year=year+1
            end
            startMonth()
            return
        end
        for x=1,7 do    -- which day was touched
            for y=1,6 do
                if t.x>x*120 and t.x<x*120+120 and t.y>y*100-20 and t.y<y*100+80 then
                    str=string.format("%04d%02d%d%d",year,month,x,y)
                    tabStr=str
                    sel=vec2(x,y)
                    if dataTab[tabStr]==nil or dataTab[tabStr]=="" then
                        dataTab[tabStr]=""
                        showKeyboard()
                    end
                    showData=true
                end
            end
        end
   end   
end

@dave1707 I’m excited as ****!
That’s what I wanted for a portion of my application, thank you so much for making it for me (even though I didn’t request it)!
I’m so grateful for this.
Basically what I’m going to do with it now if yours doesn’t (I’ll test it when I get home) is send a notification to the lock screen or user that it’s time to do whatever they need to do.
So like the Reminders application given to you when you purchase an iPhone.
:smiley:

I’ll study the code so I see what you did and all, because eventually I want to be able to code this stuff on my own!
I’m going to look for a background to really make the calendar look nice!

Nice work, @dave1707.

I started a calendar project last year for our work schedule (24 hours on, 48 hours off) that allowed 3 user inputs per day (holidays, paydays, etc.) with the option of repeating user intervals. I ran into a few snags and eventually lost interest, much like all of my projects.

But it was a fun and educational journey.

I could post the code but it is quite ugly and experimental if I remember correctly. Looking forward to trying Dave’s much nicer code out tomorrow when I get off this 24 hour shift.

Anyway, good luck @Speakmore.

@Keebo thanks a bunch!

This is pretty much what I like to do, take a little time and crank out basic code. I’lI write code that does something basic and then let whoever wants it to either see what I did or take the code and expand on it for their use. If you have any questions on what I did, just ask. I probably don’t comment the code as much as I should.