package de.fu_berlin.cdv.chasingpictures.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.widget.Toast;

/**
 * Class that provides utility methods.
 *
 * @author Simon Kalt
 */
public class Utilities {
    /**
     *
     * @param context The current context
     * @param formatString The message to be displayed
     * @param args Arguments to be formatted into the string
     * @deprecated Use {@link #showError(Context, int, Object...)} if possible.
     */
    @Deprecated
    public static void showError(Context context, String formatString, Object... args) {
        showError(context, formatString, null, args);
    }

    /**
     *
     * @param context The current context
     * @param formatString The message to be displayed
     * @param handler The handler to run Toast.show on
     *@param args Arguments to be formatted into the string  @deprecated Use {@link #showError(Context, int, Object...)} if possible.
     */
    @Deprecated
    public static void showError(Context context, String formatString, @Nullable Handler handler, Object... args) {
        @SuppressLint("ShowToast")
        final Toast toast = Toast.makeText(
                context,
                String.format(formatString, args),
                Toast.LENGTH_SHORT
        );

        if (handler != null) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    toast.show();
                }
            });
        } else {
            toast.show();
        }
    }

    /**
     * Displays an error to the user.
     * Currently does the same thing as {@link #showToast(Context, int, Object...)} but
     * could later be changed to look differently.
     * @param context The current context
     * @param resID A string resource to be displayed
     * @param args Arguments to be formatted into the string
     */
    public static void showError(Context context, @StringRes int resID, Object... args) {
        showError(context, resID, null, args);
    }

    /**
     * Displays an error to the user.
     * Currently does the same thing as {@link #showToast(Context, int, Object...)} but
     * could later be changed to look differently.
     * @param context The current context
     * @param resID A string resource to be displayed
     * @param handler
     * @param args Arguments to be formatted into the string
     */
    public static void showError(Context context, @StringRes int resID, @Nullable Handler handler, Object... args) {
        showToast(context, resID, handler, args);
    }

    /**
     * Displays a message to the user.
     * @param context The current context
     * @param resID A string resource to be displayed
     * @param args Arguments to be formatted into the string
     */
    public static void showToast(Context context, @StringRes final int resID, final Object... args) {
        showToast(context, resID, null, args);
    }

    /**
     * Displays a message to the user.
     * @param context The current context
     * @param resID A string resource to be displayed
     * @param handler
     * @param args Arguments to be formatted into the string
     */
    public static void showToast(Context context, @StringRes final int resID, @Nullable Handler handler, final Object... args) {
        @SuppressLint("ShowToast")
        final Toast toast = Toast.makeText(
                context,
                String.format(context.getString(resID), args),
                Toast.LENGTH_SHORT
        );

        // Display on main looper.
        if (handler != null) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    toast.show();
                }
            });
        } else {
            toast.show();
        }
    }
}

@@ -357,39 +357,32 @@
 ities %7B%0A    /**%0A
-     *%0A
      * @param co
@@ -379,32 +379,37 @@
  @param context 
+     
 The current cont
@@ -478,32 +478,40 @@
   * @param args 
+        
 Arguments to be 
@@ -802,15 +802,8 @@
 /**%0A
-     *%0A
     
@@ -812,32 +812,37 @@
  @param context 
+     
 The current cont
@@ -922,16 +922,21 @@
 handler 
+     
 The hand
@@ -946,32 +946,44 @@
  to 
-run
+post %7B@link
  Toast
-.
+#
 show
- on
+()%7D to
 %0A     *
+ 
 @par
@@ -982,32 +982,40 @@
   * @param args 
+        
 Arguments to be 
@@ -1896,32 +1896,39 @@
 ok differently.%0A
+     *%0A
      * @param co
@@ -1965,32 +1965,34 @@
  * @param resID 
+  
 A string resourc
@@ -2020,32 +2020,35 @@
   * @param args 
+   
 Arguments to be 
@@ -2406,24 +2406,31 @@
 ifferently.%0A
+     *%0A
      * @para
@@ -2471,32 +2471,34 @@
  * @param resID 
+  
 A string resourc
@@ -2528,32 +2528,76 @@
 * @param handler
+ The handler to post %7B@link Toast#show()%7D to
 %0A     * @param a
@@ -2592,32 +2592,35 @@
   * @param args 
+   
 Arguments to be 
@@ -2866,32 +2866,39 @@
 ge to the user.%0A
+     *%0A
      * @param co
@@ -2935,32 +2935,34 @@
  * @param resID 
+  
 A string resourc
@@ -2990,32 +2990,35 @@
   * @param args 
+   
 Arguments to be 
@@ -3250,24 +3250,31 @@
 o the user.%0A
+     *%0A
      * @para
@@ -3323,16 +3323,18 @@
 m resID 
+  
 A string
@@ -3380,16 +3380,60 @@
  handler
+ The handler to post %7B@link Toast#show()%7D to
 %0A     * 
@@ -3444,16 +3444,19 @@
 am args 
+   
 Argument

Update Javadoc