forked from gappein/Gappein-Sticker-SDK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
119 additions
and
188 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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
package com.gappein.sample | ||
|
||
import android.graphics.Color | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import com.gappein.sticker.Generator | ||
import com.gappein.sticker.model.TextValues | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.gappein.StickerView | ||
import com.gappein.util.generateSticker | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
|
||
class MainActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val x = StickerView(this) | ||
x.updateText("dsfsdfsdf") | ||
setContentView(R.layout.activity_main) | ||
|
||
val x = Generator(this).setText(TextValues(text = "hey Himanshuhey Himan")).draw() | ||
background.setImageBitmap(x) | ||
background.setImageBitmap(x.generateSticker()) | ||
} | ||
} |
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
24 changes: 0 additions & 24 deletions
24
sticker/src/androidTest/java/com/gappein/sticker/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
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,5 +1,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.gappein.sticker"> | ||
|
||
/ | ||
</manifest> | ||
package="com.gappein" /> |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.gappein | ||
|
||
import android.content.Context | ||
import android.content.res.ColorStateList | ||
import android.graphics.Bitmap | ||
import android.graphics.Canvas | ||
import android.graphics.Color | ||
import android.graphics.Paint | ||
import androidx.appcompat.widget.AppCompatTextView | ||
import androidx.core.content.res.ResourcesCompat | ||
import com.gappein.sticker.util.generateColor | ||
|
||
class StickerView(context: Context) : AppCompatTextView(context) { | ||
|
||
companion object { | ||
private const val DEFAULT_STROKE = 4f | ||
private const val DEFAULT_TEXT_SIZE = 60f | ||
private const val mStrokeWidth: Float = 10.toFloat() | ||
private const val strokeColor: Int = Color.WHITE | ||
} | ||
|
||
private var isDrawing: Boolean = false | ||
private val mShadowColors: ColorStateList = ColorStateList.valueOf(Color.GRAY) | ||
private val typeFace = ResourcesCompat.getFont(this.context, R.font.bumper) | ||
|
||
init { | ||
initResources() | ||
} | ||
|
||
private fun updateShadowColor() { | ||
setShadowLayer( | ||
DEFAULT_STROKE, | ||
DEFAULT_STROKE, | ||
DEFAULT_STROKE, | ||
mShadowColors.getColorForState(drawableState, 0) | ||
) | ||
} | ||
|
||
|
||
private fun initResources() { | ||
typeface = typeFace | ||
textSize = DEFAULT_TEXT_SIZE | ||
setTextColor(generateColor()) | ||
updateShadowColor() | ||
} | ||
|
||
fun updateText(text: String) { | ||
setText(text) | ||
} | ||
|
||
override fun invalidate() { | ||
if (isDrawing) return | ||
super.invalidate() | ||
} | ||
|
||
override fun onDraw(canvas: Canvas) { | ||
if (mStrokeWidth > 0) { | ||
isDrawing = true | ||
val textPaint = paint | ||
|
||
textPaint.style = Paint.Style.FILL | ||
|
||
super.onDraw(canvas) | ||
|
||
val currentTextColor = currentTextColor | ||
textPaint.apply { | ||
style = Paint.Style.STROKE | ||
strokeWidth = mStrokeWidth | ||
} | ||
setTextColor(strokeColor) | ||
super.onDraw(canvas) | ||
setTextColor(currentTextColor) | ||
isDrawing = false | ||
} else { | ||
super.onDraw(canvas) | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
76 changes: 0 additions & 76 deletions
76
sticker/src/main/java/com/gappein/sticker/model/DrawaingValues.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
sticker/src/main/java/com/gappein/sticker/model/TextValues.kt
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.gappein.sticker.util | ||
|
||
import android.graphics.Color | ||
import android.view.View | ||
import java.util.* | ||
|
||
fun View.generateColor(): Int { | ||
val random = Random() | ||
return Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256)) | ||
} |
20 changes: 20 additions & 0 deletions
20
sticker/src/main/java/com/gappein/util/StickerExtension.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.gappein.util | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.Canvas | ||
import android.util.Log | ||
import android.view.View.MeasureSpec | ||
import com.gappein.StickerView | ||
|
||
fun StickerView.generateSticker(): Bitmap { | ||
val view = this | ||
view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED) | ||
val bitmap = Bitmap.createBitmap( | ||
view.measuredWidth, view.measuredHeight, | ||
Bitmap.Config.ARGB_8888 | ||
) | ||
val canvas = Canvas(bitmap) | ||
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()) | ||
view.draw(canvas) | ||
return bitmap | ||
} |
17 changes: 0 additions & 17 deletions
17
sticker/src/test/java/com/gappein/sticker/ExampleUnitTest.kt
This file was deleted.
Oops, something went wrong.