Android Open Source - AnkiStats Graphics






From Project

Back to project page AnkiStats.

License

The source code is released under:

GNU General Public License

If you think the Android project AnkiStats 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

/**
 * /*from w w  w  . j  av a 2  s . c  o  m*/
 */
package com.wildplot.android.rendering.graphics.wrapper;

import android.graphics.*;
import android.graphics.PorterDuff.Mode;
import android.graphics.Paint.Style;

/**
 * Wrapper of swing/awt graphics class for android use
 * @author Michael Goldbach
 *
 */
public class Graphics {
    private Canvas canvas;
    private Paint paint;
    
    
    
    public Graphics(Canvas canvas, Paint paint) {
        super();
        this.canvas = canvas;
        this.paint = paint;
    }

    public void drawLine(float x1, float y1, float x2, float y2){
        Style oldStyle = paint.getStyle();
        paint.setStyle(Style.FILL_AND_STROKE);
        canvas.drawLine(x1, y1, x2, y2, paint);
        paint.setStyle(oldStyle);
    }
    
    public void drawRect(float x, float y, float width, float height){
        Style oldStyle = paint.getStyle();
        paint.setStyle(Style.STROKE);
        canvas.drawRect(x, y, x+width, y+height, paint);
        paint.setStyle(oldStyle);
    }
    
    public void fillRect(float x, float y, float width, float height){
        Style oldStyle = paint.getStyle();
        paint.setStyle(Style.FILL);
        canvas.drawRect(x, y, x+width, y+height, paint);
        paint.setStyle(oldStyle);
    }

    public Stroke getStroke(){
        return new Stroke(paint.getStrokeWidth());
    }
    
    public void setStroke(Stroke stroke){
        paint.setStrokeWidth(stroke.getStrokeSize());
    }
    
    public Rectangle getClipBounds(){
        return new Rectangle(canvas.getClipBounds());
    }
    
    public void setClip(Rectangle rectangle){
        //seems to be not necessary
    }
    
    public Color getColor(){
        return new Color(paint.getColor());
    }
    
    public void setColor(Color color){
        paint.setColor(color.getColorValue());
    }
    
    public void drawArc(float x, float y, float width, float height, float startAngle, float arcAngle){
        Style oldStyle = paint.getStyle();
        paint.setStyle(Style.STROKE);
        RectF rectF = new RectF(x,y,x+width,y+height);
        canvas.drawArc(rectF,startAngle,arcAngle,true,paint);
        paint.setStyle(oldStyle);
    }
    public void fillArc(float x, float y, float width, float height, float startAngle, float arcAngle){
        Style oldStyle = paint.getStyle();
        paint.setStyle(Style.FILL);
        RectF rectF = new RectF(x,y,x+width,y+height);
        canvas.drawArc(rectF,-startAngle,-arcAngle,true,paint);
        paint.setStyle(oldStyle);
    }
    
    public void drawImage(BufferedImage image, String tmp, float x, float y){
        //System.err.println("drawImage: " + image.getBitmap().getWidth() + " : "+ image.getBitmap().getHeight());
        Xfermode mode  = paint.getXfermode();
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_OVER));
        //canvas.drawBitmap(image.getBitmap(), x, y, paint);
        Bitmap bitmap = image.getBitmap();
        bitmap.prepareToDraw();
        canvas.drawBitmap(bitmap, canvas.getClipBounds(), canvas.getClipBounds(), paint);
        paint.setXfermode(mode);
    }
    
    public void drawString(String text, float x, float y){
        Style oldStyle = paint.getStyle();
        paint.setStyle(Style.FILL);
        canvas.drawText(text, x, y, paint);
        paint.setStyle(oldStyle);
        
    }

    public Canvas getCanvas() {
        return canvas;
    }

    public Paint getPaint() {
        return paint;
    }

    public Object getFont() {
        // TODO Auto-generated method stub
        return null;
    }

    public FontMetrics getFontMetrics(Object font) {
        return new FontMetrics(this);
    }
    
    public FontMetrics getFontMetrics() {
        return new FontMetrics(this);
    }
    
    public void dispose(){
        //TODO: search if there is something to do with it
    }

    public int save(){
        return canvas.save();
    }

    public void restore(){
        canvas.restore();
    }

    public void rotate(float degree, float x, float y){
        canvas.rotate(degree, x, y);
    }

    public float getFontSize(){
        return paint.getTextSize();
    }
    public void setFontSize(float size){
        paint.setTextSize(size);
    }

    public void setTypeface(Typeface typeface){
        paint.setTypeface(typeface);
    }
    public Typeface getTypeface(){
        return paint.getTypeface();
    }

    public void setShadow(float radius, float dx, float dy, Color color){
        int colorVal = color.getColorValue();
        paint.setShadowLayer(radius, dx, dy, colorVal);
    }
    public void unsetShadow(){
        paint.clearShadowLayer();
    }
    
}




