@nativescript-community/ui-label 1.1.25 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/label.android.d.ts +5 -3
- package/label.android.js +48 -12
- package/label.ios.d.ts +3 -7
- package/label.ios.js +66 -200
- package/package.json +3 -3
- package/platforms/android/include.gradle +1 -1
- package/platforms/android/native-api-usage.json +15 -0
- package/platforms/android/java/com/nativescript/label/EllipsizingTextView.java +0 -497
- package/pnpm-global/5/node_modules/.modules.yaml +0 -22
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/CHANGELOG.md +0 -212
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/LICENSE +0 -201
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/README.md +0 -14
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.d.ts +0 -40
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.js +0 -208
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.d.ts +0 -27
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.js +0 -298
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.d.ts +0 -1
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.d.ts +0 -14
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.js +0 -189
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.js +0 -25
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/package.json +0 -34
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/AndroidManifest.xml +0 -3
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/BaselineAdjustedSpan.java +0 -71
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/CustomBackgroundSpan.java +0 -70
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/CustomTypefaceSpan.java +0 -37
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/Font.java +0 -431
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/HeightSpan.java +0 -81
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/HtmlToSpannedConverter.java +0 -690
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/URLSpanNoUnderline.java +0 -24
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/DTCoreText.ios.d.ts +0 -22
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/android.d.ts +0 -32
- package/pnpm-global/5/node_modules/.pnpm/lock.yaml +0 -13
- package/pnpm-global/5/pnpm-lock.yaml +0 -13
@@ -1,497 +0,0 @@
|
|
1
|
-
package com.nativescript.label;
|
2
|
-
|
3
|
-
import android.content.Context;
|
4
|
-
import android.content.res.TypedArray;
|
5
|
-
import android.graphics.Canvas;
|
6
|
-
import android.graphics.Color;
|
7
|
-
import android.text.Layout;
|
8
|
-
import android.text.Layout.Alignment;
|
9
|
-
import android.text.Spannable;
|
10
|
-
import android.text.SpannableString;
|
11
|
-
import android.text.SpannableStringBuilder;
|
12
|
-
import android.text.Spanned;
|
13
|
-
import android.text.StaticLayout;
|
14
|
-
import android.text.TextUtils;
|
15
|
-
import android.text.TextUtils.TruncateAt;
|
16
|
-
import android.text.style.ForegroundColorSpan;
|
17
|
-
import android.util.AttributeSet;
|
18
|
-
import android.util.Log;
|
19
|
-
import android.util.TypedValue;
|
20
|
-
import android.view.View;
|
21
|
-
|
22
|
-
import java.util.ArrayList;
|
23
|
-
import java.util.List;
|
24
|
-
import java.util.regex.Pattern;
|
25
|
-
|
26
|
-
import androidx.annotation.NonNull;
|
27
|
-
import androidx.appcompat.widget.AppCompatTextView;
|
28
|
-
|
29
|
-
/**
|
30
|
-
* A {@link android.widget.TextView} that ellipsizes more intelligently.
|
31
|
-
* This class supports ellipsizing multiline text through setting {@code android:ellipsize}
|
32
|
-
* and {@code android:maxLines}.
|
33
|
-
* <p/>
|
34
|
-
* Note: {@link android.text.TextUtils.TruncateAt#MARQUEE} ellipsizing type is not supported.
|
35
|
-
* <p>
|
36
|
-
* 学习戚继光,一边儿读别人的源码,一边儿做笔记
|
37
|
-
*/
|
38
|
-
public class EllipsizingTextView extends AppCompatTextView {
|
39
|
-
public static final int ELLIPSIZE_ALPHA = 0x88;
|
40
|
-
private SpannableString ELLIPSIS = new SpannableString("\u2026");
|
41
|
-
|
42
|
-
private static final Pattern DEFAULT_END_PUNCTUATION
|
43
|
-
= Pattern.compile("[\\.!?,;:\u2026]*$", Pattern.DOTALL);
|
44
|
-
|
45
|
-
private final List<EllipsizeListener> mEllipsizeListeners = new ArrayList<>();
|
46
|
-
|
47
|
-
private EllipsizeStrategy mEllipsizeStrategy;
|
48
|
-
|
49
|
-
private boolean isEllipsized;
|
50
|
-
|
51
|
-
//In order to be the reset method only needs to be called once
|
52
|
-
private boolean isStale;
|
53
|
-
|
54
|
-
//The entry used to determine the call setText () is RESETTEXT or otherwhere call, this practice is cool.
|
55
|
-
private boolean programmaticChange;
|
56
|
-
|
57
|
-
//text
|
58
|
-
private CharSequence mFullText;
|
59
|
-
private int mMaxLines;
|
60
|
-
|
61
|
-
//The line spacing, this point is considered, great.
|
62
|
-
private float mLineSpacingMult = 1.0f;
|
63
|
-
private float mLineAddVertPad = 0.0f;
|
64
|
-
|
65
|
-
|
66
|
-
private boolean wordWrap = true;
|
67
|
-
private float minTextSize = 20;
|
68
|
-
private float maxTextSize = 30;
|
69
|
-
|
70
|
-
/**
|
71
|
-
* The end punctuation which will be removed when appending {@link #ELLIPSIS}.
|
72
|
-
*/
|
73
|
-
private Pattern mEndPunctPattern;
|
74
|
-
|
75
|
-
public EllipsizingTextView(Context context) {
|
76
|
-
this(context, null);
|
77
|
-
}
|
78
|
-
|
79
|
-
|
80
|
-
public EllipsizingTextView(Context context, AttributeSet attrs) {
|
81
|
-
this(context, attrs, android.R.attr.textViewStyle);
|
82
|
-
}
|
83
|
-
|
84
|
-
|
85
|
-
public EllipsizingTextView(Context context, AttributeSet attrs, int defStyle) {
|
86
|
-
super(context, attrs, defStyle);
|
87
|
-
TypedArray a = context.obtainStyledAttributes(attrs,
|
88
|
-
new int[]{android.R.attr.maxLines, android.R.attr.ellipsize}, defStyle, 0);
|
89
|
-
setMaxLines(a.getInt(0, Integer.MAX_VALUE));
|
90
|
-
a.recycle();
|
91
|
-
setEndPunctuationPattern(DEFAULT_END_PUNCTUATION);
|
92
|
-
maxTextSize = this.getTextSize();
|
93
|
-
if (maxTextSize < 35) {
|
94
|
-
maxTextSize = 30;
|
95
|
-
}
|
96
|
-
super.setSingleLine(false);
|
97
|
-
}
|
98
|
-
|
99
|
-
public void setEndPunctuationPattern(Pattern pattern) {
|
100
|
-
mEndPunctPattern = pattern;
|
101
|
-
}
|
102
|
-
|
103
|
-
@SuppressWarnings("unused")
|
104
|
-
public void addEllipsizeListener(@NonNull EllipsizeListener listener) {
|
105
|
-
mEllipsizeListeners.add(listener);
|
106
|
-
}
|
107
|
-
|
108
|
-
@SuppressWarnings("unused")
|
109
|
-
public void removeEllipsizeListener(@NonNull EllipsizeListener listener) {
|
110
|
-
mEllipsizeListeners.remove(listener);
|
111
|
-
}
|
112
|
-
|
113
|
-
@SuppressWarnings("unused")
|
114
|
-
public boolean isEllipsized() {
|
115
|
-
return isEllipsized;
|
116
|
-
}
|
117
|
-
|
118
|
-
/**
|
119
|
-
* @return The maximum number of lines displayed in this {@link android.widget.TextView}.
|
120
|
-
*/
|
121
|
-
public int getMaxLines() {
|
122
|
-
return mMaxLines;
|
123
|
-
}
|
124
|
-
|
125
|
-
@Override
|
126
|
-
public void setMaxLines(int maxLines) {
|
127
|
-
super.setMaxLines(maxLines);
|
128
|
-
// super.setMaxLines((maxLines == 0) ? Integer.MAX_VALUE : maxLines);
|
129
|
-
// if (maxLines == Integer.MAX_VALUE) {
|
130
|
-
// maxLines = 0;
|
131
|
-
// }
|
132
|
-
// // super.setMaxLines((maxLines == 0) ? Integer.MAX_VALUE : maxLines);
|
133
|
-
mMaxLines = maxLines;
|
134
|
-
isStale = true;
|
135
|
-
}
|
136
|
-
|
137
|
-
public float getMinTextSize() {
|
138
|
-
return minTextSize;
|
139
|
-
}
|
140
|
-
|
141
|
-
public void setMinTextSize(float minTextSize) {
|
142
|
-
this.minTextSize = minTextSize;
|
143
|
-
}
|
144
|
-
|
145
|
-
public float getMaxTextSize() {
|
146
|
-
return maxTextSize;
|
147
|
-
}
|
148
|
-
|
149
|
-
public void setMaxTextSize(float minTextSize) {
|
150
|
-
this.maxTextSize = minTextSize;
|
151
|
-
}
|
152
|
-
|
153
|
-
/**
|
154
|
-
* Determines if the last fully visible line is being ellipsized.
|
155
|
-
*
|
156
|
-
* @return {@code true} if the last fully visible line is being ellipsized;
|
157
|
-
* otherwise, returns {@code false}.
|
158
|
-
*/
|
159
|
-
public boolean ellipsizingLastFullyVisibleLine() {
|
160
|
-
return mMaxLines == Integer.MAX_VALUE;
|
161
|
-
}
|
162
|
-
|
163
|
-
@Override
|
164
|
-
public void setLineSpacing(float add, float mult) {
|
165
|
-
mLineAddVertPad = add;
|
166
|
-
mLineSpacingMult = mult;
|
167
|
-
super.setLineSpacing(add, mult);
|
168
|
-
}
|
169
|
-
|
170
|
-
@Override
|
171
|
-
public void setText(CharSequence text, BufferType type) {
|
172
|
-
if (!programmaticChange) {//Distribution source
|
173
|
-
mFullText = text instanceof Spanned ? (Spanned) text : text;
|
174
|
-
isStale = true;
|
175
|
-
}
|
176
|
-
super.setText(text, type);
|
177
|
-
}
|
178
|
-
|
179
|
-
@Override
|
180
|
-
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
181
|
-
int w = View.MeasureSpec.getSize(widthMeasureSpec);
|
182
|
-
// int wm = MeasureSpec.getMode(widthMeasureSpec);
|
183
|
-
int h = View.MeasureSpec.getSize(heightMeasureSpec);
|
184
|
-
int hm = View.MeasureSpec.getMode(heightMeasureSpec);
|
185
|
-
if (hm == 0)
|
186
|
-
h = 100000;
|
187
|
-
if ((hm == View.MeasureSpec.AT_MOST || hm == View.MeasureSpec.UNSPECIFIED)
|
188
|
-
&& (mFullText == null || mFullText.length() == 0)) {
|
189
|
-
heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.EXACTLY);
|
190
|
-
}
|
191
|
-
|
192
|
-
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
193
|
-
}
|
194
|
-
@Override
|
195
|
-
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
196
|
-
super.onSizeChanged(w, h, oldw, oldh);
|
197
|
-
if (ellipsizingLastFullyVisibleLine()) {//Rigorous, learning
|
198
|
-
isStale = true;
|
199
|
-
}
|
200
|
-
}
|
201
|
-
|
202
|
-
@Override
|
203
|
-
public void setPadding(int left, int top, int right, int bottom) {
|
204
|
-
super.setPadding(left, top, right, bottom);
|
205
|
-
if (ellipsizingLastFullyVisibleLine()) {//Rigorous, learning
|
206
|
-
isStale = true;
|
207
|
-
}
|
208
|
-
}
|
209
|
-
|
210
|
-
@Override
|
211
|
-
protected void onDraw(@NonNull Canvas canvas) {
|
212
|
-
if (isStale) {
|
213
|
-
resetText();
|
214
|
-
}
|
215
|
-
super.onDraw(canvas);
|
216
|
-
}
|
217
|
-
|
218
|
-
/**
|
219
|
-
* Sets the ellipsized text if appropriate.
|
220
|
-
*/
|
221
|
-
private void resetText() {
|
222
|
-
int maxLines = getMaxLines();
|
223
|
-
CharSequence workingText = mFullText;
|
224
|
-
boolean ellipsized = false;
|
225
|
-
|
226
|
-
if (maxLines != -1) {
|
227
|
-
if (mEllipsizeStrategy == null) setEllipsize(null);
|
228
|
-
workingText = mEllipsizeStrategy.processText(mFullText);
|
229
|
-
ellipsized = !mEllipsizeStrategy.isInLayout(mFullText);
|
230
|
-
}
|
231
|
-
|
232
|
-
if (!workingText.equals(getText())) {//Avoid useless operations
|
233
|
-
programmaticChange = true;
|
234
|
-
try {
|
235
|
-
setText(workingText);
|
236
|
-
} finally {
|
237
|
-
programmaticChange = false;
|
238
|
-
}
|
239
|
-
}
|
240
|
-
|
241
|
-
isStale = false;//Switch status
|
242
|
-
|
243
|
-
//Notification listener
|
244
|
-
if (ellipsized != isEllipsized) {
|
245
|
-
isEllipsized = ellipsized;
|
246
|
-
for (EllipsizeListener listener : mEllipsizeListeners) {
|
247
|
-
listener.ellipsizeStateChanged(ellipsized);
|
248
|
-
}
|
249
|
-
}
|
250
|
-
}
|
251
|
-
|
252
|
-
/**
|
253
|
-
* Causes words in the text that are longer than the view is wide to be ellipsized
|
254
|
-
* instead of broken in the middle. Use {@code null} to turn off ellipsizing.
|
255
|
-
* <p/>
|
256
|
-
* Note: Method does nothing for {@link android.text.TextUtils.TruncateAt#MARQUEE}
|
257
|
-
* ellipsizing type.
|
258
|
-
*
|
259
|
-
* @param where part of text to ellipsize
|
260
|
-
*/
|
261
|
-
@Override
|
262
|
-
public void setEllipsize(TruncateAt where) {
|
263
|
-
if (where == null) {
|
264
|
-
mEllipsizeStrategy = new EllipsizeNoneStrategy();
|
265
|
-
return;
|
266
|
-
}
|
267
|
-
|
268
|
-
switch (where) {
|
269
|
-
case END:
|
270
|
-
mEllipsizeStrategy = new EllipsizeEndStrategy();
|
271
|
-
break;
|
272
|
-
case START:
|
273
|
-
mEllipsizeStrategy = new EllipsizeStartStrategy();
|
274
|
-
break;
|
275
|
-
case MIDDLE:
|
276
|
-
mEllipsizeStrategy = new EllipsizeMiddleStrategy();
|
277
|
-
break;
|
278
|
-
case MARQUEE:
|
279
|
-
default:
|
280
|
-
mEllipsizeStrategy = new EllipsizeNoneStrategy();
|
281
|
-
break;
|
282
|
-
}
|
283
|
-
}
|
284
|
-
|
285
|
-
/**
|
286
|
-
* A listener that notifies when the ellipsize state has changed.
|
287
|
-
*/
|
288
|
-
public interface EllipsizeListener {
|
289
|
-
void ellipsizeStateChanged(boolean ellipsized);
|
290
|
-
}
|
291
|
-
|
292
|
-
/**
|
293
|
-
* A base class for an ellipsize strategy.
|
294
|
-
*/
|
295
|
-
private abstract class EllipsizeStrategy {
|
296
|
-
/**
|
297
|
-
* Returns ellipsized text if the text does not fit inside of the layout;
|
298
|
-
* otherwise, returns the full text.
|
299
|
-
*
|
300
|
-
* @param text text to process
|
301
|
-
* @return Ellipsized text if the text does not fit inside of the layout;
|
302
|
-
* otherwise, returns the full text.
|
303
|
-
*/
|
304
|
-
public CharSequence processText(CharSequence text) {
|
305
|
-
return !isInLayout(text) ? createEllipsizedText(text) : text;
|
306
|
-
}
|
307
|
-
|
308
|
-
/**
|
309
|
-
* Determines if the text fits inside of the layout.
|
310
|
-
*
|
311
|
-
* @param text text to fit
|
312
|
-
* @return {@code true} if the text fits inside of the layout;
|
313
|
-
* otherwise, returns {@code false}.
|
314
|
-
*/
|
315
|
-
public boolean isInLayout(CharSequence text) {
|
316
|
-
Layout layout = createWorkingLayout(text);
|
317
|
-
return layout.getLineCount() <= getLinesCount();
|
318
|
-
}
|
319
|
-
|
320
|
-
/**
|
321
|
-
* Creates a working layout with the given text.
|
322
|
-
*
|
323
|
-
* @param workingText text to create layout with
|
324
|
-
* @return {@link android.text.Layout} with the given text.
|
325
|
-
*/
|
326
|
-
protected Layout createWorkingLayout(CharSequence workingText) {
|
327
|
-
return new StaticLayout(workingText, getPaint(),
|
328
|
-
getWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight(),
|
329
|
-
Alignment.ALIGN_NORMAL, mLineSpacingMult,
|
330
|
-
mLineAddVertPad, false /* includepad */);
|
331
|
-
}
|
332
|
-
|
333
|
-
/**
|
334
|
-
* Get how many lines of text we are allowed to display.
|
335
|
-
*/
|
336
|
-
protected int getLinesCount() {
|
337
|
-
if (ellipsizingLastFullyVisibleLine()) {
|
338
|
-
int fullyVisibleLinesCount = getFullyVisibleLinesCount();
|
339
|
-
return fullyVisibleLinesCount == -1 ? 1 : fullyVisibleLinesCount;
|
340
|
-
} else {
|
341
|
-
return mMaxLines;
|
342
|
-
}
|
343
|
-
}
|
344
|
-
|
345
|
-
/**
|
346
|
-
* Get how many lines of text we can display so their full height is visible.
|
347
|
-
*/
|
348
|
-
protected int getFullyVisibleLinesCount() {
|
349
|
-
Layout layout = createWorkingLayout("");
|
350
|
-
int height = getHeight() - getCompoundPaddingTop() - getCompoundPaddingBottom();
|
351
|
-
int lineHeight = layout.getLineBottom(0);
|
352
|
-
return height / lineHeight;
|
353
|
-
}
|
354
|
-
|
355
|
-
/**
|
356
|
-
* Creates ellipsized text from the given text.
|
357
|
-
*
|
358
|
-
* @param fullText text to ellipsize
|
359
|
-
* @return Ellipsized text
|
360
|
-
*/
|
361
|
-
protected abstract CharSequence createEllipsizedText(CharSequence fullText);
|
362
|
-
}
|
363
|
-
|
364
|
-
/**
|
365
|
-
* An {@link EllipsizingTextView.EllipsizeStrategy} that
|
366
|
-
* does not ellipsize text.
|
367
|
-
*/
|
368
|
-
private class EllipsizeNoneStrategy extends EllipsizeStrategy {
|
369
|
-
@Override
|
370
|
-
protected CharSequence createEllipsizedText(CharSequence fullText) {
|
371
|
-
return fullText;
|
372
|
-
}
|
373
|
-
}
|
374
|
-
|
375
|
-
/**
|
376
|
-
* An {@link EllipsizingTextView.EllipsizeStrategy} that
|
377
|
-
* ellipsizes text at the end.
|
378
|
-
*/
|
379
|
-
private class EllipsizeEndStrategy extends EllipsizeStrategy {
|
380
|
-
@Override
|
381
|
-
protected CharSequence createEllipsizedText(CharSequence fullText) {
|
382
|
-
Layout layout = createWorkingLayout(fullText);
|
383
|
-
int lineCount = layout.getLineCount();
|
384
|
-
int lastLineIndex = Math.min(mMaxLines - 1, lineCount -1);
|
385
|
-
int cutOffIndex = layout.getLineEnd(lastLineIndex);
|
386
|
-
int textLength = fullText.length();
|
387
|
-
int cutOffLength = textLength - cutOffIndex;
|
388
|
-
if (cutOffLength < ELLIPSIS.length()) cutOffLength = ELLIPSIS.length();
|
389
|
-
|
390
|
-
//True to display text
|
391
|
-
CharSequence workingText = TextUtils.substring(fullText, 0, textLength - cutOffLength).trim();
|
392
|
-
|
393
|
-
|
394
|
-
final int lastLineStart = layout.getLineStart(lastLineIndex);
|
395
|
-
final CharSequence remainder = TextUtils.ellipsize(fullText.subSequence(lastLineStart,
|
396
|
-
fullText.length()), getPaint(), getWidth(), TextUtils.TruncateAt.END);
|
397
|
-
|
398
|
-
//seems to be handling corner case when there is still too many chars
|
399
|
-
while (!isInLayout(TextUtils.concat(stripEndPunctuation(workingText), ELLIPSIS))) {
|
400
|
-
workingText = workingText.subSequence(0, workingText.length() - 1);
|
401
|
-
|
402
|
-
}
|
403
|
-
|
404
|
-
//first we copy the text
|
405
|
-
workingText = TextUtils.concat(stripEndPunctuation(workingText), ELLIPSIS);
|
406
|
-
SpannableStringBuilder dest = new SpannableStringBuilder(workingText);
|
407
|
-
|
408
|
-
//then we apply spans if necessary
|
409
|
-
if (fullText instanceof Spanned) {
|
410
|
-
TextUtils.copySpansFrom((Spanned) fullText, 0, workingText.length(), null, dest, 0);
|
411
|
-
}
|
412
|
-
return dest;
|
413
|
-
}
|
414
|
-
|
415
|
-
/**
|
416
|
-
* Strips the end punctuation from a given text according to {@link #mEndPunctPattern}.
|
417
|
-
*
|
418
|
-
* @param workingText text to strip end punctuation from
|
419
|
-
* @return Text without end punctuation.
|
420
|
-
*/
|
421
|
-
public String stripEndPunctuation(CharSequence workingText) {
|
422
|
-
return mEndPunctPattern.matcher(workingText).replaceFirst("");
|
423
|
-
}
|
424
|
-
}
|
425
|
-
|
426
|
-
/**
|
427
|
-
* An {@link EllipsizingTextView.EllipsizeStrategy} that
|
428
|
-
* ellipsizes text at the start.
|
429
|
-
*/
|
430
|
-
private class EllipsizeStartStrategy extends EllipsizeStrategy {
|
431
|
-
@Override
|
432
|
-
protected CharSequence createEllipsizedText(CharSequence fullText) {
|
433
|
-
Layout layout = createWorkingLayout(fullText);
|
434
|
-
int cutOffIndex = layout.getLineEnd(mMaxLines - 1);
|
435
|
-
int textLength = fullText.length();
|
436
|
-
int cutOffLength = textLength - cutOffIndex;
|
437
|
-
if (cutOffLength < ELLIPSIS.length()) cutOffLength = ELLIPSIS.length();
|
438
|
-
CharSequence workingText = TextUtils.substring(fullText, cutOffLength, textLength).trim();
|
439
|
-
|
440
|
-
while (!isInLayout(TextUtils.concat(ELLIPSIS, workingText))) {
|
441
|
-
int firstSpace = TextUtils.indexOf(workingText, ' ');
|
442
|
-
if (firstSpace == -1) {
|
443
|
-
break;
|
444
|
-
}
|
445
|
-
workingText = TextUtils.substring(workingText, firstSpace, workingText.length()).trim();
|
446
|
-
}
|
447
|
-
|
448
|
-
workingText = TextUtils.concat(ELLIPSIS, workingText);
|
449
|
-
SpannableStringBuilder dest = new SpannableStringBuilder(workingText);
|
450
|
-
|
451
|
-
if (fullText instanceof Spanned) {
|
452
|
-
TextUtils.copySpansFrom((Spanned) fullText, textLength - workingText.length(),
|
453
|
-
textLength, null, dest, 0);
|
454
|
-
}
|
455
|
-
return dest;
|
456
|
-
}
|
457
|
-
}
|
458
|
-
|
459
|
-
/**
|
460
|
-
* An {@link EllipsizingTextView.EllipsizeStrategy} that
|
461
|
-
* ellipsizes text in the middle.
|
462
|
-
*/
|
463
|
-
private class EllipsizeMiddleStrategy extends EllipsizeStrategy {
|
464
|
-
@Override
|
465
|
-
protected CharSequence createEllipsizedText(CharSequence fullText) {
|
466
|
-
Layout layout = createWorkingLayout(fullText);
|
467
|
-
int cutOffIndex = layout.getLineEnd(mMaxLines - 1);
|
468
|
-
int textLength = fullText.length();
|
469
|
-
int cutOffLength = textLength - cutOffIndex;
|
470
|
-
if (cutOffLength < ELLIPSIS.length()) cutOffLength = ELLIPSIS.length();
|
471
|
-
cutOffLength += cutOffIndex % 2; // Make it even.
|
472
|
-
String firstPart = TextUtils.substring(
|
473
|
-
fullText, 0, textLength / 2 - cutOffLength / 2).trim();
|
474
|
-
String secondPart = TextUtils.substring(
|
475
|
-
fullText, textLength / 2 + cutOffLength / 2, textLength).trim();
|
476
|
-
|
477
|
-
while (!isInLayout(TextUtils.concat(firstPart, ELLIPSIS, secondPart))) {
|
478
|
-
int lastSpaceFirstPart = firstPart.lastIndexOf(' ');
|
479
|
-
int firstSpaceSecondPart = secondPart.indexOf(' ');
|
480
|
-
if (lastSpaceFirstPart == -1 || firstSpaceSecondPart == -1) break;
|
481
|
-
firstPart = firstPart.substring(0, lastSpaceFirstPart).trim();
|
482
|
-
secondPart = secondPart.substring(firstSpaceSecondPart, secondPart.length()).trim();
|
483
|
-
}
|
484
|
-
|
485
|
-
SpannableStringBuilder firstDest = new SpannableStringBuilder(firstPart);
|
486
|
-
SpannableStringBuilder secondDest = new SpannableStringBuilder(secondPart);
|
487
|
-
|
488
|
-
if (fullText instanceof Spanned) {
|
489
|
-
TextUtils.copySpansFrom((Spanned) fullText, 0, firstPart.length(),
|
490
|
-
null, firstDest, 0);
|
491
|
-
TextUtils.copySpansFrom((Spanned) fullText, textLength - secondPart.length(),
|
492
|
-
textLength, null, secondDest, 0);
|
493
|
-
}
|
494
|
-
return TextUtils.concat(firstDest, ELLIPSIS, secondDest);
|
495
|
-
}
|
496
|
-
}
|
497
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
hoistPattern:
|
2
|
-
- '*'
|
3
|
-
hoistedDependencies: {}
|
4
|
-
included:
|
5
|
-
dependencies: true
|
6
|
-
devDependencies: true
|
7
|
-
optionalDependencies: true
|
8
|
-
layoutVersion: 5
|
9
|
-
packageManager: pnpm@6.0.2
|
10
|
-
pendingBuilds: []
|
11
|
-
prunedAt: Mon, 19 Apr 2021 12:23:34 GMT
|
12
|
-
publicHoistPattern:
|
13
|
-
- '*types*'
|
14
|
-
- '*eslint*'
|
15
|
-
- '@prettier/plugin-*'
|
16
|
-
- '*prettier-plugin-*'
|
17
|
-
registries:
|
18
|
-
'@nativescript-community': https://registry.npmjs.org/
|
19
|
-
default: https://registry.npmjs.org/
|
20
|
-
skipped: []
|
21
|
-
storeDir: /usr/local/Cellar/.pnpm-store/v3
|
22
|
-
virtualStoreDir: .pnpm
|