Skip to content

Commit bb85adf

Browse files
committed
Introduced choice between scrolling and selecting text.
1 parent ab4317b commit bb85adf

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

aceeditor/src/main/java/com/susmit/aceeditor/AceEditor.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public class AceEditor extends WebView
4545

4646
private boolean loadedUI;
4747

48+
private OnTouchListener scroller;
49+
private OnTouchListener selector;
50+
51+
public static int ACTION_SCROLL=1;
52+
public static int ACTION_SELECT=0;
53+
4854
@SuppressLint("SetJavaScriptEnabled")
4955
public AceEditor(Context context)
5056
{
@@ -64,6 +70,7 @@ public AceEditor(Context context, AttributeSet attrs)
6470
initialize();
6571
}
6672

73+
@SuppressLint("SetJavaScriptEnabled")
6774
private void initialize()
6875
{
6976
inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
@@ -165,7 +172,8 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
165172
}
166173
});
167174

168-
setOnTouchListener(new View.OnTouchListener()
175+
176+
selector=new View.OnTouchListener()
169177
{
170178
float downTime;
171179
int xtimes;
@@ -217,7 +225,38 @@ else if(ytimes < 0) {
217225
}
218226
return false;
219227
}
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+
221260
setOnLongClickListener(new View.OnLongClickListener() {
222261
@Override
223262
public boolean onLongClick(View v) {
@@ -230,6 +269,7 @@ public boolean onLongClick(View v) {
230269
loadUrl("file:///android_asset/index.html");
231270
}
232271

272+
@SuppressLint("InflateParams")
233273
private void initPopup()
234274
{
235275
pw = new PopupWindow(context);
@@ -465,6 +505,14 @@ public void setMode(Mode mode)
465505
loadUrl("javascript:editor.session.setMode(\"ace/mode/" + mode.name().toLowerCase() + "\");");
466506
}
467507

508+
public void setTouchAction(int action)
509+
{
510+
if(action==ACTION_SCROLL)
511+
setOnTouchListener(scroller);
512+
else
513+
setOnTouchListener(selector);
514+
}
515+
468516
public static class Request{
469517
public static int GENERIC_REQUEST = 0;
470518
public static int TEXT_REQUEST = 1;

0 commit comments

Comments
 (0)