From f7b1d2d8f2abfb429347c55e9d2fa81194e9cb39 Mon Sep 17 00:00:00 2001 From: yangle Date: Tue, 10 Oct 2017 14:43:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=96=E6=8B=BD=E5=A1=AB=E7=A9=BA=E9=A2=98?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DragFillBlankQuestionDemo/.gitignore | 9 + DragFillBlankQuestionDemo/.idea/compiler.xml | 22 + .../.idea/copyright/profiles_settings.xml | 3 + DragFillBlankQuestionDemo/.idea/gradle.xml | 19 + DragFillBlankQuestionDemo/.idea/misc.xml | 46 ++ DragFillBlankQuestionDemo/.idea/modules.xml | 9 + .../.idea/runConfigurations.xml | 12 + DragFillBlankQuestionDemo/.idea/vcs.xml | 6 + DragFillBlankQuestionDemo/app/.gitignore | 1 + DragFillBlankQuestionDemo/app/build.gradle | 31 ++ .../app/proguard-rules.pro | 17 + .../ExampleInstrumentedTest.java | 26 ++ .../app/src/main/AndroidManifest.xml | 20 + .../AnswerRange.java | 17 + .../DragFillBlankView.java | 411 ++++++++++++++++++ .../MainActivity.java | 59 +++ .../TouchLinkMovementMethod.java | 46 ++ .../app/src/main/res/layout/activity_main.xml | 12 + .../res/layout/layout_drag_fill_blank.xml | 35 ++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../app/src/main/res/values-w820dp/dimens.xml | 6 + .../app/src/main/res/values/colors.xml | 6 + .../app/src/main/res/values/dimens.xml | 5 + .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 11 + .../ExampleUnitTest.java | 17 + DragFillBlankQuestionDemo/build.gradle | 23 + DragFillBlankQuestionDemo/gradle.properties | 17 + .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + DragFillBlankQuestionDemo/gradlew | 160 +++++++ DragFillBlankQuestionDemo/gradlew.bat | 90 ++++ DragFillBlankQuestionDemo/settings.gradle | 1 + 37 files changed, 1146 insertions(+) create mode 100644 DragFillBlankQuestionDemo/.gitignore create mode 100644 DragFillBlankQuestionDemo/.idea/compiler.xml create mode 100644 DragFillBlankQuestionDemo/.idea/copyright/profiles_settings.xml create mode 100644 DragFillBlankQuestionDemo/.idea/gradle.xml create mode 100644 DragFillBlankQuestionDemo/.idea/misc.xml create mode 100644 DragFillBlankQuestionDemo/.idea/modules.xml create mode 100644 DragFillBlankQuestionDemo/.idea/runConfigurations.xml create mode 100644 DragFillBlankQuestionDemo/.idea/vcs.xml create mode 100644 DragFillBlankQuestionDemo/app/.gitignore create mode 100644 DragFillBlankQuestionDemo/app/build.gradle create mode 100644 DragFillBlankQuestionDemo/app/proguard-rules.pro create mode 100644 DragFillBlankQuestionDemo/app/src/androidTest/java/com/yl/dragfillblankquestiondemo/ExampleInstrumentedTest.java create mode 100644 DragFillBlankQuestionDemo/app/src/main/AndroidManifest.xml create mode 100644 DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/AnswerRange.java create mode 100644 DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/DragFillBlankView.java create mode 100644 DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/MainActivity.java create mode 100644 DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/TouchLinkMovementMethod.java create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/layout/activity_main.xml create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/layout/layout_drag_fill_blank.xml create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/values-w820dp/dimens.xml create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/values/colors.xml create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/values/dimens.xml create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/values/strings.xml create mode 100644 DragFillBlankQuestionDemo/app/src/main/res/values/styles.xml create mode 100644 DragFillBlankQuestionDemo/app/src/test/java/com/yl/dragfillblankquestiondemo/ExampleUnitTest.java create mode 100644 DragFillBlankQuestionDemo/build.gradle create mode 100644 DragFillBlankQuestionDemo/gradle.properties create mode 100644 DragFillBlankQuestionDemo/gradle/wrapper/gradle-wrapper.jar create mode 100644 DragFillBlankQuestionDemo/gradle/wrapper/gradle-wrapper.properties create mode 100644 DragFillBlankQuestionDemo/gradlew create mode 100644 DragFillBlankQuestionDemo/gradlew.bat create mode 100644 DragFillBlankQuestionDemo/settings.gradle diff --git a/DragFillBlankQuestionDemo/.gitignore b/DragFillBlankQuestionDemo/.gitignore new file mode 100644 index 00000000..39fb081a --- /dev/null +++ b/DragFillBlankQuestionDemo/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/DragFillBlankQuestionDemo/.idea/compiler.xml b/DragFillBlankQuestionDemo/.idea/compiler.xml new file mode 100644 index 00000000..96cc43ef --- /dev/null +++ b/DragFillBlankQuestionDemo/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DragFillBlankQuestionDemo/.idea/copyright/profiles_settings.xml b/DragFillBlankQuestionDemo/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..e7bedf33 --- /dev/null +++ b/DragFillBlankQuestionDemo/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/DragFillBlankQuestionDemo/.idea/gradle.xml b/DragFillBlankQuestionDemo/.idea/gradle.xml new file mode 100644 index 00000000..e32a47f8 --- /dev/null +++ b/DragFillBlankQuestionDemo/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/DragFillBlankQuestionDemo/.idea/misc.xml b/DragFillBlankQuestionDemo/.idea/misc.xml new file mode 100644 index 00000000..fbb68289 --- /dev/null +++ b/DragFillBlankQuestionDemo/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DragFillBlankQuestionDemo/.idea/modules.xml b/DragFillBlankQuestionDemo/.idea/modules.xml new file mode 100644 index 00000000..b8ef768e --- /dev/null +++ b/DragFillBlankQuestionDemo/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/DragFillBlankQuestionDemo/.idea/runConfigurations.xml b/DragFillBlankQuestionDemo/.idea/runConfigurations.xml new file mode 100644 index 00000000..7f68460d --- /dev/null +++ b/DragFillBlankQuestionDemo/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/DragFillBlankQuestionDemo/.idea/vcs.xml b/DragFillBlankQuestionDemo/.idea/vcs.xml new file mode 100644 index 00000000..6c0b8635 --- /dev/null +++ b/DragFillBlankQuestionDemo/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DragFillBlankQuestionDemo/app/.gitignore b/DragFillBlankQuestionDemo/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/DragFillBlankQuestionDemo/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/DragFillBlankQuestionDemo/app/build.gradle b/DragFillBlankQuestionDemo/app/build.gradle new file mode 100644 index 00000000..05fc2021 --- /dev/null +++ b/DragFillBlankQuestionDemo/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "26.0.0" + defaultConfig { + applicationId "com.yl.dragfillblankquestiondemo" + minSdkVersion 15 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:25.3.1' + testCompile 'junit:junit:4.12' + compile 'com.jakewharton:butterknife:8.4.0' + annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' +} diff --git a/DragFillBlankQuestionDemo/app/proguard-rules.pro b/DragFillBlankQuestionDemo/app/proguard-rules.pro new file mode 100644 index 00000000..6e98ee4c --- /dev/null +++ b/DragFillBlankQuestionDemo/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Tools\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/DragFillBlankQuestionDemo/app/src/androidTest/java/com/yl/dragfillblankquestiondemo/ExampleInstrumentedTest.java b/DragFillBlankQuestionDemo/app/src/androidTest/java/com/yl/dragfillblankquestiondemo/ExampleInstrumentedTest.java new file mode 100644 index 00000000..5acc6fc5 --- /dev/null +++ b/DragFillBlankQuestionDemo/app/src/androidTest/java/com/yl/dragfillblankquestiondemo/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.yl.dragfillblankquestiondemo; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.yl.dragfillblankquestiondemo", appContext.getPackageName()); + } +} diff --git a/DragFillBlankQuestionDemo/app/src/main/AndroidManifest.xml b/DragFillBlankQuestionDemo/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a0357245 --- /dev/null +++ b/DragFillBlankQuestionDemo/app/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/AnswerRange.java b/DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/AnswerRange.java new file mode 100644 index 00000000..dbe03223 --- /dev/null +++ b/DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/AnswerRange.java @@ -0,0 +1,17 @@ +package com.yl.dragfillblankquestiondemo; + +/** + * 答案范围 + * Created by yangle on 2017/10/9. + */ + +public class AnswerRange { + + public int start; + public int end; + + public AnswerRange(int start, int end) { + this.start = start; + this.end = end; + } +} diff --git a/DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/DragFillBlankView.java b/DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/DragFillBlankView.java new file mode 100644 index 00000000..926ab6a2 --- /dev/null +++ b/DragFillBlankQuestionDemo/app/src/main/java/com/yl/dragfillblankquestiondemo/DragFillBlankView.java @@ -0,0 +1,411 @@ +package com.yl.dragfillblankquestiondemo; + +import android.content.ClipData; +import android.content.ClipDescription; +import android.content.Context; +import android.graphics.Color; +import android.graphics.Rect; +import android.text.Layout; +import android.text.SpannableStringBuilder; +import android.text.Spanned; +import android.text.TextPaint; +import android.text.TextUtils; +import android.text.style.ClickableSpan; +import android.text.style.ForegroundColorSpan; +import android.text.style.UnderlineSpan; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.view.DragEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.List; + +/** + * 拖拽填空题 + * Created by yangle on 2017/8/30. + */ + +public class DragFillBlankView extends RelativeLayout implements View.OnDragListener, + View.OnLongClickListener { + + private TextView tvContent; + private LinearLayout llOption; + // 初始数据 + private String originContent; + // 初始答案范围集合 + private List originAnswerRangeList; + // 填空题内容 + private SpannableStringBuilder content; + // 选项列表 + private List optionList; + // 答案范围集合 + private List answerRangeList; + // 答案集合 + private List answerList; + // 选项位置 + private int optionPosition; + // 一次拖拽填空是否完成 + private boolean isFillBlank; + + public DragFillBlankView(Context context) { + this(context, null); + } + + public DragFillBlankView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public DragFillBlankView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initView(); + } + + private void initView() { + LayoutInflater inflater = LayoutInflater.from(getContext()); + inflater.inflate(R.layout.layout_drag_fill_blank, this); + + tvContent = (TextView) findViewById(R.id.tv_content); + llOption = (LinearLayout) findViewById(R.id.ll_option); + } + + /** + * 设置数据 + * + * @param originContent 源数据 + * @param optionList 选项列表 + * @param answerRangeList 答案范围集合 + */ + public void setData(String originContent, List optionList, List answerRangeList) { + if (TextUtils.isEmpty(originContent) || optionList == null || optionList.isEmpty() + || answerRangeList == null || answerRangeList.isEmpty()) { + return; + } + + // 初始数据 + this.originContent = originContent; + // 初始答案范围集合 + this.originAnswerRangeList = new ArrayList<>(); + this.originAnswerRangeList.addAll(answerRangeList); + // 获取课文内容 + this.content = new SpannableStringBuilder(originContent); + // 选项列表 + this.optionList = optionList; + // 答案范围集合 + this.answerRangeList = answerRangeList; + + // 避免重复创建拖拽选项 + if (llOption.getChildCount() < 1) { + // 拖拽选项列表 + List