SlideShare a Scribd company logo
Garfield Android
Studio Plugin
MIROSLAV POPOVIC
Be smart, be lazy
PROBLEM
Lot’s of boiler plate code out there
BOILERPLATES
• Send email
• Send sms
• Mark pin on a map
• Dagger
• …
Lot’s of lines of code needed for one
logical operation
SOLUTION
CODE AUTOMATION
Let the machine do the dirty work
SOLUTION
FOR THE BEGINNIG…
How about this…
private static void setMarkerOnMap(@DrawableRes int
resMarkerIcon, LatLng latLng, GoogleMap map) {

MarkerOptions marker = new
MarkerOptions().position(latLng)

.icon(BitmapDescriptorFactory

.fromResource(resMarkerIcon));

map.addMarker(marker);

}
How about this…
public static void sendEmail(String email, String subject,
String emailBody, List<Uri> images) throws
ActivityNotFoundException {

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);

intent.putExtra(Intent.EXTRA_EMAIL,
new String[]{email});

intent.putExtra(Intent.EXTRA_SUBJECT, subject);

intent.putExtra(Intent.EXTRA_TEXT, emailBody);

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
(ArrayList<Uri>) images);

intent.setType(TEXT_PLAIN);

startActivity(intent);

}
• Save a template
• Auto complete
• Export is possible
LIVE TEMPLATES
android.content.Intent view = new Intent();

view.setAction(Intent.ACTION_VIEW);

view.setData(android.net.Uri.parse($url$));

startActivity(view);
LIVE TEMPLATES
Can
- static code
- variables
- modification
scripts
LIVE TEMPLATES
Cannot
- generate
packages
- generate classes
- check members
HEAVY CODE AUTOMATION
ANDROID STUDIO PLUGIN - GARFIELD
Dagger, MVP, helper code…
WRITING CODE THAT GENERATES CODE
Garfield Android
Studio plugin
1)
2)
3)
4)
with Garfield
5)
Garfield
exported
SETUP
• git clone IntelliJ community edition
• run sh getPlugins.sh from the terminal (android studio
plugin included into community project)
• create a new Java SDK “IDEA jdk” (and add libtools.jar
to the classpath if needed)
• make project
• create a new Intellij Platform Plugin
[1] git://git.jetbrains.org/idea/community.git
1
CREATING AN ACTION
• Define an Action
• Package com.intellij.openapi.actionSystem
• Register in plugin.xml
public class NewAction extends AnAction {

public void actionPerformed(AnActionEvent e) {

Project project = e.getProject();

Module module = e.getData(DataKeys.MODULE);





NewForm form = new NewForm(project, module);

form.show();

}

}
CREATING UI
• Common Swing UI components
• You will most probably use a dialog
• DialogWrapper used with UI Designer form
@Nullable

@Override

protected JComponent createCenterPanel() {

return rootPanel;

}
ANDROID FACET
• Needed to get base project name
• IntelliJ Facets: Android, GWT, EJB, Hibernate
public static String getPackageName(Project project, Module
module) {

AndroidFacet facet = getCurrentFacet(project, module);

VirtualFile manifestFile =
AndroidRootUtil.getPrimaryManifestFile(facet);

Manifest manifest =
AndroidUtils.loadDomElement(facet.getModule(),
manifestFile, Manifest.class);

return manifest.getPackage().getValue(); //get package

}
GENERATING CODE ← JAVAPOET
MethodSpec main = MethodSpec.methodBuilder("main")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(void.class)
.addParameter(String[].class, "args")
.addStatement("$T.out.println($S)", System.class,
"Hello, JavaPoet!")
.build();
TypeSpec helloWorld = TypeSpec.classBuilder("HelloWorld")
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.addMethod(main)
.build();
public final class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, JavaPoet!");
}
}
SUMMARY
Copy & Paste Live Templates Android Studio Plugins
Be smart, be lazy
Thank you!
Visit infinum.co or find us on social networks:
infinum.co infinumco infinumco infinum
REFERENCES
http://www.jetbrains.org/pages/viewpage.action?
pageId=983225
https://github.com/JetBrains/intellij-community
http://www.jetbrains.org/intellij/sdk/docs/basics/
getting_started.html
Setting up the environment
REFERENCES
https://github.com/JetBrains/intellij-sdk-docs/blob/master/
tutorials/action_system/grouping_action.md
http://www.jetbrains.org/intellij/sdk/docs/basics/
getting_started/creating_an_action.html
https://github.com/winterDroid/android-drawable-importer-
intellij-plugin
Action system
REFERENCES
Generating code
https://www.jetbrains.com/idea/help/managing-facets.html
https://www.jetbrains.com/idea/help/facet.html
https://android.googlesource.com/platform/tools/adt/idea/+/
1100693bbe6a6bffd566f30969f33b67c483ba7c/android/src/org/
jetbrains/android/facet/AndroidFacet.java
https://github.com/square/javapoet

More Related Content

