16
16
* Created by QarakenBacho on 13.05.2018.
17
17
*/
18
18
19
- public class CustomTextView extends android .support .v7 .widget .AppCompatTextView {
19
+ public class WaterTextView extends android .support .v7 .widget .AppCompatTextView {
20
20
21
21
private DrawableBackgroundSpan spanBoth ;
22
22
private DrawableBackgroundSpan spanTop ;
@@ -25,17 +25,17 @@ public class CustomTextView extends android.support.v7.widget.AppCompatTextView
25
25
private static int DIFFERENCE = 120 ;
26
26
27
27
28
- public CustomTextView (Context context ) {
28
+ public WaterTextView (Context context ) {
29
29
super (context );
30
30
init ();
31
31
}
32
32
33
- public CustomTextView (Context context , @ Nullable AttributeSet attrs ) {
33
+ public WaterTextView (Context context , @ Nullable AttributeSet attrs ) {
34
34
super (context , attrs );
35
35
init ();
36
36
}
37
37
38
- public CustomTextView (Context context , @ Nullable AttributeSet attrs , int defStyleAttr ) {
38
+ public WaterTextView (Context context , @ Nullable AttributeSet attrs , int defStyleAttr ) {
39
39
super (context , attrs , defStyleAttr );
40
40
init ();
41
41
}
@@ -67,42 +67,45 @@ public void onDraw(Canvas canvas){
67
67
68
68
int start = 0 ;
69
69
for (int i =0 ; i <lines .size (); i ++){
70
- BackgroundSpannable span = this . spanBoth ;
70
+ BackgroundSpannable span = spanBoth ;
71
71
int PADDING = 20 ;
72
- if (i ==0 ){
73
- if (widths .get (i +1 ) - widths .get (i )> DIFFERENCE ){
74
- if (this .spanBottom != null ) {
75
- span = spanBottom ;
76
- PADDING = 60 ;
77
- }
78
- }
79
- } else {
80
- if (i ==lines .size ()-1 ){
81
- if (widths .get (i -1 )-widths .get (i )> DIFFERENCE ){
82
- if (this .spanTop != null ) {
83
- span = spanTop ;
72
+
73
+ if (lines .size ()>1 ) {
74
+ if (i == 0 ) {
75
+ if (widths .get (i + 1 ) - widths .get (i ) > DIFFERENCE ) {
76
+ if (this .spanBottom != null ) {
77
+ span = spanBottom ;
84
78
PADDING = 60 ;
85
79
}
86
80
}
87
81
} else {
88
- if (widths .get (i +1 ) - widths .get (i ) > DIFFERENCE &&
89
- widths .get (i -1 ) - widths .get (i ) > DIFFERENCE ){
90
- if (this .spanNone != null ) {
91
- span = this .spanNone ;
92
- PADDING = 60 ;
93
- }
94
- } else {
95
- if (widths .get (i -1 )-widths .get (i )> DIFFERENCE && widths .get (i +1 ) - widths .get (i )< DIFFERENCE ){
82
+ if (i == lines .size () - 1 ) {
83
+ if (widths .get (i - 1 ) - widths .get (i ) > DIFFERENCE ) {
96
84
if (this .spanTop != null ) {
97
85
span = spanTop ;
98
86
PADDING = 60 ;
99
87
}
88
+ }
89
+ } else {
90
+ if (widths .get (i + 1 ) - widths .get (i ) > DIFFERENCE &&
91
+ widths .get (i - 1 ) - widths .get (i ) > DIFFERENCE ) {
92
+ if (this .spanNone != null ) {
93
+ span = this .spanNone ;
94
+ PADDING = 60 ;
95
+ }
100
96
} else {
101
- if (widths .get (i + 1 ) - widths .get (i )> DIFFERENCE && widths .get (i - 1 )- widths .get (i )< DIFFERENCE ){
102
- if (this .spanBottom != null ) {
103
- span = spanBottom ;
97
+ if (widths .get (i - 1 ) - widths .get (i ) > DIFFERENCE && widths .get (i + 1 ) - widths .get (i ) < DIFFERENCE ) {
98
+ if (this .spanTop != null ) {
99
+ span = spanTop ;
104
100
PADDING = 60 ;
105
101
}
102
+ } else {
103
+ if (widths .get (i + 1 ) - widths .get (i ) > DIFFERENCE && widths .get (i - 1 ) - widths .get (i ) < DIFFERENCE ) {
104
+ if (this .spanBottom != null ) {
105
+ span = spanBottom ;
106
+ PADDING = 60 ;
107
+ }
108
+ }
106
109
}
107
110
}
108
111
}
0 commit comments