Skip to main content

Posts

Showing posts from January, 2016

Using your broken screen Android phone

Yesterday I accidentally dropped my phone and the screen cracked; leaving the phone unusable (as you can see from the photo). The phone itself is still functional but the display and touch screen do not work at all. This leaves me phone-less while I wait until my new phone arrives in a few days. But how can I function without a phone!? For programming I can use the emulator on my computer but it would be nice if I could at least text until I get my new phone. Well, I can!

    Luckily I already have my phone in developer mode since I often use it to test my applications. Also, I have adb (Android Debug Bridge) installed; which comes with the Android SDK and which allows deploying apps and controlling your phone from your computer. Then I simply referenced this blog post which led me to an application, Android Control Screen, which mirrors your Android phone screen on your computer. It's still hard to navigate through the phone since the application uses a virtual keyboard and …

Java JSON Serialization

There are already a lot of JSON libraries out there you can use to convert your Entities to and from JSON Objects, such as, the Jackson library. However, I usually use the org.json library (this is also the JSON library used in Android) and for each Object create "toJSON" and "fromJSON" methods where I have a long and complex process of setting and retrieving values dependent on their particular implementation. This can be tedious, verbose, and time consuming. So, I wanted to hack up a simply alternative myself rather than using a third party library (more fun that way!). And here's the code:

JSONSerializer (class that actually performs the logic of converting objects):
/** * Created by chRyNaN on 1/9/2016. Untested as of now and doesn't work for some specific and more complex use cases. */ public class JSONSerializer { public static <T> JSONObject toJSON(T obj){ JSONObject json = new JSONObject(); JSONArray jArray = new JSON…