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

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

本文整理了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

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

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

@NonNull
public RequestManager get(@NonNull FragmentActivity activity) {
 if (Util.isOnBackgroundThread()) {
  return get(activity.getApplicationContext());
 } else {
  assertNotDestroyed(activity);
  FragmentManager fm = activity.getSupportFragmentManager();
  return supportFragmentGet(
    activity, fm, /*parentHint=*/ null, isActivityVisible(activity));
 }
}

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

@SuppressWarnings("deprecation")
@NonNull
public RequestManager get(@NonNull Activity activity) {
 if (Util.isOnBackgroundThread()) {
  return get(activity.getApplicationContext());
 } else {
  assertNotDestroyed(activity);
  android.app.FragmentManager fm = activity.getFragmentManager();
  return fragmentGet(
    activity, fm, /*parentHint=*/ null, isActivityVisible(activity));
 }
}

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

@SuppressWarnings("deprecation")
@Deprecated
@NonNull
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public RequestManager get(@NonNull android.app.Fragment fragment) {
 if (fragment.getActivity() == null) {
  throw new IllegalArgumentException(
    "You cannot start a load on a fragment before it is attached");
 }
 if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
  return get(fragment.getActivity().getApplicationContext());
 } else {
  android.app.FragmentManager fm = fragment.getChildFragmentManager();
  return fragmentGet(fragment.getActivity(), fm, fragment, fragment.isVisible());
 }
}

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

@SuppressWarnings("deprecation")
@NonNull
public RequestManager get(@NonNull View view) {
 if (Util.isOnBackgroundThread()) {
  return get(view.getContext().getApplicationContext());
 }
 Preconditions.checkNotNull(view);
 Preconditions.checkNotNull(view.getContext(),
   "Unable to obtain a request manager for a view without a Context");
 Activity activity = findActivity(view.getContext());
 // The view might be somewhere else, like a service.
 if (activity == null) {
  return get(view.getContext().getApplicationContext());
 }
 // Support Fragments.
 // Although the user might have non-support Fragments attached to FragmentActivity, searching
 // for non-support Fragments is so expensive pre O and that should be rare enough that we
 // prefer to just fall back to the Activity directly.
 if (activity instanceof FragmentActivity) {
  Fragment fragment = findSupportFragment(view, (FragmentActivity) activity);
  return fragment != null ? get(fragment) : get(activity);
 }
 // Standard Fragments.
 android.app.Fragment fragment = findFragment(view, activity);
 if (fragment == null) {
  return get(activity);
 }
 return get(fragment);
}

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

@NonNull
public RequestManager get(@NonNull Fragment fragment) {
 Preconditions.checkNotNull(fragment.getActivity(),
    "You cannot start a load on a fragment before it is attached or after it is destroyed");
 if (Util.isOnBackgroundThread()) {
  return get(fragment.getActivity().getApplicationContext());
 } else {
  FragmentManager fm = fragment.getChildFragmentManager();
  return supportFragmentGet(fragment.getActivity(), fm, fragment, fragment.isVisible());
 }
}

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

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

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

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

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

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public RequestManager get(Activity activity) {
  if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    return get(activity.getApplicationContext());
  } else {
    assertNotDestroyed(activity);
    android.app.FragmentManager fm = activity.getFragmentManager();
    return fragmentGet(activity, fm);
  }
}

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

public RequestManager get(FragmentActivity activity) {
  if (Util.isOnBackgroundThread()) {
    return get(activity.getApplicationContext());
  } else {
    assertNotDestroyed(activity);
    FragmentManager fm = activity.getSupportFragmentManager();
    return supportFragmentGet(activity, fm);
  }
}

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

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

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

