Navigation Component: How to move the Drawer under the ToolBar?

Navigation Drawer Activity Template

Recently I was struggling with Navigation Component and succeded in solving some of its issues. I am happy to share with you the solutions I’ve found.

GitHub Repo: https://github.com/Pulimet/NavigationComponentSample

Create a project and select the template “Navigation Drawer Activity”. You will get the ToolBar, Drawer and navigation stuff for free as shown in the screenshot.

Now, let’s assume that we got a request to move the drawer under the ToolBar. We need to modify activity_main.xml for that.

Create vertical LinearLayout and make it wrapping DrawerLayout

Open app_bar_main.xml copy AppBarLayout and paste it as a first item in the previously created LinearLayout.

Also from the app_bar_main.xml get the include (content_main) and put it as a first child of DrawerLayout instead of existing include of app_bar_main.xml.

Delete app_bar_main.xml file

In v21\styles.xml – remove the line that makes status bar transparent.

Keep Reading

Gradle – How to open folder with generated APK?

android {
    applicationVariants.all { variant ->
        variant.outputs.all {
            def flavor = variant.productFlavors[0].name
            if (flavor == 'prod') { // Open folder for specific flavor
                variant.assemble.finalizedBy openFolderWithApk
            }
        }
    }

    task openFolderWithApk(type:Exec) {
        workingDir '../app/prod/release/' //Update flavor and buildType
        commandLine 'cmd', '/c', 'start .' //on windows
    }
}

Change output apk name using build.gradle

Output result:  AppNameProd4.1.2_050718.apk

android {
    applicationVariants.all { variant ->
        variant.outputs.all {
            def flavor = variant.productFlavors[0].name.capitalize()
            def version = variant.versionName
            def date = new Date()
            def formattedDate = date.format('ddMMyy')
            outputFileName = "AppName${flavor}${version}_${formattedDate}.apk"
        }
    }
}

Keep Reading

Dagger 2

Simple and funny tutorial about dependency injection library Dagger 2.

In other words, manually managing the dependency injection is like, mining the dragon glass — taking permission from the dragon queen and then forging them as weapons and then to go and fight with the White Walkers (hard dependency issues). Dagger 2 framework is like the valyrian swords — it’s been created by masters and all you need is to just wield it.

https://medium.com/@harivigneshjayapalan/dagger-2-for-android-beginners-introduction-be6580cb3edb

Fragment transition with shared element supporting API 14+ example/tutorial

Now (27.0.0 support library) fragment can use support library versions of Transition for fragment transitions, including shared-element transitions.
https://developer.android.com/topic/libraries/support-library/revisions.html#27-0-0

Support android.transition classes provide transition API back to android API level 14.
https://developer.android.com/reference/android/support/transition/package-summary.html

Inspired by: Fragment Tricks (Google I/O ’17).

So let’s start with the build.gradle (support library 27.0.0+) :

implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support:design:27.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

Keep Reading