Skip to content

Commit 95a6730

Browse files
随机drawable颜色 layout控件id
1 parent b68f69a commit 95a6730

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

library/src/main/groovy/cn/hx/plugin/junkcode/task/AndroidJunkCodeTask.groovy

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AndroidJunkCodeTask extends DefaultTask {
2121
static def random = new Random()
2222

2323
static abc = "abcdefghijklmnopqrstuvwxyz".toCharArray()
24+
static color = "0123456789abcdef".toCharArray()
2425

2526
@Nested
2627
JunkCodeConfig config
@@ -192,7 +193,7 @@ class AndroidJunkCodeTask extends DefaultTask {
192193
FileWriter writer
193194
try {
194195
writer = new FileWriter(drawableFile)
195-
def template = ResTemplate.DRAWABLE
196+
def template = String.format(ResTemplate.DRAWABLE, generateColor())
196197
writer.write(template.toString())
197198
} catch (Exception e) {
198199
e.printStackTrace()
@@ -219,7 +220,7 @@ class AndroidJunkCodeTask extends DefaultTask {
219220
FileWriter writer
220221
try {
221222
writer = new FileWriter(layoutFile)
222-
def template = ResTemplate.LAYOUT_TEMPLATE
223+
def template = String.format(ResTemplate.LAYOUT_TEMPLATE, generateId())
223224
writer.write(template.toString())
224225
} catch (Exception e) {
225226
e.printStackTrace()
@@ -385,4 +386,28 @@ class AndroidJunkCodeTask extends DefaultTask {
385386
sb.append(index.toString())
386387
return sb.toString()
387388
}
389+
390+
/**
391+
* 生成颜色代码
392+
* @return
393+
*/
394+
static String generateColor() {
395+
def sb = new StringBuffer()
396+
sb.append("#")
397+
for (i in 0..5) {
398+
sb.append(color[random.nextInt(color.size())])
399+
}
400+
return sb.toString()
401+
}
402+
/**
403+
* 生成id代码
404+
* @return
405+
*/
406+
static String generateId() {
407+
def sb = new StringBuffer()
408+
for (i in 0..5) {
409+
sb.append(abc[random.nextInt(abc.size())])
410+
}
411+
return sb.toString()
412+
}
388413
}

library/src/main/groovy/cn/hx/plugin/junkcode/template/ResTemplate.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ResTemplate {
3232
</aapt:attr>
3333
</path>
3434
<path
35-
android:fillColor="#FFFFFF"
35+
android:fillColor="%s"
3636
android:fillType="nonZero"
3737
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
3838
android:strokeWidth="1"
@@ -50,7 +50,7 @@ class ResTemplate {
5050
android:orientation="vertical">
5151
5252
<TextView
53-
android:id="@+id/tv_text"
53+
android:id="@+id/tv_text_%s"
5454
android:layout_width="wrap_content"
5555
android:layout_height="wrap_content"
5656
android:layout_gravity="center" />

0 commit comments

Comments
 (0)