diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/ServiceUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/ServiceUtils.java new file mode 100644 index 000000000000..6bcfde06b892 --- /dev/null +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/ServiceUtils.java @@ -0,0 +1,16 @@ +package org.wordpress.android.util; + +import android.app.ActivityManager; +import android.content.Context; + +public class ServiceUtils { + public static boolean isServiceRunning(Context context, Class serviceClass) { + ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (serviceClass.getName().equals(service.service.getClassName())) { + return true; + } + } + return false; + } +} diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java index ec7f0144a757..6bf59b0998f2 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java @@ -1,6 +1,7 @@ package org.wordpress.android.util; import android.net.Uri; +import android.text.TextUtils; import android.webkit.MimeTypeMap; import android.webkit.URLUtil; @@ -195,4 +196,14 @@ public static boolean isValidUrlAndHostNotNull(String url) { } return true; } + + // returns true if the passed url is for an image + public static boolean isImageUrl(String url) { + if (TextUtils.isEmpty(url)) return false; + + String cleanedUrl = removeQuery(url.toLowerCase()); + + return cleanedUrl.endsWith("jpg") || cleanedUrl.endsWith("jpeg") || + cleanedUrl.endsWith("gif") || cleanedUrl.endsWith("png"); + } }