How to Dynamically Add Radio Buttons

Haven’t seen a tutorial for this that isn’t badly spelled and hard to grok, so I’ll try it.

First, include the radio group widget and and declare one. You’ll also need LayoutParams and RadioButton, so include those as well.

Inside your onCreate method, initialize the radio group.

R.id.radio_selection_group is referring to a radio group that’s declared in your XML file, so make sure you have that as well.

Back in SomeAndroidActivity, create a method to dynamically add buttons to the radio group.

Then call that method in onCreate.

Easy pie.

How to Stay Warm on a Motorbike for Cheap

I’ve had my bike insured and running since January, and damn if today wasn’t the first decent weather we’ve had in all that time.

Step 1:

Gloves. If you’re a responsible adult, get some that have nice, plush lining, carbon knuckles, leather shells with no perforations. Gauntlets that go all the way up to your elbow. Velcro fasteners. Spend $200.

If you’re an irresponsible adult, like me, who can’t keep track of a pair of gloves for more than one year, get whatever you can for 40 bucks and hope for the best. When you start to feel pain in your fingertips, turn back. When the pain goes away, pull over at once and thaw out.

Step 2:

Jacket… and another jacket underneath.

2013-03-22 17.50.13
That’s a textile jacket with a lining, and a leather jacket underneath.

And a hoodie under that, and a thermal tee under that, and a tshirt as well. And just to be safe, stuff some newspapers down the front to block the zipper draft. And wear a tshirt around your neck, scarf style. Or even just a scarf. But tshirts seem to be easier to wrap around your face, bandit style, to keep your chin nice and warm.

Step 3:

Long johns. I got a super fancy pair of merino ones long ago. Best thing in the world. Wear them under your usual pants, then wear Carhartts over that. Take the Carhartts off before you go into a place of business, those things are disgraceful.

Step 4:

Boots. The higher top the better. I dunno, I’ve just been wearing these, and they seem to work ok. At least, my feet aren’t any colder than the rest of me.

Air Force BootsYou can get them by joining Air Cadets, then keeping your issued uniform after you quit. Or, the army surplus store.

Step 5:

Just stay inside for god’s sake, this is ridiculous.

 

What is going on in my community?

I don’t know, but I’d like to.

I’ve got a team gathered, and we’re going to spend the next three months trying to answer that question. We’re making a website for people who care about Victoria. We want to know what decisions are being talked about right now, and who’s involved in making those decisions. This information is freely available online from a wide variety of sources, many of which are out of date, and of questionable reliability. City council meetings are open to the public, and take place on Monday evenings a few times a month.

Last Monday night I thumped into a City Council meeting, 10 minutes late because I couldn’t find the front door. The esteemed Councillors and the Mayor stared at me, aghast, as I burst through the emergency exit, carrying a motorcycle helmet.

After I got comfy in the front row, they continued to discuss the agenda, furtively glancing my way now and then.

They talked about garbage collection, street people, and special trees. I think. I couldn’t really hear much, as they were talking quietly and didn’t seem to be bothering with the microphones that each seat was equipped with.

I’ve got a copy of the agenda from that meeting, but it’s pretty dense, to be honest. I would have liked to hang around and chat about stuff with the councilors afterwards, but they threw me out at halftime.

So we’re making a website

It’s about Victoria and the surrounding neighborhoods, with a little bit of Wikipedia and a little bit of Reddit, with our own twist thrown in.

The Wiki

The wiki is mainly about politicians and ongoing local issues. On typical politician’s profile, you’ll see his official junior-intern-curated bio on the left half of the page.

And on the right, there’s the other side of the story. A community-edited wiki where citizens can add what they know about the pol – what they’ve voted for, what their special interests are, what core values they’ve demonstrated through words and actions over the years. If there’s a big discrepancy between the official bio and the community version, you’ll know to be suspicious.

A hypothetical politician's profile.
A hypothetical politician’s profile.

Likewise, if the pol is well-respected, hard-working, upright and honest, full credit will be given, and you’ll know that this is someone you can vote for.

The Reddit

Reddit is a great place to waste time, and also a great place to learn. Users submit links to articles, or text posts. New, controversial, and popular items float to the top and the front of the site. The content is always changing and always current.

An example of how the reddit page might work.
An example of how the reddit page might work.

On our page the first thing you’ll see is a bunch of questions. They’re going to ask things like, “Should we let Mr Clyde off the hook for his garbage collection bill this month, since he’s managed to get his annual trash down to basically nothing?”** , and other questions submitted by users.

The current administration seems a bit condescending towards Victoria youth. Let's show them how hard we're trying, despite how difficult it is to live in this city.
The current administration seems a bit condescending towards Victoria youth. Let’s show them how hard we’re trying, despite how difficult it is to live in this city.

And you can vote yes or no, or check the comments and see what everyone else thinks. The fun part is, your votes are tracked on a political compass. So if you vote like Mayor Leonard does, you move closer to him on the compass. If you always vote differently from Elizabeth May, you move away from her.

So you can see how many other people around Vic kind of agree with you on stuff, and go meet up with them, or try to convince them to see things differently, or maybe find out why a lot of people think different from you (maybe you’re wrong??). And you can also see whether a politician is going to vote for the same things you’d vote for, so that will help you when it’s time to cast ballots.

People claim they don’t vote because they don’t know enough about what’s going on. Let’s take that excuse away. Also, let’s make election day a paid stat hol, that should help as well. Do you agree? Well, you’ll be able to let me know on the site soon enough.

An example of something that young Victorians feel strongly about. The author made their feelings known on St Pat's during the 20 minutes I was inside a McDonald's. Let's give people like them a better place to be heard.
An example of something that young Victorians feel strongly about. The author made their feelings known on St Pat’s during the 20 minutes I was inside a McDonald’s. Let’s give people like them a better place to be heard.

 

** Actual agenda meeting discussed in council chambers. Is this question too trivial for you to care about? Tell them.

Goats are cool

Today I found a blog written by a seven year old named Yefet. It’s pretty good.

 

Baby Goats
Baby Goats

What makes it good:

  • His posts are very short.
  • He writes about stuff he does and enjoys, like raising his goats (he lives on a farm).
  • He is very lucky to have parents that take him to do interesting things.
  • The pictures are great.

I’m going to take a lesson from Yefet and end this post here. But go over and read his stuff!

Awkward. …Pause.

Have you ever been ignored?

People are chatting about something, you interject. In a loud clear voice, a comment that you think is funny, or smart, or at least worthy of acknowledgement. Just a grunt. Just a glance. But they ignore you.

woman

No? Just me, huh?

(Don’t mind the beautiful people, they’re just here to make reading a little easier).

I want to understand why this happens, cause it does happen, a lot. The more I become aware of how other people interact, the more sensitive I am to it. Some people say it is because my voice is different. The hard-of-hearing accent is odd-sounding L’s and R’s, missing T’s, K’s and S’s, and a lower pitch overall. Maybe this voice is so unexpected that people miss it, the way drivers sometimes miss seeing a motorcyclist. They expect 2 headlights, not one, so they don’t see the one headlight at all. Splat.

Other people say it’s a problem of timing. Even with the best mechanical ears money can buy, I only hear a small percentage of the words in a conversation. My brain fills the rest in based on context. It’s hard work, and sometimes there’s a millisecond processing delay. You know how when you’re Skyping, and the connection is a bit slow? There’s a delay, and you keep accidentally talking over the other person. Even if it’s your friend that you normally have great conversations with, the delay causes awkwardness because the timing is off.

So, I’ve got a little of that going on, but in real life.

Any other ideas?

ryan

 

Weekly Report #2

107 days remain til June 25. Not that I’m counting. But that’s the day I’m leaving for Australia, and anything that doesn’t fit in my carry on luggage ain’t coming.

Today’s a day of purging. I just went through my clothes and found 35 lbs of stuff I don’t care enough to keep.

That’s a lie.

Some of that stuff hurts to get rid of. Purging is a time of introspection – you think about how you spend your time, and you have to justify your choices based on that.

How much time do you spend in nightclubs, nice restaurants, places with dim lighting and dress codes? For me,  not much. That gets rid of about 15 lbs on its own – and it’s not like I had anything really fancy for those occasions anyway. How much time do you spend on your back in the mud, at the racetrack, or in the garage? Quite a bit more. But how many crappy pairs of jeans do you really need? Just one should do it, I think. There goes another 15 lbs. How much time do you spend at the river, the beach, riding my bike, tramping in the woods? Probably not enough. I kept a lot of that stuff, ambitiously. Dress for the life you want, right?

I ended up with a lot of jeans, short pants, purple, green and black T-shirts  and soft materials. Hopefully this’ll help me shop properly in the future.

Clearly, I know what I like.
Clearly, I know what I like.

This is hard. It really underscores the fact that I don’t know what the hell I’m doing with my life. If I was living the life I wanted, I’d have a lot of cycling jerseys, shorts and really hip jeans, for alleycat races and road rides.

I’d have tactical clothing full of pockets for helicoptering into the forest and getting really up close and personal about environmental data collection. I’d have a T-shirt with my own company’s logo on it, one of dozens that are tossed around at tech conferences. What I’ve got instead is a lot of black T-shirts and cheap jeans, for looking presentable and unremarkable in generic company. It’s like a blank slate that just keeps on being blank.

That’s what I have left after I get rid of all the stuff that isn’t me.

A different kind of college course

 

Bluetooth is not an easy thing to deal with, my instructor tells me. I didn’t believe him, and spent several fruitless weeks trying to get the Morse code Bluetooth chat app to work correctly.

The nature of application development, especially when it’s for a platform other than the one you write code on, is that you constantly stumble over bugs, weirdness and strange errors that aren’t your fault at all. It’s discouraging.

Even so, the course I’m currently taking in Android application development is the most interesting one I’ve had in my two-year Computer Systems Tech diploma program.

It was supposed to be about computer graphics. But the guy meant to teach it dropped out for some reason, and another teacher, here referred to as Robocop to protect his privacy, stepped in.

Robocop had about 3 weeks to come up with a curriculum, so the normal method of curriculum development wasn’t going to work. Instead he used the considerable leeway that the college allowed, to construct an experiment.

6 projects – students proposed and voted on ideas. (Time savings for the teacher – no assignment development).

Anyone can work in any project they want. Download the source from git, decide what you want to do, and do it. Push the changes, then sit back and wait for everyone else to bawl at you for breaking the build. Marking is done by peer reviews. You get a mark out of 10 based on whatever you’ve done this week, so anyone who makes a reasonable effort and documents it can have a perfect score. (Theoretical time savings for teacher – no assignment marking.)

The great thing is, you get as much out of it as you put in. You could do the bare minimum of testing code and maybe tossing out a toString or a small refactor once in a while, or you could rally a team, spend night and day working on, talking about, living in it, and create a commercial grade application from scratch, in three months, with adult supervision the whole time. (Now that I’m an adult I freaking loooove having adult supervision. Takes so much pressure off.)

I wouldn’t say it’s a 100% success – Robocop originally thought that we’d be able to come up with 6 commercially viable, clean, usable Android apps by the end of quarter. I think we’ll be lucky if even one of them technically does what we originally set out to do. Some people wasted a lot of time being confused, asking “What am I supposed to do? Where are the instructions?”

But as an experiment, it’s a home run. As education, it’s exactly what I wanted out of college. Preparation for working with people you don’t necessarily like, who might make brilliant decisions sometimes and really odd ones other times. The hot shame of responsibility for ruining weeks of other people’s work. The freedom to make whatever you want, if you can get the others to play along. I don’t know if the course will work long term for the college, since all the time Robocop saved before class started, he has to pay back trying to keep up with 6 open projects. I hope they keep it.

For me, personally, it’s not a success yet. Not until I can get the stupid Bluetooth connection to work right.

 

 

Signals, Pulses, and Messages in C

Further studies in pulses…messages… AND SIGNALS!

Sorry. Signals don’t rate capslock, tbh. But I shall attempt to teach you about them.

The usual includes. msg.h is my teachers’ concoction, and may be found here.

 

Gonna need some globals – the main and a couple of helpter functions both need to access the logfile, the channel id, and the timestruct.

Begin!

 

Initialize the timestruct, cos it is no longer 1970 and I am not Dennis Ritchie.

 

The void pointer – a promise of a method, soon to be revealed.

 

That logfile declaration from above? Time to use it! This is nothing more than a textfile where your program is going to write some stuff down.

 

A couple more variables; theMessage is a handle for data that is received from the client. rcvid will be used to tell the client which of it’s many messages you are currently replying to.

 

Upon startup, this message logger will report its process id, channel id, and node descriptor, and log that info in a pidfile. As I write this I can’t help noticing that chid isn’t initialized yet. I really hope I figure out an explanation for that later.

 

