最后
代码真的是重质不重量,质量高的代码,是当前代码界提倡的,当然写出高质量的代码肯定需要一个相当高的专业素养,这需要在日常的代码书写中逐渐去吸收掌握,谁不是每天都在学习呀,目的还不是为了一个,为实现某个功能写出高质量的代码。
所以,长征路还长,大家还是好好地做个务实的程序员吧。
最后,小编这里有一系列Android提升学习资料,有兴趣的小伙伴们可以来看下哦~
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
private int lrcTime; //歌词当前时间
public String getLrcStr() {
return lrcStr;
}
public void setLrcStr(String lrcStr) {
this.lrcStr = lrcStr;
}
public int getLrcTime() {
return lrcTime;
}
public void setLrcTime(int lrcTime) {
this.lrcTime = lrcTime;
}
}
–LrcView.java
package com.wwj.sb.custom;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import com.wwj.sb.domain.LrcContent;
/**
-
自定义绘画歌词,产生滚动效果
-
@author wwj
*/
public class LrcView extends android.widget.TextView {
private float width; //歌词视图宽度
private float height; //歌词视图高度
private Paint currentPaint; //当前画笔对象
private Paint notCurrentPaint; //非当前画笔对象
private float textHeight = 25; //文本高度
private float textSize = 18; //文本大小
private int index = 0; //list集合下标
private List mLrcList = new ArrayList();
public void setmLrcList(List mLrcList) {
this.mLrcList = mLrcList;
}
public LrcView(Context context) {
super(context);
init();
}
public LrcView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public LrcView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setFocusable(true); //设置可对焦
//高亮部分
currentPaint = new Paint();
currentPaint.setAntiAlias(true); //设置抗锯齿,让文字美观饱满
currentPaint.setTextAlign(Paint.Align.CENTER);//设置文本对齐方式
//非高亮部分
notCurrentPaint = new Paint();
notCurrentPaint.setAntiAlias(true);
notCurrentPaint.setTextAlign(Paint.Align.CENTER);
}
/**
- 绘画歌词
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(canvas == null) {
return;
}
currentPaint.setColor(Color.argb(210, 251, 248, 29));
notCurrentPaint.setColor(Color.argb(140, 255, 255, 255));
currentPaint.setTextSize(24);
currentPaint.setTypeface(Typeface.SERIF);
notCurrentPaint.setTextSize(textSize);
notCurrentPaint.setTypeface(Typeface.DEFAULT);
try {
setText(“”);
canvas.drawText(mLrcList.get(index).getLrcStr(), width / 2, height / 2, currentPaint);
float tempY = height / 2;
//画出本句之前的句子
for(int i = index - 1; i >= 0; i–) {
//向上推移
tempY = tempY - textHeight;
canvas.drawText(mLrcList.get(i).getLrcStr(), width / 2, tempY, notCurrentPaint);
}
tempY = height / 2;
//画出本句之后的句子
for(int i = index + 1; i < mLrcList.size(); i++) {
//往下推移
tempY = tempY + textHeight;
canvas.drawText(mLrcList.get(i).getLrcStr(), width / 2, tempY, notCurrentPaint);
}
} catch (Exception e) {
setText(“…木有歌词文件,赶紧去下载…”);
}
}
/**
- 当view大小改变的时候调用的方法
*/
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
this.width = w;
this.height = h;
}
public void setIndex(int index) {
this.index = index;
}
}
–LrcProcess.java
package com.wwj.sb.custom;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import android.util.Xml.Encoding;
import android.widget.SlidingDrawer;
import com.wwj.sb.domain.LrcContent;
/**
-
2013/6/1
-
@author wwj
-
处理歌词的类
*/
public class LrcProcess {
private List lrcList; //List集合存放歌词内容对象
private LrcContent mLrcContent; //声明一个歌词内容对象
/**
- 无参构造函数用来实例化对象
*/
public LrcProcess() {
mLrcContent = new LrcContent();
lrcList = new ArrayList();
}
/**
-
读取歌词
-
@param path
-
@return
*/
public String readLRC(String path) {
//定义一个StringBuilder对象,用来存放歌词内容
StringBuilder stringBuilder = new StringBuilder();
File f = new File(path.replace(“.mp3”, “.lrc”));
try {
//创建一个文件输入流对象
FileInputStream fis = new FileInputStream(f);
InputStreamReader isr = new InputStreamReader(fis, “utf-8”);
BufferedReader br = new BufferedReader(isr);
String s = “”;
while((s = br.readLine()) != null) {
//替换字符
s = s.replace(“[”, “”);
s = s.replace(“]”, “@”);
//分离“@”字符
String splitLrcData[] = s.split(“@”);
if(splitLrcData.length > 1) {
mLrcContent.setLrcStr(splitLrcData[1]);
//处理歌词取得歌曲的时间
int lrcTime = time2Str(splitLrcData[0]);
mLrcContent.setLrcTime(lrcTime);
//添加进列表数组
lrcList.add(mLrcContent);
//新创建歌词内容对象
mLrcContent = new LrcContent();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
stringBuilder.append(“木有歌词文件,赶紧去下载!…”);
} catch (IOException e) {
e.printStackTrace();
stringBuilder.append(“木有读取到歌词哦!”);
}
return stringBuilder.toString();
}
/**
-
解析歌词时间
-
歌词内容格式如下:
-
[00:02.32]陈奕迅
-
[00:03.43]好久不见
最后
对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长。而不成体系的学习效果低效漫长且无助。时间久了,付出巨大的时间成本和努力,没有看到应有的效果,会气馁是再正常不过的。
所以学习一定要找到最适合自己的方式,有一个思路方法,不然不止浪费时间,更可能把未来发展都一起耽误了。
如果你是卡在缺少学习资源的瓶颈上,那么刚刚好我能帮到你。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!