PPT
Input and Interaction
PPTX
Lecture 6 introduction to open gl and glut
PDF
Infinum Android Talks #20 - Making your Android apps fast like Blue Runner an...
DOCX
Intellij idea features
PDF
Writing Android Libraries
PDF
How to train the jdt dragon
PDF
Android Development 201
PDF
How to Build Developer Tools on Top of IntelliJ Platform
Input and Interaction
Lecture 6 introduction to open gl and glut
Infinum Android Talks #20 - Making your Android apps fast like Blue Runner an...
Intellij idea features
Writing Android Libraries
How to train the jdt dragon
Android Development 201
How to Build Developer Tools on Top of IntelliJ Platform

Similar to Infinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be Lazy (20)

PPTX
2 Day Android Workshop
PDF
Introduction to Andriod Studio Lecture note: Android Development Lecture 1.pdf
DOCX
CS6611 Mobile Application Development Laboratory
DOCX
Cs 6611 mad lab manual
PDF
Google Course Lecture
PDF
AN IDE FOR ANDROID MOBILE PHONES WITH EXTENDED FUNCTIONALITIES USING BEST DEV...
PDF
From Renamer Plugin to Polyglot IDE
PPT
Engineering and Industrial Mobile Application (APP) Development
PDF
Programming Android Zigurd Mednieks Laird Dornin Blake Meike
PDF
Android programming-basics
PDF
How to code to code less
PDF
Android Bootcamp
PPTX
elephant
PDF
AN ANDROID APP FOR BUILDING STUDENT PROFILES
PDF
Robotium Tutorial
ODP
Non Conventional Android Programming En
ODP
Non Conventional Android Programming (English)
PDF
Android Deep Dive
PPT
iLabs Toolbox Javashare 2008
PDF
Programming Android
2 Day Android Workshop
Introduction to Andriod Studio Lecture note: Android Development Lecture 1.pdf
CS6611 Mobile Application Development Laboratory
Cs 6611 mad lab manual
Google Course Lecture
AN IDE FOR ANDROID MOBILE PHONES WITH EXTENDED FUNCTIONALITIES USING BEST DEV...
From Renamer Plugin to Polyglot IDE
Engineering and Industrial Mobile Application (APP) Development
Programming Android Zigurd Mednieks Laird Dornin Blake Meike
Android programming-basics
How to code to code less
Android Bootcamp
elephant
AN ANDROID APP FOR BUILDING STUDENT PROFILES
Robotium Tutorial
Non Conventional Android Programming En
Non Conventional Android Programming (English)
Android Deep Dive
iLabs Toolbox Javashare 2008
Programming Android
Ad

More from Infinum (20)

PDF
Infinum Android Talks #20 - DiffUtil
PDF
Infinum Android Talks #20 - Benefits of using Kotlin
PDF
Infinum iOS Talks #4 - Making our VIPER more reactive
PDF
Infinum iOS Talks #4 - Making your Swift networking code more awesome with Re...
PDF
Infinum Android Talks #13 - Using ViewDragHelper
PDF
Infinum Android Talks #14 - Log4j
PDF
Infinum Android Talks #9 - Making your app location-aware
PDF
Infinum Android Talks #14 - Gradle plugins
PDF
Infinum Android Talks #14 - Facebook for Android API
PDF
Infinum Android Talks #19 - Stop wasting time fixing bugs with TDD by Domagoj...
PDF
Infinum Android Talks #18 - Create fun lists by Ivan Marić
PDF
Infinum Android Talks #18 - In-app billing by Ivan Marić
PDF
Infinum Android Talks #18 - How to cache like a boss by Željko Plesac
PDF
Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
PDF
Infinum iOS Talks #2 - Xamarin by Ivan Đikić
PDF
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
PDF
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
PDF
Infinum iOS Talks #1 - Becoming an iOS developer swiftly by Vedran Burojevic
PDF
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
PDF
Infinum Android Talks #17 - A quest for WebSockets by Zeljko Plesac
Infinum Android Talks #20 - DiffUtil
Infinum Android Talks #20 - Benefits of using Kotlin
Infinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making your Swift networking code more awesome with Re...
Infinum Android Talks #13 - Using ViewDragHelper
Infinum Android Talks #14 - Log4j
Infinum Android Talks #9 - Making your app location-aware
Infinum Android Talks #14 - Gradle plugins
Infinum Android Talks #14 - Facebook for Android API
Infinum Android Talks #19 - Stop wasting time fixing bugs with TDD by Domagoj...
Infinum Android Talks #18 - Create fun lists by Ivan Marić
Infinum Android Talks #18 - In-app billing by Ivan Marić
Infinum Android Talks #18 - How to cache like a boss by Željko Plesac
Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
Infinum iOS Talks #2 - Xamarin by Ivan Đikić
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum iOS Talks #1 - Becoming an iOS developer swiftly by Vedran Burojevic
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
Infinum Android Talks #17 - A quest for WebSockets by Zeljko Plesac
Ad

Recently uploaded (20)

PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
L1 - Introduction to python Backend.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Essential Infomation Tech presentation.pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Introduction to Artificial Intelligence
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
ai tools demonstartion for schools and inter college
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
L1 - Introduction to python Backend.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Navsoft: AI-Powered Business Solutions & Custom Software Development
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
CHAPTER 2 - PM Management and IT Context
Odoo Companies in India – Driving Business Transformation.pdf
Essential Infomation Tech presentation.pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Softaken Excel to vCard Converter Software.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Introduction to Artificial Intelligence
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
ai tools demonstartion for schools and inter college
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

Infinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be Lazy