Thursday, February 23, 2017

Optimize Android Studio speed

Go to/create file: /Users/aselims/Library/Preferences/AndroidStudio2.2/studio.vmoptions

Configure those options according to your RAM limits:

-Xms512m
-Xmx4096m
-XX:MetaspaceSize=512m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=512m
-XX:+UseCompressedOops

Thursday, February 9, 2017

Animations for the app

I would like to have general animations (transitions) between my activities. There are many possibilities. Use TransitionManager, use Activity#overridePendingTransition(), use ActivityOptions, FragmentTransaction#setCusotmAnimation()...

One general solution would be:

<style name="ActivityAnimations" parent="@android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">@anim/slide_up_in</item>
<item name="android:activityOpenExitAnimation">@null</item>
<item name="android:activityCloseEnterAnimation">@null</item>
<item name="android:activityCloseExitAnimation">@anim/slide_out_right</item>
</style>


and apply in the base theme:
<item name="android:windowAnimationStyle">@style/ActivityAnimations</item>


To understand what those means, here is an excerpt from here
intactivityCloseEnterAnimationWhen closing the current activity, this is the animation
 that is run on the next activity (which is entering the screen).
intactivityCloseExitAnimationWhen closing the current activity,
this is the animation that is run on the current activity (which is exiting the screen).
intactivityOpenEnterAnimationWhen opening a new activity,
this is the animation that is run on the next activity (which is entering the screen).
intactivityOpenExitAnimationWhen opening a new activity,
this is the animation that is run on the previous activity (which is exiting the screen).


<!-- In case we need to generalize for the fragments
<item name="fragmentOpenEnterAnimation">@animator/fragment_open_enter</item>
<item name="fragmentOpenExitAnimation">@animator/fragment_open_exit</item>
<item name="fragmentCloseEnterAnimation">@animator/fragment_close_enter</item>
<item name="fragmentCloseExitAnimation">@animator/fragment_close_exit</item>-->

Monday, January 30, 2017

Keep Gradle uptodate

One of the downsides of Gradle is it takes a lot of time to build for big projects. Gradle team works on this problem with continuos efforts. So that means when you update Gradle, this means it could get better with increasing the speed of the build.

How?
- Check the latest Gradle distribution at: https://services.gradle.org/distributions/
-- At the time of this post, It is : gradle-3.4-rc-1-all.zip
-- Invoke with CmdLine: ./gradlew -wrapper -gradle-version=3.4-rc-1
-- Check the config file in <project>/gradle/wrapper/gradlewrapper.properties 
is changed to 
"distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-rc-1-all.zip"

Happy build times! :)

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/