Commits

dgomes  committed 0c4b17e Merge

Added background image

  • Participants
  • Parent commits e0cc62e, f50e56d

Comments (0)

Files changed (2)

File HoloGraphLibrary/src/com/echo/holographlibrary/PieGraph.java

 import android.annotation.TargetApi;
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
     private OnSliceClickedListener mListener;
     private boolean mDrawCompleted = false;
     private RectF mRectF = new RectF();
+    private Bitmap mBackgroundImage = null;
+    private Point mBackgroundImageAnchor = new Point(0,0);
+    private boolean mBackgroundImageCenter = false;
+
 
     public PieGraph(Context context) {
         this(context, null);
         mPaint.reset();
         mPaint.setAntiAlias(true);
 
+        if(mBackgroundImage != null) {
+            if(mBackgroundImageCenter)
+                mBackgroundImageAnchor.set(
+                        getWidth() / 2 - mBackgroundImage.getWidth() / 2,
+                        getHeight() / 2 - mBackgroundImage.getHeight() / 2
+                );
+            canvas.drawBitmap(mBackgroundImage, mBackgroundImageAnchor.x, mBackgroundImageAnchor.y, mPaint);
+        }
+
         float currentAngle = 270;
         float currentSweep = 0;
         float totalValue = 0;
         return true;
     }
 
+    public Bitmap getBackgroundBitmap() {
+        return mBackgroundImage;
+    }
+
+    public void setBackgroundBitmap(Bitmap backgroundBitmap, int pos_x, int pos_y) {
+        mBackgroundImage = backgroundBitmap;
+        mBackgroundImageAnchor.set(pos_x, pos_y);
+        postInvalidate();
+    }
+
+    public void setBackgroundBitmap(Bitmap backgroundBitmap) {
+        mBackgroundImageCenter = true;
+        mBackgroundImage = backgroundBitmap;
+        postInvalidate();
+    }
+
     /**
      * sets padding
      * @param padding

File HoloGraphLibrarySample/src/com/echo/holographlibrarysample/PieFragment.java

 import android.content.res.Resources;
 import android.os.Build;
 import android.view.animation.*;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.util.Log;
             }
         });
 
+        Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
+        pg.setBackgroundBitmap(b);
+
         SeekBar seekBar = (SeekBar) v.findViewById(R.id.seekBarRatio);
         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override