GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sysn · JingMeng/AndroidCustomView@d9c1370

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main/java/com/allen/androidcustomview/widget
    • ProgressViewNote.java
    • StudyPlanProgressView.kt
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/java/com/allen/androidcustomview/widget/ProgressViewNote.java‎

Copy file name to clipboard
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.allen.androidcustomview.widget;
2+
3+
4+
import android.graphics.Canvas;
5+
import android.view.View;
6+
import android.widget.ProgressBar;
7+
8+
/**
9+
* @see StudyPlanProgressView 这个是一个kt文件,注释写在这个文件比较
10+
* @see android.widget.ProgressBar 是被比较的对象
11+
* @see #test(String) 这个是当前的引用,{@link ProgressBar#getIndeterminateDrawable()} 学习到的使用方法
12+
*/
13+
public class ProgressViewNote {
14+
15+
16+
/**
17+
* @param param 模拟参数
18+
* @see {@link ProgressBar#onMeasure(int, int)} 这里面出现了一个drawable的概念,使用这个的宽高
19+
* 什么情况下需要使用 resolveSizeAndState 呢 ??
20+
* <p>
21+
* {@link ProgressBar#onLayout(boolean, int, int, int, int)} 这个并没有进行重写
22+
* <p>
23+
* {@link ProgressBar#onDraw(Canvas)} 这个也写的比较简单,但是没有看懂
24+
* <p>
25+
* <p>
26+
* {@link ProgressBar#onVisibilityAggregated(boolean)} 考虑了可见性和动画
27+
* {@link ProgressBar#onAttachedToWindow()} 动画的开启----立即开启 ---就是自动的情况
28+
* {@link ProgressBar#onDetachedFromWindow()} 动画的暂停 --- 立即暂停
29+
* <p>
30+
* 上面这些在我们绘制任意view的时候都是需要考虑的
31+
* <p>
32+
* pb 里面还考虑了 Interpolator
33+
*/
34+
void test(String param) {
35+
36+
}
37+
}
Collapse file

‎app/src/main/java/com/allen/androidcustomview/widget/StudyPlanProgressView.kt‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/allen/androidcustomview/widget/StudyPlanProgressView.kt
+81-19Lines changed: 81 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ import kotlin.math.min
1515
* date : 2019/08/12
1616
* desc : 学习计划view
1717
* </pre>
18+
*
19+
* 这个是 类似rv的那个view,时间轴
1820
*/
19-
class StudyPlanProgressView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr) {
21+
class StudyPlanProgressView @JvmOverloads constructor(
22+
context: Context,
23+
attrs: AttributeSet? = null,
24+
defStyleAttr: Int = 0
25+
) : View(context, attrs, defStyleAttr) {
2026
private var mWidth = 0
2127
private var mHeight = 0
2228

@@ -51,14 +57,34 @@ class StudyPlanProgressView @JvmOverloads constructor(context: Context, attrs: A
5157

5258
private fun initAttr(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
5359
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.StudyPlanProgressView)
54-
iconUncheckedBitmapRes = (typedArray.getDrawable(R.styleable.StudyPlanProgressView_sppv_iconUnchecked) as? BitmapDrawable)?.bitmap
55-
iconCheckedBitmapRes = (typedArray.getDrawable(R.styleable.StudyPlanProgressView_sppv_iconChecked) as? BitmapDrawable)?.bitmap
56-
iconSize = typedArray.getDimensionPixelOffset(R.styleable.StudyPlanProgressView_sppv_iconSize, dp2px(14f).toInt())
57-
progressWidth = typedArray.getDimensionPixelOffset(R.styleable.StudyPlanProgressView_sppv_progressWidth, dp2px(2f).toInt())
58-
uncheckedProgressColor = typedArray.getColor(R.styleable.StudyPlanProgressView_sppv_uncheckedProgressColor, uncheckedProgressColor)
59-
checkedProgressColor = typedArray.getColor(R.styleable.StudyPlanProgressView_sppv_checkedProgressColor, checkedProgressColor)
60-
textSize = typedArray.getDimensionPixelSize(R.styleable.StudyPlanProgressView_sppv_textSize, sp2px(11))
61-
textColor = typedArray.getColor(R.styleable.StudyPlanProgressView_sppv_textColor, checkedProgressColor)
60+
iconUncheckedBitmapRes =
61+
(typedArray.getDrawable(R.styleable.StudyPlanProgressView_sppv_iconUnchecked) as? BitmapDrawable)?.bitmap
62+
iconCheckedBitmapRes =
63+
(typedArray.getDrawable(R.styleable.StudyPlanProgressView_sppv_iconChecked) as? BitmapDrawable)?.bitmap
64+
iconSize = typedArray.getDimensionPixelOffset(
65+
R.styleable.StudyPlanProgressView_sppv_iconSize,
66+
dp2px(14f).toInt()
67+
)
68+
progressWidth = typedArray.getDimensionPixelOffset(
69+
R.styleable.StudyPlanProgressView_sppv_progressWidth,
70+
dp2px(2f).toInt()
71+
)
72+
uncheckedProgressColor = typedArray.getColor(
73+
R.styleable.StudyPlanProgressView_sppv_uncheckedProgressColor,
74+
uncheckedProgressColor
75+
)
76+
checkedProgressColor = typedArray.getColor(
77+
R.styleable.StudyPlanProgressView_sppv_checkedProgressColor,
78+
checkedProgressColor
79+
)
80+
textSize = typedArray.getDimensionPixelSize(
81+
R.styleable.StudyPlanProgressView_sppv_textSize,
82+
sp2px(11)
83+
)
84+
textColor = typedArray.getColor(
85+
R.styleable.StudyPlanProgressView_sppv_textColor,
86+
checkedProgressColor
87+
)
6288

6389
typedArray.recycle()
6490
}
@@ -84,7 +110,8 @@ class StudyPlanProgressView @JvmOverloads constructor(context: Context, attrs: A
84110
mWidth = w
85111
mHeight = h
86112

87-
cellWidth = (mWidth - marginLeftAndRight * 2 - iconSize * ALL_POINT_SIZE) / (ALL_POINT_SIZE - 1)
113+
cellWidth =
114+
(mWidth - marginLeftAndRight * 2 - iconSize * ALL_POINT_SIZE) / (ALL_POINT_SIZE - 1)
88115
}
89116

90117
override fun onDraw(canvas: Canvas) {
@@ -96,13 +123,31 @@ class StudyPlanProgressView @JvmOverloads constructor(context: Context, attrs: A
96123
private fun drawProgressLine(canvas: Canvas) {
97124
val lineStart = (marginLeftAndRight + iconSize / 2).toFloat()
98125
linePaint.color = uncheckedProgressColor
99-
canvas.drawLine(lineStart, (mHeight / 2).toFloat(), (mWidth - marginLeftAndRight - iconSize / 2).toFloat(), (mHeight / 2).toFloat(), linePaint)
126+
//这个是花基本的颜色
127+
canvas.drawLine(
128+
lineStart,
129+
(mHeight / 2).toFloat(),
130+
(mWidth - marginLeftAndRight - iconSize / 2).toFloat(),
131+
(mHeight / 2).toFloat(),
132+
linePaint
133+
)
100134
if (getDataSize() == 0) return
101135
val lineEnd = lineStart + (getDataSize() - 1) * (cellWidth + iconSize)
102136
linePaint.color = checkedProgressColor
103-
canvas.drawLine(lineStart, (mHeight / 2).toFloat(), lineEnd, (mHeight / 2).toFloat(), linePaint)
137+
138+
//这个是选中的颜色
139+
canvas.drawLine(
140+
lineStart,
141+
(mHeight / 2).toFloat(),
142+
lineEnd,
143+
(mHeight / 2).toFloat(),
144+
linePaint
145+
)
104146
}
105147

148+
/**
149+
* 这个直接是不透明的图片覆盖的
150+
*/
106151
private fun drawProgress(canvas: Canvas) {
107152
if (iconUncheckedBitmapRes == null || iconCheckedBitmapRes == null) return
108153
for (i in 0 until ALL_POINT_SIZE) {
@@ -120,21 +165,34 @@ class StudyPlanProgressView @JvmOverloads constructor(context: Context, attrs: A
120165
} else false
121166
}
122167

168+
/**
169+
* 按照这个图片为基准绘制了 文字
170+
*
171+
* textPaint.textAlign = Paint.Align.CENTER 这个属性有捡到了
172+
*/
123173
private fun drawText(canvas: Canvas, position: Int) {
124174
if (getDataSize() == 0) return
125175
if (position < getDataSize()) {
126176
val textWidth = textPaint.measureText(dates[position].content).toInt()
127177
val isTop = position % 2 == 0
128-
val left = marginLeftAndRight + iconSize / 2 + (cellWidth + iconSize) * position - textWidth / 2
178+
// fixme 这个公式不完全一样了
179+
val left =
180+
marginLeftAndRight + iconSize / 2 + (cellWidth + iconSize) * position - textWidth / 2
129181
textRectF.left = left
130182
textRectF.right = left + textWidth
131183
textRectF.top = if (isTop) 0 else (mHeight + iconSize) / 2
132184
textRectF.bottom = if (isTop) (mHeight - iconSize) / 2 else mHeight
133185

134186
val fontMetrics = textPaint.fontMetricsInt
135-
val baseline = (textRectF.bottom + textRectF.top - fontMetrics.bottom - fontMetrics.top) / 2
187+
val baseline =
188+
(textRectF.bottom + textRectF.top - fontMetrics.bottom - fontMetrics.top) / 2
136189
//文字绘制到整个布局的中心位置
137-
canvas.drawText(dates[position].content, textRectF.centerX().toFloat(), baseline.toFloat(), textPaint)
190+
canvas.drawText(
191+
dates[position].content,
192+
textRectF.centerX().toFloat(),
193+
baseline.toFloat(),
194+
textPaint
195+
)
138196
}
139197
}
140198

@@ -150,13 +208,17 @@ class StudyPlanProgressView @JvmOverloads constructor(context: Context, attrs: A
150208
private fun getDataSize() = min(dates.size, 7)
151209

152210
fun dp2px(dpVal: Float): Float {
153-
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
154-
dpVal, resources.displayMetrics)
211+
return TypedValue.applyDimension(
212+
TypedValue.COMPLEX_UNIT_DIP,
213+
dpVal, resources.displayMetrics
214+
)
155215
}
156216

157217
fun sp2px(spVal: Int): Int {
158-
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
159-
spVal.toFloat(), resources.displayMetrics).toInt()
218+
return TypedValue.applyDimension(
219+
TypedValue.COMPLEX_UNIT_SP,
220+
spVal.toFloat(), resources.displayMetrics
221+
).toInt()
160222
}
161223

162224
class ProgressData(var content: String, var isFinished: Boolean)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.