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@6bef8d1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main/java/com/allen/androidcustomview
    • activity
      • MainActivity.kt
    • widget
      • LoadingLineView.java
      • vote
        • VoteContainerView.kt
        • VoteView.kt
        • img_1.png
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/java/com/allen/androidcustomview/activity/MainActivity.kt‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/allen/androidcustomview/activity/MainActivity.kt
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ class MainActivity : AppCompatActivity(), BaseQuickAdapter.OnItemClickListener {
105105
13 -> startActivity(Intent(this@MainActivity, AliPayHomeActivity::class.java))
106106
14 -> startActivity(Intent(this@MainActivity, RecyclerViewItemAnimActivity::class.java))
107107
15 -> startActivity(Intent(this@MainActivity, PathActivity::class.java))
108+
/**
109+
* 其实这个挺有意思的
110+
* 这个学习
111+
*/
108112
16 -> startActivity(Intent(this@MainActivity, SinaVoteActivity::class.java))
109113
17 -> startActivity(Intent(this@MainActivity, ClearScreenActivity::class.java))
110114
}
Collapse file

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

Copy file name to clipboardExpand all lines: app/src/main/java/com/allen/androidcustomview/widget/LoadingLineView.java
+57-2Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.graphics.Paint;
77
import android.support.annotation.Nullable;
88
import android.util.AttributeSet;
9+
import android.util.Log;
910
import android.util.TypedValue;
1011
import android.view.View;
1112
import android.view.animation.LinearInterpolator;
@@ -18,6 +19,7 @@
1819

