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! :)