com.bumptech.glide.util.Util.isOnBackgroundThread()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(418)

本文整理了Java中com.bumptech.glide.util.Util.isOnBackgroundThread()方法的一些代码示例,展示了Util.isOnBackgroundThread()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.isOnBackgroundThread()方法的具体详情如下:
包路径:com.bumptech.glide.util.Util
类名称:Util
方法名:isOnBackgroundThread

Util.isOnBackgroundThread介绍

[英]Returns true if called on a background thread, false otherwise.
[中]如果在后台线程上调用,则返回true,否则返回false。

代码示例

代码示例来源:origin: bumptech/glide

  1. /**
  2. * Throws an {@link java.lang.IllegalArgumentException} if called on the main thread.
  3. */
  4. public static void assertBackgroundThread() {
  5. if (!isOnBackgroundThread()) {
  6. throw new IllegalArgumentException("You must call this method on a background thread");
  7. }
  8. }

代码示例来源:origin: bumptech/glide

  1. @NonNull
  2. public RequestManager get(@NonNull FragmentActivity activity) {
  3. if (Util.isOnBackgroundThread()) {
  4. return get(activity.getApplicationContext());
  5. } else {
  6. assertNotDestroyed(activity);
  7. FragmentManager fm = activity.getSupportFragmentManager();
  8. return supportFragmentGet(
  9. activity, fm, /*parentHint=*/ null, isActivityVisible(activity));
  10. }
  11. }

代码示例来源:origin: bumptech/glide

  1. @SuppressWarnings("deprecation")
  2. @NonNull
  3. public RequestManager get(@NonNull Activity activity) {
  4. if (Util.isOnBackgroundThread()) {
  5. return get(activity.getApplicationContext());
  6. } else {
  7. assertNotDestroyed(activity);
  8. android.app.FragmentManager fm = activity.getFragmentManager();
  9. return fragmentGet(
  10. activity, fm, /*parentHint=*/ null, isActivityVisible(activity));
  11. }
  12. }

代码示例来源:origin: bumptech/glide

  1. @SuppressWarnings("deprecation")
  2. @Deprecated
  3. @NonNull
  4. @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  5. public RequestManager get(@NonNull android.app.Fragment fragment) {
  6. if (fragment.getActivity() == null) {
  7. throw new IllegalArgumentException(
  8. "You cannot start a load on a fragment before it is attached");
  9. }
  10. if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
  11. return get(fragment.getActivity().getApplicationContext());
  12. } else {
  13. android.app.FragmentManager fm = fragment.getChildFragmentManager();
  14. return fragmentGet(fragment.getActivity(), fm, fragment, fragment.isVisible());
  15. }
  16. }

代码示例来源:origin: bumptech/glide

  1. @SuppressWarnings("deprecation")
  2. @NonNull
  3. public RequestManager get(@NonNull View view) {
  4. if (Util.isOnBackgroundThread()) {
  5. return get(view.getContext().getApplicationContext());
  6. }
  7. Preconditions.checkNotNull(view);
  8. Preconditions.checkNotNull(view.getContext(),
  9. "Unable to obtain a request manager for a view without a Context");
  10. Activity activity = findActivity(view.getContext());
  11. // The view might be somewhere else, like a service.
  12. if (activity == null) {
  13. return get(view.getContext().getApplicationContext());
  14. }
  15. // Support Fragments.
  16. // Although the user might have non-support Fragments attached to FragmentActivity, searching
  17. // for non-support Fragments is so expensive pre O and that should be rare enough that we
  18. // prefer to just fall back to the Activity directly.
  19. if (activity instanceof FragmentActivity) {
  20. Fragment fragment = findSupportFragment(view, (FragmentActivity) activity);
  21. return fragment != null ? get(fragment) : get(activity);
  22. }
  23. // Standard Fragments.
  24. android.app.Fragment fragment = findFragment(view, activity);
  25. if (fragment == null) {
  26. return get(activity);
  27. }
  28. return get(fragment);
  29. }

代码示例来源:origin: bumptech/glide

  1. @NonNull
  2. public RequestManager get(@NonNull Fragment fragment) {
  3. Preconditions.checkNotNull(fragment.getActivity(),
  4. "You cannot start a load on a fragment before it is attached or after it is destroyed");
  5. if (Util.isOnBackgroundThread()) {
  6. return get(fragment.getActivity().getApplicationContext());
  7. } else {
  8. FragmentManager fm = fragment.getChildFragmentManager();
  9. return supportFragmentGet(fragment.getActivity(), fm, fragment, fragment.isVisible());
  10. }
  11. }

代码示例来源:origin: bumptech/glide

  1. if (Util.isOnBackgroundThread()) {
  2. mainHandler.post(addSelfToLifecycle);
  3. } else {

代码示例来源:origin: guolindev/giffun

  1. /**
  2. * Throws an {@link IllegalArgumentException} if called on the main thread.
  3. */
  4. public static void assertBackgroundThread() {
  5. if (!isOnBackgroundThread()) {
  6. throw new IllegalArgumentException("YOu must call this method on a background thread");
  7. }
  8. }

代码示例来源:origin: guolindev/giffun

  1. @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  2. public RequestManager get(Activity activity) {
  3. if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
  4. return get(activity.getApplicationContext());
  5. } else {
  6. assertNotDestroyed(activity);
  7. android.app.FragmentManager fm = activity.getFragmentManager();
  8. return fragmentGet(activity, fm);
  9. }
  10. }

代码示例来源:origin: guolindev/giffun

  1. public RequestManager get(FragmentActivity activity) {
  2. if (Util.isOnBackgroundThread()) {
  3. return get(activity.getApplicationContext());
  4. } else {
  5. assertNotDestroyed(activity);
  6. FragmentManager fm = activity.getSupportFragmentManager();
  7. return supportFragmentGet(activity, fm);
  8. }
  9. }

代码示例来源:origin: guolindev/giffun

  1. @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  2. public RequestManager get(android.app.Fragment fragment) {
  3. if (fragment.getActivity() == null) {
  4. throw new IllegalArgumentException("You cannot start a load on a fragment before it is attached");
  5. }
  6. if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
  7. return get(fragment.getActivity().getApplicationContext());
  8. } else {
  9. android.app.FragmentManager fm = fragment.getChildFragmentManager();
  10. return fragmentGet(fragment.getActivity(), fm);
  11. }
  12. }

代码示例来源:origin: guolindev/giffun

  1. RequestManager(Context context, final Lifecycle lifecycle, RequestManagerTreeNode treeNode,
  2. RequestTracker requestTracker, ConnectivityMonitorFactory factory) {
  3. this.context = context.getApplicationContext();
  4. this.lifecycle = lifecycle;
  5. this.treeNode = treeNode;
  6. this.requestTracker = requestTracker;
  7. this.glide = Glide.get(context);
  8. this.optionsApplier = new OptionsApplier();
  9. ConnectivityMonitor connectivityMonitor = factory.build(context,
  10. new RequestManagerConnectivityListener(requestTracker));
  11. // If we're the application level request manager, we may be created on a background thread. In that case we
  12. // cannot risk synchronously pausing or resuming requests, so we hack around the issue by delaying adding
  13. // ourselves as a lifecycle listener by posting to the main thread. This should be entirely safe.
  14. if (Util.isOnBackgroundThread()) {
  15. new Handler(Looper.getMainLooper()).post(new Runnable() {
  16. @Override
  17. public void run() {
  18. lifecycle.addListener(RequestManager.this);
  19. }
  20. });
  21. } else {
  22. lifecycle.addListener(this);
  23. }
  24. lifecycle.addListener(connectivityMonitor);
  25. }

代码示例来源:origin: guolindev/giffun

  1. public RequestManager get(Fragment fragment) {
  2. if (fragment.getActivity() == null) {
  3. throw new IllegalArgumentException("You cannot start a load on a fragment before it is attached");
  4. }
  5. if (Util.isOnBackgroundThread()) {
  6. return get(fragment.getActivity().getApplicationContext());
  7. } else {
  8. FragmentManager fm = fragment.getChildFragmentManager();
  9. return supportFragmentGet(fragment.getActivity(), fm);
  10. }
  11. }

代码示例来源:origin: mozilla-tw/Rocket

  1. /**
  2. * Throws an {@link java.lang.IllegalArgumentException} if called on the main thread.
  3. */
  4. public static void assertBackgroundThread() {
  5. if (!isOnBackgroundThread()) {
  6. throw new IllegalArgumentException("You must call this method on a background thread");
  7. }
  8. }

