-
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
13 changed files
with
231 additions
and
61 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
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.fizzer.base.lib"> | ||
|
||
</manifest> |
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
113 changes: 58 additions & 55 deletions
113
.../java/com/fizzer/widget/RadiusCardView.kt → .../com/fizzer/widget/view/RadiusCardView.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,56 +1,59 @@ | ||
package com.fizzer.widget | ||
|
||
import android.content.Context | ||
import android.graphics.* | ||
import android.graphics.drawable.ColorDrawable | ||
import android.util.AttributeSet | ||
import androidx.cardview.widget.CardView | ||
|
||
/** | ||
* Author:Fizzer | ||
* Date:10/02/2022 | ||
* Email:Fizzer@miaoshitech.com | ||
* Description:可以指定CardView的圆角 | ||
*/ | ||
class RadiusCardView @JvmOverloads constructor( | ||
context: Context, attrs: AttributeSet? = null | ||
) : CardView(context, attrs) { | ||
|
||
private var tlRadius: Float = 0f | ||
private var trRadius: Float = 0f | ||
private var blRadius: Float = 0f | ||
private var brRadius: Float = 0f | ||
|
||
init { | ||
radius = 0f | ||
var ta = context.obtainStyledAttributes(attrs, R.styleable.RadiusCardView) | ||
ta.let { | ||
tlRadius = it.getDimension(R.styleable.RadiusCardView_rcv_topLeftRadiu, 0f) | ||
trRadius = it.getDimension(R.styleable.RadiusCardView_rcv_topRightRadiu, 0f) | ||
blRadius = it.getDimension(R.styleable.RadiusCardView_rcv_bottomLeftRadiu, 0f) | ||
brRadius = it.getDimension(R.styleable.RadiusCardView_rcv_bottomRightRadiu, 0f) | ||
it.recycle() | ||
} | ||
background = ColorDrawable() | ||
} | ||
|
||
fun getRectF(): RectF { | ||
var rect = Rect() | ||
getDrawingRect(rect) | ||
return RectF(rect) | ||
} | ||
|
||
override fun onDraw(canvas: Canvas?) { | ||
var path = Path() | ||
var rectf = getRectF() | ||
var radius = floatArrayOf( | ||
tlRadius, tlRadius, | ||
trRadius, trRadius, | ||
brRadius, brRadius, | ||
blRadius, blRadius | ||
) | ||
path.addRoundRect(rectf, radius, Path.Direction.CW) | ||
canvas?.clipPath(path, Region.Op.INTERSECT) | ||
super.onDraw(canvas) | ||
} | ||
package com.fizzer.widget.view | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.graphics.* | ||
import android.graphics.drawable.ColorDrawable | ||
import android.util.AttributeSet | ||
import androidx.cardview.widget.CardView | ||
import com.fizzer.widget.R | ||
|
||
/** | ||
* Author:Fizzer | ||
* Date:10/02/2022 | ||
* Email:Fizzer@miaoshitech.com | ||
* Description:可以指定CardView的圆角 | ||
*/ | ||
class RadiusCardView @JvmOverloads constructor( | ||
context: Context, attrs: AttributeSet? = null | ||
) : CardView(context, attrs) { | ||
|
||
private var tlRadius: Float = 0f | ||
private var trRadius: Float = 0f | ||
private var blRadius: Float = 0f | ||
private var brRadius: Float = 0f | ||
|
||
init { | ||
radius = 0f | ||
val ta = context.obtainStyledAttributes(attrs, R.styleable.RadiusCardView) | ||
ta.let { | ||
tlRadius = it.getDimension(R.styleable.RadiusCardView_rcv_topLeftRadius, 0f) | ||
trRadius = it.getDimension(R.styleable.RadiusCardView_rcv_topRightRadius, 0f) | ||
blRadius = it.getDimension(R.styleable.RadiusCardView_rcv_bottomLeftRadius, 0f) | ||
brRadius = it.getDimension(R.styleable.RadiusCardView_rcv_bottomRightRadius, 0f) | ||
} | ||
ta.recycle() | ||
background = ColorDrawable() | ||
} | ||
|
||
private fun getRectF(): RectF { | ||
val rect = Rect() | ||
getDrawingRect(rect) | ||
return RectF(rect) | ||
} | ||
|
||
@SuppressLint("DrawAllocation") | ||
override fun onDraw(canvas: Canvas?) { | ||
val path = Path() | ||
val rectf = getRectF() | ||
val radius = floatArrayOf( | ||
tlRadius, tlRadius, | ||
trRadius, trRadius, | ||
brRadius, brRadius, | ||
blRadius, blRadius | ||
) | ||
path.addRoundRect(rectf, radius, Path.Direction.CW) | ||
canvas?.clipPath(path) | ||
super.onDraw(canvas) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.fizzer.lib.lib | ||
|
||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.fizzer.base.lib.ext.clickWithTrigger | ||
import com.fizzer.lib.databinding.ActivityLibPageBinding | ||
|
||
class LibPage : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityLibPageBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityLibPageBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
initEvent() | ||
} | ||
|
||
private fun initEvent(){ | ||
|
||
binding.openAirMode.clickWithTrigger { } | ||
binding.closeAirMode.clickWithTrigger { } | ||
binding.getAirMode.clickWithTrigger { } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/fizzer/lib/widget/RadiusCardViewPage.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,14 @@ | ||
package com.fizzer.lib.widget | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.fizzer.lib.databinding.ActivityRadiusCardPageBinding | ||
|
||
class RadiusCardViewPage : AppCompatActivity() { | ||
private lateinit var binding: ActivityRadiusCardPageBinding | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityRadiusCardPageBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/openAirMode" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="开启飞行模式" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/closeAirMode" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="关闭飞行模式" | ||
app:layout_constraintStart_toEndOf="@id/openAirMode" | ||
app:layout_constraintTop_toTopOf="@id/openAirMode" /> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/getAirMode" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="获取飞行模式状态" | ||
app:layout_constraintStart_toEndOf="@id/closeAirMode" | ||
app:layout_constraintTop_toTopOf="@id/closeAirMode" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.fizzer.widget.view.RadiusCardView | ||
android:id="@+id/cardView1" | ||
android:layout_width="match_parent" | ||
android:layout_height="300dp" | ||
android:layout_margin="15dp" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginTop="16dp" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:rcv_bottomLeftRadius="9dp" | ||
app:rcv_bottomRightRadius="9dp" | ||
app:rcv_topLeftRadius="9dp" | ||
app:rcv_topRightRadius="9dp"> | ||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#D13C74"/> | ||
</com.fizzer.widget.view.RadiusCardView> | ||
|
||
<com.fizzer.widget.view.RadiusCardView | ||
android:layout_width="match_parent" | ||
android:layout_height="300dp" | ||
android:layout_margin="15dp" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginTop="16dp" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/cardView1" | ||
app:rcv_bottomLeftRadius="9dp" | ||
app:rcv_bottomRightRadius="25dp" | ||
app:rcv_topLeftRadius="3dp" | ||
app:rcv_topRightRadius="0dp"> | ||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#D13C74"/> | ||
</com.fizzer.widget.view.RadiusCardView> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |