Friday, 22 April 2016

Formatting time in Android/Java, the right way

I suppose this is very obvious for someone, but I spent a fair bit of time trying to understand what is the right, no, the right way to do time formatting in Java. I know about Joda, and don't really want to use it (because size, and frankly, I don't need all of it's features). I know about SimpleDateFormat and hate it because I have to hardcode my format. What I wanted is the way to use system-defined, user-preferred way to format time - i.e. if user specified 12-hour time, we want to add AM/PM, and if they happen to use Russian layout, that should magically become "ДП/ПП" however odd I would find this. This is, I think, the quickest the way to get it - using standard framework features:

When using this approach, you will get correctly formatted time, e.g. for 23:10 you will get "23:10" in 24-hour time, "11:10 PM" with English locale and 12-hour time, and "11:10 ПП" in Russian. Makes me very happy this is actually achievable without resorting to hacks like this, or, even worse, this.

Friday, 15 April 2016

Notifications, lockscreen and timed silence

So I got bored the other day and though: why my wonderful Samsung S7 Edge just doesn't seem to support an ability to shut up all the notification sounds for a timed interval? After all, this has been supported by Android Marshmallow since forever, and yet they decided to pull it. Then again, my better half was complaining about exactly the same thing as she always switches sound off for meetings and then inevitably forgets to turn it back on again (something I like to complain about).

Prospects did not look good. But then I thought - hang on a sec, there should be an app for that! So I searched Play Store, and searched again, and there are lots of apps, but they look like shit, and most importantly, are hard to use as I have to define a schedule (like, really, would anybody do that?). And I decided this is something I can fix.

I spent like a Saturday afternoon coding and a proof-of-concept was born - an app which can silence notifications for a period of time. Then I realised that user still has to unlock the screen and launch the app, which is not very user friendly, and remembered about fancy Lollipop notifications which has been there since forever. Et voila - Silencer was born.

 



Don't judge it too harshly as this is just a simple app to solve a simple problem - however, I find it using a lot. When I walk into a meeting, I fire up the screen on my phone and silence all notifications for 30 minutes, without even unlocking it. Try it, might work for you as well :) If you feel this app is desperately lacking something - get back to me and I'll try to add it.

https://play.google.com/store/apps/details?id=info.romankirillov.silencer