1414import com .tungsten .fclcore .task .Schedulers ;
1515import com .tungsten .fcllibrary .component .view .FCLTextView ;
1616
17+ import java .util .ArrayList ;
18+ import java .util .List ;
19+
1720public class LogWindow extends ScrollView {
1821
19- private boolean autoTint ;
20- private BooleanProperty visibilityProperty ;
22+ private final boolean autoTint ;
2123 private FCLTextView textView ;
2224 private int lineCount ;
23-
25+ private final List < Long > timeList = new ArrayList <>();
2426 public LogWindow (Context context ) {
2527 super (context );
2628 autoTint = false ;
@@ -29,25 +31,17 @@ public LogWindow(Context context) {
2931
3032 public LogWindow (Context context , AttributeSet attrs ) {
3133 super (context , attrs );
32- TypedArray typedArray = context .obtainStyledAttributes (attrs , R .styleable .LogWindow );
33- autoTint = typedArray .getBoolean (R .styleable .LogWindow_auto_log_tint , false );
34- typedArray . recycle ();
34+ try ( TypedArray typedArray = context .obtainStyledAttributes (attrs , R .styleable .LogWindow )) {
35+ autoTint = typedArray .getBoolean (R .styleable .LogWindow_auto_log_tint , false );
36+ }
3537 init (context );
3638 }
3739
3840 public LogWindow (Context context , AttributeSet attrs , int defStyleAttr ) {
3941 super (context , attrs , defStyleAttr );
40- TypedArray typedArray = context .obtainStyledAttributes (attrs , R .styleable .LogWindow );
41- autoTint = typedArray .getBoolean (R .styleable .LogWindow_auto_log_tint , false );
42- typedArray .recycle ();
43- init (context );
44- }
45-
46- public LogWindow (Context context , AttributeSet attrs , int defStyleAttr , int defStyleRes ) {
47- super (context , attrs , defStyleAttr , defStyleRes );
48- TypedArray typedArray = context .obtainStyledAttributes (attrs , R .styleable .LogWindow );
49- autoTint = typedArray .getBoolean (R .styleable .LogWindow_auto_log_tint , false );
50- typedArray .recycle ();
42+ try (TypedArray typedArray = context .obtainStyledAttributes (attrs , R .styleable .LogWindow )) {
43+ autoTint = typedArray .getBoolean (R .styleable .LogWindow_auto_log_tint , false );
44+ }
5145 init (context );
5246 }
5347
@@ -62,46 +56,14 @@ private void init(Context context) {
6256 textView .setEllipsize (null );
6357 }
6458
65- public final void setVisibilityValue (boolean visibility ) {
66- visibilityProperty ().set (visibility );
67- }
68-
69- public final boolean getVisibilityValue () {
70- return visibilityProperty == null || visibilityProperty .get ();
71- }
72-
73- public final BooleanProperty visibilityProperty () {
74- if (visibilityProperty == null ) {
75- visibilityProperty = new BooleanPropertyBase () {
76-
77- @ Override
78- public void invalidated () {
79- Schedulers .androidUIThread ().execute (() -> {
80- boolean visible = get ();
81- setVisibility (visible ? VISIBLE : GONE );
82- if (!visible ) {
83- cleanLog ();
84- }
85- });
86- }
87-
88- @ Override
89- public Object getBean () {
90- return this ;
91- }
92-
93- @ Override
94- public String getName () {
95- return "visibility" ;
96- }
97- };
98- }
99-
100- return visibilityProperty ;
59+ public final void setVisibility (boolean visibility ) {
60+ setVisibility (visibility ? VISIBLE : GONE );
61+ if (!visibility )
62+ cleanLog ();
10163 }
10264
10365 public void appendLog (String str ) {
104- if (! getVisibilityValue () ) {
66+ if (getVisibility () != VISIBLE ) {
10567 return ;
10668 }
10769 lineCount ++;
@@ -115,6 +77,12 @@ public void appendLog(String str) {
11577 fullScroll (View .FOCUS_DOWN );
11678 }
11779 });
80+ long now = System .currentTimeMillis ();
81+ timeList .removeIf (time -> now - time > 200 );
82+ timeList .add (now );
83+ if (timeList .size () > 200 ) {
84+ setVisibility (false );
85+ }
11886 }
11987
12088 public void cleanLog () {
0 commit comments