@@ -39,6 +39,8 @@ public abstract class ShellHandlerBase extends Handler {
3939 */
4040 public static final int EVENT_EXIT = -2 ;
4141
42+ protected abstract void onToast (String text );
43+
4244 protected abstract void onProgress (int current , int total );
4345
4446 protected abstract void onStart (Object msg );
@@ -79,17 +81,35 @@ public void handleMessage(Message msg) {
7981 }
8082
8183 protected void onReaderMsg (Object msg ) {
82- if (msg != null ) {
83- String log = msg .toString ().trim ();
84- if (Pattern .matches ("^progress:\\ [[\\ -0-9\\ \\ ]{1,}/[0-9\\ \\ ]{1,}]$" , log )) {
85- String [] values = log .substring ("progress:[" .length (), log .indexOf ("]" )).split ("/" );
86- int start = Integer .parseInt (values [0 ]);
87- int total = Integer .parseInt (values [1 ]);
88- onProgress (start , total );
89- } else {
90- onReader (msg );
84+ if (msg == null ) return ;
85+
86+ // KHÔNG trim để giữ newline
87+ String log = msg .toString ();
88+
89+ // progress:[x/y]
90+ if (Pattern .matches ("^progress:\\ [[\\ -0-9]+/[0-9]+]$" , log .trim ())) {
91+ String [] values = log
92+ .substring ("progress:[" .length (), log .indexOf ("]" ))
93+ .split ("/" );
94+
95+ int start = Integer .parseInt (values [0 ]);
96+ int total = Integer .parseInt (values [1 ]);
97+ onProgress (start , total );
98+ return ;
99+ }
100+
101+ // toast:[text...]
102+ if (log .startsWith ("toast:[" )) {
103+ int end = log .lastIndexOf ("]" );
104+ if (end > 6 ) {
105+ String text = log .substring (6 , end );
106+ onToast (text );
91107 }
108+ return ;
92109 }
110+
111+ // log thường
112+ onReader (msg );
93113 }
94114
95115 protected void onReader (Object msg ) {
0 commit comments