@@ -0,0 +1,2313 @@
+package org.projectbuendia.client.utils;%0A%0Aimport android.app.AlertDialog;%0Aimport android.content.Context;%0Aimport android.content.ContextWrapper;%0Aimport android.view.LayoutInflater;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0A%0Aimport javax.annotation.Nonnull;%0A%0Apublic class ContextUtils extends ContextWrapper %7B%0A    private LayoutInflater inflater = null;%0A    private View lastView = null;%0A%0A    public static ContextUtils from(Context context) %7B%0A        return (context instanceof ContextUtils) ? (ContextUtils) context : new ContextUtils(context);%0A    %7D%0A%0A    public static ContextUtils from(Provider provider) %7B%0A        return from(provider.getContext());%0A    %7D%0A%0A    public static ContextUtils from(View view) %7B%0A        return from(view.getContext());%0A    %7D%0A%0A    private ContextUtils(Context context) %7B%0A        super(context);%0A    %7D%0A%0A    /** Always use this method, never the awful, confusing LayoutInflater.inflate(). */%0A    public View inflate(int layoutId, @Nonnull ViewGroup layoutParent) %7B%0A        if (inflater == null) %7B%0A            inflater = LayoutInflater.from(this);%0A        %7D%0A        // Provide the parent so that the proper LayoutParams are created, but%0A        // set attachToRoot = false so that the returned value is the inflated%0A        // view, not a useless reference to its parent.%0A        lastView = inflater.inflate(layoutId, layoutParent, false);%0A        return lastView;%0A    %7D%0A%0A    /** Constructs an AlertDialog.Builder inflated from a given layout. */%0A    public AlertDialog.Builder buildDialog(int layoutId) %7B%0A        // This is the only situation where it's okay to pass null for the parent.%0A        return new AlertDialog.Builder(this).setView(inflate(layoutId, null));%0A    %7D%0A%0A    /** The parent can be null only when inflating a view for a dialog. */%0A    public View inflateForDialog(int id) %7B%0A        return inflate(id, null);%0A    %7D%0A%0A    /** Finds a view in the last view that was inflated. */%0A    public %3CT extends View%3E T findView(int id) %7B%0A        return lastView != null ? lastView.findViewById(id) : null;%0A    %7D%0A%0A    /** getColor() doesn't exist for API %3C 23, but it's final, so this can't be named getColor(). */%0A    public int color(int id) %7B%0A        return getResources().getColor(id);%0A    %7D%0A%0A    public interface Provider %7B%0A        Context getContext();%0A    %7D%0A%7D%0A

Add ContextUtils, a Context-aware utility class.