Ever seen the face of deception?
How about this:
Any android programmer out there should run, now. For those brave to stay, don’t expect to stay sane.
So, I have always wanted to automate my workshop lights. The kind of useless shit a bit to show off and a bit to please oneself. Having a new and bigger place, allowed me to install enough lights as to sort of justify such endeavor.
To control the lights themselves, I opted for a cheap bluetooth relay board like this one:
They comunicate with any serial terminal and obey few simple rules.
- X0, “Momentary”: Activates relay 1 second.
- X1, “Self-locking”: Switches relay state.
- X2, “Interlock”: I don’t understand this function.
- X3, “Open”: Relay ON.
- X4, “Close”: Relay OFF.
With that in mind, I figured there should be some App in the playstore that would allow me to control the relays AND look good while doing it.
However, that wasn’t the case, not even the not-free ones. Everything kinda looks like this:
You can customize the commands sent by the buttons, and even sometimes the text displayed per button, but that’s it. Awful, right?
Once it was clear that no existing App could work for me, I decided to look into Android programming. Remember, I HATE progamming.
Anyhow, I ended in a sort of WYSWYG suite called Android Studio. I was sure I could not program an App from scratch, but maybe I could pick an open source one and modify it to suit my needs, as shabby the idea was.
After much looking, this gem was found. As hard as I tried, I wasn’t able to understand how it actually turned the text box content into a string for the bluetooth terminal “subroutine” to send it to the relay board, so I was forced to make the program extremely long, copypasting the same routine over and over. Anyhow, managed to hide it’s functions and piggyback new buttons and invisible text boxes into it.
First, I copypasted -> public void sendCommand(View view), renaming it sendCommand2. Also renamed commandEditText, to commandEditText2 (everything increases in number just to keep track of what I added).
With that, I created some text boxes in the activity_terminal.xml. The id will increase numerically as well “editText”, “editText2”, etc…
Add the relay commands in the text area, and make the box invisible.
Then, add some buttons, whose id will increase like the text boxes did. The text they will reflect comes from the strings.xml, and each button will activate one sendCommand, wich will be selected in the “onClick” option, in Attributes.
Finally, added the button text definitions in the strings.xml:
Compile, test and adjust positions in screen.
I haven’t mentioned button size/placement because it is a WYSWYG editor, so you just jostle them around, being careful with their relationships.
IT IS NOT A PROPER APP, I made the buttons stay at specific places and distances to look good in the tablet I am using, and won’t work on any other tablet with different screen. BUT it works and looks very nice in my wall, so, shut up and go make yourself a better one.