├── install.sh ├── README.md └── styles └── grandcentrix.xml /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Installs GCX AndroidStudio Code Style into your AndroidStudio codestyles folder. 3 | # You can optional put a path (to your Android project) as argument. 4 | # Then the codestyle will be only added there. 5 | # 6 | # Inspired by https://git.io/v7jmC 7 | 8 | echo "Installing GCX AndroidStudio code style..." 9 | echo "" 10 | 11 | LATEST_CODE_STYLE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/styles/grandcentrix.xml" 12 | if [ "$1" != "" ]; then 13 | lastChar=${1: -1} 14 | if [[ $lastChar == '/' ]]; then 15 | TARGET_DIR=("$1.idea") 16 | else 17 | TARGET_DIR=("$1/.idea") 18 | fi 19 | else 20 | TARGET_DIR=("$HOME/Library/Preferences/AndroidStudio*" "$HOME/Library/Preferences/AndroidStudioPreview*" \ 21 | "~/.AndroidStudio*/config" "~/.AndroidStudioPreview*/config") 22 | fi 23 | 24 | for target in $TARGET_DIR 25 | do 26 | # create codestyles dir and ... 27 | mkdir -p ${target}/codestyles 28 | # ... copy to latest style to ${TARGET_DIR} 29 | echo "Copying..." 30 | cp -frv ${LATEST_CODE_STYLE} ${target}/codestyles/ 31 | if [ "$1" != "" ]; then 32 | echo "Renaming grandcentrix.xml to Project.xml" 33 | mv ${target}/codestyles/grandcentrix.xml ${target}/codestyles/Project.xml 34 | fi 35 | done 36 | 37 | echo "" 38 | echo "Done." 39 | echo "Restart AndroidStudio. Go to Preferences->Editor->Code Style and apply Scheme 'grandcentrix'." 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Code Style 2 | 3 | Code formatting rules for Android Studio 4 | 5 | ## Features 6 | - Based on googles java code style (https://git.io/v5XuB) 7 | - [Hungarian Notation (m-Prefix)](https://github.com/grandcentrix/AndroidCodeStyle/issues/4) 8 | - [No star imports](https://github.com/grandcentrix/AndroidCodeStyle/issues/5) except for testing libraries 9 | - Increase the line length to 118 (default 100) 10 | - `android:id` after `xmlns` declaration in XML layouts 11 | - [Keep lifecycle methods together](https://github.com/grandcentrix/AndroidCodeStyle/issues/3) 12 | - [Keep getters and setters together](https://github.com/grandcentrix/AndroidCodeStyle/issues/7) 13 | - Advanced code Arrangement rules for Java (Sort methods alphabetically (a-z) and by visibility (`public`-`private`)) 14 | - Inner classes (classes, interfaces, enums) 15 | - Fields (grouped by visibility, a-z) 16 | - [public static methods](https://github.com/grandcentrix/AndroidCodeStyle/issues/8) (a-z) 17 | - Constructors 18 | - [Android Lifecycle methods](https://github.com/grandcentrix/AndroidCodeStyle/issues/3) in correct order 19 | - Methods ([grouped by visibility, a-z](https://github.com/grandcentrix/AndroidCodeStyle/issues/6)) 20 | - static methods (grouped by visibility (except public), a-z) 21 | - Official [Kotlin Code Style](https://kotlinlang.org/docs/reference/coding-conventions.html) 22 | 23 | ## Installation on your local machine 24 | 25 | ### Automatically (the easiest way) 26 | Just run the [`install`](install.sh) script. 27 | It will automatically copy the latest Code Style to each existing `AndroidStudio` and `AndroidStudioPreview` version you have installed. 28 | 29 | ### Manually (the hard way) 30 | 1. Copy the [`grandcentrix.xml`](styles/grandcentrix.xml) into (MacOS) ``~/Library/Preferences/AndroidStudio{VERSION}/codestyles/`` or (Linux) ``~/.AndroidStudio{VERSION}/config/codestyles/`` 31 | 2. Restart AndroidStudio 32 | 3. Select the codestyle scheme via `Preferences --> Editor --> Code Style`. 33 | 34 | The codestyle will be enabled/used for **all projects** that are used with AndroidStudio! 35 | 36 | ## Enabling project specific code styles for a project 37 | If the codestyle is added to the git repository and IntelliJ is configured accordingly each project can have it's own style. 38 | 39 | 1. Install the [`grandcentrix.xml`](styles/grandcentrix.xml) locally (see above) 40 | 2. Restart AndroidStudio 41 | 3. In AndroidStudio, go to `Preferences --> Editor --> Code style` 42 | 4. Open the scheme list by clicking on the `Scheme:` drop down 43 | 5. From the `Stored in the IDE` section select `grandcentrix` 44 | 6. Click the cogwheel just on the right and select `Copy to project` 45 | 7. Confirm overwriting project settings with the new scheme 46 | 47 | Finally add the code style to the git repository: 48 | ``` 49 | git add -f .idea/codestyles/Project.xml .idea/codestyles/codeStyleConfig.xml 50 | ``` 51 | 52 | ## Contributing 53 | To contribute just change the code style locally to your needs. 54 | Then you can create a PR to this repository. 55 | 56 | The PR should always contain: 57 | * Some information what have changed. 58 | * A updated [`grandcentrix.xml`](styles/grandcentrix.xml). 59 | 60 | ## License 61 | [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) 62 | -------------------------------------------------------------------------------- /styles/grandcentrix.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 25 | 809 | --------------------------------------------------------------------------------