zoukankan      html  css  js  c++  java
  • 歌词的获取

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#000000"
        android:orientation="vertical" >
    
        <Button
            android:id="@+id/play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="play" />
    
        <com.anjoyo.getlyric.ui.LyricView
            android:id="@+id/LyricShow"
            android:layout_width="fill_parent"
            android:layout_height="300dip" >
        </com.anjoyo.getlyric.ui.LyricView>
    
    </LinearLayout>

    package com.anjoyo.getlyric.ui;
    
    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 android.widget.TextView;
    
    /**
     * 自定义TextView,用于显示歌词
     * 
     * @author anjoyo
     * 
     */
    public class LyricView extends TextView {
    
            private float high;
    
            private float width;
    
            private Paint CurrentPaint;
    
            private Paint NotCurrentPaint;
    
            private float TextHigh = 25;
    
            private float TextSize = 15;
    
            private int Index = 0;
    
            private List<LyricContent> mSentenceEntities = new ArrayList<LyricContent>();
    
            public void setSentenceEntities(List<LyricContent> mSentenceEntities) {
                    this.mSentenceEntities = mSentenceEntities;
            }
    
            public LyricView(Context context) {
                    super(context);
                    init();
                    // TODO Auto-generated constructor stub
            }
    
            public LyricView(Context context, AttributeSet attrs, int defStyle) {
                    super(context, attrs, defStyle);
                    init();
                    // TODO Auto-generated constructor stub
            }
    
            public LyricView(Context context, AttributeSet attrs) {
                    super(context, attrs);
                    init();
                    // TODO Auto-generated constructor stub
            }
    
            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) {
                    // TODO Auto-generated method stub
                    super.onDraw(canvas);
    
                    if (canvas == null) {
                            return;
                    }
    
                    CurrentPaint.setColor(Color.YELLOW);
                    NotCurrentPaint.setColor(Color.GREEN);
    
                    CurrentPaint.setTextSize(TextSize);
                    CurrentPaint.setTypeface(Typeface.SERIF);
    
                    NotCurrentPaint.setTextSize(TextSize);
                    NotCurrentPaint.setTypeface(Typeface.SERIF);
    
                    try {
                            canvas.drawText(mSentenceEntities.get(Index).getLyric(), width / 2,
                                            high / 2, CurrentPaint);
    
                            float tempY = high / 2;
                            // 画出本句之前的句子
                            for (int i = Index - 1; i >= 0; i--) {
    
                                    // 向上推移
                                    tempY = tempY - TextHigh;
    
                                    canvas.drawText(mSentenceEntities.get(i).getLyric(), width / 2,
                                                    tempY, NotCurrentPaint);
    
                            }
    
                            tempY = high / 2;
                            // 画出本句之后的句子
                            for (int i = Index + 1; i < mSentenceEntities.size(); i++) {
                                    // 往下推移
                                    tempY = tempY + TextHigh;
    
                                    canvas.drawText(mSentenceEntities.get(i).getLyric(), width / 2,
                                                    tempY, NotCurrentPaint);
    
                            }
                    } catch (Exception e) {
                            // TODO: handle exception
                    }
    
            }
    
            @Override
            protected void onSizeChanged(int w, int h, int oldw, int oldh) {
                    // TODO Auto-generated method stub
                    super.onSizeChanged(w, h, oldw, oldh);
                    this.high = h;
                    this.width = w;
            }
    
            public void SetIndex(int index) {
                    this.Index = index;
                    // System.out.println(index);
            }
    
    }
    


  • 相关阅读:
    Linux下Fortran多文件编译
    java用poi实现对word读取和修改操作
    SQL DATEDIFF语法及时间函数 Sql 查询当天、本周、本月记录
    深入Java集合学习系列:LinkedHashSet的实现原理
    Log4Net日志
    程序员创业如何才能成功?
    Asp.net 数据采集基类(远程抓取,分解,保存,匹配)
    response.setContentType()的String参数及对应类型
    深入Java集合学习系列:LinkedHashMap的实现原理
    深入Java集合学习系列:HashSet的实现原理
  • 原文地址:https://www.cnblogs.com/allencoder/p/3643918.html
Copyright © 2011-2022 走看看