Android Open Source - SmartHome Utils






From Project

Back to project page SmartHome.

License

The source code is released under:

GNU General Public License

If you think the Android project SmartHome listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.geekytheory.SmartHome_App;
/* w ww  .j a  va  2 s  .c om*/
import android.app.Activity;
import android.content.res.Resources;
import android.util.Log;
import android.widget.Toast;

/**
 * Author: Mario Prez Esteso
 * Website: http://geekytheory.com
 * Mail: mario@geekytheory.com
 */

public class Utils {

    public static void logAndShow(Activity activity, String tag, Throwable t) {
        Log.e(tag, "Error", t);
        String message = t.getMessage();
        showError(activity, message);
    }

    public static void logAndShowError(Activity activity, String tag,
                                       String message) {
        String errorMessage = getErrorMessage(activity, message);
        Log.e(tag, errorMessage);
        showErrorInternal(activity, errorMessage);
    }

    public static void showError(Activity activity, String message) {
        String errorMessage = getErrorMessage(activity, message);
        showErrorInternal(activity, errorMessage);
    }

    private static void showErrorInternal(final Activity activity,
                                          final String errorMessage) {
        activity.runOnUiThread(new Runnable() {
            public void run() {
                Toast.makeText(activity, errorMessage, Toast.LENGTH_LONG)
                        .show();
            }
        });
    }

    private static String getErrorMessage(Activity activity, String message) {
        Resources resources = activity.getResources();
        if (message == null) {
            return resources.getString(R.string.error);
        }
        return resources.getString(R.string.error_format, message);
    }
}




Java Source Code List

com.geekytheory.SmartHome_App.About.java
com.geekytheory.SmartHome_App.AsyncLoadTasks.java
com.geekytheory.SmartHome_App.CommonAsyncTask.java
com.geekytheory.SmartHome_App.CustomHttpClient.java
com.geekytheory.SmartHome_App.DeviceItem.java
com.geekytheory.SmartHome_App.JSONuse.java
com.geekytheory.SmartHome_App.MyActivity.java
com.geekytheory.SmartHome_App.TestFragment.java
com.geekytheory.SmartHome_App.Utils.java