Skip to content

Commit ff8e0a1

Browse files
committed
HighlightEditText: 修复无法复制的问题 #1
1 parent 871e4d5 commit ff8e0a1

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

highLightText/src/main/java/org/evilbinary/highliter/HighlightEditText.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* Copyright (C) 2015 evilbinary.
22
3+
* Copyright 2016 Alex Zhang aka. ztc1997
34
This program is free software: you can redistribute it and/or modify
45
it under the terms of the GNU General Public License as published by
56
the Free Software Foundation, either version 3 of the License, or
@@ -17,22 +18,16 @@
1718
package org.evilbinary.highliter;
1819

1920
import android.content.Context;
20-
import android.graphics.Canvas;
21-
import android.graphics.Paint;
22-
import android.graphics.Point;
23-
import android.graphics.Rect;
24-
import android.graphics.Typeface;
21+
import android.graphics.*;
2522
import android.text.SpannableStringBuilder;
2623
import android.text.Spanned;
27-
import android.text.method.ScrollingMovementMethod;
2824
import android.text.style.CharacterStyle;
2925
import android.view.GestureDetector;
3026
import android.view.GestureDetector.OnGestureListener;
3127
import android.view.MotionEvent;
3228
import android.view.inputmethod.InputMethodManager;
3329
import android.widget.EditText;
3430
import android.widget.Scroller;
35-
3631
import org.evilbinary.highliter.parsers.MyTagToSpannedConverter;
3732
import org.evilbinary.highliter.parsers.SyntaxHighlight;
3833
import org.evilbinary.managers.Configure;
@@ -91,6 +86,9 @@ public class HighlightEditText extends EditText implements OnGestureListener {
9186

9287
public HighlightEditText(Context context, Configure conf) {
9388
super(context);
89+
90+
setTextIsSelectable(true);
91+
9492
mConfigure = conf;
9593

9694
mPaintNumbers = new Paint();
@@ -276,7 +274,7 @@ private void updateSettings() {
276274
// wordwrap
277275
setHorizontallyScrolling(!mConfigure.mSettings.WORDWRAP);
278276
if (!mConfigure.mSettings.WORDWRAP)// 卡顿问题
279-
setMovementMethod(ScrollingMovementMethod.getInstance());
277+
setMovementMethod(SelectableScrollingMovementMethod.getInstance());
280278

281279
// setTextColor(Color.BLACK);
282280
mPaintHighlight.setColor(mConfigure.mLineHighlightColor);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2016 Alex Zhang aka. ztc1997
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.evilbinary.highliter;
18+
19+
import android.text.method.MovementMethod;
20+
import android.text.method.ScrollingMovementMethod;
21+
22+
public class SelectableScrollingMovementMethod extends ScrollingMovementMethod {
23+
private static MovementMethod sInstance;
24+
25+
@Override
26+
public boolean canSelectArbitrarily() {
27+
return true;
28+
}
29+
30+
public static MovementMethod getInstance() {
31+
if (sInstance == null) {
32+
sInstance = new SelectableScrollingMovementMethod();
33+
}
34+
35+
return sInstance;
36+
}
37+
}

0 commit comments

Comments
 (0)