BVB Source Codes

The Android source code for beginners music player design and source code Show LrcView.java Source code

Return Download The Android source code for beginners music player design and source code: download LrcView.java Source code - Download The Android source code for beginners music player design and source code Source code - Type:.java
  1. package com.android.cwd;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import android.content.Context;
  7. import android.graphics.Canvas;
  8. import android.graphics.Color;
  9. import android.graphics.Paint;
  10. import android.graphics.Typeface;
  11. import android.util.AttributeSet;
  12. import android.widget.TextView;
  13.  
  14. import com.android.cwd.LrcProcess.LrcContent;
  15.  
  16. /**
  17.  * 自定义绘画歌词,产生滚动效果
  18.  */
  19. public class LrcView extends TextView {
  20.  
  21.         private float width;
  22.         private float high;
  23.         private Paint CurrentPaint;
  24.         private Paint NotCurrentPaint;
  25.         private float TextHigh = 25;
  26.         private float TextSize = 18;
  27.         private int Index = 0;
  28.  
  29.         private List<LrcContent> mSentenceEntities = new ArrayList<LrcContent>();
  30.  
  31.         public void setSentenceEntities(List<LrcContent> mSentenceEntities) {
  32.                 this.mSentenceEntities = mSentenceEntities;
  33.         }
  34.  
  35.         public LrcView(Context context) {
  36.                 super(context);
  37.                 // TODO Auto-generated constructor stub
  38.                 init();
  39.         }
  40.  
  41.         public LrcView(Context context, AttributeSet attrs, int defStyle) {
  42.                 super(context, attrs, defStyle);
  43.                 // TODO Auto-generated constructor stub
  44.                 init();
  45.         }
  46.  
  47.         public LrcView(Context context, AttributeSet attrs) {
  48.                 super(context, attrs);
  49.                 // TODO Auto-generated constructor stub
  50.                 init();
  51.         }
  52.  
  53.         private void init() {
  54.                 // TODO Auto-generated method stub
  55.                 setFocusable(true);
  56.  
  57.                 // 高亮部分
  58.                 CurrentPaint = new Paint();
  59.                 CurrentPaint.setAntiAlias(true);
  60.                 CurrentPaint.setTextAlign(Paint.Align.CENTER);
  61.  
  62.                 // 非高亮部分
  63.                 NotCurrentPaint = new Paint();
  64.                 NotCurrentPaint.setAntiAlias(true);
  65.                 NotCurrentPaint.setTextAlign(Paint.Align.CENTER);
  66.         }
  67.  
  68.         @Override
  69.         protected void onDraw(Canvas canvas) {
  70.                 // TODO Auto-generated method stub
  71.                 super.onDraw(canvas);
  72.  
  73.                 if (canvas == null) {
  74.                         return;
  75.                 }
  76.  
  77.                 CurrentPaint.setColor(Color.argb(210, 251, 248, 29));
  78.                 NotCurrentPaint.setColor(Color.argb(140, 255, 255, 255));
  79.  
  80.                 CurrentPaint.setTextSize(24);
  81.                 CurrentPaint.setTypeface(Typeface.SERIF);
  82.  
  83.                 NotCurrentPaint.setTextSize(TextSize);
  84.                 NotCurrentPaint.setTypeface(Typeface.DEFAULT);
  85.  
  86.                 try {
  87.                         setText("");
  88.                         canvas.drawText(mSentenceEntities.get(Index).getLrc(), width / 2,
  89.                                         high / 2, CurrentPaint);
  90.  
  91.                         float tempY = high / 2;
  92.                         // 画出本句之前的句子
  93.                         for (int i = Index - 1; i >= 0; i--) {
  94.                                 // 向上推移
  95.                                 tempY = tempY - TextHigh;
  96.  
  97.                                 canvas.drawText(mSentenceEntities.get(i).getLrc(), width / 2,
  98.                                                 tempY, NotCurrentPaint);
  99.                         }
  100.                         tempY = high / 2;
  101.                         // 画出本句之后的句子
  102.                         for (int i = Index + 1; i < mSentenceEntities.size(); i++) {
  103.                                 // 往下推移
  104.                                 tempY = tempY + TextHigh;
  105.                                 canvas.drawText(mSentenceEntities.get(i).getLrc(), width / 2,
  106.                                                 tempY, NotCurrentPaint);
  107.                         }
  108.                 } catch (Exception e) {
  109.                         setText("...木有歌词文件,赶紧去下载...");
  110.                 }
  111.         }
  112.  
  113.         @Override
  114.         protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  115.                 // TODO Auto-generated method stub
  116.                 super.onSizeChanged(w, h, oldw, oldh);
  117.  
  118.                 this.width = w;
  119.                 this.high = h;
  120.         }
  121.  
  122.         public void SetIndex(int index) {
  123.                 this.Index = index;
  124.         }
  125. }
  126.  
downloadLrcView.java Source code - Download The Android source code for beginners music player design and source code Source code
Related Source Codes/Software:
The Android source code to use baidu weather love weather program source code - What's the weather like in this project is an andr... 2016-12-31
Textview perfect display HTML code - Textview perfect display HTML code, including cust... 2016-12-31
Eliminate to bring Android game source code list diamond little game - This project is a based on android AndEngine open ... 2016-12-31
Fast sliding Android example source code letters index and prompt contact list - A simple fast sliding contact list and initials pr... 2016-12-31
The Android source Jane. Beautiful music player development program source code - This project is an open source music player progra... 2016-12-31
skeuocard - Skeuocard progressively enhances credit card input... 2016-12-31
hubot-scripts - DEPRECATED, see https://github.com/github/hubot-sc... 2016-12-31
Jcrop - Jcrop (official) - Image Cropping Plugin for jQuer... 2016-12-31
volt - A Ruby web framework where your Ruby runs on both ... 2016-12-31
touchstonejs - Mobile App Framework powered by React ... 2016-12-31
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top