Thursday, October 6, 2016

Save objects in Shared Preferences


private SharedPreferences preferences;
private SharedPreferences.Editor editor;

//Save objects
preferences = context.getSharedPreferences(namePreferences, mode);
editor = preferences.edit();
editor.putString(key, GSON.toJson(object));
editor.commit();

//Retrieve objects
String gson = preferences.getString(key, null);
Object o = GSON.fromJson(gson, a);

Tuesday, May 24, 2016

Calculate battery drain in your app

Interesting slide
 for each API call, it consumes 1/3 mAh
so if you just make API call a minute, you will drain the battery by 1/3 a day!


https://www.youtube.com/watch?v=QR3PIg0RDnk
#io16

Location, save battery and still have a great user experience!

Through patching data from Sensors (e.g. GPS, WiFi, Cell, Gyro, Magno, Acce) via FLP (Fused Location Provider) this leads to more battery saving as it sends those batched data at specific intervals which you can define according to your use case.
But if the user wants to know the exact location right now, they can immediately check it through Flushing callback which provides a seamless user experience.

Changes in Hardware (Lowest level of abstraction) makes User Experience much better (Highest level of abstraction)




Sources:
https://www.youtube.com/watch?v=OEvycEMoLUg
https://developers.google.com/awareness-location/

Thursday, March 17, 2016

Google Tag Manager and Analytics Integration

Firstly, we can say that you can send events from your app to GA directly. However, you can send events to GTM and then GTM will send those to analytics. Many reasons can be said why to use GTM over GA such as in here. But it always a Design/Need decision!

Anyhow, For Android, A draft implementation is at https://developers.google.com/tag-manager/android/v4/#getting-started

Check it, you may have some questions, you would find the answers in here I hope. So those are some of the lessons I learnt:
- Event Names and keys at Android code should match the corresponding ones at GTM.
dataLayer.pushEvent("openScreen",      DataLayer.mapOf("screenName", screenName));
- If you send Events from GTM to GA, the "value" field should be always Integer . if not, it will not be sent
public static void pushEvent(Context context, String event,String category, String label, Integer labelValue) {
        DataLayer dataLayer = TagManager.getInstance(context).getDataLayer();
        dataLayer.pushEvent(event, DataLayer.mapOf("eventCategory", category,"eventLabel", label, "eventValue", labelValue);
    }

- Configure GTM with Variables, Triggers, and Tags. as described here: https://developers.google.com/tag-manager/android/v4/ua#create-transaction-tag

- Use pushEvent rather than push. It is easier!

Thursday, March 10, 2016

Wednesday, March 9, 2016

Android font and caligraphy



So if you want to set an external font to a text view, you have different options:

- A common step: Get the font and put it under assets/fonts folder (create it if it not already created)

1 - Use this Gist:
Typeface typeface = Typeface.createFromAsset(getAssets(),"Roboto-Regular.ttf");
TextView textview = (TextView) findViewById(R.id.textview);
textview.setTypeface(typeface); 
2 - Use DataBinding Lib as described in here: fontbinding
3- Use XML attributes through custom widget: this is a good blog covering it all Custom fonts

Sunday, February 21, 2016

Some questions and answers "About me!"

I got those questions from a recruiter and I thought it is Ok to share them as a kind of about me!:
  1. What position are you looking for? Android Pervasive Engineer with great capacity of Technology Evangelism 
  2. Do you have any experience working in a Scrum environment?
    1. If yes, what was your role? Developer among Development Team
    2. What did you like about the process? Adapting to changes responsively and actively. Continous communication with frequent updates.
  3. What is your opinion on CI? Continous Integration is an essential building block in Software Development. Whenever you develop a feature, you are pretty sure that it will work seamlessly with other parts of software. if used properly, gives confidence about the product and its quality.
  4. What is QA for you and who is responsible for it? Quality Assurance is a proactive approach to tell this app would not crash. Every one working on the app is responsible for the quality of the app besides the QA team.
  5. What does Software Architecture mean to you? How do you ensure you have a maintainable and extensible code base? Building blocks interacting with each other and if you want to scale, you need architecture.  By following Best Practices, Design Patterns, Separating Concerns, Readable Naming Convention and surely Unit Testing.
     
  6. How big were the teams you worked in? And what is the ideal team size you feel comfortable with? as Android mobile development team 2-4 people. And it depends on the context 2 to 4 is nice with capacity of Pair Programming. 
  7. What is your experience in terms of mobile? I started with the early version of Android 1.1. I keep on track with latest trends in Android development as I am still eager to learn. I conduct presentations, workshops and participate in hackathons whenever possible besides I consider myself as a Mobile Computing Evangelist.