Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.graphics.LinearGradient;

import android.graphics.Shader;
import android.graphics.drawable.PaintDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;

public class Main {
    public static PaintDrawable getPaintDrawable(int startX, int endX) {
        PaintDrawable drawable = new PaintDrawable();
        drawable.setShape(new RectShape());
        drawable.setShaderFactory(getShaderFactory(startX, endX));
        return drawable;
    }

    private static ShapeDrawable.ShaderFactory getShaderFactory(final int startX, final int endX) {
        return new ShapeDrawable.ShaderFactory() {

            @Override
            public Shader resize(int width, int height) {
                return new LinearGradient(startX, 0, endX, 0,
                        new int[] { 0xFFDCDAD5, 0xFFFDFDF4, 0xFFFFFFFF, 0xFFFDFBEF },
                        new float[] { 0, 0.18f, 0.48f, 1 }, Shader.TileMode.REPEAT);
            }
        };
    }
}