代码示例来源:origin: mozilla-tw/Rocket

  1. public RequestManager get(Activity activity) {
  2. if (Util.isOnBackgroundThread()) {
  3. return get(activity.getApplicationContext());
  4. } else {
  5. assertNotDestroyed(activity);
  6. android.app.FragmentManager fm = activity.getFragmentManager();
  7. return fragmentGet(activity, fm, null /*parentHint*/);
  8. }
  9. }

代码示例来源:origin: mozilla-tw/Rocket

  1. public RequestManager get(FragmentActivity activity) {
  2. if (Util.isOnBackgroundThread()) {
  3. return get(activity.getApplicationContext());
  4. } else {
  5. assertNotDestroyed(activity);
  6. FragmentManager fm = activity.getSupportFragmentManager();
  7. return supportFragmentGet(activity, fm, null /*parentHint*/);
  8. }
  9. }

代码示例来源:origin: mozilla-tw/Rocket

  1. @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  2. public RequestManager get(android.app.Fragment fragment) {
  3. if (fragment.getActivity() == null) {
  4. throw new IllegalArgumentException(
  5. "You cannot start a load on a fragment before it is attached");
  6. }
  7. if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
  8. return get(fragment.getActivity().getApplicationContext());
  9. } else {
  10. android.app.FragmentManager fm = fragment.getChildFragmentManager();
  11. return fragmentGet(fragment.getActivity(), fm, fragment);
  12. }
  13. }

代码示例来源:origin: mozilla-tw/Rocket

  1. public RequestManager get(View view) {
  2. if (Util.isOnBackgroundThread()) {
  3. return get(view.getContext().getApplicationContext());
  4. }
  5. Preconditions.checkNotNull(view);
  6. Preconditions.checkNotNull(view.getContext(),
  7. "Unable to obtain a request manager for a view without a Context");
  8. Activity activity = findActivity(view.getContext());
  9. // The view might be somewhere else, like a service.
  10. if (activity == null) {
  11. return get(view.getContext().getApplicationContext());
  12. }
  13. // Support Fragments.
  14. // Although the user might have non-support Fragments attached to FragmentActivity, searching
  15. // for non-support Fragments is so expensive pre O and that should be rare enough that we
  16. // prefer to just fall back to the Activity directly.
  17. if (activity instanceof FragmentActivity) {
  18. Fragment fragment = findSupportFragment(view, (FragmentActivity) activity);
  19. return fragment != null ? get(fragment) : get(activity);
  20. }
  21. // Standard Fragments.
  22. android.app.Fragment fragment = findFragment(view, activity);
  23. if (fragment == null) {
  24. return get(activity);
  25. }
  26. return get(fragment);
  27. }

代码示例来源:origin: mozilla-tw/Rocket

  1. public RequestManager get(Fragment fragment) {
  2. Preconditions.checkNotNull(fragment.getActivity(),
  3. "You cannot start a load on a fragment before it is attached or after it is destroyed");
  4. if (Util.isOnBackgroundThread()) {
  5. return get(fragment.getActivity().getApplicationContext());
  6. } else {
  7. FragmentManager fm = fragment.getChildFragmentManager();
  8. return supportFragmentGet(fragment.getActivity(), fm, fragment);
  9. }
  10. }

代码示例来源:origin: mozilla-tw/Rocket

  1. @SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
  2. RequestManager(
  3. Glide glide,
  4. Lifecycle lifecycle,
  5. RequestManagerTreeNode treeNode,
  6. RequestTracker requestTracker,
  7. ConnectivityMonitorFactory factory) {
  8. this.glide = glide;
  9. this.lifecycle = lifecycle;
  10. this.treeNode = treeNode;
  11. this.requestTracker = requestTracker;
  12. final Context context = glide.getGlideContext().getBaseContext();
  13. connectivityMonitor =
  14. factory.build(context, new RequestManagerConnectivityListener(requestTracker));
  15. // If we're the application level request manager, we may be created on a background thread.
  16. // In that case we cannot risk synchronously pausing or resuming requests, so we hack around the
  17. // issue by delaying adding ourselves as a lifecycle listener by posting to the main thread.
  18. // This should be entirely safe.
  19. if (Util.isOnBackgroundThread()) {
  20. mainHandler.post(addSelfToLifecycle);
  21. } else {
  22. lifecycle.addListener(this);
  23. }
  24. lifecycle.addListener(connectivityMonitor);
  25. setRequestOptions(glide.getGlideContext().getDefaultRequestOptions());
  26. glide.registerRequestManager(this);
  27. }

相关文章