Snippet Manager

This article will cover on how to use add, create and insert snippets into the file

Understanding

A snippet is a generally a common pasted code which can be reused by others in a project.

const/4 v0, 0x1
const-string v1, "Message"
invoke-static {p0, v1, v0}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;
move-result-object v0
invoke-virtual {v0}, Landroid/widget/Toast;->show()V

For eg: (as above) This is a smali code to display a toast message which can be used as common snippet. All snippets are stored in toolssnippets.xml file. It is read whenever application is started and Snippet Manager is opened, you can also manually edit it.

<?xml version="1.0" encoding="utf-8"?>
<Snippets>
   <Category>
    <Name>dot_os_banner</Name>
    <Type>1</Type>
    <Code>
ui_print("                                               ");
ui_print("***********************************************");
ui_print("            _____     _____    __              ");
ui_print("           |____    / ___   |  |             ");
ui_print("            _     | |   | |                ");
ui_print("           | |   | || |   | |                ");
ui_print("           | |__/ / | |___| |____|  |          ");
ui_print("           |_____/   _____/|______/           ");
ui_print("                 Droid On Time                 ");
ui_print("***********************************************");
ui_print("                                               ");
</Code>
  </Category>
</Snippets>

Above is an example of snippets.xml. Name is where the snippet name will exist, no two snippet can have same names, Type (generally 1,2 or 3) represents for which type of file the snippets are! For eg: Type 1 means for Updater-Script, Type 2 means for Smali, Type 3 is for all types of file irrespective of its extension. Code is where you actual snippet will present.

You can manually create your own snippet and append to this file or use built-in snippet manager to create one.

Creating Snippets

In ADK, go to Edit > Snippet Manager (or press Alt + Q) to open snippet manager. Now from above go to the tab says Create. Here you can create your snippet.

From bottom, you have to set come params.

Language: This is change the language of textbox (above) for proper syntax highlighting (nothing to do with code).

Name: You must mention a name for snippet. This will be the text for snippet item.

Type: As mentioned earlier, you have to select from this drop down box.

Export to Xml: This will export current document as XML file, you can then add or merge it (How? discussed below). You can also share this with any ADK user. Inshort, this will create a standalone snippet file.

Merge with exisiting Snippets: This will merge the snippet and append the document to toolssnippets.xml. No need to add or merge it again, this will automatically do it. This will not create standalone snippet file.

You can also do one thing to easily create a snippet. Just select a text in editor and right click, you will see a new option “Create a snippet”. When you click on it, you have to first specify the name for snippet and it will create same window like above.

Adding/Managing Snippets

As said earlier all snippets are stored in toolssnippets.xml. You can easily manage it from snippet manager itself.

So open snippet manager, you will get something like below.

On right side you will see your snippet file text. On left side is the list of snippets name stored in snippets.xml.

Add/Merge: This will add and merge a standalone snippet xml to your snippets.xml.

Delete: This will remove any selected snippets from left side.

Note: All changes are invoke only when this above form is close. Also making any changes to “Code” doesn’t affect snippets.xml, it will only depends on the snippets item (shown on left side). If you want to save changes to “Code” just click Export button to create standalone snippet and the add/merge it. Also, you cannot edit existing snippet within this editor; you must delete and recreate new one.

A tip, you can hover mouse on snippets item to see their codes.

Inserting Snippets

It is very easy, you just need to remember this things.

Type 1 (update-script) snippets will be added to Project > Add Templates with Text as the snippet name.

Type 2 (smali) snippets will be added to Project > Smali Insert with Text as the snippet name.

Type 3 (custom) snippets will be added to Project > Insert Snippets with Text as the snippet name.

You can then select the snippet item which will insert the snippet to current line position.

PRO TIP

To insert type 3 snippet you can also Press CTRL + SHIFT + I  to show a dialog like below then use arrow keys to select the snippet and press enter to insert it. You can also cancel it by pressing ESCAPE  button on keyboard.

A general workaround is shown below!

Leave a comment

Design a site like this with WordPress.com
Get started