package com.xixun.xixunplayer;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Environment;
import android.view.View;

public class BackView extends View {

    private Bitmap img;
    Bitmap cosImg;
    Rect rect = new Rect();

    public BackView(Context context, int width, int height) {
        super(context);
        img = BitmapFactory.decodeResource(context.getResources(), R.drawable.back, Util.noScaled);
        cosImg = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/XixunPlayer/background", Util.noScaled);
        rect.right = width;
        rect.bottom = height;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(cosImg!=null) canvas.drawBitmap(cosImg, null, rect, null);
        else if(img!=null) for(int y=0; y<rect.bottom; y+=img.getHeight()) for(int x=0; x<rect.right; x+=img.getWidth()) canvas.drawBitmap(img, x, y, null);
    }
}
