All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.ShadowTextUtils Maven / Gradle / Ivy

There is a newer version: 4.14.1
Show newest version
package org.robolectric.shadows;

import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

/**
 * Implement {@lint TextUtils#ellipsize} by truncating the text.
 */
@SuppressWarnings({"UnusedDeclaration"})
@Implements(TextUtils.class)
public class ShadowTextUtils {

  @Implementation
  protected static CharSequence ellipsize(
      CharSequence text, TextPaint p, float avail, TruncateAt where) {
    // This shadow follows the convention of ShadowPaint#measureText where each
    // characters width is 1.0.
    if (avail <= 0) {
      return "";
    } else if (text.length() < (int) (avail)) {
      return text;
    } else {
      return text.subSequence(0, (int) avail);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy