@@ -0,0 +1,2416 @@
+package cn.diaovision.omnicontrol.widget;%0A%0Aimport android.content.Context;%0Aimport android.graphics.Canvas;%0Aimport android.graphics.Color;%0Aimport android.graphics.Paint;%0Aimport android.graphics.Rect;%0Aimport android.support.annotation.Nullable;%0Aimport android.util.AttributeSet;%0Aimport android.view.View;%0A%0A/**%0A * Created by TaoYimin on 2017/8/28.%0A * %E9%9F%B3%E9%A2%91%E9%A2%91%E8%B0%B1%E6%98%BE%E7%A4%BA%E6%8E%A7%E4%BB%B6%0A */%0A%0Apublic class VisualizerView extends View %7B%0A    private byte%5B%5D mBytes;%0A    private float%5B%5D mPoints;%0A    private Rect mRect = new Rect();%0A    private Paint mForePaint = new Paint();%0A    //%E6%9D%A1%E5%BD%A2%E5%9B%BE%E4%B8%AA%E6%95%B0%0A    private int mSpectrumNum = 48;%0A%0A    public VisualizerView(Context context) %7B%0A        this(context, null);%0A    %7D%0A%0A    public VisualizerView(Context context, @Nullable AttributeSet attrs) %7B%0A        this(context, attrs, 0);%0A    %7D%0A%0A    public VisualizerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) %7B%0A        super(context, attrs, defStyleAttr);%0A        init();%0A    %7D%0A%0A    /**%0A     * %E5%88%9D%E5%A7%8B%E5%8C%96%0A     */%0A    private void init() %7B%0A        mBytes = null;%0A        mForePaint.setStrokeWidth(8f);%0A        mForePaint.setAntiAlias(true);%0A        mForePaint.setColor(Color.rgb(0, 128, 255));%0A    %7D%0A%0A    /**%0A     * %E6%9B%B4%E6%96%B0%E9%A2%91%E8%B0%B1%0A     * @param fft%0A     */%0A    public void updateVisualizer(byte%5B%5D fft) %7B%0A        byte%5B%5D model = new byte%5Bfft.length / 2 + 1%5D;%0A        model%5B0%5D = (byte) Math.abs(fft%5B0%5D);%0A        for (int i = 2, j = 1; j %3C mSpectrumNum; ) %7B%0A            model%5Bj%5D = (byte) Math.hypot(fft%5Bi%5D, fft%5Bi + 1%5D);%0A            i += 2;%0A            j++;%0A        %7D%0A        mBytes = model;%0A        invalidate();%0A    %7D%0A%0A    @Override%0A    protected void onDraw(Canvas canvas) %7B%0A        super.onDraw(canvas);%0A        if (mBytes == null) %7B%0A            return;%0A        %7D%0A        if (mPoints == null %7C%7C mPoints.length %3C mBytes.length * 4) %7B%0A            mPoints = new float%5BmBytes.length * 4%5D;%0A        %7D%0A        mRect.set(0, 0, getWidth(), getHeight());%0A        //%E7%BB%98%E5%88%B6%E9%A2%91%E8%B0%B1%0A        final int baseX = mRect.width() / mSpectrumNum;%0A        final int height = mRect.height();%0A        for (int i = 0; i %3C mSpectrumNum; i++) %7B%0A            if (mBytes%5Bi%5D %3C 0) %7B%0A                mBytes%5Bi%5D = 127;%0A            %7D%0A            final int xi = baseX * i + baseX / 2;%0A            mPoints%5Bi * 4%5D = xi;%0A            mPoints%5Bi * 4 + 1%5D = height;%0A            mPoints%5Bi * 4 + 2%5D = xi;%0A            mPoints%5Bi * 4 + 3%5D = height - mBytes%5Bi%5D;%0A        %7D%0A        canvas.drawLines(mPoints, mForePaint);%0A    %7D%0A%7D%0A

add VisualizerView widget to show audio spectrum