Excluding dependencies in Gradle

This is the way that use to exclude some transitive dependency.

When come to project type dependency this is the way.

Keep in mind the additional brackets around  project(project(':library:view_pager_indicator'))



Android – Fix for Duplicate files copied in APK

If you are an android developer you may already familiar with this issue.

Usually you’re getting this for some text files or license files like  META-INF/notice.txt ,  META-INF/license.txt ,  META-INF/ASL2.0

In such scenarios we can exclude those files from APK packaging without any hesitation because we definitely know those will not affect our application functionality. We can do so using gradle  packagingOptions .

What can we do when we get like

or

or

We cannot exclude those files since they required for app functionality. So we need another way to handle such scenarios.

We can use  pickFirst in  packagingOptions to avoid duplicate file copying to APK as below.



Add read more/ less to Android TextView

In this article I’m going to show you how to add  read more/ less component to  android TextView. Finally your text view looks like this.

Screenshot_20170814-014733 (2)



Low Key Portraits of Yash

DSC_0220-1-2

Today I bring you a set of low key portraits of my lovely wife Yash.

I covered all the windows in our living room except one that brings evening sun light to my shots. This beautiful diffused side light emphasized gestures of the face and skin nicely. I planned to produce those photos in back and white but when I see above one in the post processing stage I realize that it looks more attractive with the skin tone. So I exported it as colored one.

You can find the full collection below.



Little Guy Living Under Leafs

 

Today I found this little guy on a flower tree in our garden. Jumping Spider, I totally agree with the name since this one was jumping allover when I tried to take a few clicks. It jumped to the lens several times and I had to put it back on a leaf to continue.

I used my Nikon D5500 DSLR with Nikor 18-55 mm f 3.5-5.6 lens. I put 12 mm and 20 mm extension tubes to achieve extra level of reach. Also I used pop-up flash of the camera to light it up a bit.

Few more clicks are added below.

Is comment required?

Comments are used to describe the code for other users who will reuse or do changes on that code. After few time comments are also very useful even us to realize that what we done in there. So developers used to add comments in everywhere of the code. Is it the best practice?

Add comment isn’t a best practice always. It is better if we can write descriptive code rather than adding comment to describe what we do with the code. If a code can read and get what it done that kind of code says as a descriptive code. Let’s see some example.

or we can change the code as

Which one is more descriptive? In second one it is easy to understand what it done even without a comments. Also it save the time that we wast for adding comments.

But some comments are important and we couldn’t miss. First one is legal comments that contains details about authorship and copyrights. Legal notes are generally added at the start of each source file.

For a example Oracle added Legal note like this in every sources of its products

Also there are some points that we should mention some useful information in comments.

In here we inform the user who refer the code that what do with this property and what can do with change it. At that point comment is very important and it added some value to the code.

Another useful comment is //TODO comments. TODO comment explains what are the features that should implemented but can’t done it now for some reason.

Comments can be use to amplify the important of something that can feel another user as useless.

Javadocs are very important when you are writing public APIs

Rather than that most of the other comments aren’t added much sense on the user except repeating code content to the user. Let’s lock some example comments that we can eliminate from our codes.is

Try to avoid Separator comments because with modern IDEs no use of those separators.

Don’t use comments to keep in track with version histories and author’s details. Modern version controllers manage this task much better. So don’t pollute the code with those things.



Also don’t remain unwanted commented codes in your sources. New comers will not be remove those commented codes unless you remove it. It any code really unwanted delete it without comment it.

When a code is written in first time developer properly organize the code and properly add comments. There is no problem with the code. Problems began when we had to refactor the code urgently as usually happening. Developers quickly done the refactorings and done it in time but most probably they missed the comments to refactor. So there remains irrelevant comments with the code.

Comments are very important but unwanted comments are headache for developers. So think before adding a comment if it’s really useful and be sure it says that actually done.

Next developer only get that we remains on the code. If we didn’t do nicely it’ll be a huge mess for them.

Version file generation using Gradle

Have you noticed the placeholder “${version}” that’ll be replaced with the actual version in the build process. Then new gradle task need to be defined. So we can define a class extending DefaultTask in our build.gradle script.