Skip to content

Instantly share code, notes, and snippets.

@izumin5210
Last active Aug 29, 2015
Embed
What would you like to do?
Code templates for Android Studio ref: http://qiita.com/KeithYokoma/items/c046dcb54607262c041a
package ${PACKAGE_NAME};
import android.app.Activity;
import android.os.Bundle;
#parse("File Header.java")
public class ${NAME} extends Activity {
public static final String TAG = ${NAME}.class.getSimpleName();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
public static final String TAG = ${NAME}.class.getSimpleName();
}
package ${PACKAGE_NAME};
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
#parse("File Header.java")
public class ${NAME} extends Fragment {
public static final String TAG = ${NAME}.class.getSimpleName();
// Note: only the system can call this constructor by reflection.
public ${NAME}() {}
public static ${NAME} getInstance() {
${NAME} fragment = new ${NAME}();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return null;
}
}
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.support.v4.content.AsyncTaskLoader;
#parse("File Header.java")
public class ${NAME} extends AsyncTaskLoader<${RESULT}> {
public static final String TAG = ${NAME}.class.getSimpleName();
public ${NAME}(Context context) {
super(context);
}
@Override
public ${RESULT} loadInBackground() {
return null;
}
@Override
public void onStartLoading() {
super.onStartLoading();
forceLoad();
}
}
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.support.v4.content.AsyncTaskLoader;
#parse("File Header.java")
public class ${NAME} extends AsyncTaskLoader<${RESULT}> {
public static final String TAG = ${NAME}.class.getSimpleName();
private ${CACHE_TYPE} mCache;
public ${NAME}(Context context) {
super(context);
}
@Override
public ${RESULT} loadInBackground() {
return null;
}
@Override
public void deliverResult(${RESULT} data) {
if (isReset()) {
if (mCache != null) {
mCache = null;
}
return;
}
mCache = data;
if (isStarted()) {
super.deliverResult(data);
}
}
@Override
public void onStartLoading() {
if (this.result != null) {
deliverResult(mCache);
}
if (takeContentChanged() || mCache == null) {
forceLoad();
}
}
@Override
protected void onStopLoading() {
super.onStopLoading();
cancelLoad();
}
@Override
protected void onReset() {
super.onReset();
onStopLoading();
}
}
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "") package ${PACKAGE_NAME};#end
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
#parse("File Header.java")
public class ${NAME} implements Parcelable{
public static final String TAG = ${NAME}.class.getSimpleName();
public static final Creator<${NAME}> CREATOR = new Creator<${NAME}>() {
@Nullable
@Override
public ${NAME} createFromParcel(Parcel source) {
return new ${NAME}(source);
}
@Override
public ${NAME}[] newArray(int size) {
return new ${NAME}[size];
}
}
public ${NAME}(Parcel source) {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
}
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "") package ${PACKAGE_NAME};#end
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
#parse("File Header.java")
public class ${NAME} implements Parcelable{
public static final String TAG = ${NAME}.class.getSimpleName();
public static final Creator<${NAME}> CREATOR = new Creator<${NAME}>() {
@Nullable
@Override
public ${NAME} createFromParcel(Parcel source) {
return new ${NAME}(source);
}
@Override
public ${NAME}[] newArray(int size) {
return new ${NAME}[size];
}
}
// Note: only the builder of this type can call this constructor.
private ${NAME} () {}
public ${NAME}(Parcel source) {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
public static class Builder {
private final ${NAME} mTarget;
public Builder() {
mTarget = new ${NAME}();
}
public ${NAME} create() {
return mTarget;
}
}
}
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME}{
public static final String TAG = ${NAME}.class.getSimpleName();
private static ${NAME} ourInstance = new ${NAME}();
public static ${NAME} getInstance() {
return ourInstance;
}
private ${NAME}() {
}
}
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "") package ${PACKAGE_NAME};#end
#parse("File Header.java")
public final class ${NAME} {
private ${NAME}() {
throw new AssertionError("constructor of the utility class should not be called");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment