Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
H
HFile Manager Master
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
HFile Manager Master
Commits
37094dd6
Commit
37094dd6
authored
Mar 12, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
圆弧是以全圆来绘制的
parent
23714731
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
46 additions
and
31 deletions
+46
-31
ManagerFragment.kt
...va/com/zxhy/hfilemanagermaster/manager/ManagerFragment.kt
+10
-7
IndicatorView.kt
.../java/com/zxhy/hfilemanagermaster/widget/IndicatorView.kt
+33
-21
fragment_manager.xml
app/src/main/res/layout/fragment_manager.xml
+3
-3
dad_58978.png
app/src/main/res/mipmap-hdpi/dad_58978.png
+0
-0
dad_58978.png
app/src/main/res/mipmap-mdpi/dad_58978.png
+0
-0
dad_58978.png
app/src/main/res/mipmap-xhdpi/dad_58978.png
+0
-0
dad_58978.png
app/src/main/res/mipmap-xxhdpi/dad_58978.png
+0
-0
dad_58978.png
app/src/main/res/mipmap-xxxhdpi/dad_58978.png
+0
-0
No files found.
app/src/main/java/com/zxhy/hfilemanagermaster/manager/ManagerFragment.kt
View file @
37094dd6
...
@@ -28,8 +28,8 @@ class ManagerFragment : Fragment() {
...
@@ -28,8 +28,8 @@ class ManagerFragment : Fragment() {
}
}
override
fun
onCreateView
(
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
savedInstanceState
:
Bundle
?
):
View
?
{
):
View
?
{
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_manager
,
container
,
false
)
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_manager
,
container
,
false
)
binding
=
FragmentManagerBinding
.
bind
(
view
.
rootView
)
binding
=
FragmentManagerBinding
.
bind
(
view
.
rootView
)
...
@@ -42,9 +42,12 @@ class ManagerFragment : Fragment() {
...
@@ -42,9 +42,12 @@ class ManagerFragment : Fragment() {
val
disk
=
requireContext
().
getMountInfoList
().
first
()
val
disk
=
requireContext
().
getMountInfoList
().
first
()
binding
.
tvFree
.
text
=
disk
.
getTotalContent
(
requireContext
())
binding
.
tvFree
.
text
=
disk
.
getTotalContent
(
requireContext
())
val
percent
=
BigDecimal
(
disk
.
used
)
val
percent
F
=
BigDecimal
(
disk
.
used
)
.
divide
(
BigDecimal
(
disk
.
total
),
2
,
BigDecimal
.
ROUND_HALF_UP
).
multiply
(
BigDecimal
(
100
)).
toInt
(
)
.
divide
(
BigDecimal
(
disk
.
total
),
2
,
BigDecimal
.
ROUND_HALF_UP
)
// binding.indicatorView.setPercent(percentF.toFloat())
binding
.
indicatorView
.
setPercent
(
0.3f
)
val
percent
=
percentF
.
multiply
(
BigDecimal
(
100
)).
toInt
()
binding
.
tvUse
.
text
=
"$percent%"
binding
.
tvUse
.
text
=
"$percent%"
(
requireActivity
()
as
OverviewActivity
).
showManager
()
(
requireActivity
()
as
OverviewActivity
).
showManager
()
...
@@ -75,9 +78,9 @@ class ManagerFragment : Fragment() {
...
@@ -75,9 +78,9 @@ class ManagerFragment : Fragment() {
companion
object
{
companion
object
{
@JvmStatic
@JvmStatic
fun
newInstance
(
param1
:
String
,
param2
:
String
)
=
fun
newInstance
(
param1
:
String
,
param2
:
String
)
=
ManagerFragment
().
apply
{
ManagerFragment
().
apply
{
arguments
=
Bundle
().
apply
{
arguments
=
Bundle
().
apply
{
}
}
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/zxhy/hfilemanagermaster/widget/IndicatorView.kt
View file @
37094dd6
...
@@ -5,26 +5,31 @@ import android.content.Context
...
@@ -5,26 +5,31 @@ import android.content.Context
import
android.graphics.Bitmap
import
android.graphics.Bitmap
import
android.graphics.BitmapFactory
import
android.graphics.BitmapFactory
import
android.graphics.Canvas
import
android.graphics.Canvas
import
android.graphics.Matrix
import
android.graphics.Paint
import
android.graphics.Paint
import
android.graphics.Rect
import
android.graphics.RectF
import
android.graphics.RectF
import
android.util.AttributeSet
import
android.util.AttributeSet
import
android.util.Log
import
android.util.Log
import
android.view.View
import
android.view.View
import
androidx.core.content.ContextCompat
import
androidx.core.content.ContextCompat
import
com.example.hfilemanagermaster.R
import
com.example.hfilemanagermaster.R
import
com.zxhy.hfilemanagermaster.knife.setImageSize
import
java.math.BigDecimal
import
java.math.BigDecimal
import
java.math.RoundingMode
import
java.math.RoundingMode
import
kotlin.math.min
import
kotlin.math.min
class
IndicatorView
:
View
{
class
IndicatorView
:
View
{
private
lateinit
var
bgBitmap
:
Bitmap
private
var
strokeWidth
=
40f
//圆弧线宽
private
var
scale
=
1f
//背景图像缩放比例
private
var
radius
=
425f
//圆弧半径(外圆弧)
private
var
strokeWidth
=
1f
//圆弧线宽
private
var
hMargin
=
75f
//圆弧水平间距
private
var
radius
=
50f
//圆弧半径(外圆弧)
private
var
hMargin
=
50f
//圆弧水平间距
private
var
topMargin
=
50f
//圆弧顶部距离
private
var
topMargin
=
50f
//圆弧顶部距离
private
var
sweepAngle
=
0f
private
lateinit
var
bgBitmap
:
Bitmap
private
var
scale
=
1f
//指针图像缩放比例
private
var
rotationDegrees
=
0f
// 旋转的角度
// 画原始刻度的画笔
// 画原始刻度的画笔
...
@@ -47,21 +52,23 @@ class IndicatorView : View {
...
@@ -47,21 +52,23 @@ class IndicatorView : View {
}
}
private
fun
setResource
()
{
private
fun
setResource
()
{
bgBitmap
=
BitmapFactory
.
decodeResource
(
context
.
resources
,
R
.
mipmap
.
ee_98985
)
bgBitmap
=
BitmapFactory
.
decodeResource
(
context
.
resources
,
R
.
mipmap
.
dad_58978
)
arcPaint
.
strokeWidth
=
strokeWidth
arcPaint
.
strokeWidth
=
strokeWidth
arcPaint
.
color
=
ContextCompat
.
getColor
(
context
,
R
.
color
.
color_DCFE86
)
arcPaint
.
color
=
ContextCompat
.
getColor
(
context
,
R
.
color
.
color_DCFE86
)
arcPaint
.
isAntiAlias
=
true
arcPaint
.
isAntiAlias
=
true
arcPaint
.
style
=
Paint
.
Style
.
STROKE
arcPaint
.
style
=
Paint
.
Style
.
STROKE
arcPaint
.
strokeCap
=
Paint
.
Cap
.
ROUND
}
}
@SuppressLint
(
"DrawAllocation"
)
@SuppressLint
(
"DrawAllocation"
)
override
fun
onLayout
(
changed
:
Boolean
,
left
:
Int
,
top
:
Int
,
right
:
Int
,
bottom
:
Int
)
{
override
fun
onLayout
(
changed
:
Boolean
,
left
:
Int
,
top
:
Int
,
right
:
Int
,
bottom
:
Int
)
{
super
.
onLayout
(
changed
,
left
,
top
,
right
,
bottom
)
super
.
onLayout
(
changed
,
left
,
top
,
right
,
bottom
)
scale
=
BigDecimal
(
measuredWidth
).
divide
(
scale
=
BigDecimal
(
measuredWidth
).
divide
(
BigDecimal
(
bgBitmap
.
width
),
3
,
RoundingMode
.
HALF_UP
BigDecimal
(
bgBitmap
.
width
),
3
,
RoundingMode
.
HALF_UP
).
toFloat
()
).
toFloat
()
}
}
override
fun
onMeasure
(
widthMeasureSpec
:
Int
,
heightMeasureSpec
:
Int
)
{
override
fun
onMeasure
(
widthMeasureSpec
:
Int
,
heightMeasureSpec
:
Int
)
{
...
@@ -83,25 +90,30 @@ class IndicatorView : View {
...
@@ -83,25 +90,30 @@ class IndicatorView : View {
override
fun
onDraw
(
canvas
:
Canvas
)
{
override
fun
onDraw
(
canvas
:
Canvas
)
{
super
.
onDraw
(
canvas
)
super
.
onDraw
(
canvas
)
//绘制背景图片
val
srcRect
=
Rect
(
0
,
0
,
measuredWidth
,
measuredHeight
)
val
dstRect
=
Rect
(
0
,
0
,
measuredWidth
,
measuredHeight
)
// canvas.drawBitmap(bgBitmap.setImageSize(scale), srcRect, dstRect, Paint())
Log
.
e
(
"IndicatorView"
,
"radius=$radius"
)
Log
.
e
(
"IndicatorView"
,
"radius=$radius"
)
val
left
=
hMargin
val
left
=
hMargin
+
strokeWidth
/
2
val
top
=
topMargin
val
top
=
topMargin
+
strokeWidth
/
2
val
right
=
hMargin
+
radius
*
2
val
right
=
radius
*
2
+
left
val
bottom
=
hMargin
+
radius
*
2
val
bottom
=
radius
*
2
+
top
Log
.
e
(
"IndicatorView"
,
"left=$left top=$top right=$right bottom=$bottom"
)
Log
.
e
(
"IndicatorView"
,
"left=$left top=$top right=$right bottom=$bottom"
)
//绘制半圆
//绘制半圆
val
arcRect
=
RectF
(
left
,
top
,
right
,
bottom
)
val
arcRect
=
RectF
(
left
,
top
,
right
,
bottom
)
canvas
.
drawArc
(
arcRect
,
-
180f
,
sweepAngle
,
false
,
arcPaint
)
canvas
.
translate
((
measuredWidth
/
2
).
toFloat
()
+
50
,
measuredHeight
-
250f
)
// 绘制旋转后的图片
// val srcRect = Rect(0, 0, 100, 100)
// val dstRect = Rect(0, 0, 100, 100)
//绘制指针
}
// RectF(0f, 0f, 100f,100f)
//绘制百分比
// val w=measuredWidth.toFloat()
fun
setPercent
(
percent
:
Float
)
{
// val h=measuredHeight.toFloat()
sweepAngle
=
180f
*
percent
// Log.e("arcRect","W=$w h=$h")
rotationDegrees
=
180f
*
percent
-
80f
canvas
.
drawArc
(
arcRect
,
0f
,
-
180f
,
false
,
arcPaint
)
invalidate
(
)
}
}
}
}
\ No newline at end of file
app/src/main/res/layout/fragment_manager.xml
View file @
37094dd6
...
@@ -63,10 +63,10 @@
...
@@ -63,10 +63,10 @@
app:layout_constraintTop_toBottomOf=
"@+id/tv_r"
/>
app:layout_constraintTop_toBottomOf=
"@+id/tv_r"
/>
<com.zxhy.hfilemanagermaster.widget.IndicatorView
<com.zxhy.hfilemanagermaster.widget.IndicatorView
android:layout_width=
"0dp"
android:id=
"@+id/indicatorView"
android:background=
"#FF5F4A"
android:layout_width=
"350dp"
android:layout_marginBottom=
"-10dp"
android:layout_height=
"159dp"
android:layout_height=
"159dp"
android:background=
"@mipmap/ee_98985"
android:layout_marginHorizontal=
"20dp"
android:layout_marginHorizontal=
"20dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
...
...
app/src/main/res/mipmap-hdpi/dad_58978.png
0 → 100644
View file @
37094dd6
5.32 KB
app/src/main/res/mipmap-mdpi/dad_58978.png
0 → 100644
View file @
37094dd6
5.32 KB
app/src/main/res/mipmap-xhdpi/dad_58978.png
0 → 100644
View file @
37094dd6
5.32 KB
app/src/main/res/mipmap-xxhdpi/dad_58978.png
0 → 100644
View file @
37094dd6
13.8 KB
app/src/main/res/mipmap-xxxhdpi/dad_58978.png
0 → 100644
View file @
37094dd6
13.8 KB
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment