Skip to content

Commit

Permalink
Fixing Issues (1 & 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sina-seyfi committed Mar 11, 2020
1 parent 266dc05 commit 47206bb
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class AdvancedCardView: FrameLayout {
private var stroke_Paint = Paint(Paint.ANTI_ALIAS_FLAG)
private var stroke_Mask = Path()
private var stroke_Path = Path()
private var no_Stroke_Path = Path()
var stroke_Alpha: Float = NOT_DEFINED_ALPHA
set(value) {
field = floatPercentCheck(value)
Expand Down Expand Up @@ -471,6 +472,11 @@ class AdvancedCardView: FrameLayout {
stroke_Mask.fillType = Path.FillType.EVEN_ODD
}

private fun initNoStrokePath() {
no_Stroke_Path.reset()
addNoStrokeAreaRectF(no_Stroke_Path)
}

private fun initBackgroundGradientColors() {
background_Gradient_Colors = getColorArray(background_Gradient_Colors_Xml, background_Alpha)
}
Expand Down Expand Up @@ -595,12 +601,16 @@ class AdvancedCardView: FrameLayout {
return alpha / 255f
}

private fun angleToRadians(angle: Float): Double {
return Math.toRadians(angle.toDouble())
}

private fun getDx(distance: Float, angle: Float): Float {
return (distance * sin(Math.toRadians(angle.toDouble()))).toFloat()
return (distance * sin(angleToRadians(angle))).toFloat()
}

private fun getDy(distance: Float, angle: Float): Float {
return (distance * cos(Math.toRadians(angle.toDouble()))).toFloat()
return (distance * cos(angleToRadians(angle))).toFloat()
}

private fun getDiameter(x: Float, y: Float): Float {
Expand All @@ -618,7 +628,7 @@ class AdvancedCardView: FrameLayout {
private fun getSweepShader(colorArray: IntArray, angle: Float, offCenterX: Float, offCenterY: Float): SweepGradient {
val sweepGradient = SweepGradient(getCenterX(offCenterX), getCenterY(offCenterY), colorArray, null)
val matrix = Matrix()
matrix.postRotate(angle, getCenterX(offCenterX), getCenterY(offCenterY))
matrix.postRotate(angle - 90, getCenterX(offCenterX), getCenterY(offCenterY))
sweepGradient.setLocalMatrix(matrix)
return sweepGradient
}
Expand Down Expand Up @@ -747,6 +757,11 @@ class AdvancedCardView: FrameLayout {
return stroke_Paint
}

private fun getNoStrokePath(): Path {
initNoStrokePath()
return no_Stroke_Path
}

private fun isDashed(): Boolean {
return stroke_Type == StrokeType.Dash
}
Expand Down Expand Up @@ -1019,7 +1034,7 @@ class AdvancedCardView: FrameLayout {
}

override fun drawChild(canvas: Canvas?, child: View?, drawingTime: Long): Boolean {
canvas?.clipPath(getBackgroundPath())
canvas?.clipPath(getNoStrokePath())
return super.drawChild(canvas, child, drawingTime)
}

Expand Down
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".RainbowActivity"
android:label="Rotate It !">
</activity>
<activity android:name=".SomeCardsActivity"></activity>
<activity
android:name=".RainbowActivity"
android:label="Rotate It !"></activity>
<activity
android:name=".LiftItUpActivity"
android:label="Lift It Up!!" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ListAdapter(val context: Context): RecyclerView.Adapter<ListItem>() {
0 -> intent.setClass(context, AHoleInYourScreenActivity::class.java)
1 -> intent.setClass(context, LiftItUpActivity::class.java)
2 -> intent.setClass(context, RainbowActivity::class.java)
3 -> intent.setClass(context, SomeCardsActivity::class.java)
}
return intent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.sinaseyfi.advancedcardviewsample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.activity_main.*
Expand All @@ -13,6 +14,25 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
list.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
list.adapter = ListAdapter(this)
sampleAlgorithm(intArrayOf(1, 2, 3, 4))
}

fun sampleAlgorithm(input: IntArray) {
var left = IntArray(input.size, {x -> 1})
var right = IntArray(input.size, {x -> 1})
var output = IntArray(input.size)
for(i in 1 until input.size) {
left[i] = left[i - 1] * input[i - 1]
}
for(i in input.size - 2 downTo 0) {
right[i] = right[i + 1] * input[i + 1]
}
for(i in input.indices) {
output[i] = left[i] * right[i]
}
for(j in output) {
Log.d("TAG", j.toString() + ", ")
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sinaseyfi.advancedcardviewsample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class SomeCardsActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_some_cards)
}

}
45 changes: 45 additions & 0 deletions app/src/main/res/layout/activity_some_cards.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2C2A2E"
tools:context=".SomeCardsActivity">

<com.sinaseyfi.advancedcardview.AdvancedCardView
android:id="@+id/example_1"
android:layout_width="240dp"
android:layout_height="64dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:background_Type="stroke"
app:background_ColorType="gradient_linear"
app:background_Gradient_Color0="#A53AC3"
app:background_Gradient_ColorEnd="#8441AE"
app:background_Gradient_Angle="-80"
app:cornerRadius="8dp"
app:stroke_ColorType="gradient_sweep"
app:stroke_Gradient_Color0="#D32828"
app:stroke_Gradient_Color1="#F66D11"
app:stroke_Gradient_Color2="#CFCF19"
app:stroke_Gradient_Color3="#2ABA2A"
app:stroke_Gradient_Color4="#1DD5D5"
app:stroke_Gradient_Color5="#3838F8"
app:stroke_Gradient_Color6="#9225E1"
app:stroke_Gradient_Angle="180"
app:shadow0_Inner_Blur="16dp"
app:shadow0_Inner_Alpha="0.32"
app:shadow0_Inner_Color="#000000"
app:stroke_Width="2dp">

<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2C2A2E"/>

</com.sinaseyfi.advancedcardview.AdvancedCardView>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<item>A Hole In Your Screen!!</item>
<item>Lift It Uppp!!</item>
<item>Rainbow Box</item>
<item>Some Card Activity!!</item>
</string-array>
</resources>

0 comments on commit 47206bb

Please sign in to comment.