Category Archives: Documentation

Android, Smartphone, Android Developer, Android Studio

Auto ‘versionCode’ increment when building production apk’s

Since I adopted Fabric as a way to monitor vital app stats such as ‘Time in App per User‘ and it’s Beta distribution platform to distribute test builds, increasing APK’s versionCode numbers became a tedious task.

I decided to simplify the things by letting Gradle to do auto versionCode increments when producing release APK’s

Our implementation of build number increments will consist of a property file named version.properties located in the root folder of our project.

The property file will contain 2 variables, one defining the version name such as “2.3” and one defining the version code such as 15

VERSION_NAME=2.3
VERSION_CODE=19

In our app module build.gradle file

build.gradle

we will define a function which takes care of retrieving the a bough mentioned values from the properties file and increment the VERSION_CODE if needed.

/**
 * Get's value from 'version.properties' file
 * @param varName the name of the variable which value we wan't to get.
 * @return the variable value.
 */
def getVersionPropertiesValue(def varName)
{
    def propertiesFile = file('version.properties')
 
    if(!propertiesFile.canRead()) {
        throw new GradleException("Could not read " + propertiesFile.name)
    }
 
    Properties properties = new Properties();
    properties.load(new FileInputStream(propertiesFile))
 
    def propertyValue = properties[varName]
    if(varName == 'VERSION_CODE')
    {
        // If we are building release increment the version code
        List gradleTasksNames = gradle.startParameter.getTaskNames();
        for(String taskName : gradleTasksNames)
        {
            if(taskName.contains("Release"))
            {
                propertyValue = propertyValue.toInteger() + 1
                properties[varName] = propertyValue.toString()
                properties.store(propertiesFile.newWriter(), null)
                break
            }
        }
    }
 
    return propertyValue
}

In the defaultConfig section of the gradle build script we will call this function to retrieve values for the versionName and versionCode of our app.

android {
    compileSdkVersion 28
 
    defaultConfig {
        applicationId "com.example.foo"
        versionCode Integer.valueOf(getVersionPropertiesValue('VERSION_CODE'))
        versionName getVersionPropertiesValue('VERSION_NAME')
        minSdkVersion 14
        targetSdkVersion 28
    }
}

Now each time a release build is made, the version code will increment automatically. If we want to change the version name we can do so by changing the value of VERSION_NAME property.

Fighting spammers: Removing Website URL Field from Comment Form

I’m tired of receiving massive amount of spam comments on my blog (1280 spam comments for about a month) and doing:

DELETE FROM `wp_comments` WHERE `comment_approved` = 0

Beside using SI Captcha Anti-Spam which does pretty good job in keeping some of the automated spam bots at bay, I noticed some trend in the spam comments flooding my posts, they are all full of SEO keywords and they are heavy abusing the Website field in the comment form.

Here is a small “plugin” which will remove (unset) the URL field in the comments form:

<?php
/*
Plugin Name: Remove Website field from comments.
*/
function custom_comment_fields( $fields ){
  if(isset($fields['url']))
    unset($fields['url']);
  return $fields;
}
 
add_filter( 'comment_form_default_fields', 'custom_comment_fields' );

Create a file in /wp-content/plugins/ with the code a bough. Go to the ‘Plugins’ section of the admin panel and activate the newly created plugin named “Remove Website field from comments”.

Yey, no more “Website” field in the “Leave a Reply” section 🙂

Eclipse, IDE, Java

Eclipse Hotkeys Fix

Eclipse on GNU/Linux has an annoying bug with hotkeys for users with multiply keyboard layouts.

For example when the user is working with the English keyboard layout, hotkeys such as “Ctrl-C”, “Ctrl-V” will work as expected, but when switched to different layout (ex: Bulgarian) the keys will no longer work.

After a bit of searching I found a fix for this inconvenience at GitHub.

Thank you “amozzhuhin“!

Command Prompt Here

Have you ever wanted to open a Command Prompt in the folder you are currently browsing in Windows Explorer. It’s time saving feauture that’s not present currently in Windows. If you do a Google search, you will find various methods for doing this. The method that I will show you will not require instalation of some software sush as Cmd Here powertoy.

So here is how is done:
1. Open Control Panel ( or in Windows Explorer select the Tools menu and then Folder Options ) and navigate to Folder Options

2. In the “Folder Options” property page select File Types and in the “Registered file types:” list select {NONE} | Folder

Folder Options property page
3.Click the “Advanced” button. The “Edit File Type” dialog will apear


4.Click on the “New” button, the “New Action” dialog will apear


5. In the “Action:” field type “Command Prpmpt” or name of your choice, and in the “Application used to preform the action:” type cmd.exe.

6. Click “OK” to close the “New Action” dialog, click “OK” to close “Edit File Type” dialog and “OK” to close the “Folder Options” dialog.

Now when you right click on a folder in Windows Explorer you shoud see an context menu entry labeled “Command Prompt”, click on it to open a “cmd.exe” window in the selected folder.

Adding custom resources in Visual Studio 2003 “Add Resource” dialog box

For some projects I create resources that can be reused in other projects. Such as dialog boxes, images, etc…

It’s waste of time to recreate those resources again and again for each project you use them in, so after some investigation I have found a way to add custom resources in VS 2003 “Add Resource” dialog box.

Open C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\VCResourceTemplates\1033\mfc.rct in VS 2003. Open a resource file from wich you want to get some resources. Right click on the resource you want to copy and from the popup menu select “Copy” then paste the resource in mfc.rct. Or just drag selected resource to mfc.rct.

Note: mfc.rct may have different path. It depends on your VS 2003 instalation!