Last active
October 21, 2015 18:12
-
-
Save mlc/964063224f585f0f6fbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Attempts to set copy into a TextView using the normal copy. If it ends up | |
* wrapping onto more than one line, uses the short copy alternative instead. | |
* @param textView The TextView (or Button or whatever) to setText on. | |
* @param normalCopyResId The preferred copy string resource id. | |
* @param shortCopyResId The alternate (shorter) copy string resource id. | |
*/ | |
public static void maybeUseShorterCopy(final TextView textView, | |
@StringRes final int normalCopyResId, | |
@StringRes final int shortCopyResId) { | |
textView.post(new Runnable() { | |
@Override | |
public void run() { | |
// posting to the view ensures that it's been laid out and sized first | |
textView.setText(normalCopyResId); | |
if (textView.getLineCount() > 1) { | |
textView.setText(shortCopyResId); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment