Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: color parse form address #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/src/main/java/io/arcblock/did_motif/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MainActivity : AppCompatActivity() {
}
}
binding.identiconRg.check(5)

val color = DIDMotif.calculateColorOfAddress(address)
binding.bgColor.setBackgroundColor(color)
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@
android:text="Square"
/>
</RadioGroup>
<View
android:id="@+id/bg_color"
android:layout_width="40dp"
android:layout_height="40dp"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
13 changes: 10 additions & 3 deletions did-motif/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ android {
}

dependencies {
api 'io.arcblock.walletkit:walletkit:0.5.18'
// api 'io.arcblock.walletkit:walletkit:0.5.18'
api('org.bitcoinj:bitcoinj-core:0.16.1') {
exclude group: 'com.google.protobuf'
exclude group: 'org.bouncycastle'
}
api('org.web3j:core:4.6.0-android')
api('io.arcblock.did:wallet-sdk:1.0.10') {
exclude group: 'org.web3j'
exclude group: 'org.bouncycastle'
}
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
Expand Down Expand Up @@ -102,8 +111,6 @@ publishing {
developers {
developer {
id = 'ArcBlock'
name = 'ArcBlock'
email = '[email protected]'
}
}
scm {
Expand Down
88 changes: 53 additions & 35 deletions did-motif/src/main/java/io/arcblock/did_motif/didmotif/DIDMotif.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,6 @@ class DIDMotif(
Hexagon
}

private val bgColors = arrayListOf(
"#E94E4E",
"#E41115",
"#E96B4E",
"#E5502E",
"#E98F4E",
"#E57A2E",
"#E98F4E",
"#E5A82E",
"#DACD5D",
"#DAC825",
"#BDD13D",
"#C8E31C",
"#AEE94E",
"#7FD558",
"#52CC19",
"#4FC469",
"#59DE9C",
"#19CC73",
"#5ED9D1",
"#19CCC0",
"#4ED7E9",
"#19B7CC",
"#45ACE8",
"#1C97DE",
"#4E68E9",
"#2E4DE5",
"#7F4EE9",
"#682EE5",
"#BE65E7",
"#AF40E2",
"#DF58C2",
"#E94E8F",
)

private val DEBUG_MODE = false
private val totalIndex = arrayListOf<Int>()
Expand Down Expand Up @@ -131,7 +97,7 @@ class DIDMotif(
address: String,
type: Shape? = null,
withAnimation: Boolean = true
) {
): Int {
val info = if (address.address().length < 10) {
randomMotif()
} else try {
Expand Down Expand Up @@ -163,8 +129,10 @@ class DIDMotif(
} else {
invalidate()
}
return bgColor
}


private fun randomMotif(): Triple<Int, List<Int>, RoleType> {
val colorIndexes = arrayListOf<Int>()
for (i in 0..31) {
Expand Down Expand Up @@ -266,4 +234,54 @@ class DIDMotif(
localPath.close()
return localPath
}


companion object {

private val bgColors = arrayListOf(
"#E94E4E",
"#E41115",
"#E96B4E",
"#E5502E",
"#E98F4E",
"#E57A2E",
"#E98F4E",
"#E5A82E",
"#DACD5D",
"#DAC825",
"#BDD13D",
"#C8E31C",
"#AEE94E",
"#7FD558",
"#52CC19",
"#4FC469",
"#59DE9C",
"#19CC73",
"#5ED9D1",
"#19CCC0",
"#4ED7E9",
"#19B7CC",
"#45ACE8",
"#1C97DE",
"#4E68E9",
"#2E4DE5",
"#7F4EE9",
"#682EE5",
"#BE65E7",
"#AF40E2",
"#DF58C2",
"#E94E8F",
)
fun calculateColorOfAddress(address: String) : Int {
val info = if (address.address().length < 10) {
return Color.parseColor(bgColors[0])
} else try {
DIDMotifUtils.getIndexFromDID(address)
} catch (e: Exception) {
// 如果发生异常,随机一个组合
return Color.parseColor(bgColors[0])
}
return Color.parseColor(bgColors[info.first])
}
}
}
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.4
1.0.5