diff --git a/.idea/misc.xml b/.idea/misc.xml index b50a2dc..72ac3b7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,6 +4,8 @@ diff --git a/app/src/main/java/com/example/spinwill/MainActivity.kt b/app/src/main/java/com/example/spinwill/MainActivity.kt index dfdf48d..e1bb644 100644 --- a/app/src/main/java/com/example/spinwill/MainActivity.kt +++ b/app/src/main/java/com/example/spinwill/MainActivity.kt @@ -2,16 +2,22 @@ package com.example.spinwill import android.annotation.SuppressLint import android.graphics.Bitmap +import android.graphics.Color import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log +import android.widget.FrameLayout import android.widget.ImageView +import androidx.core.content.ContextCompat import androidx.work.* import com.example.spinwill.adapter.WillItemAdapter import com.example.spinwill.cron.SpinWillWorker import com.example.spinwill.cron.SpinWillWorkerFactory import com.example.spinwill.database.local.SpinWillLocalDbImpl import com.example.spinwill.di.SpinWillInjector +import com.example.spinwill.ui.SpinWillView1 +import com.example.spinwill.ui.WillView1 +import com.example.spinwill.ui.adapters.WillItemUiAdapter import com.example.spinwill.usecases.SpinWillBitmapLoadUseCaseImpl import com.example.spinwill.utils.Resource import kotlinx.coroutines.* @@ -30,20 +36,55 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - AppWillRoomDatabase.getInstance(this.applicationContext) setupDependencies() // setupWork() - setupUi() + // setupUi() + setupWheelView() + } + + private fun setupWheelView() { + val layout = findViewById(R.id.frame) + val willView = SpinWillView1(this) + layout.addView(willView) + scope.launch(Dispatchers.IO) { + injector.getRepository().fetchAndUpdateWheelItem() + val result = injector.getRepository().loadBitmapAndSave() + + if (result is Resource.Success && result.data != null) { + val list = result.data!! + Log.d("MainAct", "result size " + list.size) + + runOnUiThread { + willView.getWillView().paintProps.textPaint.apply { + color = Color.WHITE + } + willView.setItems(result.data!!) + willView.setItemAdapter(object : WillItemUiAdapter { + override fun getRewardText(item: SpinWillItem): String { + return item.rewardText + } + + override fun getOverlayText(item: SpinWillItem): String { + return item.rewardText + } + + override fun getRewardBitmap(item: SpinWillItem): Bitmap? { + return item.rewardBitmap + } + }) + } + } + } } private fun setupDependencies() { // set context, remoteDb, localDb, dao, bitmap load use-case. injector.init(this, RemoteDatabaseImpl()) - val daoConc = SpinWillDaoConc() - daoConc.setDao(AppWillRoomDatabase.getInstance(this.applicationContext).getSpinWillDao()) + val daoActions = SpinWillDaoConc() + daoActions.setDao(AppWillRoomDatabase.getInstance(this.applicationContext).getSpinWillDao()) injector.setLocalDatabase( - SpinWillLocalDbImpl(daoConc) + SpinWillLocalDbImpl(daoActions) ) injector.setBitmapLoadUseCase( diff --git a/app/src/main/java/com/example/spinwill/RemoteDatabaseImpl.kt b/app/src/main/java/com/example/spinwill/RemoteDatabaseImpl.kt index b108805..a479118 100644 --- a/app/src/main/java/com/example/spinwill/RemoteDatabaseImpl.kt +++ b/app/src/main/java/com/example/spinwill/RemoteDatabaseImpl.kt @@ -10,28 +10,20 @@ class RemoteDatabaseImpl : SpinWillRemoteDatabase { Log.d("App", "23") val list = mutableListOf() - list.add( - SpinWillItem( - rewardId = 1L, - rewardAmount = 100L, - rewardImage = "https://images.pexels.com/photos/2014422/pexels-photo-2014422.jpeg", - rewardText = "100 COINS" + /* + when number of items is odd it creates repetition in color of arcs + */ + for (i in 0..5) { + list.add( + SpinWillItem( + rewardId = 1L, + rewardAmount = i * 100L, + rewardImage = "https://images.pexels.com/photos/2014422/pexels-photo-2014422.jpeg", + rewardText = "${i}00" + ) ) - ) - - delay(1000L) - - list.add( - SpinWillItem( - rewardId = 1L, - rewardAmount = 100L, - rewardImage = "https://images.pexels.com/photos/2014422/pexels-photo-2014422.jpeg", - rewardText = "100 COINS" - ) - ) - + } Log.d("App", "19") - return Resource.Success(list) } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8e6be4d..b64577f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -10,23 +10,27 @@ android:id="@+id/iv_1" android:layout_width="100dp" android:layout_height="100dp" - app:layout_constraintTop_toTopOf="parent" + android:visibility="gone" + app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintEnd_toEndOf="parent"/> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@id/iv_1" /> - + app:layout_constraintTop_toTopOf="parent" /> \ No newline at end of file diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..1bfc0d7 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,4 @@ +jdk: + - openjdk11 +before_install: + - ./scripts/prepareJitpackEnvironment.sh \ No newline at end of file diff --git a/spinwill/build.gradle b/spinwill/build.gradle index 7176542..471180e 100644 --- a/spinwill/build.gradle +++ b/spinwill/build.gradle @@ -4,6 +4,7 @@ plugins { id 'kotlin-android' id 'kotlin-android-extensions' id 'kotlin-kapt' + id 'maven-publish' } android { @@ -58,4 +59,18 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} + +afterEvaluate { + publishing { + publications { + release(MavenPublication) { + from components.release + + groupId = 'com.github.sidsharma2002' + artifactId = 'SpinWill' + version = '0.1' + } + } + } } \ No newline at end of file diff --git a/spinwill/src/main/java/com/example/spinwill/adapter/WillPaintAdapter.kt b/spinwill/src/main/java/com/example/spinwill/adapter/WillPaintAdapter.kt new file mode 100644 index 0000000..0024599 --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/adapter/WillPaintAdapter.kt @@ -0,0 +1,7 @@ +package com.example.spinwill.adapter + +import android.graphics.Paint + +interface WillPaintAdapter { + fun setPaintProperties(paint: Paint) +} \ No newline at end of file diff --git a/spinwill/src/main/java/com/example/spinwill/models/WillDimenProperties.kt b/spinwill/src/main/java/com/example/spinwill/models/WillDimenProperties.kt new file mode 100644 index 0000000..1026277 --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/models/WillDimenProperties.kt @@ -0,0 +1,11 @@ +package com.example.spinwill.models + +data class WillDimenProperties( + var paddingLeft: Int = 0, + var paddingRight: Int = 0, + var paddingTop: Int = 0, + var paddingBottom: Int = 0, + var padding: Int = 0, + var radius: Int = 0, + var center: Int = 0 +) diff --git a/spinwill/src/main/java/com/example/spinwill/models/WillGradient.kt b/spinwill/src/main/java/com/example/spinwill/models/WillGradient.kt new file mode 100644 index 0000000..69e3b10 --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/models/WillGradient.kt @@ -0,0 +1,8 @@ +package com.example.spinwill.models + +import android.graphics.RadialGradient + +data class WillGradient( + var darkYellow: RadialGradient? = null, + var lightYellow: RadialGradient? = null +) diff --git a/spinwill/src/main/java/com/example/spinwill/models/WillPaintProperties.kt b/spinwill/src/main/java/com/example/spinwill/models/WillPaintProperties.kt new file mode 100644 index 0000000..e0d8ec3 --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/models/WillPaintProperties.kt @@ -0,0 +1,34 @@ +package com.example.spinwill.models + +import android.graphics.Paint +import com.example.spinwill.adapter.WillPaintAdapter + +data class WillPaintProperties( + val archPaint: Paint = Paint().apply { + isAntiAlias = true + isDither = true + style = Paint.Style.FILL_AND_STROKE + }, + val textPaint: Paint = Paint().apply { + isAntiAlias = true + isDither = true + letterSpacing = 0.1f + }, + val overlayTextPaint: Paint = Paint().apply { + isAntiAlias = true + isDither = true + letterSpacing = 0.1f + }, + val separationArchPaint: Paint = Paint().apply { + style = Paint.Style.STROKE + isAntiAlias = true + isDither = true + }, + val bitmapPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG or Paint.FILTER_BITMAP_FLAG), + + var archPaintAdapter: WillPaintAdapter? = null, + var textPaintAdapter: WillPaintAdapter? = null, + var overlayTextPaintAdapter: WillPaintAdapter? = null, + var separationArchPaintAdapter: WillPaintAdapter? = null, + var bitmapPaintAdapter: WillPaintAdapter? = null +) \ No newline at end of file diff --git a/spinwill/src/main/java/com/example/spinwill/ui/DimenAdapters/DimenAdapter1.kt b/spinwill/src/main/java/com/example/spinwill/ui/DimenAdapters/DimenAdapter1.kt new file mode 100644 index 0000000..5a361ce --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/ui/DimenAdapters/DimenAdapter1.kt @@ -0,0 +1,25 @@ +package com.example.spinwill.ui.DimenAdapters + +import com.example.spinwill.models.WillDimenProperties +import com.example.spinwill.models.WillPaintProperties + +interface OffSetDimenAdapter1 { + + fun getVOffsetOverLayText( + tempAngle: Float, + sweepAngle: Float, + text: String, + itemsSize: Int, + paintProps: WillPaintProperties, + dimenProps: WillDimenProperties + ): Int + + fun getHOffsetOverlayText( + tempAngle: Float, + sweepAngle: Float, + text: String, + itemsSize: Int, + paintProps: WillPaintProperties, + dimenProps: WillDimenProperties + ): Int +} \ No newline at end of file diff --git a/spinwill/src/main/java/com/example/spinwill/ui/SpinWillView1.kt b/spinwill/src/main/java/com/example/spinwill/ui/SpinWillView1.kt new file mode 100644 index 0000000..f5f5278 --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/ui/SpinWillView1.kt @@ -0,0 +1,46 @@ +package com.example.spinwill.ui + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.widget.FrameLayout +import androidx.annotation.ColorRes +import androidx.annotation.IdRes +import androidx.constraintlayout.widget.ConstraintLayout +import com.example.spinwill.R +import com.example.spinwill.ui.adapters.WillItemUiAdapter + +class SpinWillView1 constructor( + context: Context +) : ConstraintLayout(context) { + + private lateinit var willView1: WillView1 + + init { + val parentView = + LayoutInflater.from(context).inflate(R.layout.layout_spinwillview1, null, false) + willView1 = WillView1(context, null) + val parentLayout: FrameLayout = parentView.findViewById(R.id.container) + parentLayout.addView(willView1) + addView(parentView) + postInvalidate() + } + + fun setItems(data: List) { + willView1.setItems(data) + willView1.invalidate() + } + + fun setItemAdapter(willItemUiAdapter: WillItemUiAdapter) { + willView1.setItemAdapter(willItemUiAdapter) + willView1.invalidate() + } + + fun getWillView(): WillView1 { + return willView1 + } + + fun setTextColor(@IdRes color: Int) { + willView1.paintProps.textPaint.color = color + } +} \ No newline at end of file diff --git a/spinwill/src/main/java/com/example/spinwill/ui/WillView1.kt b/spinwill/src/main/java/com/example/spinwill/ui/WillView1.kt new file mode 100644 index 0000000..9433e58 --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/ui/WillView1.kt @@ -0,0 +1,333 @@ +package com.example.spinwill.ui + +import android.content.Context +import android.graphics.* +import android.util.AttributeSet +import android.view.View +import androidx.core.content.ContextCompat +import androidx.core.content.res.ResourcesCompat +import com.example.spinwill.R +import com.example.spinwill.adapter.WillPaintAdapter +import com.example.spinwill.models.WillDimenProperties +import com.example.spinwill.models.WillGradient +import com.example.spinwill.models.WillPaintProperties +import com.example.spinwill.ui.DimenAdapters.OffSetDimenAdapter1 +import com.example.spinwill.ui.adapters.WillItemUiAdapter +import com.example.spinwill.ui.defaultImpl.OverlayDimenAdapter1Impl +import com.example.spinwill.ui.defaultImpl.TextDimenAdapter1Impl +import com.example.spinwill.utils.dp +import kotlin.math.PI +import kotlin.math.cos +import kotlin.math.min +import kotlin.math.sin + +/** + * * note : this cannot be inflated directly from xml. + */ +class WillView1 constructor( + context: Context, + attributeSet: AttributeSet? +) : View(context, attributeSet) { + + companion object { + const val DEF_BORDER_PERCENT = 3f + } + + private var wheelSize: Int = 0 + + /** + * list for the will-data items + */ + private lateinit var items: List + + fun setItems(items: List) { + this.items = items + wheelSize = items.size + } + + /** + * adapter for will-data items. + */ + private lateinit var itemAdapter: WillItemUiAdapter + + fun setItemAdapter(adapter: WillItemUiAdapter) { + itemAdapter = adapter + } + + private val dimenProps = WillDimenProperties() + val paintProps = WillPaintProperties() + val gradientProps = WillGradient() + private var willRange = RectF() + private var mPath = Path() + private var mRect = Rect() + private var mMatrix = Matrix() + + private var overlayDimenAdapter1: OffSetDimenAdapter1 = OverlayDimenAdapter1Impl() + + fun setOverLayDimenAdapter1(adapter: OffSetDimenAdapter1) { + overlayDimenAdapter1 = adapter + } + + private var textDimenAdapter1: OffSetDimenAdapter1 = TextDimenAdapter1Impl() + + fun setTextDimenAdapter1(adapter: OffSetDimenAdapter1) { + textDimenAdapter1 = adapter + } + + override fun onDraw(canvas: Canvas?) { + super.onDraw(canvas) + if (canvas == null || ::items.isInitialized.not() || ::itemAdapter.isInitialized.not()) return + + var tempAngle = 0f + val sweepAngle: Float = 360f / wheelSize + val rotateAngle = sweepAngle / 2 + 90 + + for (i in items.indices) { + // drawPieBackgroundBorder(canvas) + drawPieBackground(i, tempAngle, sweepAngle, canvas) + + val bitmap = itemAdapter.getRewardBitmap(items[i]) + if (bitmap != null) { + drawImage(canvas, tempAngle, itemAdapter.getRewardBitmap(items[i])!!, rotateAngle) + } + + drawOverlayText( + canvas, + tempAngle, + sweepAngle, + itemAdapter.getOverlayText(items[i]) + ) + drawText( + canvas, + tempAngle, + sweepAngle, + itemAdapter.getRewardText(items[i]) + ) + drawSeparationArc(willRange, tempAngle, sweepAngle, canvas) + // prepare for next iteration + tempAngle += sweepAngle + paintProps.archPaint.reset() + } + } + + private fun drawPieBackground(i: Int, tempAngle: Float, sweepAngle: Float, canvas: Canvas) { + if (i % 2 == 0) paintProps.archPaint.shader = gradientProps.darkYellow + if (i % 2 == 1) paintProps.archPaint.shader = gradientProps.lightYellow + canvas.drawArc(willRange, tempAngle, sweepAngle, true, paintProps.archPaint) + } + + private fun drawImage(canvas: Canvas, tempAngle: Float, bitmap: Bitmap, rotateAngle: Float) { + // get every arc img width and angle + val imgWidth: Int = getImageWidth() + val angle: Float = ((tempAngle + 360 / wheelSize / 2) * Math.PI / 180).toFloat() + + val x: Int = + (dimenProps.center + 5 * (dimenProps.radius) / 9 * cos(angle.toDouble())).toInt() + val y: Int = + (dimenProps.center + 5 * (dimenProps.radius) / 9 * sin(angle.toDouble())).toInt() + + // create arc to draw + mRect.set(x - imgWidth / 2, y - imgWidth / 2, x + imgWidth / 2, y + imgWidth / 2) + + // rotate main bitmap + val px: Float = mRect.exactCenterX() + val py: Float = mRect.exactCenterY() + val ar = bitmap.width.toFloat() / bitmap.height + + mMatrix.postTranslate( + (-bitmap.width shr 1).toFloat(), + (-bitmap.height shr 1).toFloat() + ) + mMatrix.postScale( + imgWidth.toFloat() / bitmap.width, + imgWidth.toFloat() / ar / bitmap.height + ) + mMatrix.postRotate(tempAngle + rotateAngle) + mMatrix.postTranslate(px, py) + canvas.drawBitmap(bitmap, mMatrix, paintProps.bitmapPaint) + mMatrix.reset() + mRect.setEmpty() + } + + private fun getImageWidth(): Int { + val sweepAngle: Double = 360.0 / wheelSize + val angle = Math.toRadians((180 - sweepAngle) / 2) + + return (2f * (dimenProps.radius) / 4 * cos(angle)).toInt() + } + + + private fun drawOverlayText( + canvas: Canvas, + tempAngle: Float, + sweepAngle: Float, + text: String + ) { + mPath.addArc(willRange, tempAngle, sweepAngle) + val hOffset: Int = overlayDimenAdapter1.getHOffsetOverlayText( + tempAngle, + sweepAngle, + text, + wheelSize, + paintProps, + dimenProps + ) + val vOffset: Int = overlayDimenAdapter1.getVOffsetOverLayText( + tempAngle, + sweepAngle, + text, + wheelSize, + paintProps, + dimenProps + ) + canvas.drawTextOnPath( + text, + mPath, + hOffset.toFloat(), + vOffset.toFloat(), + paintProps.overlayTextPaint + ) + mPath.reset() + } + + private fun drawText(canvas: Canvas, tempAngle: Float, sweepAngle: Float, text: String) { + mPath.addArc(willRange, tempAngle, sweepAngle) //used global Path + + val hOffset: Int = textDimenAdapter1.getHOffsetOverlayText( + tempAngle, + sweepAngle, + text, + wheelSize, + paintProps, + dimenProps + ) + + val vOffset: Int = textDimenAdapter1.getVOffsetOverLayText( + tempAngle, + sweepAngle, + text, + wheelSize, + paintProps, + dimenProps + ) + + paintProps.textPaint.color = ContextCompat.getColor(context, R.color.spinwill_text_color) + + canvas.drawTextOnPath( + text, + mPath, + hOffset.toFloat(), + vOffset.toFloat(), + paintProps.textPaint + ) + + mPath.reset() + } + + private fun drawSeparationArc( + range: RectF, + tempAngle: Float, + sweepAngle: Float, + canvas: Canvas + ) { + canvas.drawArc(range, tempAngle, sweepAngle, true, paintProps.separationArchPaint) + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + val width = min(measuredWidth, measuredHeight) + + val padding = (width * DEF_BORDER_PERCENT / 100).toInt() + + dimenProps.let { + it.paddingLeft = padding // paddingLeft + it.paddingBottom = padding // paddingBottom + it.paddingTop = padding // paddingTop + it.paddingRight = padding // paddingRight + it.padding = padding + } + + dimenProps.radius = (width - (dimenProps.paddingLeft + dimenProps.paddingRight)) / 2 + dimenProps.center = width / 2 + + setMeasuredDimension( + width, + width + ) // hence the size for the view will be min(w,h) i.e square + + initComponents() + } + + private fun initComponents() { + if (paintProps.archPaintAdapter != null) { + paintProps.archPaintAdapter!!.setPaintProperties(paintProps.archPaint) + } else { + paintProps.archPaint.apply { + color = ContextCompat.getColor(context, R.color.coin_txt) + strokeWidth = 0.01f + } + } + + if (paintProps.textPaintAdapter != null) { + paintProps.textPaintAdapter!!.setPaintProperties(paintProps.textPaint) + } else { + paintProps.textPaint.apply { + typeface = ResourcesCompat.getFont( + context, + R.font.montserrat_extrabolditalic + ) + textSize = (dimenProps.radius * 1.5 / 9).toFloat() + } + } + + if (paintProps.overlayTextPaintAdapter != null) { + paintProps.overlayTextPaintAdapter!!.setPaintProperties(paintProps.overlayTextPaint) + } else { + paintProps.overlayTextPaint.apply { + color = ContextCompat.getColor( + context, + R.color.spinwill_overalytext_color + ) + typeface = ResourcesCompat.getFont( + context, + R.font.montserrat_extrabolditalic + ) + textSize = (dimenProps.radius * 3 / 9).toFloat() + } + } + + if (paintProps.separationArchPaintAdapter != null) { + paintProps.separationArchPaintAdapter!!.setPaintProperties(paintProps.separationArchPaint) + } else { + paintProps.separationArchPaint.apply { + color = ContextCompat.getColor( + context, + R.color.spinwill_arc_seperation_line + ) + strokeWidth = dimenProps.radius / 55f + } + } + + val padding = dimenProps.padding.toFloat() + val diameter = dimenProps.radius * 2 + willRange = RectF(padding, padding, padding + diameter, padding + diameter) + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + gradientProps.darkYellow = RadialGradient( + w / 2f, h / 2f, + h / 3.5f, + ContextCompat.getColor(context, R.color.spinwill_darkyellow_gradientLight), + ContextCompat.getColor(context, R.color.spinwill_darkyellow_gradientDark), + Shader.TileMode.CLAMP + ) + gradientProps.lightYellow = RadialGradient( + w / 2f, h / 2f, + h / 2.6f, + ContextCompat.getColor(context, R.color.white), + ContextCompat.getColor(context, R.color.spinwil_lightyellow_gradientDark), + Shader.TileMode.CLAMP + ) + } +} \ No newline at end of file diff --git a/spinwill/src/main/java/com/example/spinwill/ui/adapters/WillItemUiAdapter.kt b/spinwill/src/main/java/com/example/spinwill/ui/adapters/WillItemUiAdapter.kt new file mode 100644 index 0000000..9e12b03 --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/ui/adapters/WillItemUiAdapter.kt @@ -0,0 +1,9 @@ +package com.example.spinwill.ui.adapters + +import android.graphics.Bitmap + +interface WillItemUiAdapter { + fun getRewardText(item: T): String + fun getOverlayText(item: T): String + fun getRewardBitmap(item: T): Bitmap? +} \ No newline at end of file diff --git a/spinwill/src/main/java/com/example/spinwill/ui/defaultImpl/DimenAdapter1Impl.kt b/spinwill/src/main/java/com/example/spinwill/ui/defaultImpl/DimenAdapter1Impl.kt new file mode 100644 index 0000000..8e86eab --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/ui/defaultImpl/DimenAdapter1Impl.kt @@ -0,0 +1,57 @@ +package com.example.spinwill.ui.defaultImpl + +import com.example.spinwill.models.WillDimenProperties +import com.example.spinwill.models.WillPaintProperties +import com.example.spinwill.ui.DimenAdapters.OffSetDimenAdapter1 + + +class OverlayDimenAdapter1Impl : OffSetDimenAdapter1 { + override fun getHOffsetOverlayText( + tempAngle: Float, + sweepAngle: Float, + text: String, + itemsSize: Int, + paintProps: WillPaintProperties, + dimenProps: WillDimenProperties + ): Int { + val textWidth: Float = paintProps.overlayTextPaint.measureText(text) + return (dimenProps.radius * Math.PI / itemsSize - textWidth / 2).toInt() + } + + override fun getVOffsetOverLayText( + tempAngle: Float, + sweepAngle: Float, + text: String, + itemsSize: Int, + paintProps: WillPaintProperties, + dimenProps: WillDimenProperties + ): Int { + return dimenProps.radius / 4 - 5 + } +} + +class TextDimenAdapter1Impl : OffSetDimenAdapter1 { + override fun getHOffsetOverlayText( + tempAngle: Float, + sweepAngle: Float, + text: String, + itemsSize: Int, + paintProps: WillPaintProperties, + dimenProps: WillDimenProperties + ): Int { + val textWidth: Float = paintProps.overlayTextPaint.measureText(text) + val h = (2 * dimenProps.radius * Math.PI / itemsSize - textWidth / 2).toInt() + return h / 2 + } + + override fun getVOffsetOverLayText( + tempAngle: Float, + sweepAngle: Float, + text: String, + itemsSize: Int, + paintProps: WillPaintProperties, + dimenProps: WillDimenProperties + ): Int { + return dimenProps.radius / 5 - 3 + } +} \ No newline at end of file diff --git a/spinwill/src/main/java/com/example/spinwill/utils/DimenExt.kt b/spinwill/src/main/java/com/example/spinwill/utils/DimenExt.kt new file mode 100644 index 0000000..e8ac857 --- /dev/null +++ b/spinwill/src/main/java/com/example/spinwill/utils/DimenExt.kt @@ -0,0 +1,14 @@ +package com.example.spinwill.utils + +import android.content.res.Resources +import android.util.TypedValue + +fun Int.dp(): Float { + val dip = this + val r: Resources = Resources.getSystem() + return TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + dip.toFloat(), + r.displayMetrics + ) +} \ No newline at end of file diff --git a/spinwill/src/main/res/drawable/bg_spinwill.xml b/spinwill/src/main/res/drawable/bg_spinwill.xml new file mode 100644 index 0000000..e44d071 --- /dev/null +++ b/spinwill/src/main/res/drawable/bg_spinwill.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/spinwill/src/main/res/drawable/ic_spinwill_pointer.webp b/spinwill/src/main/res/drawable/ic_spinwill_pointer.webp new file mode 100644 index 0000000..505dbfa Binary files /dev/null and b/spinwill/src/main/res/drawable/ic_spinwill_pointer.webp differ diff --git a/spinwill/src/main/res/font/montserrat_extrabolditalic.ttf b/spinwill/src/main/res/font/montserrat_extrabolditalic.ttf new file mode 100644 index 0000000..66ccd46 Binary files /dev/null and b/spinwill/src/main/res/font/montserrat_extrabolditalic.ttf differ diff --git a/spinwill/src/main/res/layout/layout_spinwillview1.xml b/spinwill/src/main/res/layout/layout_spinwillview1.xml new file mode 100644 index 0000000..374b9d3 --- /dev/null +++ b/spinwill/src/main/res/layout/layout_spinwillview1.xml @@ -0,0 +1,26 @@ + + + + + + + + \ No newline at end of file diff --git a/spinwill/src/main/res/values-night/colors.xml b/spinwill/src/main/res/values-night/colors.xml new file mode 100644 index 0000000..71bf6c7 --- /dev/null +++ b/spinwill/src/main/res/values-night/colors.xml @@ -0,0 +1,6 @@ + + + #fbb42a + #12770E00 + #80E08720 + \ No newline at end of file diff --git a/spinwill/src/main/res/values/colors.xml b/spinwill/src/main/res/values/colors.xml index f8c6127..e917c79 100644 --- a/spinwill/src/main/res/values/colors.xml +++ b/spinwill/src/main/res/values/colors.xml @@ -7,4 +7,11 @@ #FF018786 #FF000000 #FFFFFFFF + #fbb42a + #12770E00 + #FCDEA667 + #FFC87E + #F4C21A + #FDE79E + #770E00 \ No newline at end of file