RequestManager(Context context, final Lifecycle lifecycle, RequestManagerTreeNode treeNode,
    RequestTracker requestTracker, ConnectivityMonitorFactory factory) {
  this.context = context.getApplicationContext();
  this.lifecycle = lifecycle;
  this.treeNode = treeNode;
  this.requestTracker = requestTracker;
  this.glide = Glide.get(context);
  this.optionsApplier = new OptionsApplier();
  ConnectivityMonitor connectivityMonitor = factory.build(context,
      new RequestManagerConnectivityListener(requestTracker));
  // If we're the application level request manager, we may be created on a background thread. In that case we
  // cannot risk synchronously pausing or resuming requests, so we hack around the issue by delaying adding
  // ourselves as a lifecycle listener by posting to the main thread. This should be entirely safe.
  if (Util.isOnBackgroundThread()) {
    new Handler(Looper.getMainLooper()).post(new Runnable() {
      @Override
      public void run() {
        lifecycle.addListener(RequestManager.this);
      }
    });
  } else {
    lifecycle.addListener(this);
  }
  lifecycle.addListener(connectivityMonitor);
}

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

public RequestManager get(Fragment fragment) {
  if (fragment.getActivity() == null) {
    throw new IllegalArgumentException("You cannot start a load on a fragment before it is attached");
  }
  if (Util.isOnBackgroundThread()) {
    return get(fragment.getActivity().getApplicationContext());
  } else {
    FragmentManager fm = fragment.getChildFragmentManager();
    return supportFragmentGet(fragment.getActivity(), fm);
  }
}

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

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

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

public RequestManager get(Activity activity) {
 if (Util.isOnBackgroundThread()) {
  return get(activity.getApplicationContext());
 } else {
  assertNotDestroyed(activity);
  android.app.FragmentManager fm = activity.getFragmentManager();
  return fragmentGet(activity, fm, null /*parentHint*/);
 }
}

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

public RequestManager get(FragmentActivity activity) {
 if (Util.isOnBackgroundThread()) {
  return get(activity.getApplicationContext());
 } else {
  assertNotDestroyed(activity);
  FragmentManager fm = activity.getSupportFragmentManager();
  return supportFragmentGet(activity, fm, null /*parentHint*/);
 }
}

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

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

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

public RequestManager get(View view) {
 if (Util.isOnBackgroundThread()) {
  return get(view.getContext().getApplicationContext());
 }
 Preconditions.checkNotNull(view);
 Preconditions.checkNotNull(view.getContext(),
   "Unable to obtain a request manager for a view without a Context");
 Activity activity = findActivity(view.getContext());
 // The view might be somewhere else, like a service.
 if (activity == null) {
  return get(view.getContext().getApplicationContext());
 }
 // Support Fragments.
 // Although the user might have non-support Fragments attached to FragmentActivity, searching
 // for non-support Fragments is so expensive pre O and that should be rare enough that we
 // prefer to just fall back to the Activity directly.
 if (activity instanceof FragmentActivity) {
  Fragment fragment = findSupportFragment(view, (FragmentActivity) activity);
  return fragment != null ? get(fragment) : get(activity);
 }
 // Standard Fragments.
 android.app.Fragment fragment = findFragment(view, activity);
 if (fragment == null) {
  return get(activity);
 }
 return get(fragment);
}

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

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

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

@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
RequestManager(
  Glide glide,
  Lifecycle lifecycle,
  RequestManagerTreeNode treeNode,
  RequestTracker requestTracker,
  ConnectivityMonitorFactory factory) {
 this.glide = glide;
 this.lifecycle = lifecycle;
 this.treeNode = treeNode;
 this.requestTracker = requestTracker;
 final Context context = glide.getGlideContext().getBaseContext();
 connectivityMonitor =
   factory.build(context, new RequestManagerConnectivityListener(requestTracker));
 // If we're the application level request manager, we may be created on a background thread.
 // In that case we cannot risk synchronously pausing or resuming requests, so we hack around the
 // issue by delaying adding ourselves as a lifecycle listener by posting to the main thread.
 // This should be entirely safe.
 if (Util.isOnBackgroundThread()) {
  mainHandler.post(addSelfToLifecycle);
 } else {
  lifecycle.addListener(this);
 }
 lifecycle.addListener(connectivityMonitor);
 setRequestOptions(glide.getGlideContext().getDefaultRequestOptions());
 glide.registerRequestManager(this);
}

相关文章