-
-
Save hyuni/59fa23a3b8d9d41048d4 to your computer and use it in GitHub Desktop.
A few live templates for Android Studio. On my Mac, this file lives in `~/Library/Preferences/AndroidStudioPreview1.3/templates/android.xml`. The location of the file depends on the version of Android Studio and the type of the operating system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<templateSet group="android"> | |
<template name="focvb" value="@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_$END$, container, false); ButterKnife.inject(this, view); return view; } " description="Fragment onCreateView with ButterKnife" toReformat="true" toShortenFQNames="true"> | |
<context> | |
<option name="JAVA_CODE" value="false" /> | |
<option name="JAVA_STATEMENT" value="false" /> | |
<option name="JAVA_EXPRESSION" value="true" /> | |
<option name="JAVA_DECLARATION" value="true" /> | |
<option name="JAVA_COMMENT" value="false" /> | |
<option name="JAVA_STRING" value="false" /> | |
<option name="COMPLETION" value="false" /> | |
</context> | |
</template> | |
<template name="fni" value="public static $CLASS_NAME$ newInstance() { return new $CLASS_NAME$(); } " description="Fragment newInstance" toReformat="false" toShortenFQNames="true"> | |
<variable name="CLASS_NAME" expression="className" defaultValue="" alwaysStopAt="false" /> | |
<context> | |
<option name="JAVA_DECLARATION" value="true" /> | |
</context> | |
</template> | |
<template name="fnia" value="private static final String $ARG_PARAM$ = "$CLASS_NAME$.$ARG_PARAM$"; private $ARG_CLASS_DITTO$ m$INST_VAR$; public static $CLASS_NAME$ newInstance($ARG_CLASS$ $ARG_VAR$) { $CLASS_NAME$ fragment = new $CLASS_NAME$(); Bundle args = new Bundle(); args.put$ARG_CLASS$($ARG_PARAM$, $ARG_VAR$); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); m$INST_VAR$ = getArguments().get$ARG_CLASS$($ARG_PARAM$); } " description="Fragment newInstance with arguments" toReformat="true" toShortenFQNames="true"> | |
<variable name="ARG_CLASS" expression="typeOfVariable(VAR)" defaultValue="" alwaysStopAt="true" /> | |
<variable name="ARG_VAR" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" /> | |
<variable name="ARG_CLASS_DITTO" expression="ARG_CLASS" defaultValue="" alwaysStopAt="false" /> | |
<variable name="ARG_PARAM" expression="capitalizeAndUnderscore(ARG_VAR)" defaultValue="" alwaysStopAt="false" /> | |
<variable name="CLASS_NAME" expression="className" defaultValue="" alwaysStopAt="false" /> | |
<variable name="INST_VAR" expression="capitalize(ARG_VAR)" defaultValue="" alwaysStopAt="false" /> | |
<context> | |
<option name="JAVA_DECLARATION" value="true" /> | |
</context> | |
</template> | |
<template name="@sn" value="@SerializedName("$VAR$") private $TYPE$ m$INSTVAR$;" description="@SerializedName inst var" toReformat="false" toShortenFQNames="true"> | |
<variable name="VAR" expression="" defaultValue="" alwaysStopAt="true" /> | |
<variable name="TYPE" expression="" defaultValue="" alwaysStopAt="true" /> | |
<variable name="INSTVAR" expression="capitalize(VAR)" defaultValue="" alwaysStopAt="false" /> | |
<context> | |
<option name="JAVA_DECLARATION" value="true" /> | |
</context> | |
</template> | |
<template name="ani" value="public static Intent newIntent(Context context) { return new Intent(context, $CLASS_NAME$.class); } " description="Activity newIntent" toReformat="false" toShortenFQNames="true"> | |
<variable name="CLASS_NAME" expression="className()" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="JAVA_DECLARATION" value="true" /> | |
</context> | |
</template> | |
<template name="ania" value="private static final String $EXTRA_PARAM$ = "$CLASS_NAME$.$EXTRA_PARAM$"; public static Intent newIntent(Context context, $EXTRA_CLASS$ $EXTRA_VAR$) { Intent intent = new Intent(context, $CLASS_NAME$.class); intent.putExtra($EXTRA_PARAM$, $EXTRA_VAR$);$END$ return intent; } @Override protected Fragment getFragment() { $EXTRA_CLASS$ $EXTRA_VAR$ = getIntent().get$EXTRA_CLASS$Extra($EXTRA_PARAM$); return $FRAGMENT_CLASS$.newInstance($EXTRA_VAR$); } " description="Activity newIntent with arguments" toReformat="false" toShortenFQNames="true"> | |
<variable name="EXTRA_CLASS" expression="typeOfVariable(VAR)" defaultValue="" alwaysStopAt="true" /> | |
<variable name="EXTRA_VAR" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" /> | |
<variable name="CLASS_NAME" expression="className" defaultValue="" alwaysStopAt="false" /> | |
<variable name="EXTRA_PARAM" expression="capitalizeAndUnderscore(EXTRA_VAR)" defaultValue="" alwaysStopAt="false" /> | |
<variable name="FRAGMENT_CLASS" expression="groovyScript("_1.replaceAll('Activity','Fragment')", CLASS_NAME)" defaultValue="" alwaysStopAt="false" /> | |
<context> | |
<option name="JAVA_DECLARATION" value="true" /> | |
</context> | |
</template> | |
<template name="toast" value="Toast.makeText($context$, "$text$", Toast.LENGTH_SHORT).show();" description="Toast in fragment or activity" toReformat="false" toShortenFQNames="true"> | |
<variable name="context" expression="groovyScript("_1.endsWith('Activity') ? _1+'.this' : 'getActivity()'", className())" defaultValue="" alwaysStopAt="false" /> | |
<variable name="text" expression="" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="JAVA_STATEMENT" value="true" /> | |
</context> | |
</template> | |
</templateSet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment