@@ -45,6 +45,12 @@ public class AceEditor extends WebView
45
45
46
46
private boolean loadedUI ;
47
47
48
+ private OnTouchListener scroller ;
49
+ private OnTouchListener selector ;
50
+
51
+ public static int ACTION_SCROLL =1 ;
52
+ public static int ACTION_SELECT =0 ;
53
+
48
54
@ SuppressLint ("SetJavaScriptEnabled" )
49
55
public AceEditor (Context context )
50
56
{
@@ -64,6 +70,7 @@ public AceEditor(Context context, AttributeSet attrs)
64
70
initialize ();
65
71
}
66
72
73
+ @ SuppressLint ("SetJavaScriptEnabled" )
67
74
private void initialize ()
68
75
{
69
76
inflater = (LayoutInflater ) context .getSystemService ( Context .LAYOUT_INFLATER_SERVICE );
@@ -165,7 +172,8 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
165
172
}
166
173
});
167
174
168
- setOnTouchListener (new View .OnTouchListener ()
175
+
176
+ selector =new View .OnTouchListener ()
169
177
{
170
178
float downTime ;
171
179
int xtimes ;
@@ -217,7 +225,38 @@ else if(ytimes < 0) {
217
225
}
218
226
return false ;
219
227
}
220
- });
228
+ };
229
+
230
+ scroller = new OnTouchListener () {
231
+ float downTime ;
232
+ int xtimes ;
233
+ int ytimes ;
234
+ @ SuppressLint ("ClickableViewAccessibility" )
235
+ @ Override
236
+ public boolean onTouch (View v , MotionEvent event ) {
237
+ switch (event .getAction ())
238
+ {
239
+ case MotionEvent .ACTION_DOWN :
240
+ downTime = event .getEventTime ();
241
+ x =event .getX ();
242
+ y =event .getY ();
243
+ break ;
244
+ case MotionEvent .ACTION_UP :
245
+ x = event .getX ();
246
+ y = event .getY ();
247
+ break ;
248
+ case MotionEvent .ACTION_MOVE :
249
+ xtimes = (int ) (x - event .getX ());
250
+ ytimes = (int ) (y - event .getY ());
251
+ scrollBy (xtimes ,ytimes );
252
+ break ;
253
+ }
254
+ return false ;
255
+ }
256
+ };
257
+
258
+ setOnTouchListener (selector );
259
+
221
260
setOnLongClickListener (new View .OnLongClickListener () {
222
261
@ Override
223
262
public boolean onLongClick (View v ) {
@@ -230,6 +269,7 @@ public boolean onLongClick(View v) {
230
269
loadUrl ("file:///android_asset/index.html" );
231
270
}
232
271
272
+ @ SuppressLint ("InflateParams" )
233
273
private void initPopup ()
234
274
{
235
275
pw = new PopupWindow (context );
@@ -465,6 +505,14 @@ public void setMode(Mode mode)
465
505
loadUrl ("javascript:editor.session.setMode(\" ace/mode/" + mode .name ().toLowerCase () + "\" );" );
466
506
}
467
507
508
+ public void setTouchAction (int action )
509
+ {
510
+ if (action ==ACTION_SCROLL )
511
+ setOnTouchListener (scroller );
512
+ else
513
+ setOnTouchListener (selector );
514
+ }
515
+
468
516
public static class Request {
469
517
public static int GENERIC_REQUEST = 0 ;
470
518
public static int TEXT_REQUEST = 1 ;
0 commit comments