Skip to content

Commit

Permalink
[优化] 除去两个不必要的对象
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauzy committed Jun 4, 2018
1 parent a0e3d90 commit ed5c96b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -64,7 +65,9 @@ private static List<Lrc> parseInputStream(InputStream inputStream) {
}
sortLrcs(lrcs);
return lrcs;
} catch (Exception e) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
Expand Down
13 changes: 4 additions & 9 deletions library/src/main/java/com/lauzy/freedom/library/LrcView.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public class LrcView extends View {
private boolean isShowTimeIndicator;
private Rect mPlayRect;
private Paint mIndicatorPaint;
private Paint.FontMetricsInt mFontMetrics;
private Rect mIndicateTimeBounds;
private float mIndicatorLineWidth;
private float mIndicatorTextSize;
private int mCurrentIndicateLineTextColor;
Expand Down Expand Up @@ -140,8 +138,6 @@ private void setupConfigs(Context context) {
mIndicatorPaint.setColor(mIndicatorLineColor);
mPlayRect = new Rect();
mIndicatorPaint.setTextSize(mIndicatorTextSize);
mFontMetrics = mIndicatorPaint.getFontMetricsInt();
mIndicateTimeBounds = new Rect();
}

@Override
Expand Down Expand Up @@ -207,13 +203,12 @@ protected void onDraw(Canvas canvas) {
if (isShowTimeIndicator) {
mPlayDrawable.draw(canvas);
long time = mLrcData.get(indicatePosition).getTime();
mIndicatorPaint.getTextBounds(LrcHelper.formatTime(time), 0,
(LrcHelper.formatTime(time)).length(), mIndicateTimeBounds);
float timeWidth = mIndicatorPaint.measureText(LrcHelper.formatTime(time));
mIndicatorPaint.setColor(mIndicatorLineColor);
canvas.drawLine(mPlayRect.right + mIconLineGap, getHeight() / 2,
getWidth() - mIndicateTimeBounds.width() * 1.4f, getHeight() / 2, mIndicatorPaint);
int baseX = (int) (getWidth() - mIndicateTimeBounds.width() * 1.2f);
int baseline = getHeight() / 2 - (mFontMetrics.descent - mFontMetrics.ascent) / 2 - mFontMetrics.ascent;
getWidth() - timeWidth * 1.3f, getHeight() / 2, mIndicatorPaint);
int baseX = (int) (getWidth() - timeWidth * 1.1f);
float baseline = getHeight() / 2 - (mIndicatorPaint.descent() - mIndicatorPaint.ascent()) / 2 - mIndicatorPaint.ascent();
mIndicatorPaint.setColor(mIndicatorTextColor);
canvas.drawText(LrcHelper.formatTime(time), baseX, baseline, mIndicatorPaint);
}
Expand Down

0 comments on commit ed5c96b

Please sign in to comment.