Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ghiyats Hanif - Android Templates

Ghiyats Hanif - Android Templates

Android Templates

Android VIP

April 13, 2019
Tweet

More Decks by Android VIP

Other Decks in Programming

Transcript

  1. Types of Templates in Android Studio • Live Templates •

    File Templates • Group of File Templates
  2. Live Templates “frequently-used or custom code constructs that you can

    insert into your source code file quickly, efficiently and accurately.” • Toast - show a toast message • inn - check if not null • fori - create for loop • exfun - create extension function • etc..
  3. File Templates File templates are specifications of the default contents

    to be generated when creating a new file. Depending on the type of file you are creating, templates provide initial code and formatting that is expected to be in all files of that type (according to industry standards, your corporate policy, or for other reasons). • Creation of type of classes which repeated everywhere (e.g Adapter, Fragment)
  4. • You can introduce your own variable by placing it

    like ${your_variable_name}$ • Avoid using variable name as the predefined ones: ◦ ${NAME} ◦ ${PACKAGE_NAME} ◦ ${USER} ◦ etc.
  5. Android File Templates (Group of File Templates) Group of -

    File templates are specifications of the default contents to be generated when creating a new file. Depending on the type of file you are creating, templates provide initial code and formatting that is expected to be in all files of that type (according to industry standards, your corporate policy, or for other reasons). • Creation of default/blank activity. It generates -> activity class, manifest declaration, activity's layout xml • In the era of MVx feature creation is quite a long journey • Using FreeMarker.org convention
  6. Template.xml • Handles Creation of the wizard by defining sets

    of parameters • Boolean -> CheckBox • String -> Input Text • Enum -> Dropdown
  7. Recipe.xml.ftl Define how templates will be implemented Instantiate -> It

    provides bridge between Template files and input content received from templates.xml Merge  -> merges your template code into your project files. Dependency -> add dependencies to the app build.gradle file.
  8. Recipe.xml.ftl Define how templates will be implemented copy ->  It copies

    the contents from template to project folder. open — it opens the files you want to open on the launch after codes are generated from Templates.
  9. How To share templates across teammates • Live Templates &

    File Templates ◦ are saved in android studio settings, export/import settings file ◦ Set shared settings repository • Android File Templates ◦ Save it in repository ◦ Or manually paste it to Teammates' Android Studio Directory