This bit is kinda weird. These two functions are both at the bottom of this program, so you’re sending pulses and signals to yourself. Why do that? Narcissism? Shpakism? Just do it.

This is also weird. You’re bascially announcing, “Hey, a signal might show up, and if it does, here’s what you do.” And that instruction is standing orders for the rest of the program, or til you change it.

K, with all that established, begin a for loop that will run until further notice, taking messages and reporting them in the logfile.

Now, this part confuses me. Cause I thought that a pulse was just a message, with a rcvid of zero. But the teacher has us, apparently, handling two cases that both match the definition of “pulse” in my mind.

So, the first “if” handles rcvid == 0.

The second “if” redirects to a helper method that has the same big switch statement from my previous post. It also handles a “pulse”, and like I said, I’m confused. However, I swear to god this code runs and drive as written.

Take note of the timeToQuit int there. It takes the return value of the handleMessage function – if the message was a … sigh … pulse, I guess … it returns something other than zero, which terminates the loop, and the program.

So where are these pulses and signals coming from? Upsettingly, they are coming from within this very program.

Here’s the setup for a pulse. It is straight out of Getting Started With QNX Neutrino, which can be found here, page 152. RTFM fools.

The signal setup works almost exactly the same, there’s like one line that’s different.

My message handler. It logs a message if a message turns up, and shuts the whole show down if a confusingly explained pulse shows up.

And finally, the signal handler. It’s pretty easy.

And that’s the whole mess. It runs on my machine; I take no responsibility if it causes your computer to have a stroke instead. Here’s the finished code.

How to write a message logger in C

You are probably here because some demanding professor has ordered you to produce an example of a program that recieves messages and pulses and logs stuff about them.

Here I will provide  the answer to all your questions. Well, some of your questions.

I can’t, for example, tell you why you decided to take this stupid degree in the first place.
I can’t tell you where to find true love, or the secret of happiness.

I can’t even tell you how to code – I can attempt to give you some information, but everyone basically has to teach themselves how to program. Also, I apologize for the formatting – wordpress’s text editor is literally the worst thing in the universe.

Oh well, read on if you must.
First, some inclusions. The usual suspects – we’ll need the ability to write to the command line, concatenate a string, make timestamps.

“msg.h” is a header file provided by my teacher. There’s a bunch of stuff in there, but the important bits are:

The message header can be accessed by theMessage.m_hdr. Pulses can send codes, and this particular pulse code can be accessed with theMessage.pulse.code. I can’t remember what the rest of the includes are for. I might’ve copied them from a different lab.

Begin!

First, we’re going to need a bunch of variables.

You could probably write a better usage message. This just means that the program was called with too few arguements – no logfile was specified, so it doesn’t know where to store logs.

Establish a connection to whatever client program is trying to get ahold of you. This function will not execute until the client shows up.

When the client does show up, its process id, channel id and node descriptor will be recorded in the pidfile, via this bit:

Then open the logfile to record whatever messages the client wants to send.

At this point, you’re going to start an infinite while loop. It will keep running as long as the client wants to keep sending messages. It only terminates when the client sends a pulse.

In each iteration of the while loop, the logger looks for a new message and stores it at theMessage’s memory location. The timestruct initalization doesn’t have to be in the while loop, but there it is. It does have to exist though, cause if you don’t initialize the timestruct then it will just claim that it’s Jan 1 1970. You can pass arguments to specify a time format, or just send it null for the default.

Next is a switch to check the message header to see what sort of thing it is.

  • If it’s a regular message, it’ll have a unique rcvid.
  • If it’s a pulse, the rcvid will be 0, since you don’t need to reply to pulses. The whole idea of a pulse is that it’s non-blocking – it doesn’t wait for a reply. Kinda like HTTP, in that pulses sends out messages and hope for the best. If no acknowledgement arrives after while it just gives up./li>

The first case, a proper message arrives. Report on the command line that something happened, and log the item and the date. Reply with an acknowledgement that the message is fine, flush the buffer, and carry on.

In this program, we’re using pulses to terminate the logger program. So if a pulse arrives,

You know it’s a pulse because the theMessage.m_hdr == 0, though it’s translated to the enum MSG_ENG for the sake of readability.

If anything other than a pulse or a valid message turns up, the logger just shrugs and carries on.

And that’s basically it – just clean up and exit.

The Complete Code

I hope it’s helpful. I also hope you actually understand it, rather than just turning it in as is.

msg.h