@@ -31,8 +31,8 @@ public class CodeView extends ScrollView {
3131 private TextView line ;
3232 private LinearLayout bg ;
3333 private Theme theme ;
34- private int fontPX =50 ;
35- private int leftPX =50 ;
34+ private int fontPX =60 ;
35+ private int leftPX =60 ;
3636 private int W =0 ,H =0 ;
3737
3838 private HighLighter keywords = new HighLighter (
@@ -71,6 +71,7 @@ private void initialize(Context context) {
7171 bg =findViewById (R .id .bg );
7272 line =findViewById (R .id .line_text );
7373 code =findViewById (R .id .body_text );
74+ code .setHorizontallyScrolling (true );
7475 Point p =new Point ();
7576 WindowManager manager = (WindowManager )context .getSystemService (Context .WINDOW_SERVICE );
7677 Display display = manager .getDefaultDisplay ();
@@ -117,35 +118,28 @@ public void drawLine(String str){
117118 String [] lines = str .split ("\n " );
118119 leftPX =(int )(Math .log10 (lines .length +1 )+1 )*fontPX ;
119120 for (int i = 0 ; i < lines .length ; i ++) {
120- int len =lines [i ].length ()*fontPX ;
121- while (len +leftPX +1 >W ){
122- nstr +='\n' ;
123- len -=W -leftPX ;
124- }
125121 nstr += String .valueOf (count ) + '\n' ;
126122 count ++;
127123 }
128-
129124 line .setWidth (leftPX );
130125 line .setText (nstr );
131126 }
132127 public void paint (Editable s ){
133128 removeSpans (s , ForegroundColorSpan .class );
134- for ( HighLighter scheme : schemes ) {
135- for (Matcher m = scheme .pattern .matcher (s ); m .find (); ) {
136- s .setSpan (new ForegroundColorSpan (scheme .color ),
137- m .start (),
138- m .end (),
139- Spanned .SPAN_EXCLUSIVE_EXCLUSIVE );
140- }
141- }
129+ for ( HighLighter scheme : schemes )
130+ for (Matcher m = scheme .pattern .matcher (s ); m .find (); )
131+ s .setSpan (new ForegroundColorSpan (scheme .color ),m .start (),m .end (),Spanned .SPAN_EXCLUSIVE_EXCLUSIVE );
142132 }
143133 //remove old highlighting
144134 public void removeSpans (Editable e , Class <? extends CharacterStyle > type ) {
145135 CharacterStyle [] spans = e .getSpans (0 , e .length (), type );
146- for (CharacterStyle span : spans ) {
136+ for (CharacterStyle span : spans )
147137 e .removeSpan (span );
148- }
138+ }
139+ public void setTextSize (int px ){
140+ fontPX =px ;
141+ line .setTextSize (TypedValue .COMPLEX_UNIT_PX ,fontPX );
142+ code .setTextSize (TypedValue .COMPLEX_UNIT_PX ,fontPX );
149143 }
150144 public void setColor (Theme theme ){
151145 setBgColor (theme .getBackgroundColor ());
@@ -187,10 +181,7 @@ public void setPrintStatmentsColor(int color) {
187181 public void onConfigurationChanged (Configuration newConfig ) {
188182 super .onConfigurationChanged (newConfig );
189183 Log .d ("onConfigurationChanged" , "onConfigurationChanged" );
190-
191- int t =W ;
192- W =H ;
193- H =t ;
184+ int t =W ; W =H ; H =t ;
194185 try {
195186 setColor (theme );
196187 drawLine (code .getText ().toString ());
@@ -202,23 +193,20 @@ private boolean checkValidity(String s) {
202193 Stack stackCheck = new Stack ();
203194 char [] valid = s .toCharArray ();
204195 for (int i = 0 ; i < valid .length ; i ++) {
205- if (valid [i ] == '{' || valid [i ] == '(' ) {
196+ if (valid [i ] == '{' || valid [i ] == '(' )
206197 stackCheck .push ((valid [i ]));
207- }
208198 if (valid [i ] == '}' || valid [i ] == ')' ) {
209199 if (stackCheck .empty ()) {
210200 return false ;
211201 } else {
212- if (!matchPair ((char ) stackCheck .peek (), valid [i ])) {
202+ if (!matchPair ((char ) stackCheck .peek (), valid [i ]))
213203 return false ;
214- }
215204 stackCheck .pop ();
216205 }
217206 }
218207 }
219- if (stackCheck .size () == 1 ) {
208+ if (stackCheck .size () == 1 )
220209 return false ;
221- }
222210 return true ;
223211 }
224212
0 commit comments