-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Parabox-App/develop
1.0.10-beta
- Loading branch information
Showing
66 changed files
with
7,071 additions
and
1,535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ | |
.cxx | ||
local.properties | ||
app/release | ||
.idea/gradle.xml | ||
.idea/gradle.xml | ||
.idea/deploymentTargetDropDown.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
263 changes: 185 additions & 78 deletions
263
app/src/main/java/com/ojhdtapp/parabox/MainActivity.kt
Large diffs are not rendered by default.
Oops, something went wrong.
67 changes: 65 additions & 2 deletions
67
app/src/main/java/com/ojhdtapp/parabox/core/util/AvatarUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,72 @@ | ||
package com.ojhdtapp.parabox.core.util | ||
|
||
import android.graphics.BitmapFactory | ||
import android.content.Context | ||
import android.graphics.* | ||
import android.net.Uri | ||
import android.util.Log | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.asImageBitmap | ||
import androidx.compose.ui.graphics.toArgb | ||
import com.ojhdtapp.parabox.core.util.FileUtil.checkUriAvailable | ||
import java.util.* | ||
|
||
fun ByteArray.toAvatarBitmap(): ImageBitmap{ | ||
|
||
fun ByteArray.toAvatarBitmap(): ImageBitmap { | ||
return BitmapFactory.decodeByteArray(this, 0, this.size).asImageBitmap() | ||
} | ||
|
||
object AvatarUtil { | ||
fun getAvatar( | ||
context: Context, | ||
uri: Uri? = null, | ||
url: String? = null, | ||
name: String? = null, | ||
backgroundColor: androidx.compose.ui.graphics.Color, | ||
textColor: androidx.compose.ui.graphics.Color, | ||
): Any { | ||
return (if(uri?.checkUriAvailable(context) == true) uri else null) ?: url ?: createNamedAvatarBm( | ||
backgroundColor = backgroundColor.toArgb(), | ||
textColor = textColor.toArgb(), | ||
name = name?.ifBlank { null }?.substring(0, 1)?.uppercase(Locale.getDefault()) | ||
).getCircledBitmap() | ||
} | ||
|
||
fun createNamedAvatarBm( | ||
width: Int = 150, height: Int = 150, | ||
backgroundColor: Int, | ||
textColor: Int, | ||
name: String? | ||
): Bitmap { | ||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) | ||
val rect = Rect(0, 0, width, height) | ||
val canvas = Canvas(bitmap) | ||
|
||
val backgroundPaint = Paint() | ||
backgroundPaint.color = backgroundColor | ||
canvas.drawRect(rect, backgroundPaint) | ||
|
||
val textPaint = Paint() | ||
textPaint.color = textColor | ||
textPaint.textSize = 72f | ||
textPaint.textScaleX = 1f | ||
textPaint.textAlign = Paint.Align.CENTER | ||
if (name != null) { | ||
val baselineY = rect.centerY() - (textPaint.descent() + textPaint.ascent()) / 2 | ||
canvas.drawText(name, rect.centerX().toFloat(), baselineY, textPaint) | ||
} | ||
return bitmap | ||
} | ||
|
||
fun Bitmap.getCircledBitmap(): Bitmap { | ||
val output = Bitmap.createBitmap(this.width, this.height, Bitmap.Config.ARGB_8888) | ||
val canvas = Canvas(output) | ||
val paint = Paint() | ||
val rect = Rect(0, 0, this.width, this.height) | ||
paint.isAntiAlias = true | ||
canvas.drawARGB(0, 0, 0, 0) | ||
canvas.drawCircle(this.width / 2f, this.height / 2f, this.width / 2f, paint) | ||
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) | ||
canvas.drawBitmap(this, rect, rect, paint) | ||
return output | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.