LynxMediaResourceFetcher

LynxMediaResourceFetcher is defined inside LynxEngine and injected from outside to implement the path redirection capability of Image and other third-party resources.

Android

Interface Definition:

LynxMediaResourceFetcher.java
public abstract class LynxMediaResourceFetcher {
  public abstract String shouldRedirectUrl(LynxResourceRequest request);

  /**
   * Quick check for a local path.
   *
   * @param url input path
   * @return
   *  TRUE if is a local path;
   *  FALSE if not a local path;
   *  UNDEFINED if not sure;
   */
  public OptionalBool isLocalResource(String url) {
    return OptionalBool.UNDEFINED;
  }

  /**
   * fetch Image Drawable directly.
   *
   * @param request
   * @param callback Response with the needed drawable.
   */
  public void fetchImage(LynxResourceRequest request, LynxResourceCallback<Closeable> callback) {}
}

Method introduction:

shouldRedirectUrl

LynxEngine redirects the image path by calling this method internally, and the return result is required to be of String type;

NOTE

This method must be implemented;

isLocalResource

LynxEngine internally calls this method to determine whether the resource path exists on disk;

NOTE

This method must be implemented;

fetchImage

LynxEngine will use this method to obtain the bitmap information of the image, and the return content must be of Closeable type;

NOTE

This method is optional to implement;

Injection:

Inject when constructing a LynxView using LynxViewBuilder:

LynxViewBuilder builder = new LynxViewBuilder();
builder.setMediaResourceFetcher(new MediaTemplateResourceFetcher());

Also enable this capability in LynxViewBuilder:

LynxViewBuilder builder = new LynxViewBuilder();
builder.setMediaResourceFetcher(new MediaTemplateResourceFetcher());
builder.setEnableGenericResourceFetcher(LynxBooleanOption.TRUE);

iOS

Interface Definition:

LynxMediaResourceFetcher.h
@protocol LynxMediaResourceFetcher <NSObject>

@required
- (NSString* _Nonnull)shouldRedirectUrl:(LynxResourceRequest* _Nonnull)request;

/**
 * Quick check for a local path.
 *
 * @param url input path
 * @return TRUE if is a local path; FALSE if not a local path
 */
@optional
- (LynxResourceOptionalBool)isLocalResource:(NSURL* _Nonnull)url;

/**
 * fetch UIImage directly.
 *
 * @param request
 * @param callback Response with the needed uiImage.
 *
 * @return A block which can cancel the image request if it is not finished. nil if cancel action is
 * not supported.
 */
@optional
- (dispatch_block_t)fetchUIImage:(LynxResourceRequest* _Nonnull)request
                      onComplete:(LynxMediaResourceCompletionBlock _Nonnull)response;

@end

Method introduction:

shouldRedirectUrl

LynxEngine redirects the image path by calling this method internally, and the return result is required to be of String type;

NOTE

This method must be implemented;

isLocalResource

LynxEngine internally calls this method to determine whether the resource path exists on disk;

NOTE

This method is optional to implement;

fetchUIImage

LynxEngine will use this method to obtain the bitmap information of the image, and the return content must be of Closeable type;

NOTE

This method is optional to implement;

Injection:

Inject when constructing a LynxView using LynxViewBuilder:

LynxViewBuilder *builder = [[LynxViewBuilder alloc] init];
builder.mediaResourceFetcher = [[ExampleMediaResourceFetcher alloc] init];

Also enable this capability in LynxViewBuilder:

LynxViewBuilder *builder = [[LynxViewBuilder alloc] init];
builder.mediaResourceFetcher = [[ExampleMediaResourceFetcher alloc] init];
builder.enableGenericResourceFetcher = LynxBooleanOptionTrue;

Compatibility

LCD tables only load in the browser

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.