react-native-navigation的迁移库

ImageLoader.java 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.reactnativenavigation.react;
  2. import android.graphics.drawable.BitmapDrawable;
  3. import android.graphics.drawable.Drawable;
  4. import android.net.Uri;
  5. import com.reactnativenavigation.NavigationApplication;
  6. public class ImageLoader {
  7. private static final String FILE_SCHEME = "file";
  8. public static Drawable loadImage(String iconSource) {
  9. if (NavigationApplication.instance.isDebug()) {
  10. return JsDevImageLoader.loadIcon(iconSource);
  11. } else {
  12. Uri uri = Uri.parse(iconSource);
  13. if (isLocalFile(uri)) {
  14. return loadFile(uri);
  15. } else {
  16. return loadResource(iconSource);
  17. }
  18. }
  19. }
  20. private static boolean isLocalFile(Uri uri) {
  21. return FILE_SCHEME.equals(uri.getScheme());
  22. }
  23. private static Drawable loadFile(Uri uri) {
  24. return new BitmapDrawable(NavigationApplication.instance.getResources(), uri.getPath());
  25. }
  26. private static Drawable loadResource(String iconSource) {
  27. return ResourceDrawableIdHelper.instance.getResourceDrawable(NavigationApplication.instance, iconSource);
  28. }
  29. }