Android Open Source - android-placeholder Grid Drawable






From Project

Back to project page android-placeholder.

License

The source code is released under:

Apache License

If you think the Android project android-placeholder listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package se.lightside.placeholder.graphics.drawable;
//from  ww w  .  ja v a 2 s.  com
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

/**
 * A placeholder that draws a grid on its canvas
 */
public class GridDrawable extends AbstractPlaceholderDrawable {

    float   xspacing;
    float[] xpositions;
    float   yspacing;
    float[] ypositions;

    public GridDrawable(float xd, float yd, Paint paint) {
        super();
        xspacing = xd;
        yspacing = yd;
        setPaint(paint);
    }

    @Override
    public void draw(Canvas canvas) {
        int y = canvas.getHeight();
        int x = canvas.getWidth();

        for (float xline : xpositions) {
            canvas.drawLine(xline, 0, xline, y, getPaint());
        }

        for (float yline : ypositions) {
            canvas.drawLine(0, yline, x, yline, getPaint());
        }
    }

    @Override
    protected void onBoundsChange(Rect bounds) {
        xpositions = calculateCache(bounds.width(),  xspacing);
        ypositions = calculateCache(bounds.height(), yspacing);

    }

    private static float[] calculateCache(int total, float spacing) {
        int count = (int) (total / spacing);
        float[] arr = new float[count];
        float d = 0;
        for (int i=0;i<count;i++) {
            d += spacing;
            arr[i] = d;
        }
        return arr;
    }
}




Java Source Code List

se.lightside.placeholder.ApplicationTest.java
se.lightside.placeholder.PlaceholderBuilder.java
se.lightside.placeholder.graphics.drawable.AbstractPlaceholderDrawable.java
se.lightside.placeholder.graphics.drawable.CrossDrawable.java
se.lightside.placeholder.graphics.drawable.DimensionsDrawable.java
se.lightside.placeholder.graphics.drawable.GridDrawable.java
se.lightside.placeholder.sample.DemoFragment.java
se.lightside.placeholder.sample.DemoHostActivity.java
se.lightside.placeholder.text.method.BlockTransformationMethod.java
se.lightside.placeholder.util.MetricsConverter.java
se.lightside.placeholder.util.ViewCompat.java
se.lightside.placeholder.view.RatioLineOverlay.java
se.lightside.placeholder.view.RatioLine.java
se.lightside.placeholder.widget.BlockedOutTextView.java
se.lightside.placeholder.widget.PlaceholderView.java