Android

Project Setup

Resource Guidelines

Common Libraries

Core Skills

Android engineers are expected to be self-directed in skill acquisition on these subjects, in addition to the shared core skills. Quarterly reviews will include a skills self-assessment and goal setting for the next quarter. See the Quarterly Skills Review document for more details on this process.

Java (Android) Code Formatting Standards

Java Coding Guidelines

These guidelines should be followed when writing Java code for the Android platform. Patches and additions to any code base will be checked for adherence to these guidelines. If code is in violation, you will be asked to reformat it. For Android Studio you can import the this code style scheme: Vokal.xml (Preferences > Editor > Code Style > Manage... > Import...)

Naming Guidelines

    vokalApi[‘IO’] and not vokalApi[‘Io’]
    vokalApi[‘Api’]

Variables

    int camelCase;
     private String mSomeClassString;
     private static String sSomeStaticString;
    public static final String SOME_CONSTANT_STRING = "hello, world";

Classes

    SomeClass, SocialLoginActivity
    public class SocialLoginActivity extends Activity {
        ...
    }
    public class NetworkAlertFragment extends Fragment {
        public interface NetworkAlertFragmentListener {
            public void alertDismissed();
        }

        [ALL YOUR OTHER CODE]     

        public static class Type {
            public static final int SUCCESS = 0;
            public static final int FAILURE = 1;
        }
    }

Methods

    public void someFunction(aParam1, aParam2) {
        ...
    }
    public void someFunction(param1, param2) {
        ...
    }
    public void someHypotheticallyLongQueryFunction(Context aContext, Uri aContentUri,
                                                    String aQuery, String[] aQueryArgs) {
        ...
    }
    onOptionSelect() {}
    onClickSubmit() {}
    onSubmitSuccess() {}

Coding Style

, . ; : { } ( [ = < > ? ! + - * / % ~ ^ | & == != <= >= += -= *= /= %= ^= |= &= << >> || && === !== <<= >>= >>> >>>=
    String someMessage = (conditional) ? "This is the message when some thing is true"
                                       : "This is the message when some thing is false!";
    if (condition) {
        callSomeFunction(args);
    }
    mAdLayout = (RelativeLayout) findViewById(R.id.ad);
    public void foo() {
        if (condition) {
            ...
        } else if (condition) {
            ...
        }

        while (condition) {
            ...
        }
    }
    int total = x + 2;
    String someString = otherString + anotherString;
    if(variable == 14.76) {
        ...
    }
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.*;

import com.vokal.myapp.MyClass;
// Bad:
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;

// Good:
import android.content.*;

Implementation Guidelines

Commenting

        i = 0; // Set i to zero.

General optimization rules

        Collection<Type> myCollection = ...

        for (Type current : myCollection) {
            ...
        }
        public class Foo {
            private int mValue;

            ...

            class Inner {
                public void someFunction() {
                    Foo.this.doSomething(Foo.this.mValue);
                }
            }
        }
    try {
        // some file operation
    } catch (IOException | FileNotFoundException ex) {
        ex.printStackTrace();
    }