Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
More Features Added
Browse files Browse the repository at this point in the history
  • Loading branch information
rjdary.7@gmail.com committed Sep 26, 2019
1 parent 9802668 commit 1ef4260
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 34 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/New_User.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/vcs.xml

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

Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.microdevrj.superellipseexample

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.runner.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:fontFamily="@font/m_b"
android:padding="24dp"
android:text="@string/app_name"
android:textAlignment="center"
android:textColor="@color/colorStroke"
android:textSize="24sp" />
android:textSize="24sp"
tools:targetApi="jelly_bean" />


<com.microdevrj.superellipse.custom_superellipse_views.SuperellipseImageView
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
</style>

</resources>
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.microdevrj.superellipse

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.runner.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ object SuperellipseLogic {
/**
* @param w width of the bitmap.
* @param h height of the bitmap.
* @param strkClr color of the stroke (only applies if Paint.style == STROKE || STROKE_AND_FILL)
* @param pddng bitmap pddng (this will not off-center the bitmap).
* @param pnt pnt to use for drawing the bitmap.
* @param strokeColor color of the stroke (only applies if Paint.style == STROKE || STROKE_AND_FILL)
* @param padding bitmap padding (this will not off-center the bitmap).
* @param paint paint to use for drawing the bitmap.
* If canvas not centered, center it.
* Create drawing bitmap.
* Draw squircle path on bitmap.
Expand All @@ -58,56 +58,72 @@ object SuperellipseLogic {
private fun getSquircleBitmapBackground(
w: Int,
h: Int,
pddng: Int,
pnt: Paint,
strkClr: Int
padding: Int,
paint: Paint,
strokeColor: Int
): Bitmap {
val b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)

this.canvas.setBitmap(b)
this.canvas.translate(w / 2f, h / 2f)

recalculatePath((w / 2) - pddng, (h / 2) - pddng)
recalculatePath((w / 2) - padding, (h / 2) - padding)


val ogStl = pnt.style
val ogClr = pnt.color
val ogStl = paint.style
val ogClr = paint.color

if (ogStl == FILL || ogStl == FILL_AND_STROKE) {
canvas.drawPath(path, pnt)
canvas.drawPath(path, paint)
}
if (ogStl == STROKE || ogStl == FILL_AND_STROKE) {

pnt.color = strkClr
pnt.style = STROKE
paint.color = strokeColor
paint.style = STROKE

canvas.drawPath(path, pnt)
canvas.drawPath(path, paint)
//Reassign values to not interfere with objects og values
pnt.style = ogStl
pnt.color = ogClr
paint.style = ogStl
paint.color = ogClr
}

return b
}


private fun recalculatePath(radX: Int, radY: Int) {
private fun getSuperEllipsePath(
radX: Int,
radY: Int,
corners: Double = DEF_CORNERS_CONSTANT
): Path {
val newPath = Path()
addSuperEllipseToPath(newPath, radX, radY, corners)
return newPath
}

private fun addSuperEllipseToPath(p: Path, radX: Int, radY: Int, corners: Double) {
var l = 0.0
var angle: Double
path.reset()
for (i in 0 until 360) {
angle = Math.toRadians(l)
val x = getX(radX, angle, DEF_CORNERS_CONSTANT)
val y = getY(radY, angle, DEF_CORNERS_CONSTANT)
val x = getX(radX, angle, corners)
val y = getY(radY, angle, corners)
if (i == 0) {
path.moveTo(x, y)
p.moveTo(x, y)
}
l++
angle = Math.toRadians(l)
val x2 = getX(radX, angle, DEF_CORNERS_CONSTANT)
val y2 = getY(radY, angle, DEF_CORNERS_CONSTANT)
path.lineTo(x2, y2)
val x2 = getX(radX, angle, corners)
val y2 = getY(radY, angle, corners)
p.lineTo(x2, y2)
}
p.close()
}


private fun recalculatePath(radX: Int, radY: Int, corners: Double = DEF_CORNERS_CONSTANT) {
path.reset()
addSuperEllipseToPath(path, radX, radY, corners)
path.close()
}

Expand Down

0 comments on commit 1ef4260

Please sign in to comment.