Example usage for android.text Layout getEllipsisCount

List of usage examples for android.text Layout getEllipsisCount

Introduction

In this page you can find the example usage for android.text Layout getEllipsisCount.

Prototype

public abstract int getEllipsisCount(int line);

Source Link

Document

Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.

Usage

From source file:Main.java

/**
 * Returns true if the textview is ellipsized
 * @param textView//  w  w  w. j  a  v  a 2 s  .  co  m
 * @return
 */
public static boolean isTextEllipsized(TextView textView) {

    Layout textViewLayout = textView.getLayout();

    if (textViewLayout != null) {

        int lines = textViewLayout.getLineCount();

        if (lines > 0) {

            if (textViewLayout.getEllipsisCount(lines - 1) > 0)
                return true;
        }
    }

    return false;
}

From source file:free.yhc.feeder.model.Utils.java

/**
 * Text in given TextView is ellipsed?//w  w w. j a  va  2  s  .  com
 * @param tv
 * @return
 */
public static boolean isEllipsed(TextView tv) {
    Layout l = tv.getLayout();
    if (null != l) {
        int lines = l.getLineCount();
        if (lines > 0)
            if (l.getEllipsisCount(lines - 1) > 0)
                return true;
    }
    return false;
}

From source file:uk.ac.horizon.artcodes.activity.ExperienceActivity.java

@Override
public void loaded(Experience experience) {
    super.loaded(experience);
    GoogleAnalytics.trackScreen("View Experience", experience.getId());
    binding.setExperience(experience);/*from w w w  . j av a 2 s.c  o  m*/

    binding.experienceDescription.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (binding.experienceDescription.getLineCount() > 1) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            binding.experienceDescription.getViewTreeObserver()
                                    .removeOnGlobalLayoutListener(this);
                        }
                        final Layout layout = binding.experienceDescription.getLayout();
                        if (layout != null) {
                            final int lines = layout.getLineCount();
                            int ellipsisCount = 0;
                            for (int index = 0; index < lines; index++) {
                                ellipsisCount += layout.getEllipsisCount(index);
                            }

                            Log.i("Ellipsis", "Lines = " + lines + ", ellipsis = " + ellipsisCount);
                            if (ellipsisCount == 0) {
                                binding.experienceDescriptionMore.setVisibility(View.GONE);
                            } else {
                                final int lineChars = layout.getLineStart(1);
                                if (ellipsisCount < (lineChars * 2)) {
                                    binding.experienceDescription.setMaxLines(Integer.MAX_VALUE);
                                    binding.experienceDescriptionMore.setVisibility(View.GONE);
                                } else {
                                    binding.experienceDescriptionMore.setVisibility(View.VISIBLE);
                                }
                            }
                        }
                    } else {
                        binding.experienceDescriptionMore.setVisibility(View.GONE);
                    }
                }
            });

    binding.experienceLocations.removeAllViews();
    for (final Availability availability : experience.getAvailabilities()) {
        if (availability.getName() != null && availability.getLat() != null && availability.getLon() != null) {
            final LocationItemBinding locationBinding = LocationItemBinding.inflate(getLayoutInflater(),
                    binding.experienceLocations, false);
            locationBinding.setAvailability(availability);
            locationBinding.getRoot().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final Uri gmmIntentUri = Uri
                            .parse("geo:" + availability.getLat() + "," + availability.getLon());
                    final Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                    mapIntent.setPackage("com.google.android.apps.maps");
                    startActivity(mapIntent);
                }
            });
            binding.experienceLocations.addView(locationBinding.getRoot());
        }
    }

    if (experience.getOriginalID() != null) {
        getServer().loadExperience(experience.getOriginalID(), new LoadCallback<Experience>() {
            @Override
            public void loaded(Experience item) {
                originalExperience = item;
                binding.setOriginalExperience(item);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    if (updateActions()) {
        LocalBroadcastManager.getInstance(this).registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.hasExtra("experience")) {
                    loaded(new Gson().fromJson(intent.getStringExtra("experience"), Experience.class));
                }
            }
        }, new IntentFilter(getUri()));
    }
    updateStarred();
}

From source file:android.support.v7.widget.Toolbar.java

/** @hide */
public boolean isTitleTruncated() {
    if (mTitleTextView == null) {
        return false;
    }/*from  w  ww  . j a v  a  2  s . c  om*/

    final Layout titleLayout = mTitleTextView.getLayout();
    if (titleLayout == null) {
        return false;
    }

    final int lineCount = titleLayout.getLineCount();
    for (int i = 0; i < lineCount; i++) {
        if (titleLayout.getEllipsisCount(i) > 0) {
            return true;
        }
    }
    return false;
}