Class ResponsiveUrl

java.lang.Object
com.cloudinary.android.ResponsiveUrl

public class ResponsiveUrl
extends java.lang.Object
This class is used to generate view-size aware cloudinary Urls. It takes any View and a Url as input and returns a modified Url with the width/height transformation included, according to the chosen parameters. Note: When using this class, it's preferable to not include any cropping/scaling/dpr transformation in the base Url used. This can lead to unexpected results.
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static interface  ResponsiveUrl.Callback
    Callback to send to generate(Url, View, Callback)
    static class  ResponsiveUrl.Preset
    Ready made presets for common responsive use cases
  • Method Summary

    Modifier and Type Method Description
    com.cloudinary.Url buildUrl​(com.cloudinary.Url baseUrl, int width, int height)
    Construct the final url with the dimensions included as the last transformation in the url.
    void generate​(com.cloudinary.Url baseUrl, android.view.View view, ResponsiveUrl.Callback callback)
    Generate the modified url.
    void generate​(java.lang.String publicId, android.view.View view, ResponsiveUrl.Callback callback)
    Generate the modified url.
    ResponsiveUrl maxDimension​(int maxDimension)
    Limit the minimum allowed dimension, in pixels.
    ResponsiveUrl minDimension​(int minDimension)
    Limit the minimum allowed dimension, in pixels.
    ResponsiveUrl stepSize​(int stepSize)
    Step size i pixels.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • stepSize

      public ResponsiveUrl stepSize​(int stepSize)
      Step size i pixels. This is used to limit the number of generated transformations. The actual width/height parameter in the constructed url will always be a multiplication of step size and not the exact view width/height. For example, when using `width` with `stepSize` 100 on a view with width between 301 and 400 will render as `w_400` in the url.
      Parameters:
      stepSize - The step size to use, in pixels.
      Returns:
      Itself for chaining.
    • maxDimension

      public ResponsiveUrl maxDimension​(int maxDimension)
      Limit the minimum allowed dimension, in pixels. If the actual view width or height are larger than the value chosen here, this value will be used instead. This is useful to limit the total number of generated transformations.
      Parameters:
      maxDimension - The highest allowed dimension, in pixels.
      Returns:
      itself for chaining.
    • minDimension

      public ResponsiveUrl minDimension​(int minDimension)
      Limit the minimum allowed dimension, in pixels. If the actual view width or height are smaller than the value chosen here, this value will be used instead. This is useful to limit the total number of generated transformations.
      Parameters:
      minDimension - The smallest allowed dimension, in pixels.
      Returns:
      itself for chaining.
    • generate

      public void generate​(java.lang.String publicId, android.view.View view, ResponsiveUrl.Callback callback)
      Generate the modified url.
      Parameters:
      publicId - The public id of the cloudinary resource
      view - The view to adapt the resource dimensions to.
      callback - Callback to called when the modified Url is ready.
    • generate

      public void generate​(com.cloudinary.Url baseUrl, android.view.View view, ResponsiveUrl.Callback callback)
      Generate the modified url.
      Parameters:
      baseUrl - A url to be used as a base to the responsive transformation. This url can contain any configurations and transformations. The generated responsive transformation will be chained as the last transformation in the url. Important: When generating using a base url, it's preferable to not include any cropping/scaling in the original transformations.
      view - The view to adapt the resource dimensions to.
      callback - Callback to called when the modified Url is ready.
    • buildUrl

      public com.cloudinary.Url buildUrl​(com.cloudinary.Url baseUrl, int width, int height)
      Construct the final url with the dimensions included as the last transformation in the url.
      Parameters:
      baseUrl - The base cloudinary Url to chain the transformation to.
      width - The width to adapt the image width to.
      height - The height to adapt the image height to.
      Returns:
      The url with the responsive transformation.