forked from ImangazalievM/CircleMenu
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from NetoDevel/master
Adds border to multiple check
- Loading branch information
Showing
8 changed files
with
336 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions
76
library/src/main/java/com/imangazaliev/circlemenu/BitmapHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.imangazaliev.circlemenu; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapShader; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.RectF; | ||
import android.graphics.Shader; | ||
import android.graphics.drawable.BitmapDrawable; | ||
import android.graphics.drawable.Drawable; | ||
|
||
/** | ||
* @author NetoDevel | ||
*/ | ||
public class BitmapHelper { | ||
|
||
public static void transformCircularBitmap(Canvas canvas, Bitmap newBitmap) { | ||
BitmapShader shader; | ||
shader = new BitmapShader(newBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); | ||
|
||
Paint paint = new Paint(); | ||
paint.setAntiAlias(true); | ||
paint.setShader(shader); | ||
|
||
float r = newBitmap.getWidth() / 2f; | ||
|
||
canvas.drawCircle(r, r, r, paint); | ||
} | ||
|
||
public static RectF createRectFFromBitmap(Bitmap bitmap, int mBorderWidth) { | ||
RectF fBounds = new RectF(); | ||
|
||
int offset = (bitmap.getWidth() - bitmap.getHeight()) / 2; | ||
|
||
int left = offset + mBorderWidth; | ||
int right = bitmap.getWidth() - offset - mBorderWidth; | ||
int bottom = bitmap.getHeight() - mBorderWidth; | ||
int top = mBorderWidth; | ||
|
||
fBounds.left = left + mBorderWidth / 2f + .5f; | ||
fBounds.right = right - mBorderWidth / 2f - .5f; | ||
fBounds.top = top + mBorderWidth / 2f + .5f; | ||
fBounds.bottom = bottom - mBorderWidth / 2f - .5f; | ||
|
||
return fBounds; | ||
} | ||
|
||
public static Bitmap resizeBitmap(Bitmap source, int width, int height) { | ||
return Bitmap.createScaledBitmap(source, width, height, false); | ||
} | ||
|
||
public static Bitmap drawableToBitmap(Drawable drawable) { | ||
Bitmap bitmap = null; | ||
|
||
if (drawable instanceof BitmapDrawable) { | ||
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; | ||
if(bitmapDrawable.getBitmap() != null) { | ||
return bitmapDrawable.getBitmap(); | ||
} | ||
} | ||
|
||
if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { | ||
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); | ||
} else { | ||
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); | ||
} | ||
|
||
Canvas canvas = new Canvas(bitmap); | ||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); | ||
drawable.draw(canvas); | ||
return bitmap; | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.