├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── blank
│ │ └── simple
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ ├── blank-stu.json
│ │ ├── blank.json
│ │ ├── blank1.json
│ │ └── blank2.json
│ ├── java
│ │ └── com
│ │ │ └── blank
│ │ │ └── simple
│ │ │ ├── BlankActivity.kt
│ │ │ ├── GsonUtils.kt
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_blank.xml
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── blank
│ └── simple
│ └── ExampleUnitTest.java
├── blank
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── xc
│ │ └── blank
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── xc
│ │ │ └── blank
│ │ │ ├── BlankRootView.kt
│ │ │ ├── BlankView.java
│ │ │ ├── ChoiceBlankBean.kt
│ │ │ ├── FillAnswerInfo.java
│ │ │ ├── FlowLayout.java
│ │ │ ├── LineInfo.java
│ │ │ ├── Status.java
│ │ │ └── TextInfo.java
│ └── res
│ │ ├── drawable
│ │ ├── btn_rectangle_gray_b3b3b3.xml
│ │ ├── btn_rectangle_gray_e0e0e0.xml
│ │ ├── btn_rectangle_gray_ff7171.xml
│ │ ├── selector_task_answer.xml
│ │ └── selector_task_answer_text.xml
│ │ ├── layout
│ │ ├── blank_root_view.xml
│ │ └── item_task_answer.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ └── dimens.xml
│ └── test
│ └── java
│ └── com
│ └── xc
│ └── blank
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
└── simple.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 | .cxx
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 一款不错的选词填空题的自定义view,样式可以自己定制。
2 | 
3 |
4 | ### 使用:
5 | - 如果想直接有流失布局的选项样式直接用:
6 | ```
7 |
11 | ```
12 | 如果想自己定义选项的view那你可以直接定义BlankView:
13 | ```
14 |
21 | ```
22 | 后期会考虑加入自定义属性!!!
23 |
24 | 如果想第一时间看demo效果扫描下面二维码:
25 |
26 | 
27 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.3"
8 |
9 | defaultConfig {
10 | applicationId "com.blank.simple"
11 | minSdkVersion 16
12 | targetSdkVersion 29
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: "libs", include: ["*.jar"])
29 | implementation 'androidx.appcompat:appcompat:1.1.0'
30 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
31 | implementation project(path: ':blank')
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
34 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
35 | implementation 'com.google.code.gson:gson:2.8.6'
36 | implementation "androidx.core:core-ktx:+"
37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
38 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
39 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/blank/simple/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.blank.simple;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 |
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.blank.simple", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/assets/blank-stu.json:
--------------------------------------------------------------------------------
1 | {
2 | "questionContent": "(1)大会选举萧同兹一人为_____\n(2)大会选举赵敏恒(《中央日报》)、周钦岳(《新蜀报》)等十九人为_____\n(3)大会选举杜协民(《国民公报》)、潘梓年(《新华日报》)等七人为_____",
3 | "stuAnswer": [
4 | {
5 | "optValue": "①理事",
6 | "answer": 1
7 | },
8 | {
9 | "optValue": "②候补理事",
10 | "answer": 0
11 | },
12 | {
13 | "optValue": "③理事长",
14 | "answer": 0
15 | }
16 | ],
17 |
18 | "choiceOptions": [
19 | {
20 | "optValue": "①理事"
21 | },
22 | {
23 | "optValue": "②候补理事"
24 | },
25 | {
26 | "optValue": "③理事长"
27 | }
28 | ]
29 | }
--------------------------------------------------------------------------------
/app/src/main/assets/blank.json:
--------------------------------------------------------------------------------
1 | {
2 | "questionContent": "①中医通过望、闻、问、切等方法来了解_____,作出诊断\n②孩子过多玩网络游戏,父母应适当加以_____。\n③他们心中依然珍藏着那段美好的回忆,_____他们已经远离了那段激情燃烧的岁月。",
3 | "choiceOptions": [
4 | {
5 | "optValue": "病症"
6 | },
7 | {
8 | "optValue": "病征"
9 | }
10 | ]
11 | }
--------------------------------------------------------------------------------
/app/src/main/assets/blank1.json:
--------------------------------------------------------------------------------
1 | {
2 | "questionContent": "(1)床前明月_____\n(2)疑是地上_____\n(3)举头望_____\n(4)低头_____",
3 | "choiceOptions": [
4 | {
5 | "optValue": "①光"
6 | },
7 | {
8 | "optValue": "②明月"
9 | },
10 | {
11 | "optValue": "③霜"
12 | },
13 | {
14 | "optValue": "④思故乡"
15 | }
16 | ]
17 | }
--------------------------------------------------------------------------------
/app/src/main/assets/blank2.json:
--------------------------------------------------------------------------------
1 | {
2 | "questionContent": "《祖国啊,我亲爱的祖国》这首诗的艺术力量不仅在于诗人用①_____来关照内心的情感记忆,出格而入理地描绘了祖国深重的②_____,以及新生的希望,光明的前程;而且还在于诗人把③_____摆进④_____相交错的现实中,寓己于形象,对祖国的过去和将来进行了深刻的思考,表达了深挚的热爱和⑤_____的决心",
3 | "choiceOptions": [
4 | {
5 | "optValue": "幼年/小时候/自幼/童年"
6 | },
7 | {
8 | "optValue": "观察/自然/思考/热爱(1分)"
9 | },
10 | {
11 | "optValue": "吸引/好奇"
12 | },
13 | {
14 | "optValue": "想象力/求知欲/创造力/好奇心/动脑/学习/激发"
15 | },
16 | {
17 | "optValue": "起点/萌芽/今后/科学/昆虫学家/文学家/贡献/喜爱/赞赏"
18 | },
19 | {
20 | "optValue": "所以/因此/故"
21 | },
22 | {
23 | "optValue": "查询/检索/搜索"
24 | },
25 | {
26 | "optValue": "认真/揭穿"
27 | }
28 | ]
29 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/blank/simple/BlankActivity.kt:
--------------------------------------------------------------------------------
1 | package com.blank.simple
2 |
3 | import android.os.Bundle
4 | import android.text.TextUtils
5 | import android.util.Log
6 | import androidx.appcompat.app.AppCompatActivity
7 | import com.xc.blank.ChoiceBlankBean
8 | import kotlinx.android.synthetic.main.activity_blank.blank_root_view
9 | import kotlinx.android.synthetic.main.activity_blank.get_answer
10 | import kotlinx.android.synthetic.main.activity_blank.tv
11 | import kotlinx.coroutines.Dispatchers
12 | import kotlinx.coroutines.GlobalScope
13 | import kotlinx.coroutines.Job
14 | import kotlinx.coroutines.coroutineScope
15 | import kotlinx.coroutines.launch
16 | import kotlinx.coroutines.withContext
17 | import java.lang.StringBuilder
18 |
19 | class BlankActivity : AppCompatActivity() {
20 | lateinit var launch: Job
21 | lateinit var path: String
22 | override fun onCreate(savedInstanceState: Bundle?) {
23 | super.onCreate(savedInstanceState)
24 | setContentView(R.layout.activity_blank)
25 | path = intent.getStringExtra("path")
26 | initData()
27 | get_answer.setOnClickListener {
28 | val answerResult = blank_root_view.getAnswerResult()
29 | val sb = StringBuilder()
30 | answerResult.forEach {
31 | if (!TextUtils.isEmpty(it.optValue)) {
32 | sb.append("${it.optValue};")
33 | } else {
34 | sb.append(";")
35 | }
36 | }
37 | tv.text = sb.toString()
38 | }
39 | }
40 |
41 | private fun initData() {
42 | //最原始的协程,阻塞式的,需要在onDestroy的时候关掉协程
43 | launch = GlobalScope.launch(Dispatchers.IO) {
44 | val jsonData = getJsonData()
45 | withContext(Dispatchers.Main) {
46 | blank_root_view.setText(jsonData)
47 | }
48 | }
49 |
50 | }
51 |
52 | override fun onDestroy() {
53 | super.onDestroy()
54 | launch.cancel()
55 | }
56 |
57 | private suspend fun getJsonData() = coroutineScope {
58 | var bean: ChoiceBlankBean? = null
59 | try {
60 | assets.open(path).use { inputStream ->
61 | bean = inputStream.reader().use { reader ->
62 | val gsonToBean = GsonToBean(reader, ChoiceBlankBean::class.java)
63 | gsonToBean
64 | }
65 | bean
66 | }
67 | bean
68 | } catch (e: Exception) {
69 | bean
70 |
71 | }
72 | }
73 |
74 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/blank/simple/GsonUtils.kt:
--------------------------------------------------------------------------------
1 | package com.blank.simple
2 |
3 | import com.google.gson.Gson
4 | import java.io.InputStreamReader
5 |
6 | fun GsonToBean(reader: InputStreamReader, clas: Class): T {
7 | val gson = Gson()
8 | return gson.fromJson(reader, clas)
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/blank/simple/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.blank.simple;
2 |
3 | import android.content.Intent;
4 | import android.view.View;
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import android.os.Bundle;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | }
15 |
16 | public void toBlank(View view) {
17 | Intent intent = new Intent(this, BlankActivity.class);
18 | switch (view.getId()) {
19 | case R.id.goToDragBtn:
20 | intent.putExtra("path", "blank.json");
21 | break;
22 | case R.id.goToDrag1Btn:
23 | intent.putExtra("path", "blank1.json");
24 | break;
25 | case R.id.goToDrag2Btn:
26 | intent.putExtra("path", "blank-stu.json");
27 | break;
28 | case R.id.goToDrag3Btn:
29 | intent.putExtra("path", "blank2.json");
30 | break;
31 | }
32 | startActivity(intent);
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_blank.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
18 |
19 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
23 |
24 |
30 |
31 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BlankView
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/blank/simple/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.blank.simple;
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 |
14 | @Test
15 | public void addition_isCorrect() {
16 | assertEquals(4, 2 + 2);
17 | }
18 | }
--------------------------------------------------------------------------------
/blank/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/blank/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | android {
5 | compileSdkVersion 29
6 | buildToolsVersion "29.0.3"
7 |
8 | defaultConfig {
9 | minSdkVersion 16
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | consumerProguardFiles "consumer-rules.pro"
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: "libs", include: ["*.jar"])
28 | // implementation 'androidx.appcompat:appcompat:1.1.0'
29 | // testImplementation 'junit:junit:4.12'
30 | // androidTestImplementation 'androidx.test.ext:junit:1.1.1'
31 | // androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
32 |
33 | implementation "androidx.core:core-ktx:1.3.0"
34 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
35 | //
36 | // implementation 'com.github.bumptech.glide:glide:4.9.0'
37 | // implementation 'com.github.bumptech.glide:compiler:4.9.0'
38 | }
--------------------------------------------------------------------------------
/blank/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/blank/consumer-rules.pro
--------------------------------------------------------------------------------
/blank/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/blank/src/androidTest/java/com/xc/blank/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.xc.blank;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 |
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.xc.blank.test", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/blank/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | /
5 |
--------------------------------------------------------------------------------
/blank/src/main/java/com/xc/blank/BlankRootView.kt:
--------------------------------------------------------------------------------
1 | package com.xc.blank
2 |
3 | import android.content.Context
4 | import android.util.AttributeSet
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.View.OnClickListener
8 | import android.widget.FrameLayout
9 | import android.widget.TextView
10 | import com.xc.blank.BlankView.OnStatusChange
11 | import kotlinx.android.synthetic.main.blank_root_view.view.blankView
12 | import kotlinx.android.synthetic.main.blank_root_view.view.flow
13 |
14 | class BlankRootView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
15 | FrameLayout(context, attrs, defStyleAttr), OnClickListener, OnStatusChange {
16 | constructor(context: Context) : this(context, null)
17 | constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
18 |
19 | init {
20 | LayoutInflater.from(context).inflate(R.layout.blank_root_view, this)
21 | blankView.setOnStatusChange(this)
22 | }
23 |
24 | fun setText(jsonData: ChoiceBlankBean?) {
25 | if (jsonData?.stuAnswer != null) {
26 | initTextView(jsonData)
27 | } else {
28 | initFlowLayout(jsonData)
29 | initTextView(jsonData)
30 | }
31 | }
32 |
33 | private fun initTextView(jsonData: ChoiceBlankBean?) {
34 | blankView.setText(jsonData)
35 | }
36 |
37 | private fun initFlowLayout(jsonData: ChoiceBlankBean?) {
38 | val lp = MarginLayoutParams(
39 | LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT
40 | )
41 | lp.rightMargin = resources.getDimension(R.dimen.dp_15).toInt()
42 | lp.topMargin = resources.getDimension(R.dimen.dp_15).toInt()
43 | jsonData?.choiceOptions?.run {
44 | forEach {
45 | addView(lp, it)
46 | }
47 | }
48 | }
49 |
50 | private fun addView(lp: MarginLayoutParams, choiceOptions: ChoiceOptions) {
51 | val v = View.inflate(context, R.layout.item_task_answer, null)
52 | val mTvKey = v.findViewById(R.id.mTvKey) as TextView
53 | mTvKey.setOnClickListener(this)
54 | mTvKey.text = choiceOptions.optValue
55 | mTvKey.tag = choiceOptions
56 | flow.addView(v, lp)
57 | }
58 |
59 | override fun onClick(v: View) {
60 | when (v.id) {
61 | R.id.mTvKey -> {
62 | //选中流失布局的item
63 | val key = v.tag as ChoiceOptions?
64 | key?.run {
65 | val isCheckOptions = blankView.fillAnswer(key, v)
66 | if (isCheckOptions) {
67 | v.isEnabled = false
68 | }
69 | }
70 | }
71 | }
72 | }
73 |
74 | override fun onReduce(v: View?) {
75 | v?.run {
76 | v.isEnabled = true
77 | }
78 | }
79 |
80 | fun getAnswerResult(): List {
81 | return blankView.answerResult
82 | }
83 |
84 | }
--------------------------------------------------------------------------------
/blank/src/main/java/com/xc/blank/BlankView.java:
--------------------------------------------------------------------------------
1 | package com.xc.blank;
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.Rect;
8 | import android.text.TextUtils;
9 | import android.util.AttributeSet;
10 | import android.util.Log;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 | import androidx.annotation.Nullable;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 | import org.intellij.lang.annotations.Flow;
17 | import org.jetbrains.annotations.NotNull;
18 |
19 | import static com.xc.blank.Status.CORRECTED;
20 | import static com.xc.blank.Status.ERROR;
21 |
22 | public class BlankView extends View {
23 |
24 | private static final String TAG = "BlankView";
25 | private static final String PARAGRAPHTIPS = "\n";
26 | private static final String BLOCKTIPS = "_____";
27 | private Paint paint;
28 | private Paint linePaint;
29 | private float lineWidth;
30 | private int width;
31 | private float lineHeight;
32 | private float lineSpace;
33 | private float paragraphSpace;//段落间距
34 | private float lineDetaY;//横线的高度
35 | private Paint.FontMetrics fontMetrics;
36 |
37 | private boolean isCheckOptions;//选了某个选项选过之后是否不可选了,是否可选条件根据选项大于空格
38 |
39 | private List textInfos = new ArrayList<>();
40 | private List lineInfos = new ArrayList<>();//下划线信息
41 | private List fillAnswerInfos = new ArrayList<>();
42 | private List answerResult = new ArrayList<>();
43 | private List answers = new ArrayList<>();//填充的答案
44 | private List> allLineInfos = new ArrayList<>();//主要是用来标记是一组画横线的内容
45 | List selectLineInfos = null;//用来标识已经被选中的横线
46 |
47 | private int lineIndex = 0;
48 | private float totalHeight = 0;//总高度
49 | private float originHeight = 0;//原来的总高度
50 | private String orginText;
51 | private boolean isParsing;//是否是解析类型的
52 |
53 | public BlankView(Context context) {
54 | this(context, null);
55 | }
56 |
57 | public BlankView(Context context, @Nullable AttributeSet attrs) {
58 | this(context, attrs, 0);
59 | }
60 |
61 | public BlankView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
62 | super(context, attrs, defStyleAttr);
63 | paint = new Paint(Paint.ANTI_ALIAS_FLAG);
64 | paint.setColor(Color.parseColor("#333333"));
65 | paint.setTextSize(getResources().getDimension(R.dimen.sp_15));
66 |
67 | lineSpace = getResources().getDimension(R.dimen.dp_5);
68 | paragraphSpace = getResources().getDimension(R.dimen.dp_8);
69 | lineDetaY = getResources().getDimension(R.dimen.dp_0_5);
70 | lineWidth = getResources().getDimension(R.dimen.dp_75);
71 | fontMetrics = paint.getFontMetrics();
72 | lineHeight = fontMetrics.descent - fontMetrics.ascent;
73 |
74 | linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
75 | linePaint.setColor(Color.parseColor("#333333"));
76 | linePaint.setStrokeWidth(lineDetaY);
77 | linePaint.setStyle(Paint.Style.FILL);
78 | }
79 |
80 | private void setText() {
81 | String[] split = orginText.split(PARAGRAPHTIPS);//分段落
82 | boolean isOnlyInvalidate = caculateLines(split);
83 | Log.d("setText", "isOnlyInvalidate:" + isOnlyInvalidate);
84 | if (isOnlyInvalidate) {
85 | invalidate();
86 | } else {
87 | requestLayout();
88 | }
89 | }
90 |
91 | /**
92 | * 解析的话调用该方法
93 | */
94 | public void setText(ChoiceBlankBean choiceBlankBean) {
95 | if (choiceBlankBean == null) {
96 | return;
97 | }
98 | orginText = choiceBlankBean.getQuestionContent();
99 | List stuAnswer = choiceBlankBean.getStuAnswer();
100 | List choiceOptions = choiceBlankBean.getChoiceOptions();
101 | int count = 0;
102 | initParsing(stuAnswer);
103 | String[] split = initFillAnswerInfos(choiceOptions, count);
104 | boolean isOnlyInvalidate = caculateLines(split);
105 | if (isOnlyInvalidate) {
106 | invalidate();
107 | } else {
108 | requestLayout();
109 | }
110 | }
111 |
112 | /**
113 | * 初始化空格的默认答案
114 | */
115 | @NotNull
116 | private String[] initFillAnswerInfos(List choiceOptions, int count) {
117 | String[] split = orginText.split(PARAGRAPHTIPS);//分段落
118 | for (String s : split) {
119 | String[] s1 = s.split(BLOCKTIPS);
120 | for (int i = 0; i < s1.length; i++) {
121 | //不是解析的时候才会去添加默认横线信息
122 | if (!isParsing && (i < s1.length - 1 || (i == s1.length - 1 && orginText.endsWith(BLOCKTIPS)))) {
123 | FillAnswerInfo fillAnswerInfo = new FillAnswerInfo();
124 | fillAnswerInfo.lineWidth = lineWidth;
125 | fillAnswerInfo.lineText = "";
126 | fillAnswerInfos.add(fillAnswerInfo);
127 | answerResult.add(new ChoiceOptions());
128 | }
129 | count++;
130 | }
131 | }
132 | if (count <= choiceOptions.size()) {
133 | isCheckOptions = true;
134 | }
135 | return split;
136 | }
137 |
138 | /**
139 | * 初始化解析
140 | */
141 | private void initParsing(List stuAnswer) {
142 | if (stuAnswer != null && stuAnswer.size() > 0) {
143 | //解析学生的答案
144 | for (int i = 0; i < stuAnswer.size(); i++) {
145 | ChoiceOptions choiceOption = stuAnswer.get(i);
146 | FillAnswerInfo fillAnswerInfo = new FillAnswerInfo();
147 | fillAnswerInfo.lineWidth = paint.measureText(choiceOption.getOptValue());
148 | fillAnswerInfo.lineText = choiceOption.getOptValue();
149 | int answer = choiceOption.getAnswer();
150 | if (answer == 1) {
151 | fillAnswerInfo.status = CORRECTED;
152 | } else if (answer == 0) {
153 | fillAnswerInfo.status = ERROR;
154 | }
155 | fillAnswerInfos.add(fillAnswerInfo);
156 | }
157 | isParsing = true;
158 |
159 | }
160 | }
161 |
162 | /**
163 | * 计算行、空格、下划线、下划线答案信息
164 | * 返回值:是否只是绘制操作
165 | */
166 | private boolean caculateLines(String[] split) {
167 | lineInfos.clear();
168 | textInfos.clear();
169 | answers.clear();
170 | allLineInfos.clear();
171 | lineIndex = 0;
172 | float top = -fontMetrics.ascent;
173 | for (String s : split) {
174 | float hasWidth = width;
175 | float left = 0;
176 | String[] s1 = s.split(BLOCKTIPS);
177 | Log.d("BlankView", "s1.size:" + s1.length);
178 | for (int i = 0; i < s1.length; i++) {
179 | String s2 = s1[i];
180 | float v = paint.measureText(s2);
181 | if (v <= hasWidth) {//没超过剩余的宽度
182 | addBlockText(top, left, s2);
183 | hasWidth -= v;
184 | left += v;
185 | } else {
186 | //超过了剩余宽度,需要进行截取
187 | int lineCount = 0;
188 | while (s2.length() > 0) {
189 | if (lineCount == 0) {
190 | int hasWordCount = paint.breakText(s2, true, hasWidth, null);
191 | String substring = s2.substring(0, hasWordCount);
192 | addBlockText(top, left, substring);
193 | top += lineHeight + lineSpace;
194 | left = 0;
195 | hasWidth = width;
196 | s2 = s2.substring(hasWordCount);
197 | } else {
198 | int hasWordCount = paint.breakText(s2, true, width, null);
199 | if (hasWordCount == s2.length()) {
200 | float v1 = paint.measureText(s2);
201 | //说明不够一行
202 | String substring = s2.substring(0, hasWordCount);
203 | addBlockText(top, left, substring);
204 | left = v1;
205 | hasWidth -= v1;
206 | s2 = s2.substring(hasWordCount);
207 | } else if (hasWordCount > 0 && hasWordCount < s2.length()) {
208 | String substring = s2.substring(0, hasWordCount);
209 | addBlockText(top, left, substring);
210 | top += lineHeight + lineSpace;
211 | left = 0;
212 | hasWidth = width;
213 | s2 = s2.substring(hasWordCount);
214 | }
215 |
216 | }
217 | lineCount++;
218 | }
219 | }
220 |
221 | //--------------计算横线的信息
222 | if (i < s1.length - 1 || (i == s1.length - 1 && orginText.endsWith(BLOCKTIPS))) {
223 | FillAnswerInfo fillAnswerInfo = fillAnswerInfos.get(lineIndex);
224 | String lineText = fillAnswerInfo.lineText;
225 | Float currentLineWidth = fillAnswerInfo.lineWidth;//拿到当前自己的横线长度
226 | Status status = fillAnswerInfo.status;
227 | if (currentLineWidth <= hasWidth) {//没超过剩余的宽度
228 | List relatedLineInfos = new ArrayList<>();
229 | LineInfo textInfo = addBlockUnderLine(top, left, currentLineWidth, status);
230 | //添加横线的文字
231 | addUnderLineText(top, left, lineText, status);
232 | relatedLineInfos.add(textInfo);
233 | hasWidth -= currentLineWidth;
234 | left += currentLineWidth;
235 | allLineInfos.add(relatedLineInfos);
236 | } else {
237 |
238 | //超过了剩余宽度,需要进行截取
239 | int lineCount = 0;
240 | float lineW = currentLineWidth;
241 | List relatedLineInfos = new ArrayList<>();
242 | String hasLineText = null;
243 | while (lineW > 0) {
244 | if (lineCount == 0) {
245 | lineW -= hasWidth;
246 | LineInfo textInfo = new LineInfo();
247 | textInfo.start = left;
248 | textInfo.end = width;
249 | textInfo.lineTop = top + fontMetrics.descent + lineDetaY;
250 | textInfo.index = lineIndex;
251 | textInfo.status = status;
252 | lineInfos.add(textInfo);
253 | //LineInfo textInfo = addBlockUnderLine(top, left, (float) width-left, view);
254 | //添加横线到右边距离问题
255 | if (!TextUtils.isEmpty(lineText)) {
256 | int word = paint.breakText(lineText, true, hasWidth, null);
257 | String text = lineText.substring(0, word);
258 | float textWidth = paint.measureText(text);
259 | TextInfo textInfo1 = new TextInfo();
260 | textInfo1.text = text;
261 | textInfo1.left = left;
262 | textInfo1.top = top;
263 | textInfo1.status = status;
264 | //修正横线的问题
265 | textInfo.end = left + textWidth;
266 | lineW += hasWidth - textWidth;
267 | hasLineText = lineText.substring(word);
268 | answers.add(textInfo1);
269 | }
270 | relatedLineInfos.add(textInfo);
271 | top += lineHeight + lineSpace;
272 | left = 0;
273 | hasWidth = width;
274 | } else {
275 | float deta = lineW - width;
276 | if (deta < 0) {
277 | //说明不够一行
278 | LineInfo textInfo = addBlockUnderLine(top, left, left + lineW, status);
279 | hasLineText = addHashUnderLineText(top, left, lineW, hasLineText, status);
280 | relatedLineInfos.add(textInfo);
281 | left = left + lineW;
282 | hasWidth -= lineW;
283 | } else {
284 | LineInfo textInfo = addBlockUnderLine(top, left, (float) width, status);
285 | hasLineText = addHashUnderLineText(top, left, width, hasLineText, status);
286 | relatedLineInfos.add(textInfo);
287 | top += lineHeight + lineSpace;
288 | left = 0;
289 | hasWidth = width;
290 | }
291 | lineW -= width;
292 |
293 | }
294 | lineCount++;
295 |
296 | }
297 | allLineInfos.add(relatedLineInfos);
298 | }
299 | lineIndex++;
300 | }
301 | }
302 | top += lineHeight + lineSpace + paragraphSpace;
303 | }
304 | //最后一行有横线的时候
305 | //int size = allLineInfos.get(allLineInfos.size() - 1).size();
306 | float lineTop = lineInfos.get(lineInfos.size() - 1).lineTop;
307 | float textTop = textInfos.get(textInfos.size() - 1).top;
308 | if (orginText.endsWith(BLOCKTIPS) || lineTop > textTop) {//加上最后一个横线的高度
309 | totalHeight = top - paragraphSpace - lineSpace - lineHeight + fontMetrics.descent + 2 * lineDetaY;
310 | } else {
311 | totalHeight = top - paragraphSpace - lineSpace - lineHeight + fontMetrics.descent;
312 | }
313 |
314 | //originHeight = Log.d(TAG, "currentLineCount:" + currentLineCount);
315 | Log.d(TAG, "originCount:" + originHeight);
316 | Log.d(TAG, "totalHeight:" + totalHeight);
317 | if (totalHeight == originHeight) {//如果原来的高度和现在不一样则需要onMeasure
318 | return true;
319 | }
320 | originHeight = totalHeight;
321 | return false;
322 | }
323 |
324 | @NotNull
325 | private LineInfo addBlockUnderLine(float top, float left, Float currentLineWidth, Status status) {
326 | LineInfo textInfo = new LineInfo();
327 | textInfo.start = left;
328 | textInfo.end = left + currentLineWidth;
329 | textInfo.lineTop = top + fontMetrics.descent + lineDetaY;
330 | textInfo.index = lineIndex;
331 | //textInfo.view = view;
332 | textInfo.status = status;
333 | lineInfos.add(textInfo);
334 | return textInfo;
335 | }
336 |
337 | /**
338 | * 添加块信息的text
339 | */
340 | private void addBlockText(float top, float left, String s2) {
341 | TextInfo textInfo = new TextInfo();
342 | textInfo.left = left;
343 | textInfo.top = top;
344 | textInfo.text = s2;
345 | textInfos.add(textInfo);
346 | }
347 |
348 | /**
349 | * 添加不够一行的答案内容
350 | */
351 | @org.jetbrains.annotations.Nullable
352 | private String addHashUnderLineText(float top, float left, float lineW, String hasLineText, Status status) {
353 | if (!TextUtils.isEmpty(hasLineText)) {
354 | int word = paint.breakText(hasLineText, true, lineW, null);
355 | TextInfo textInfo1 = new TextInfo();
356 | textInfo1.text = hasLineText.substring(0, word);
357 | textInfo1.left = left;
358 | textInfo1.top = top;
359 | textInfo1.status = status;
360 | hasLineText = hasLineText.substring(word);
361 | answers.add(textInfo1);
362 | }
363 | return hasLineText;
364 | }
365 |
366 | /**
367 | * 添加够一行的答案内容
368 | */
369 | private void addUnderLineText(float top, float left, String lineText, Status status) {
370 | if (!TextUtils.isEmpty(lineText)) {
371 | TextInfo textInfo1 = new TextInfo();
372 | textInfo1.text = lineText;
373 | textInfo1.left = left;
374 | textInfo1.top = top;
375 | textInfo1.status = status;
376 | answers.add(textInfo1);
377 | }
378 | }
379 |
380 | @Override
381 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
382 | super.onSizeChanged(w, h, oldw, oldh);
383 | width = w;
384 | Log.d("onSizeChanged", "width:" + width);
385 | }
386 |
387 | @Override
388 | protected void onDraw(Canvas canvas) {
389 | super.onDraw(canvas);
390 | for (TextInfo textInfo : textInfos) {
391 | paint.setColor(Color.parseColor("#333333"));
392 | canvas.drawText(textInfo.text, textInfo.left, textInfo.top, paint);
393 | }
394 | //绘制横线
395 | for (LineInfo lineInfo : lineInfos) {
396 | if (!isParsing) {
397 | if (lineInfo.isSelect) {
398 | linePaint.setColor(Color.parseColor("#52BCFF"));
399 | } else {
400 | linePaint.setColor(Color.parseColor("#333333"));
401 | }
402 | } else {
403 | if (lineInfo.status == ERROR) {
404 | linePaint.setColor(Color.parseColor("#FF7C64"));
405 | } else if (lineInfo.status == CORRECTED) {
406 | linePaint.setColor(Color.parseColor("#06D265"));
407 | }
408 | }
409 | canvas.drawLine(lineInfo.start, lineInfo.lineTop, lineInfo.end, lineInfo.lineTop, linePaint);
410 | }
411 | //绘制用户的答案
412 | for (TextInfo answer : answers) {
413 | if (isParsing) {
414 | if (answer.status == ERROR) {
415 | paint.setColor(Color.parseColor("#FF7C64"));
416 | } else if (answer.status == CORRECTED) {
417 | paint.setColor(Color.parseColor("#06D265"));
418 | }
419 | }
420 | canvas.drawText(answer.text, answer.left, answer.top, paint);
421 | }
422 | //requestLayout();
423 | }
424 |
425 | @Override
426 | public boolean onTouchEvent(MotionEvent event) {
427 | //找出当前按下的时候那个点
428 | if (isParsing) {
429 | return true;
430 | }
431 | if (event.getAction() == MotionEvent.ACTION_UP) {
432 | float x = event.getX();
433 | float y = event.getY();
434 | LineInfo lineInfo = checkSelectInfo(x, y);
435 | if (lineInfo != null) {
436 | //如果上面有内容,则重置成横线内容
437 | FillAnswerInfo fillAnswerInfo = fillAnswerInfos.get(lineInfo.index);
438 | if (!TextUtils.isEmpty(fillAnswerInfo.lineText)) {
439 | fillAnswerInfo.lineWidth = lineWidth;
440 | fillAnswerInfo.lineText = "";
441 | answerResult.set(lineInfo.index, new ChoiceOptions());
442 | if (onStatusChange != null) {
443 | onStatusChange.onReduce(fillAnswerInfo.view);
444 | }
445 | setText();
446 | return true;
447 | }
448 | drawUnderLine(lineInfo);
449 | } else {
450 | Log.d("onTouchEvent", "lineInfo is null");
451 | }
452 | }
453 | return true;
454 | }
455 |
456 | /**
457 | * 绘制横线
458 | */
459 | private void drawUnderLine(LineInfo lineInfo) {
460 | //重置已经被选中过了的
461 | if (selectLineInfos != null) {
462 | for (LineInfo selectLineInfo : selectLineInfos) {
463 | selectLineInfo.isSelect = false;
464 | }
465 | selectLineInfos = null;
466 | }
467 | Log.d("drawUnderLine", "allLineInfos:" + allLineInfos.size());
468 | for (List allLineInfo : allLineInfos) {
469 | for (LineInfo info : allLineInfo) {
470 | if (info == lineInfo) {
471 | selectLineInfos = allLineInfo;
472 | break;
473 | }
474 | }
475 | }
476 | //如果之前的已经有被选中的,则取消之前被选中的
477 | if (selectLineInfos != null) {
478 | for (LineInfo selectLineInfo : selectLineInfos) {
479 | selectLineInfo.isSelect = true;
480 | }
481 | invalidate();
482 | }
483 | }
484 |
485 | /**
486 | * 检查是否选中了下划线
487 | */
488 | private LineInfo checkSelectInfo(float x, float y) {
489 | LineInfo selectLineInfo = null;
490 | for (LineInfo lineInfo : lineInfos) {
491 | if (x >= lineInfo.start
492 | && x <= lineInfo.end
493 | && y >= lineInfo.lineTop - lineDetaY - lineHeight
494 | && y <= lineInfo.lineTop) {
495 | selectLineInfo = lineInfo;
496 | break;
497 | }
498 | }
499 | return selectLineInfo;
500 | }
501 |
502 | /**
503 | * 填充答案
504 | */
505 | public boolean fillAnswer(ChoiceOptions choiceOptions, View view) {
506 | //直接给已经选中过的下划线处加文字
507 | if (selectLineInfos != null && selectLineInfos.size() > 0) {
508 | float answerWidth = paint.measureText(choiceOptions.getOptValue());//测量出答案的长度
509 | FillAnswerInfo fillAnswerInfo = fillAnswerInfos.get(selectLineInfos.get(0).index);
510 | fillAnswerInfo.lineWidth = answerWidth;
511 | fillAnswerInfo.lineText = choiceOptions.getOptValue();
512 | fillAnswerInfo.view = view;
513 | answerResult.set(selectLineInfos.get(0).index, choiceOptions);
514 | selectLineInfos = null;
515 | setText();
516 | return isCheckOptions;
517 | } else {
518 | //按照顺序进行填充答案
519 | for (int i = 0; i < fillAnswerInfos.size(); i++) {
520 | FillAnswerInfo fillAnswerInfo = fillAnswerInfos.get(i);
521 | if (TextUtils.isEmpty(fillAnswerInfo.lineText)) {
522 | float answerWidth = paint.measureText(choiceOptions.getOptValue());//测量出答案的长度
523 | fillAnswerInfo.lineWidth = answerWidth;
524 | fillAnswerInfo.lineText = choiceOptions.getOptValue();
525 | fillAnswerInfo.view = view;
526 | answerResult.set(i, choiceOptions);
527 | setText();
528 | return isCheckOptions;
529 | }
530 | }
531 | return false;
532 | }
533 | }
534 |
535 | @Override
536 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
537 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
538 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
539 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
540 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
541 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
542 | int width, height;
543 | int paddingTop = getPaddingTop();
544 | int paddingBottom = getPaddingBottom();
545 | int paddingLeft = getPaddingLeft();
546 | int paddingRight = getPaddingRight();
547 | //宽度的测量
548 | if (widthMode == MeasureSpec.EXACTLY) {
549 | width = widthSize;
550 | } else {
551 | StringBuilder sb = new StringBuilder();
552 | for (TextInfo textInfo : textInfos) {
553 | sb.append(textInfo.text);
554 | }
555 | for (TextInfo textInfo : answers) {
556 | sb.append(textInfo.text);
557 | }
558 | if (TextUtils.isEmpty(sb.toString())) {
559 | width = 0;
560 | } else {
561 | width = (int) Math.min(widthSize, paint.measureText(sb.toString()) + paddingLeft + paddingRight);
562 | }
563 | }
564 | //高度的测量
565 | if (heightMode == MeasureSpec.EXACTLY) {
566 | height = heightSize;
567 | } else {
568 | height = (int) totalHeight + paddingTop + paddingBottom;
569 | }
570 | setMeasuredDimension(width, height);
571 | }
572 |
573 | public List getAnswerResult() {
574 | return answerResult;
575 | }
576 |
577 | public OnStatusChange onStatusChange;
578 |
579 | public void setOnStatusChange(OnStatusChange onStatusChange) {
580 | this.onStatusChange = onStatusChange;
581 | }
582 |
583 | public interface OnStatusChange {
584 |
585 | void onReduce(View view);
586 | }
587 | }
588 |
--------------------------------------------------------------------------------
/blank/src/main/java/com/xc/blank/ChoiceBlankBean.kt:
--------------------------------------------------------------------------------
1 | package com.xc.blank
2 |
3 | data class ChoiceBlankBean(
4 |
5 | val questionContent: String,
6 | val choiceOptions: List,
7 | val stuAnswer: List?
8 | )
9 |
10 | data class ChoiceOptions(val optValue: String?=null, val answer: Int?=null)
--------------------------------------------------------------------------------
/blank/src/main/java/com/xc/blank/FillAnswerInfo.java:
--------------------------------------------------------------------------------
1 | package com.xc.blank;
2 |
3 | import android.view.View;
4 |
5 | import static com.xc.blank.Status.NORMAL;
6 |
7 | class FillAnswerInfo {
8 |
9 | public float lineWidth;
10 | public String lineText;
11 | public Status status = NORMAL;
12 | public View view;
13 | }
14 |
--------------------------------------------------------------------------------
/blank/src/main/java/com/xc/blank/FlowLayout.java:
--------------------------------------------------------------------------------
1 | package com.xc.blank;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * 搜索热门关键词的控件
13 | */
14 | public class FlowLayout extends ViewGroup {
15 |
16 | private Context mContext;
17 | private int mUsefulWidth; // the space of a line we can use(line's width minus the sum of left and right padding
18 | private int mLineSpacing = 0; // the spacing between lines in flowlayout
19 | List mChildList = new ArrayList();
20 |
21 | public FlowLayout(Context context) {
22 | this(context, null);
23 | }
24 |
25 | public FlowLayout(Context context, AttributeSet attrs) {
26 | this(context, attrs, 0);
27 | }
28 |
29 | public FlowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
30 | super(context, attrs, defStyleAttr);
31 | mContext = context;
32 | TypedArray mTypedArray = context.obtainStyledAttributes(attrs,
33 | R.styleable.FlowLayout);
34 | mLineSpacing = mTypedArray.getDimensionPixelSize(
35 | R.styleable.FlowLayout_lineSpacing, 0);
36 | mTypedArray.recycle();
37 | }
38 |
39 | @Override
40 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
41 | int mPaddingLeft = getPaddingLeft();
42 | int mPaddingRight = getPaddingRight();
43 | int mPaddingTop = getPaddingTop();
44 | int mPaddingBottom = getPaddingBottom();
45 |
46 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
47 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
48 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
49 | int lineUsed = mPaddingLeft + mPaddingRight;
50 | int lineY = mPaddingTop;
51 | int lineHeight = 0;
52 | for (int i = 0; i < this.getChildCount(); i++) {
53 | View child = this.getChildAt(i);
54 | if (child.getVisibility() == GONE) {
55 | continue;
56 | }
57 | measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, lineY);
58 | MarginLayoutParams mlp = (MarginLayoutParams) child.getLayoutParams();
59 | int childWidth = child.getMeasuredWidth();
60 | int childHeight = child.getMeasuredHeight();
61 | int spaceWidth = mlp.leftMargin + childWidth + mlp.rightMargin;
62 | int spaceHeight = mlp.topMargin + childHeight + mlp.bottomMargin;
63 | if (lineUsed + spaceWidth > widthSize) {
64 | //approach the limit of width and move to next line
65 | lineY += lineHeight + mLineSpacing;
66 | lineUsed = mPaddingLeft + mPaddingRight;
67 | lineHeight = 0;
68 | }
69 | if (spaceHeight > lineHeight) {
70 | lineHeight = spaceHeight;
71 | }
72 | lineUsed += spaceWidth;
73 | }
74 | setMeasuredDimension(
75 | widthSize,
76 | heightMode == MeasureSpec.EXACTLY ? heightSize : lineY + lineHeight + mPaddingBottom
77 | );
78 | }
79 |
80 | @Override
81 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
82 | int mPaddingLeft = getPaddingLeft();
83 | int mPaddingRight = getPaddingRight();
84 | int mPaddingTop = getPaddingTop();
85 |
86 | int lineX = mPaddingLeft;
87 | int lineY = mPaddingTop;
88 | int lineWidth = r - l;
89 | mUsefulWidth = lineWidth - mPaddingLeft - mPaddingRight;
90 | int lineUsed = mPaddingLeft + mPaddingRight;
91 | int lineHeight = 0;
92 | for (int i = 0; i < this.getChildCount(); i++) {
93 | View child = this.getChildAt(i);
94 | if (child.getVisibility() == GONE) {
95 | continue;
96 | }
97 | MarginLayoutParams mlp = (MarginLayoutParams) child.getLayoutParams();
98 | int childWidth = child.getMeasuredWidth();
99 | int childHeight = child.getMeasuredHeight();
100 | int spaceWidth = mlp.leftMargin + childWidth + mlp.rightMargin;
101 | int spaceHeight = mlp.topMargin + childHeight + mlp.bottomMargin;
102 | if (lineUsed + spaceWidth > lineWidth) {
103 | //approach the limit of width and move to next line
104 | lineY += lineHeight + mLineSpacing;
105 | lineUsed = mPaddingLeft + mPaddingRight;
106 | lineX = mPaddingLeft;
107 | lineHeight = 0;
108 | }
109 | child.layout(lineX + mlp.leftMargin, lineY + mlp.topMargin, lineX + mlp.leftMargin + childWidth, lineY + mlp.topMargin + childHeight);
110 | if (spaceHeight > lineHeight) {
111 | lineHeight = spaceHeight;
112 | }
113 | lineUsed += spaceWidth;
114 | lineX += spaceWidth;
115 |
116 | }
117 | }
118 |
119 | /**
120 | * resort child elements to use lines as few as possible
121 | */
122 | public void relayoutToCompress() {
123 | int childCount = this.getChildCount();
124 | if (0 == childCount) {
125 | //no need to sort if flowlayout has no child view
126 | return;
127 | }
128 | int count = 0;
129 | for (int i = 0; i < childCount; i++) {
130 | View v = getChildAt(i);
131 | if (v instanceof BlankView) {
132 | //BlankView is just to make childs look in alignment, we should ignore them when we relayout
133 | continue;
134 | }
135 | count++;
136 | }
137 | View[] childs = new View[count];
138 | int[] spaces = new int[count];
139 | int n = 0;
140 | for (int i = 0; i < childCount; i++) {
141 | View v = getChildAt(i);
142 | if (v instanceof BlankView) {
143 | //BlankView is just to make childs look in alignment, we should ignore them when we relayout
144 | continue;
145 | }
146 | childs[n] = v;
147 | MarginLayoutParams mlp = (MarginLayoutParams) v.getLayoutParams();
148 | int childWidth = v.getMeasuredWidth();
149 | spaces[n] = mlp.leftMargin + childWidth + mlp.rightMargin;
150 | n++;
151 | }
152 | sortToCompress(childs, spaces);
153 | this.removeAllViews();
154 | for (View v : mChildList) {
155 | this.addView(v);
156 | }
157 | mChildList.clear();
158 | }
159 |
160 | private void sortToCompress(View[] childs, int[] spaces) {
161 | int childCount = childs.length;
162 | int[][] table = new int[childCount + 1][mUsefulWidth + 1];
163 | for (int i = 0; i < childCount +1; i++) {
164 | for (int j = 0; j < mUsefulWidth; j++) {
165 | table[i][j] = 0;
166 | }
167 | }
168 | boolean[] flag = new boolean[childCount];
169 | for (int i = 0; i < childCount; i++) {
170 | flag[i] = false;
171 | }
172 | for (int i = 1; i <= childCount; i++) {
173 | for (int j = spaces[i-1]; j <= mUsefulWidth; j++) {
174 | table[i][j] = (table[i-1][j] > table[i-1][j-spaces[i-1]] + spaces[i-1]) ? table[i-1][j] : table[i-1][j-spaces[i-1]] + spaces[i-1];
175 | }
176 | }
177 | int v = mUsefulWidth;
178 | for (int i = childCount ; i > 0 && v >= spaces[i-1]; i--) {
179 | if (table[i][v] == table[i-1][v-spaces[i-1]] + spaces[i-1]) {
180 | flag[i-1] = true;
181 | v = v - spaces[i - 1];
182 | }
183 | }
184 | int rest = childCount;
185 | View[] restArray;
186 | int[] restSpaces;
187 | for (int i = 0; i < flag.length; i++) {
188 | if (flag[i] == true) {
189 | mChildList.add(childs[i]);
190 | rest--;
191 | }
192 | }
193 |
194 | if (0 == rest) {
195 | return;
196 | }
197 | restArray = new View[rest];
198 | restSpaces = new int[rest];
199 | int index = 0;
200 | for (int i = 0; i < flag.length; i++) {
201 | if (flag[i] == false) {
202 | restArray[index] = childs[i];
203 | restSpaces[index] = spaces[i];
204 | index++;
205 | }
206 | }
207 | table = null;
208 | childs = null;
209 | flag = null;
210 | sortToCompress(restArray, restSpaces);
211 | }
212 |
213 | /**
214 | * add some blank view to make child elements look in alignment
215 | */
216 | public void relayoutToAlign() {
217 | int childCount = this.getChildCount();
218 | if (0 == childCount) {
219 | //no need to sort if flowlayout has no child view
220 | return;
221 | }
222 | int count = 0;
223 | for (int i = 0; i < childCount; i++) {
224 | View v = getChildAt(i);
225 | if (v instanceof BlankView) {
226 | //BlankView is just to make childs look in alignment, we should ignore them when we relayout
227 | continue;
228 | }
229 | count++;
230 | }
231 | View[] childs = new View[count];
232 | int[] spaces = new int[count];
233 | int n = 0;
234 | for (int i = 0; i < childCount; i++) {
235 | View v = getChildAt(i);
236 | if (v instanceof BlankView) {
237 | //BlankView is just to make childs look in alignment, we should ignore them when we relayout
238 | continue;
239 | }
240 | childs[n] = v;
241 | MarginLayoutParams mlp = (MarginLayoutParams) v.getLayoutParams();
242 | int childWidth = v.getMeasuredWidth();
243 | spaces[n] = mlp.leftMargin + childWidth + mlp.rightMargin;
244 | n++;
245 | }
246 | int lineTotal = 0;
247 | int start = 0;
248 | this.removeAllViews();
249 | for (int i = 0; i < count; i++) {
250 | if (lineTotal + spaces[i] > mUsefulWidth) {
251 | int blankWidth = mUsefulWidth - lineTotal;
252 | int end = i - 1;
253 | int blankCount = end - start;
254 | if (blankCount > 0) {
255 | int eachBlankWidth = blankWidth / blankCount;
256 | MarginLayoutParams lp = new MarginLayoutParams(eachBlankWidth, 0);
257 | for (int j = start; j < end; j++) {
258 | this.addView(childs[j]);
259 | BlankView blank = new BlankView(mContext);
260 | this.addView(blank, lp);
261 | }
262 | this.addView(childs[end]);
263 | start = i;
264 | i --;
265 | lineTotal = 0;
266 | }
267 | } else {
268 | lineTotal += spaces[i];
269 | }
270 | }
271 | for (int i = start; i < count; i++) {
272 | this.addView(childs[i]);
273 | }
274 | }
275 |
276 | /**
277 | * use both of relayout methods together
278 | */
279 | public void relayoutToCompressAndAlign(){
280 | this.relayoutToCompress();
281 | this.relayoutToAlign();
282 | }
283 | @Override
284 | protected LayoutParams generateLayoutParams(LayoutParams p) {
285 | return new MarginLayoutParams(p);
286 | }
287 |
288 | @Override
289 | public LayoutParams generateLayoutParams(AttributeSet attrs)
290 | {
291 | return new MarginLayoutParams(getContext(), attrs);
292 | }
293 |
294 | class BlankView extends View {
295 |
296 | public BlankView(Context context) {
297 | super(context);
298 | }
299 | }
300 | }
301 |
--------------------------------------------------------------------------------
/blank/src/main/java/com/xc/blank/LineInfo.java:
--------------------------------------------------------------------------------
1 | package com.xc.blank;
2 |
3 | import static com.xc.blank.Status.NORMAL;
4 |
5 | class LineInfo {
6 |
7 | public float start;
8 | public float end;
9 | public float lineTop;
10 | public boolean isSelect;
11 | public int index;//下划线对应的下划线集合的索引
12 | //public View view;//绑定的view,该view作为释放view状态用的
13 | public Status status = NORMAL;
14 | }
15 |
--------------------------------------------------------------------------------
/blank/src/main/java/com/xc/blank/Status.java:
--------------------------------------------------------------------------------
1 | package com.xc.blank;
2 |
3 | enum Status {
4 | CORRECTED,ERROR,NORMAL
5 | }
6 |
--------------------------------------------------------------------------------
/blank/src/main/java/com/xc/blank/TextInfo.java:
--------------------------------------------------------------------------------
1 | package com.xc.blank;
2 |
3 | import static com.xc.blank.Status.NORMAL;
4 |
5 | class TextInfo {
6 | public float top;
7 | public float left;
8 | public String text;
9 | public Status status = NORMAL;
10 | }
11 |
--------------------------------------------------------------------------------
/blank/src/main/res/drawable/btn_rectangle_gray_b3b3b3.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/blank/src/main/res/drawable/btn_rectangle_gray_e0e0e0.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/blank/src/main/res/drawable/btn_rectangle_gray_ff7171.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/blank/src/main/res/drawable/selector_task_answer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/blank/src/main/res/drawable/selector_task_answer_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/blank/src/main/res/layout/blank_root_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
21 |
22 |
--------------------------------------------------------------------------------
/blank/src/main/res/layout/item_task_answer.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/blank/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/blank/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 75dp
4 | 54dp
5 | 23dp
6 | 20dp
7 | 16dp
8 | 30dp
9 | 2dp
10 | 15dp
11 | 13dp
12 | 12dp
13 | 11dp
14 | 8dp
15 | 10dp
16 | 5dp
17 | 1dp
18 | 0.5dp
19 |
20 | 15sp
21 |
22 |
--------------------------------------------------------------------------------
/blank/src/test/java/com/xc/blank/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xc.blank;
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 |
14 | @Test
15 | public void addition_isCorrect() {
16 | assertEquals(4, 2 + 2);
17 | }
18 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | ext.kotlin_version = '1.3.72'
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath "com.android.tools.build:gradle:4.0.0"
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jul 12 20:51:49 CST 2020
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-6.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/images/simple.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangcman/BlankView/07337deabbd34612c9b8289a220e3441e41809f3/images/simple.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':blank'
2 | include ':app'
3 | rootProject.name = "BlankView"
--------------------------------------------------------------------------------