├── .gitattributes
├── .gitignore
├── README.md
├── ReaderTextSelect
└── ReaderTextSelect
│ ├── .gitignore
│ ├── .idea
│ ├── compiler.xml
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── encodings.xml
│ ├── gradle.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── runConfigurations.xml
│ ├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hw
│ │ │ └── readertextselect
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hw
│ │ │ │ └── readertextselect
│ │ │ │ ├── BreakResult.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── ShowChar.java
│ │ │ │ ├── ShowLine.java
│ │ │ │ ├── TextBreakUtil.java
│ │ │ │ └── TextSlelectView.java
│ │ └── res
│ │ │ ├── layout
│ │ │ └── activity_main.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── hw
│ │ └── readertextselect
│ │ └── ExampleUnitTest.java
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
├── readertextselect.gif
├── 滑动选择文字2.png
├── 滑动选择文字3.png
└── 长按选中文字1.png
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear on external disk
35 | .Spotlight-V100
36 | .Trashes
37 |
38 | # Directories potentially created on remote AFP share
39 | .AppleDB
40 | .AppleDesktop
41 | Network Trash Folder
42 | Temporary Items
43 | .apdisk
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ReaderTextSelect
2 | 阅读器长按选择文字功能实现,效果如下:
3 |
4 | 
5 | 
6 | 
7 | 
8 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Android API 23, N preview Platform
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.0"
6 | defaultConfig {
7 | applicationId "com.hw.readertextselect"
8 | minSdkVersion 15
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:26.+'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\android\studiosdk\Android\Android/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/androidTest/java/com/hw/readertextselect/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hw.readertextselect;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.hw.readertextselect", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/java/com/hw/readertextselect/BreakResult.java:
--------------------------------------------------------------------------------
1 | package com.hw.readertextselect;
2 |
3 | import java.util.List;
4 |
5 | public class BreakResult {
6 |
7 | public int ChartNums = 0;
8 | public Boolean IsFullLine = false;
9 | public List showChars = null;
10 |
11 | public Boolean HasData() {
12 | return showChars != null && showChars.size() > 0;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/java/com/hw/readertextselect/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hw.readertextselect;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | public class MainActivity extends Activity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_main);
12 | }
13 |
14 |
15 |
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/java/com/hw/readertextselect/ShowChar.java:
--------------------------------------------------------------------------------
1 | package com.hw.readertextselect;
2 |
3 | import android.graphics.Point;
4 |
5 | public class ShowChar {
6 |
7 | public char chardata ;
8 |
9 | public Boolean Selected =false;
10 |
11 | public Point TopLeftPosition = null;
12 | public Point TopRightPosition = null;
13 | public Point BottomLeftPosition = null;
14 | public Point BottomRightPosition = null;
15 |
16 | public float charWidth = 0;
17 | public int Index = 0;
18 |
19 | @Override
20 | public String toString() {
21 | return "ShowChar [chardata=" + chardata + ", Selected=" + Selected + ", TopLeftPosition=" + TopLeftPosition
22 | + ", TopRightPosition=" + TopRightPosition + ", BottomLeftPosition=" + BottomLeftPosition
23 | + ", BottomRightPosition=" + BottomRightPosition + ", charWidth=" + charWidth + ", Index=" + Index
24 | + "]";
25 | }
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/java/com/hw/readertextselect/ShowLine.java:
--------------------------------------------------------------------------------
1 | package com.hw.readertextselect;
2 |
3 | import java.util.List;
4 |
5 | public class ShowLine {
6 | public List CharsData = null;
7 |
8 | @Override
9 | public String toString() {
10 | return "ShowLine [Linedata=" + getLineData() + "]";
11 | }
12 |
13 | public String getLineData(){
14 | String linedata = "";
15 | if(CharsData==null||CharsData.size()==0) return linedata;
16 | for(ShowChar c:CharsData){
17 | linedata = linedata+c.chardata;
18 | }
19 | return linedata;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/java/com/hw/readertextselect/TextBreakUtil.java:
--------------------------------------------------------------------------------
1 | package com.hw.readertextselect;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.graphics.Paint;
6 | import android.text.TextUtils;
7 |
8 | public class TextBreakUtil {
9 |
10 | /**
11 | *@param cs
12 | *@param medsurewidth
13 | *@param textpadding
14 | *@param paint
15 | *@return 如果cs为空或者长度为0,返回null
16 | *--------------------
17 | *TODO
18 | *--------------------
19 | * author: huangwei
20 | * 2017年5月4日下午3:31:03
21 | */
22 | public static BreakResult BreakText(char[] cs, float medsurewidth, float textpadding, Paint paint) {
23 | if(cs==null||cs.length==0){return null;}
24 | BreakResult breakResult = new BreakResult();
25 | breakResult.showChars = new ArrayList();
26 | float width = 0;
27 |
28 | for (int i = 0, size = cs.length; i < size; i++) {
29 | String mesasrustr = String.valueOf(cs[i]);
30 | float charwidth = paint.measureText(mesasrustr);
31 |
32 | if (width <= medsurewidth && (width + textpadding + charwidth) > medsurewidth) {
33 | breakResult.ChartNums = i;
34 | breakResult.IsFullLine = true;
35 | return breakResult;
36 | }
37 |
38 | ShowChar showChar = new ShowChar();
39 | showChar.chardata = cs[i];
40 | showChar.charWidth = charwidth;
41 | breakResult.showChars.add(showChar);
42 | width += charwidth + textpadding;
43 | }
44 |
45 | breakResult.ChartNums = cs.length;
46 | return breakResult;
47 | }
48 |
49 | /**
50 | *@param text
51 | *@param medsurewidth
52 | *@param textpadding
53 | *@param paint
54 | *@return 如果text为空,返回null
55 | *--------------------
56 | *TODO
57 | *--------------------
58 | * author: huangwei
59 | * 2017年7月3日下午3:12:12
60 | */
61 | public static BreakResult BreakText(String text, float medsurewidth, float textpadding, Paint paint) {
62 | if (TextUtils.isEmpty(text)) {
63 | int[] is = new int[2];
64 | is[0] = 0;
65 | is[1] = 0;
66 | return null;
67 | }
68 | return BreakText(text.toCharArray(), medsurewidth, textpadding, paint);
69 |
70 | }
71 |
72 | public static float MeasureText(String text, float textpadding, Paint paint) {
73 | if (TextUtils.isEmpty(text))
74 | return 0;
75 | char[] cs = text.toCharArray();
76 | float width = 0;
77 | for (int i = 0, size = cs.length; i < size; i++) {
78 | String mesasrustr = String.valueOf(cs[i]);
79 | float charwidth = paint.measureText(mesasrustr);
80 | width += charwidth + textpadding;
81 | }
82 |
83 | return width;
84 | }
85 |
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/java/com/hw/readertextselect/TextSlelectView.java:
--------------------------------------------------------------------------------
1 | package com.hw.readertextselect;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Paint.FontMetrics;
8 | import android.graphics.Path;
9 | import android.graphics.Point;
10 | import android.graphics.RectF;
11 | import android.graphics.Region;
12 | import android.util.AttributeSet;
13 | import android.util.Log;
14 | import android.view.MotionEvent;
15 | import android.view.View;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | public class TextSlelectView extends View {
21 |
22 | String TextData = "jEh话说天下大势,分久必合,合久必分。周末七国分争,并入于秦。及秦灭之后,楚、汉分争,又并入于汉。汉朝自高祖斩白蛇而起义,一统天下,后来光武中兴,传至献帝,遂分为三国。推其致乱之由,殆始于桓、灵二帝。桓帝禁锢善类,崇信宦官。及桓帝崩,灵帝即位,大将军窦武、太傅陈蕃共相辅佐。时有宦官曹节等弄权,窦武、陈蕃谋诛之,机事不密,反为所害,中涓自此愈横"
23 | +
24 |
25 | "建宁二年四月望日,帝御温德殿。方升座,殿角狂风骤起。只见一条大青蛇,从梁上飞将下来,蟠于椅上。帝惊倒,左右急救入宫,百官俱奔避。须臾,蛇不见了。忽然大雷大雨,加以冰雹,落到半夜方止,坏却房屋无数。建宁四年二月,洛阳地震;又海水泛溢,沿海居民,尽被大浪卷入海中。光和元年,雌鸡化雄。六月朔,黑气十余丈,飞入温德殿中。秋七月,有虹现于玉堂;五原山岸,尽皆崩裂。种种不祥,非止一端。帝下诏问群臣以灾异之由,议郎蔡邕上疏,以为堕鸡化,乃妇寺干政之所致,言颇切直。帝览奏叹息,因起更衣。曹节在后窃视,悉宣告左右;遂以他事陷邕于罪,放归田里。后张让、赵忠、封、段、曹节、侯览、蹇硕、程旷、夏恽、郭胜十人朋比为奸,号为“十常侍”。帝尊信张让,呼为“阿父”。朝政日非,以致天下人心思乱,盗贼蜂起。";
26 |
27 | public TextSlelectView(Context context) {
28 | super(context);
29 | init();
30 |
31 | }
32 |
33 | public TextSlelectView(Context context, AttributeSet attrs) {
34 | super(context, attrs);
35 | init();
36 | }
37 |
38 | public TextSlelectView(Context context, AttributeSet attrs, int defStyleAttr) {
39 | super(context, attrs, defStyleAttr);
40 | init();
41 | }
42 |
43 | private Paint mPaint = null;
44 | private Paint mTextSelectPaint = null;
45 | private Paint mBorderPointPaint = null;
46 | private int TextSelectColor = Color.parseColor("#77fadb08");
47 | private int BorderPointColor = Color.RED;
48 |
49 | private void init() {
50 | mPaint = new Paint();
51 | mPaint.setAntiAlias(true);
52 | mPaint.setTextSize(39);
53 |
54 | mTextSelectPaint = new Paint();
55 | mTextSelectPaint.setAntiAlias(true);
56 | mTextSelectPaint.setTextSize(19);
57 | mTextSelectPaint.setColor(TextSelectColor);
58 |
59 | mBorderPointPaint = new Paint();
60 | mBorderPointPaint.setAntiAlias(true);
61 | mBorderPointPaint.setTextSize(19);
62 | mBorderPointPaint.setColor(BorderPointColor);
63 |
64 | FontMetrics fontMetrics = mPaint.getFontMetrics();
65 | TextHeight = Math.abs(fontMetrics.ascent) + Math.abs(fontMetrics.descent);
66 |
67 | setOnLongClickListener(mLongClickListener);
68 |
69 | }
70 |
71 | private OnLongClickListener mLongClickListener = new OnLongClickListener() {
72 |
73 | @Override
74 | public boolean onLongClick(View v) {
75 |
76 | if (mCurrentMode == Mode.Normal) {
77 | if (Down_X > 0 && Down_Y > 0) {// 说明还没释放,是长按事件
78 | mCurrentMode = Mode.PressSelectText;
79 | postInvalidate();
80 | }
81 | }
82 | return false;
83 | }
84 | };
85 |
86 | private float Tounch_X = 0, Tounch_Y = 0;
87 | private float Down_X = -1, Down_Y = -1;
88 | private Mode mCurrentMode = Mode.Normal;
89 |
90 | @Override
91 | public boolean onTouchEvent(MotionEvent event) {
92 |
93 | Tounch_X = event.getX();
94 | Tounch_Y = event.getY();
95 |
96 | switch (event.getAction()) {
97 | case MotionEvent.ACTION_DOWN:
98 | Down_X = Tounch_X;
99 | Down_Y = Tounch_Y;
100 |
101 | if (mCurrentMode != Mode.Normal) {
102 | Boolean isTrySelectMove = CheckIfTrySelectMove(Down_X, Down_Y);
103 |
104 | if (!isTrySelectMove) {// 如果不是准备滑动选择文字,转变为正常模式,隐藏选择框
105 | mCurrentMode = Mode.Normal;
106 | invalidate();
107 | }
108 | }
109 |
110 | break;
111 | case MotionEvent.ACTION_MOVE:
112 |
113 | if (mCurrentMode == Mode.SelectMoveForward) {
114 |
115 | if (CanMoveForward(event.getX(), event.getY())) {// 判断是否是向上移动
116 |
117 | Log.e("is CanMoveForward", "CanMoveForward");
118 |
119 | ShowChar firstselectchar = DetectPressShowChar(event.getX(), event.getY());
120 | if (firstselectchar != null) {
121 | FirstSelectShowChar = firstselectchar;
122 | invalidate();
123 | } else {
124 | Log.e("firstselectchar", "firstselectchar is null");
125 | }
126 |
127 | } else {
128 | Log.e("is CanMoveForward", "CanMoveForward");
129 | }
130 |
131 | } else if (mCurrentMode == Mode.SelectMoveBack) {
132 |
133 | if (CanMoveBack(event.getX(), event.getY())) {// 判断是否可以向下移动
134 | Log.e("CanMoveBack", "not CanMoveBack");
135 |
136 | ShowChar lastselectchar = DetectPressShowChar(event.getX(), event.getY());
137 |
138 | if (lastselectchar != null) {
139 | LastSelectShowChar = lastselectchar;
140 | invalidate();
141 | } else {
142 | Log.e("is lastselectchar", "lastselectchar is null");
143 | }
144 |
145 | } else {
146 | Log.e("is CanMoveBack", "not CanMoveBack");
147 | }
148 | }
149 |
150 | break;
151 |
152 | case MotionEvent.ACTION_UP:
153 | Release();
154 |
155 | break;
156 |
157 | default:
158 | break;
159 | }
160 |
161 | return super.onTouchEvent(event);
162 | }
163 |
164 | private boolean CanMoveBack(float Tounchx, float Tounchy) {
165 |
166 | Path p = new Path();
167 | p.moveTo(FirstSelectShowChar.TopLeftPosition.x, FirstSelectShowChar.TopLeftPosition.y);
168 | p.lineTo(getWidth(), FirstSelectShowChar.TopLeftPosition.y);
169 | p.lineTo(getWidth(), getHeight());
170 | p.lineTo(0, getHeight());
171 | p.lineTo(0, FirstSelectShowChar.BottomLeftPosition.y);
172 | p.lineTo(FirstSelectShowChar.BottomLeftPosition.x, FirstSelectShowChar.BottomLeftPosition.y);
173 | p.lineTo(FirstSelectShowChar.TopLeftPosition.x, FirstSelectShowChar.TopLeftPosition.y);
174 |
175 | return computeRegion(p).contains((int) Tounchx, (int) Tounchy);
176 | }
177 |
178 | private boolean CanMoveForward(float Tounchx, float Tounchy) {
179 |
180 | Path p = new Path();
181 | p.moveTo(LastSelectShowChar.TopRightPosition.x, LastSelectShowChar.TopRightPosition.y);
182 | p.lineTo(getWidth(), LastSelectShowChar.TopRightPosition.y);
183 | p.lineTo(getWidth(), 0);
184 | p.lineTo(0, 0);
185 | p.lineTo(0, LastSelectShowChar.BottomRightPosition.y);
186 | p.lineTo(LastSelectShowChar.BottomRightPosition.x, LastSelectShowChar.BottomRightPosition.y);
187 | p.lineTo(LastSelectShowChar.TopRightPosition.x, LastSelectShowChar.TopRightPosition.y);
188 |
189 | return computeRegion(p).contains((int) Tounchx, (int) Tounchy);
190 | }
191 |
192 | private void Release() {
193 | Down_X = -1;// 释放
194 | Down_Y = -1;
195 | }
196 |
197 | private Boolean CheckIfTrySelectMove(float xposition, float yposition) {// 检测是否准备滑动选择文字
198 | if (FirstSelectShowChar == null || LastSelectShowChar == null) {
199 | return false;
200 | }
201 |
202 | float flx, fty, frx, fby;
203 |
204 | float hPadding = FirstSelectShowChar.charWidth;
205 | hPadding = hPadding < 10 ? 10 : hPadding;
206 |
207 | flx = FirstSelectShowChar.TopLeftPosition.x - hPadding;
208 | frx = FirstSelectShowChar.TopLeftPosition.x;
209 |
210 | fty = FirstSelectShowChar.TopLeftPosition.y;
211 | fby = FirstSelectShowChar.BottomLeftPosition.y;
212 |
213 | float llx, lty, lrx, lby;
214 |
215 | llx = LastSelectShowChar.BottomRightPosition.x;
216 | lrx = LastSelectShowChar.BottomRightPosition.x + hPadding;
217 |
218 | lty = LastSelectShowChar.TopRightPosition.y;
219 | lby = LastSelectShowChar.BottomRightPosition.y;
220 |
221 | if ((xposition >= flx && xposition <= frx) && (yposition >= fty && yposition <= fby)) {
222 | mCurrentMode = Mode.SelectMoveForward;
223 | return true;
224 | }
225 |
226 | if ((xposition >= llx && xposition <= lrx) && (yposition >= lty && yposition <= lby)) {
227 | mCurrentMode = Mode.SelectMoveBack;
228 | return true;
229 | }
230 |
231 | return false;
232 |
233 | }
234 |
235 | /**
236 | * 通过路径计算区域
237 | *
238 | * @param path
239 | * 路径对象
240 | * @return 路径的Region
241 | */
242 | private Region computeRegion(Path path) {
243 | Region region = new Region();
244 | RectF f = new RectF();
245 | path.computeBounds(f, true);
246 | region.setPath(path, new Region((int) f.left, (int) f.top, (int) f.right, (int) f.bottom));
247 | return region;
248 | }
249 |
250 | @Override
251 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
252 |
253 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
254 |
255 | int viewwidth = getMeasuredWidth();
256 | int viewheight = getMeasuredHeight();
257 |
258 | initData(viewwidth, viewheight);
259 | }
260 |
261 | List mLinseData = null;
262 |
263 | private void initData(int viewwidth, int viewheight) {
264 | if (mLinseData == null) {
265 | mLinseData = BreakText(viewwidth, viewheight);
266 | }
267 |
268 | }
269 |
270 | private List BreakText(int viewwidth, int viewheight) {
271 | List showLines = new ArrayList();
272 | while (TextData.length() > 0) {
273 | BreakResult breakResult = TextBreakUtil.BreakText(TextData, viewwidth, 0, mPaint);
274 |
275 | if (breakResult != null && breakResult.HasData()) {
276 | ShowLine showLine = new ShowLine();
277 | showLine.CharsData = breakResult.showChars;
278 | showLines.add(showLine);
279 |
280 | } else {
281 | break;
282 | }
283 |
284 | TextData = TextData.substring(breakResult.ChartNums);
285 |
286 | }
287 |
288 | int index = 0;
289 | for (ShowLine l : showLines) {
290 | for (ShowChar c : l.CharsData) {
291 | c.Index = index++;
292 | }
293 | }
294 | return showLines;
295 | }
296 |
297 | @Override
298 | protected void onDraw(Canvas canvas) {
299 |
300 | super.onDraw(canvas);
301 |
302 | LineYPosition = TextHeight + LinePadding;
303 |
304 | for (ShowLine line : mLinseData) {
305 | DrawLineText(line, canvas);
306 |
307 | }
308 |
309 | if (mCurrentMode != Mode.Normal) {
310 | DrawSelectText(canvas);
311 | }
312 | }
313 |
314 | private Path mSelectTextPath = new Path();
315 | private ShowChar FirstSelectShowChar = null;
316 | private ShowChar LastSelectShowChar = null;
317 |
318 | private void DrawSelectText(Canvas canvas) {
319 | if (mCurrentMode == Mode.PressSelectText) {
320 | DrawPressSelectText(canvas);
321 | } else if (mCurrentMode == Mode.SelectMoveForward) {
322 | DrawMoveSelectText(canvas);
323 | } else if (mCurrentMode == Mode.SelectMoveBack) {
324 | DrawMoveSelectText(canvas);
325 | }
326 | }
327 |
328 | private List mSelectLines = new ArrayList();
329 |
330 | private void DrawMoveSelectText(Canvas canvas) {
331 | if (FirstSelectShowChar == null || LastSelectShowChar == null)
332 | return;
333 | GetSelectData();
334 | DrawSeletLines(canvas);
335 | DrawBorderPoint(canvas);
336 | }
337 |
338 | private void DrawSeletLines(Canvas canvas) {
339 | // DrawRectangleSeletLinesBg(canvas);
340 | DrawOaleSeletLinesBg(canvas);
341 | }
342 |
343 | private void DrawOaleSeletLinesBg(Canvas canvas) {// 绘制椭圆型的选中背景
344 | for (ShowLine l : mSelectLines) {
345 | Log.e("selectline", l.getLineData() + "");
346 |
347 | if (l.CharsData != null && l.CharsData.size() > 0) {
348 |
349 |
350 | ShowChar fistchar = l.CharsData.get(0);
351 | ShowChar lastchar = l.CharsData.get(l.CharsData.size() - 1);
352 |
353 | float fw = fistchar.charWidth;
354 | float lw = lastchar.charWidth;
355 |
356 | RectF rect = new RectF(fistchar.TopLeftPosition.x, fistchar.TopLeftPosition.y,
357 | lastchar.TopRightPosition.x, lastchar.BottomRightPosition.y);
358 |
359 | canvas.drawRoundRect(rect, fw / 2,
360 | TextHeight / 2, mTextSelectPaint);
361 |
362 | }
363 | }
364 | }
365 |
366 | private void DrawRectangleSeletLinesBg(Canvas canvas) {
367 | for (ShowLine l : mSelectLines) {
368 | Log.e("selectline", l.getLineData() + "");
369 |
370 | if (l.CharsData != null && l.CharsData.size() > 0) {
371 | mSelectTextPath.reset();
372 |
373 | ShowChar fistchar = l.CharsData.get(0);
374 | ShowChar lastchar = l.CharsData.get(l.CharsData.size() - 1);
375 |
376 | mSelectTextPath.moveTo(fistchar.TopLeftPosition.x, fistchar.TopLeftPosition.y);
377 | mSelectTextPath.lineTo(lastchar.TopRightPosition.x, lastchar.TopRightPosition.y);
378 | mSelectTextPath.lineTo(lastchar.BottomRightPosition.x, lastchar.BottomRightPosition.y);
379 | mSelectTextPath.lineTo(fistchar.BottomLeftPosition.x, fistchar.BottomLeftPosition.y);
380 | mSelectTextPath.lineTo(fistchar.TopLeftPosition.x, fistchar.TopLeftPosition.y);
381 |
382 | canvas.drawPath(mSelectTextPath, mTextSelectPaint);
383 | }
384 | }
385 | }
386 |
387 | private void GetSelectData() {
388 |
389 | Boolean Started = false;
390 | Boolean Ended = false;
391 |
392 | mSelectLines.clear();
393 |
394 | // 找到选择的字符数据,转化为选择的行,然后将行选择背景画出来
395 | for (ShowLine l : mLinseData) {
396 |
397 | ShowLine selectline = new ShowLine();
398 | selectline.CharsData = new ArrayList();
399 |
400 | for (ShowChar c : l.CharsData) {
401 |
402 | if (!Started) {
403 | if (c.Index == FirstSelectShowChar.Index) {
404 | Started = true;
405 | selectline.CharsData.add(c);
406 | if (c.Index == LastSelectShowChar.Index) {
407 | Ended = true;
408 | break;
409 | }
410 | }
411 | } else {
412 |
413 | if (c.Index == LastSelectShowChar.Index) {
414 | Ended = true;
415 | if (!selectline.CharsData.contains(c)) {
416 | selectline.CharsData.add(c);
417 | }
418 | break;
419 | } else {
420 | selectline.CharsData.add(c);
421 | }
422 | }
423 | }
424 |
425 | mSelectLines.add(selectline);
426 |
427 | if (Started && Ended) {
428 | break;
429 | }
430 | }
431 | }
432 |
433 | private void DrawPressSelectText(Canvas canvas) {
434 | ShowChar p = DetectPressShowChar(Down_X, Down_Y);
435 |
436 | if (p != null) {// 找到了选择的字符
437 |
438 | FirstSelectShowChar = LastSelectShowChar = p;
439 | mSelectTextPath.reset();
440 | mSelectTextPath.moveTo(p.TopLeftPosition.x, p.TopLeftPosition.y);
441 | mSelectTextPath.lineTo(p.TopRightPosition.x, p.TopRightPosition.y);
442 | mSelectTextPath.lineTo(p.BottomRightPosition.x, p.BottomRightPosition.y);
443 | mSelectTextPath.lineTo(p.BottomLeftPosition.x, p.BottomLeftPosition.y);
444 | canvas.drawPath(mSelectTextPath, mTextSelectPaint);
445 |
446 | DrawBorderPoint(canvas);
447 |
448 | }
449 | }
450 |
451 | private float BorderPointradius = 10;
452 |
453 | /**
454 | *@param canvas
455 | *--------------------
456 | *TODO 绘制按着移动时的边界点
457 | *--------------------
458 | * author: huangwei
459 | * 2017年7月4日下午3:01:41
460 | */
461 | private void DrawBorderPoint(Canvas canvas) {
462 | if (FirstSelectShowChar != null && LastSelectShowChar != null) {
463 | DrawPoint(canvas);
464 | //DrawRectangle(canvas);
465 | }
466 |
467 | }
468 |
469 | private Path BorderPath = new Path();
470 |
471 | private void DrawRectangle(Canvas canvas) {
472 | float Padding = 0;
473 |
474 | canvas.drawLine(FirstSelectShowChar.TopLeftPosition.x - Padding,
475 | FirstSelectShowChar.TopLeftPosition.y - Padding, FirstSelectShowChar.BottomLeftPosition.x - Padding,
476 | FirstSelectShowChar.BottomLeftPosition.y, mBorderPointPaint);
477 |
478 | canvas.drawLine(LastSelectShowChar.BottomRightPosition.x + Padding,
479 | LastSelectShowChar.BottomRightPosition.y + Padding, LastSelectShowChar.TopRightPosition.x + Padding,
480 | LastSelectShowChar.TopRightPosition.y, mBorderPointPaint);
481 |
482 | // mBorderPointPaint.setColor(Color.parseColor("#ff0000"));
483 |
484 | float hPadding = 25;
485 | float hPadding1 = 10;
486 |
487 | BorderPath.reset();
488 |
489 | BorderPath.moveTo(FirstSelectShowChar.TopLeftPosition.x - hPadding, FirstSelectShowChar.TopLeftPosition.y);
490 | BorderPath.lineTo(FirstSelectShowChar.TopLeftPosition.x - hPadding1, FirstSelectShowChar.TopLeftPosition.y);
491 | BorderPath.lineTo(FirstSelectShowChar.TopLeftPosition.x,
492 | FirstSelectShowChar.TopLeftPosition.y + TextHeight / 2);
493 | BorderPath.lineTo(FirstSelectShowChar.TopLeftPosition.x - hPadding1,
494 | FirstSelectShowChar.TopLeftPosition.y + TextHeight);
495 | BorderPath.lineTo(FirstSelectShowChar.TopLeftPosition.x - hPadding,
496 | FirstSelectShowChar.TopLeftPosition.y + TextHeight);
497 | BorderPath.lineTo(FirstSelectShowChar.TopLeftPosition.x - hPadding, FirstSelectShowChar.TopLeftPosition.y);
498 |
499 | canvas.drawPath(BorderPath, mBorderPointPaint);
500 |
501 | BorderPath.reset();
502 |
503 | BorderPath.moveTo(LastSelectShowChar.TopRightPosition.x + hPadding1, LastSelectShowChar.TopRightPosition.y);
504 | BorderPath.lineTo(LastSelectShowChar.TopRightPosition.x + hPadding, LastSelectShowChar.TopRightPosition.y);
505 | BorderPath.lineTo(LastSelectShowChar.BottomRightPosition.x + hPadding,
506 | LastSelectShowChar.BottomRightPosition.y);
507 | BorderPath.lineTo(LastSelectShowChar.BottomRightPosition.x + hPadding1,
508 | LastSelectShowChar.BottomRightPosition.y);
509 | BorderPath.lineTo(LastSelectShowChar.BottomRightPosition.x,
510 | LastSelectShowChar.TopRightPosition.y + TextHeight / 2);
511 | BorderPath.lineTo(LastSelectShowChar.BottomRightPosition.x + hPadding1, LastSelectShowChar.TopRightPosition.y);
512 |
513 | canvas.drawPath(BorderPath, mBorderPointPaint);
514 |
515 | // mBorderPointPaint.setColor(BorderPointColor);
516 | }
517 |
518 | private void DrawPoint(Canvas canvas) {
519 | float Padding = 0;
520 |
521 | canvas.drawCircle(FirstSelectShowChar.TopLeftPosition.x - Padding,
522 | FirstSelectShowChar.TopLeftPosition.y - Padding, BorderPointradius, mBorderPointPaint);
523 |
524 | canvas.drawCircle(LastSelectShowChar.BottomRightPosition.x + Padding,
525 | LastSelectShowChar.BottomRightPosition.y + Padding, BorderPointradius, mBorderPointPaint);
526 |
527 | canvas.drawLine(FirstSelectShowChar.TopLeftPosition.x - Padding,
528 | FirstSelectShowChar.TopLeftPosition.y - Padding, FirstSelectShowChar.BottomLeftPosition.x - Padding,
529 | FirstSelectShowChar.BottomLeftPosition.y, mBorderPointPaint);
530 |
531 | canvas.drawLine(LastSelectShowChar.BottomRightPosition.x + Padding,
532 | LastSelectShowChar.BottomRightPosition.y + Padding, LastSelectShowChar.TopRightPosition.x + Padding,
533 | LastSelectShowChar.TopRightPosition.y, mBorderPointPaint);
534 | }
535 |
536 | /**
537 | *@param down_X2
538 | *@param down_Y2
539 | *@return
540 | *--------------------
541 | *TODO 检测获取按压坐标所在位置的字符,没有的话返回null
542 | *--------------------
543 | * author: huangwei
544 | * 2017年7月4日上午10:23:19
545 | */
546 | private ShowChar DetectPressShowChar(float down_X2, float down_Y2) {
547 |
548 | for (ShowLine l : mLinseData) {
549 | for (ShowChar c : l.CharsData) {
550 | if (down_Y2 > c.BottomLeftPosition.y) {
551 | break;// 说明是在下一行
552 | }
553 | if (down_X2 >= c.BottomLeftPosition.x && down_X2 <= c.BottomRightPosition.x) {
554 | return c;
555 | }
556 |
557 | }
558 | }
559 |
560 | return null;
561 | }
562 |
563 | private int LinePadding = 30;
564 | private float LineYPosition = 0;
565 | private float TextHeight = 0;
566 |
567 | private void DrawLineText(ShowLine line, Canvas canvas) {
568 | canvas.drawText(line.getLineData(), 0, LineYPosition, mPaint);
569 | //canvas.drawLine(0f, LineYPosition, 680f, LineYPosition, mTextSelectPaint);
570 |
571 | float leftposition = 0;
572 | float rightposition = 0;
573 | float bottomposition = LineYPosition + mPaint.getFontMetrics().descent;
574 |
575 | for (ShowChar c : line.CharsData) {
576 | rightposition = leftposition + c.charWidth;
577 | Point tlp = new Point();
578 | c.TopLeftPosition = tlp;
579 | tlp.x = (int) leftposition;
580 | tlp.y = (int) (bottomposition - TextHeight);
581 |
582 | Point blp = new Point();
583 | c.BottomLeftPosition = blp;
584 | blp.x = (int) leftposition;
585 | blp.y = (int) bottomposition;
586 |
587 | Point trp = new Point();
588 | c.TopRightPosition = trp;
589 | trp.x = (int) rightposition;
590 | trp.y = (int) (bottomposition - TextHeight);
591 |
592 | Point brp = new Point();
593 | c.BottomRightPosition = brp;
594 | brp.x = (int) rightposition;
595 | brp.y = (int) bottomposition;
596 |
597 | leftposition = rightposition;
598 |
599 | }
600 | LineYPosition = LineYPosition + TextHeight + LinePadding;
601 | }
602 |
603 | private enum Mode {
604 | Normal, PressSelectText, SelectMoveForward, SelectMoveBack
605 | }
606 |
607 | }
608 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
14 |
15 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ReaderTextSelect
3 |
4 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/app/src/test/java/com/hw/readertextselect/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hw.readertextselect;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/ReaderTextSelect/ReaderTextSelect/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Aug 29 19:46:46 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/ReaderTextSelect/ReaderTextSelect/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/readertextselect.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/readertextselect.gif
--------------------------------------------------------------------------------
/滑动选择文字2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/滑动选择文字2.png
--------------------------------------------------------------------------------
/滑动选择文字3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/滑动选择文字3.png
--------------------------------------------------------------------------------
/长按选中文字1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bifan-wei/ReaderTextSelect/fcd7aa5ca9b80147b6529eafb4ff578925c7a7b6/长按选中文字1.png
--------------------------------------------------------------------------------