Java Source Code List

com.wildplot.android.ankistats.AnkiDb.java
com.wildplot.android.ankistats.AnkiStatsActivity.java
com.wildplot.android.ankistats.AnkiStatsApplication.java
com.wildplot.android.ankistats.AnswerButton.java
com.wildplot.android.ankistats.ApplicationTest.java
com.wildplot.android.ankistats.CardsTypes.java
com.wildplot.android.ankistats.CollectionData.java
com.wildplot.android.ankistats.Forecast.java
com.wildplot.android.ankistats.HourlyBreakdown.java
com.wildplot.android.ankistats.Intervals.java
com.wildplot.android.ankistats.ReviewCount.java
com.wildplot.android.ankistats.Utils.java
com.wildplot.android.ankistats.WeeklyBreakdown.java
com.wildplot.android.parsing.Atom.java
com.wildplot.android.parsing.ExpressionFormatException.java
com.wildplot.android.parsing.Expression.java
com.wildplot.android.parsing.Factor.java
com.wildplot.android.parsing.Pow.java
com.wildplot.android.parsing.Term.java
com.wildplot.android.parsing.TopLevelParser.java
com.wildplot.android.parsing.TreeElement.java
com.wildplot.android.parsing.AtomTypes.FunctionXAtom.java
com.wildplot.android.parsing.AtomTypes.FunctionXYAtom.java
com.wildplot.android.parsing.AtomTypes.MathFunctionAtom.java
com.wildplot.android.parsing.AtomTypes.NumberAtom.java
com.wildplot.android.parsing.AtomTypes.VariableAtom.java
com.wildplot.android.parsing.AtomTypes.XVariableAtom.java
com.wildplot.android.parsing.AtomTypes.YVariableAtom.java
com.wildplot.android.rendering.AdvancedPlotSheet.java
com.wildplot.android.rendering.BarGraph.java
com.wildplot.android.rendering.DrawableContainer.java
com.wildplot.android.rendering.FunctionDrawer.java
com.wildplot.android.rendering.FunctionDrawer_y.java
com.wildplot.android.rendering.Integral.java
com.wildplot.android.rendering.LegendDrawable.java
com.wildplot.android.rendering.LinesPoints.java
com.wildplot.android.rendering.Lines.java
com.wildplot.android.rendering.MultiScreenPart.java
com.wildplot.android.rendering.PieChart.java
com.wildplot.android.rendering.PlotSheet.java
com.wildplot.android.rendering.PointDrawer2D.java
com.wildplot.android.rendering.RelativeColorGradient.java
com.wildplot.android.rendering.ReliefDrawer.java
com.wildplot.android.rendering.XAxisBarGraph.java
com.wildplot.android.rendering.XAxisHistoGram.java
com.wildplot.android.rendering.XAxis.java
com.wildplot.android.rendering.XGrid.java
com.wildplot.android.rendering.YAxisBarGraph.java
com.wildplot.android.rendering.YAxisHistoGram.java
com.wildplot.android.rendering.YAxis.java
com.wildplot.android.rendering.YGrid.java
com.wildplot.android.rendering.graphics.wrapper.BasicStroke.java
com.wildplot.android.rendering.graphics.wrapper.BufferedImage.java
com.wildplot.android.rendering.graphics.wrapper.Color.java
com.wildplot.android.rendering.graphics.wrapper.FontMetrics.java
com.wildplot.android.rendering.graphics.wrapper.Graphics2D.java
com.wildplot.android.rendering.graphics.wrapper.Graphics.java
com.wildplot.android.rendering.graphics.wrapper.Rectangle.java
com.wildplot.android.rendering.graphics.wrapper.Stroke.java
com.wildplot.android.rendering.interfaces.Drawable.java
com.wildplot.android.rendering.interfaces.Function2D.java
com.wildplot.android.rendering.interfaces.Function3D.java
com.wildplot.android.rendering.interfaces.Legendable.java
com.wildplot.android.rendering.interfaces.StepFunction2D.java