1920
public class LoadingLineView extends View {
2021

22+
private static final String TAG ="LoadingLineView" ;
2123
private int mWidth;
2224
private int mHeight;
2325

@@ -290,6 +292,55 @@ protected void onDraw(Canvas canvas) {
290292

291293
/**
292294
* 初始化动画
295+
*
296+
* =====上面的===========0
297+
* =====上面的===========0
298+
* =====上面的===========10
299+
* =====上面的===========21
300+
* =====上面的===========31
301+
* =====上面的===========42
302+
* =====上面的===========53
303+
* =====上面的===========63
304+
* =====上面的===========74
305+
* =====上面的===========85
306+
* =====上面的===========95
307+
* =====上面的===========106
308+
* =====上面的===========117
309+
* =====上面的===========127
310+
* =====上面的===========138
311+
* =====上面的===========149
312+
* =====上面的===========159
313+
* =====上面的===========170
314+
* =====上面的===========181
315+
* =====上面的===========191
316+
* =====上面的===========202
317+
* =====上面的===========212
318+
* =====上面的===========223
319+
* =====上面的===========233
320+
* =====上面的===========244
321+
* -----------------------------------
322+
* =====下面的===========-10
323+
* =====下面的===========-31
324+
* =====下面的===========-53
325+
* =====下面的===========-63
326+
* =====下面的===========-74
327+
* =====下面的===========-85
328+
* =====下面的===========-95
329+
* =====下面的===========-106
330+
* =====下面的===========-117
331+
* =====下面的===========-127
332+
* =====下面的===========-138
333+
* =====下面的===========-149
334+
* =====下面的===========-159
335+
* =====下面的===========-170
336+
* =====下面的===========-181
337+
* =====下面的===========-191
338+
* =====下面的===========-202
339+
* =====下面的===========-212
340+
* =====下面的===========-223
341+
* =====下面的===========-233
342+
* =====下面的===========-244
343+
* =====下面的===========-255
293344
*/
294345
private void initLoadingAnimation() {
295346
final float loadingMoveDistance = mWidth / 2;
@@ -311,9 +362,13 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) {
311362
* 透明色的处理
312363
*/
313364
if (value <= loadingMoveDistance / 2) {
314-
loadingPaint.setAlpha((int) ((255 * value) * 2 / loadingMoveDistance));
365+
int i = (int) ((255 * value) * 2 / loadingMoveDistance);
366+
Log.i(TAG,"=====上面的==========="+i);
367+
loadingPaint.setAlpha(i);
315368
} else {
316-
loadingPaint.setAlpha((int) (255 - (255 * value) * 2 / loadingMoveDistance));
369+
int i = (int) (255 - (255 * value) * 2 / loadingMoveDistance);
370+
Log.i(TAG,"=====下面的==========="+i);
371+
loadingPaint.setAlpha(i);
317372
}
318373
invalidate();
319374
}
Collapse file

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

Copy file name to clipboardExpand all lines: app/src/main/java/com/allen/androidcustomview/widget/vote/VoteContainerView.kt
+40-21Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import java.lang.ref.WeakReference
2424
* desc :
2525
* </pre>
2626
*/
27-
class VoteContainerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) {
27+
class VoteContainerView @JvmOverloads constructor(
28+
context: Context,
29+
attrs: AttributeSet? = null,
30+
defStyleAttr: Int = 0
31+
) : FrameLayout(context, attrs, defStyleAttr) {
2832

2933
private var voteViewHolders: ArrayList<VoteItemViewHolder> = arrayListOf()
3034

@@ -63,7 +67,10 @@ class VoteContainerView @JvmOverloads constructor(context: Context, attrs: Attri
6367
setVoteStatus(data)
6468
setVoteBtnStatus()
6569
vote_item_ll.removeAllViews()
66-
data.options?.forEachIndexed { index, voteOption ->
70+
/**
71+
* 也是没有使用什么rv之类的复杂操作,这种地方没有必要这么使用
72+
*/
73+
data.options.forEachIndexed { index, voteOption ->
6774
val viewHolder = onCreateViewHolder()
6875
viewHolder.bind(index, voteOption, data)
6976
voteViewHolders.add(viewHolder)
@@ -80,7 +87,8 @@ class VoteContainerView @JvmOverloads constructor(context: Context, attrs: Attri
8087
val isVoteMulti = vote.choiceType == VOTE_TYPE_MULTIPLE
8188
val voteResult = vote.sumVoteCount ?: 0
8289
val voted = vote.voted
83-
vote_container_vote_btn.visibility = if (voted != true && isVoteMulti) View.VISIBLE else View.GONE
90+
vote_container_vote_btn.visibility =
91+
if (voted != true && isVoteMulti) View.VISIBLE else View.GONE
8492
vote_container_vote_result.visibility = if (voted == true) View.VISIBLE else View.GONE
8593
setVoteResult("共${voteResult}人参与了投票")
8694
}
@@ -168,8 +176,8 @@ class VoteContainerView @JvmOverloads constructor(context: Context, attrs: Attri
168176
val voteResultCount = voteOption.showCount ?: 0
169177

170178
voteView.setVoteIsSelected(voteOption.voted ?: false)
171-
.setVoteContent(voteOption.content)
172-
.setVoteResultText("${voteResultCount}人").refreshView()
179+
.setVoteContent(voteOption.content)
180+
.setVoteResultText("${voteResultCount}人").refreshView()
173181

174182
if (isHaveVoted()) {
175183
val sum = mainVote?.sumVoteCount ?: 0
@@ -179,13 +187,17 @@ class VoteContainerView @JvmOverloads constructor(context: Context, attrs: Attri
179187
voteView.setProgress(progress)
180188
}
181189

190+
/**
191+
* 点击事件的处理
192+
*/
182193
voteView.setOnClickListener {
194+
//已经投票了就不要处理了
183195
if (isHaveVoted()) return@setOnClickListener
184196
if (isVoteMulti) {
185197
setMultiChoice(voteView, voteOption)
186198
ref()?.onVoteClickListener?.onVoteItemClick(mainVote, data)
187199
} else {
188-
if (ref()?.getOptionIdsSize() ?: 0 > 0) return@setOnClickListener
200+
if ((ref()?.getOptionIdsSize() ?: 0) > 0) return@setOnClickListener
189201
setSingleChoice(voteView, voteOption)
190202
ref()?.onVoteClickListener?.onVoteItemClick(mainVote, data)
191203
}
@@ -229,7 +241,8 @@ class VoteContainerView @JvmOverloads constructor(context: Context, attrs: Attri
229241
voteOption.voted = true
230242
ref()?.addOptionIds(voteOption.id ?: 0)
231243
} else {
232-
Toast.makeText(ref()?.context, "最多可选${maxSelect}个", Toast.LENGTH_SHORT).show()
244+
Toast.makeText(ref()?.context, "最多可选${maxSelect}个", Toast.LENGTH_SHORT)
245+
.show()
233246
}
234247
}
235248
ref()?.setVoteBtnStatus()
@@ -240,36 +253,42 @@ class VoteContainerView @JvmOverloads constructor(context: Context, attrs: Attri
240253
voteOption.voted = true
241254
ref()?.addOptionIds(voteOption.id ?: 0)
242255
voteView.setVoteIsSelected(voteOption.voted ?: false).refreshView()
243-
ref()?.onVoteClickListener?.onVoteCommitBtnClick(mainVote, ref()?.optionIds
244-
?: arrayListOf())
256+
ref()?.onVoteClickListener?.onVoteCommitBtnClick(
257+
mainVote, ref()?.optionIds
258+
?: arrayListOf()
259+
)
245260
}
246261

247262
}
248263

249264
private fun getVoteView(context: Context): VoteView {
250265
val voteView = VoteView(context)
251266
voteView.setVoteTextSize(voteView.sp2px(15))
252-
.setVoteUncheckedContentTextColor(resources.getColor(R.color.unchecked_content_text_color))
253-
.setVoteCheckedContentTextColor(resources.getColor(R.color.checked_content_text_color))
254-
.setVoteUncheckedResultTextColor(resources.getColor(R.color.unchecked_result_text_color))
255-
.setVoteCheckedResultTextColor(resources.getColor(R.color.checked_result_text_color))
256-
.setVoteUncheckedProgressColor(resources.getColor(R.color.unchecked_progress_color))
257-
.setVoteCheckedProgressColor(resources.getColor(R.color.checked_progress_color))
258-
.setVoteCheckedIcon(resources.getDrawable(R.mipmap.icon_vote_check))
259-
.setVoteBorderRadius(voteView.dp2px(3f))
260-
.setVoteBorderColor(resources.getColor(R.color.border_color))
261-
.setVoteRightIconSize(voteView.dp2px(18f).toInt())
262-
.setVoteAnimDuration(2000L)
267+
.setVoteUncheckedContentTextColor(resources.getColor(R.color.unchecked_content_text_color))
268+
.setVoteCheckedContentTextColor(resources.getColor(R.color.checked_content_text_color))
269+
.setVoteUncheckedResultTextColor(resources.getColor(R.color.unchecked_result_text_color))
270+
.setVoteCheckedResultTextColor(resources.getColor(R.color.checked_result_text_color))
271+
.setVoteUncheckedProgressColor(resources.getColor(R.color.unchecked_progress_color))
272+
.setVoteCheckedProgressColor(resources.getColor(R.color.checked_progress_color))
273+
.setVoteCheckedIcon(resources.getDrawable(R.mipmap.icon_vote_check))
274+
.setVoteBorderRadius(voteView.dp2px(3f))
275+
.setVoteBorderColor(resources.getColor(R.color.border_color))
276+
.setVoteRightIconSize(voteView.dp2px(18f).toInt())
277+
.setVoteAnimDuration(2000L)
263278
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
264279
voteView.clipToOutline = true
280+
//裁剪view的操作
265281
voteView.outlineProvider = object : ViewOutlineProvider() {
266282
override fun getOutline(view: View, outline: Outline) {
267283
outline.setRoundRect(0, 0, view.width, view.height, voteView.dp2px(3f))
268284
}
269285
}
270286
}
271287

272-
val layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, voteView.dp2px(40f).toInt())
288+
val layoutParams = LinearLayout.LayoutParams(
289+
ViewGroup.LayoutParams.MATCH_PARENT,
290+
voteView.dp2px(40f).toInt()
291+
)
273292
layoutParams.bottomMargin = voteView.dp2px(12f).toInt()
274293
voteView.layoutParams = layoutParams
275294
return voteView

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.