Android Open Source - android-grid-wichterle Draw View






From Project

Back to project page android-grid-wichterle.

License

The source code is released under:

Apache License

If you think the Android project android-grid-wichterle 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 eu.inmite.android.gridwichterle.views;
/*www .j a v a 2 s .  co m*/
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
import eu.inmite.android.gridwichterle.core.Config;
import eu.inmite.android.gridwichterle.core.Utils;

import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Michal Matl (michal.matl@inmite.eu)
 * Date: 7/21/13
 * Time: 4:32 PM
 */
public class DrawView extends View {

  private final Paint paint = new Paint();
  private final int height;
  private final int width;
  private final int mSquare;
  private float[] points;

  public DrawView(Context context, int height, int width) {
    super(context);

    this.height = height;
    this.width = width;

    Config config = (Config) getContext().getApplicationContext().getSystemService(Config.class.getName());
    paint.setColor(config.getColor());
    mSquare = Utils.getPxFromDpi(getContext(), config.getGridSideSize());
  }

  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    List<Float> gridPoints = new LinkedList<Float>();

    int countHorizontalLines = height / mSquare;
    int countVerticalLines = width / mSquare;

    //prepare horizontal lines
    float gap = mSquare;
    for (int i = 0; i <= countHorizontalLines; i++) {
      gridPoints.add(0f);
      gridPoints.add(gap);
      gridPoints.add((float) width);
      gridPoints.add(gap);

      gap = gap + mSquare;

    }

    //prepare vertical lines
    gap = mSquare;
    for (int i = 0; i <= countVerticalLines; i++) {
      gridPoints.add(gap);
      gridPoints.add(0f);
      gridPoints.add(gap);
      gridPoints.add((float) height);

      gap = gap + mSquare;
    }

    points = new float[gridPoints.size()];
    for (int i = 0; i < gridPoints.size(); i++) {
      points[i] = gridPoints.get(i);
    }
  }

  @Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //draw whole grid
    canvas.drawLines(points, paint);
  }
}




Java Source Code List

com.larswerkman.colorpicker.ColorPicker.java
com.larswerkman.colorpicker.OpacityBar.java
com.larswerkman.colorpicker.SVBar.java
com.larswerkman.colorpicker.SaturationBar.java
com.larswerkman.colorpicker.ValueBar.java
eu.inmite.android.gridwichterle.App.java
eu.inmite.android.gridwichterle.activity.MainActivity.java
eu.inmite.android.gridwichterle.activity.SettingsActivity.java
eu.inmite.android.gridwichterle.bus.BusProvider.java
eu.inmite.android.gridwichterle.bus.CancelGridBus.java
eu.inmite.android.gridwichterle.bus.ColorChangeBus.java
eu.inmite.android.gridwichterle.bus.GridOnOffBus.java
eu.inmite.android.gridwichterle.bus.ShowSettingsBus.java
eu.inmite.android.gridwichterle.core.Config.java
eu.inmite.android.gridwichterle.core.Constants.java
eu.inmite.android.gridwichterle.core.NotificationReceiver.java
eu.inmite.android.gridwichterle.core.Utils.java
eu.inmite.android.gridwichterle.dialogs.ColorsDialog.java
eu.inmite.android.gridwichterle.services.GridOverlayService.java
eu.inmite.android.gridwichterle.views.DrawView.java
eu.inmite.android.gridwichterle.views.GridOverlay.java