Skip to content

Commit

Permalink
Merge pull request #2 from NetoDevel/master
Browse files Browse the repository at this point in the history
Adds border to multiple check
  • Loading branch information
netodevel authored Oct 23, 2017
2 parents 28f4a52 + f7dbc9a commit a0f04bd
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 7 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Also you can enable hints, that shows in Toast by long pressing a button

### If you want to use multiple checks


<p align="center">
<img src="etc/circle-menu-checked.gif" height="500" alt="progress image view" />
</p>
Expand All @@ -118,11 +119,40 @@ Also you can enable hints, that shows in Toast by long pressing a button
</com.imangazaliev.circlemenu.CircleMenu>
```

### Multiple checks attributes
### Animated border to multiple checks

<p align="center">
<img src="etc/check-border.gif" height="500" alt="progress image view" />
</p>

```xml
<com.imangazaliev.circlemenu.CircleMenu
...
app:multiple_check="true"
app:border_check="true"
app:alpha_check="false"
app:center_drawable="@drawable/ic_add_alert_black_24dp"
app:confirmation_center_drawable="@drawable/ic_send_red">

<!-- Add your menu button items here -->

</com.imangazaliev.circlemenu.CircleMenu>
```

### Multiple checks attributes on Circle Menu

* `app:multiple_check` : Enables the multiple_check selection (Default: `false`)
* `app:border_check="true"`: Enable animation border
* `app:alpha_check="false"`: Enable animation alpha
* `app:center_drawable` : Path to your custom graphic resource
* `app:confirmation_center_drawable` : Path to your custom confirmation button graphic resource

### Attributes on Circle Menu Button

* `app:enable_border` : Enable animation border
* `app:full_drawable` : When you want to draw in full circle


## License

The MIT License
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ protected void onCreate(Bundle savedInstanceState) {
final ViewGroup snackbarContainer = (ViewGroup) findViewById(R.id.snackbar_contaner);

final CircleMenu circleMenuDefault = (CircleMenu) findViewById(R.id.circle_menu_default);
final CircleMenu circleMenuMultiple = (CircleMenu) findViewById(R.id.circle_menu_multiple);
//final CircleMenu circleMenuMultiple = (CircleMenu) findViewById(R.id.circle_menu_multiple);
final CircleMenu circleMenuMultipleBorder = (CircleMenu) findViewById(R.id.circle_menu_multiple_border);

prepareViewCircleMenuDefault(circleMenuDefault, snackbarContainer);
prepareViewCircleMenuMultiple(circleMenuMultiple);
//prepareViewCircleMenuMultiple(circleMenuMultiple);
prepareViewCircleMenuMultipleBorder(circleMenuMultipleBorder);
}

private void prepareViewCircleMenuDefault(CircleMenu circleMenu, final ViewGroup snackbarContainer) {
Expand Down Expand Up @@ -58,6 +60,7 @@ private void prepareViewCircleMenuMultiple(CircleMenu circleMenuMultiple) {
circleMenuButton.setColorNormal(R.color.color_normal);
circleMenuButton.setColorPressed(R.color.color_pressed);
circleMenuButton.setIconResId(R.drawable.ic_favorite);
circleMenuButton.setFullDrawable(false);
circleMenuButton.setMetaData(new ExampleData(i));

circleMenuMultiple.addButton(circleMenuButton);
Expand All @@ -77,4 +80,35 @@ public void onConfirmation(List<Object> listData) {
});
}


private void prepareViewCircleMenuMultipleBorder(CircleMenu circleMenu) {
/**
* adding dynamically
*/
for (int i = 0; i < 4; i ++) {
CircleMenuButton circleMenuButton = new CircleMenuButton(this);

circleMenuButton.setColorNormal(R.color.color_normal);
circleMenuButton.setColorPressed(R.color.color_pressed);
circleMenuButton.setIconResId(R.drawable.ic_favorite);
circleMenuButton.setEnableBorder(true);
circleMenuButton.setMetaData(new ExampleData(i));

circleMenu.addButton(circleMenuButton);
}

/**
* get meta data of circles selected
*/
circleMenu.setOnConfirmationListener(new CircleMenu.OnConfirmationListener() {
@Override
public void onConfirmation(List<Object> listData) {
for (int i =0; i< listData.size(); i++ ) {
ExampleData exampleData = (ExampleData) listData.get(i);
Log.d("MainActivity", "Id: " + exampleData.getId());
}
}
});
}

}
16 changes: 15 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,27 @@

</com.imangazaliev.circlemenu.CircleMenu>

<!--<com.imangazaliev.circlemenu.CircleMenu-->
<!--android:id="@+id/circle_menu_multiple"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_centerInParent="true"-->
<!--app:hintsEnabled="true"-->
<!--app:multiple_check="true"-->
<!--app:center_drawable="@drawable/ic_add_alert_black_24dp"-->
<!--app:confirmation_center_drawable="@drawable/ic_send_red">-->
<!--</com.imangazaliev.circlemenu.CircleMenu>-->


<com.imangazaliev.circlemenu.CircleMenu
android:id="@+id/circle_menu_multiple"
android:id="@+id/circle_menu_multiple_border"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:hintsEnabled="true"
app:multiple_check="true"
app:border_check="true"
app:alpha_check="false"
app:center_drawable="@drawable/ic_add_alert_black_24dp"
app:confirmation_center_drawable="@drawable/ic_send_red">
</com.imangazaliev.circlemenu.CircleMenu>
Expand Down
Binary file added etc/check-border.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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;
}

}


46 changes: 43 additions & 3 deletions library/src/main/java/com/imangazaliev/circlemenu/CircleMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public interface OnConfirmationListener {
private int circleStartAngle;
private boolean hintsEnabled;
private boolean multipleCheck;
private boolean borderCheck;
private boolean alphaCheck;

public CenterMenuButton getCenterButton() {
return centerButton;
Expand All @@ -61,6 +63,9 @@ public void setCenterButton(CenterMenuButton centerButton) {
private Drawable centerMenuButtonDrawable;
private Drawable confirmationMenuButtonDrawable;

private float alphaChecked = 0.5f;
private float alphaUnChecked = 1f;

public CircleMenu(Context context) {
this(context, null);
}
Expand All @@ -84,6 +89,8 @@ private void init(AttributeSet attrs) {
hintsEnabled = typedArray.getBoolean(R.styleable.CircleMenu_hintsEnabled, false);
centerMenuButtonDrawable = typedArray.getDrawable(R.styleable.CircleMenu_center_drawable);
multipleCheck = typedArray.getBoolean(R.styleable.CircleMenu_multiple_check, false);
borderCheck = typedArray.getBoolean(R.styleable.CircleMenu_border_check, false);
alphaCheck = typedArray.getBoolean(R.styleable.CircleMenu_alpha_check, true);
confirmationMenuButtonDrawable = typedArray.getDrawable(R.styleable.CircleMenu_confirmation_center_drawable);
listObjectData = new ArrayList<>();
listIndentifyChildMenuButton = new HashMap<>();
Expand Down Expand Up @@ -114,6 +121,7 @@ private void addChildrenToController() {

private void createCenterButton(Context context) {
centerButton = new CenterMenuButton(context);
centerButton.setHasCenterButton(true);
centerButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -271,7 +279,9 @@ public void onCollapsed() {
addCenterDrawableIfEnable();
centerButton.setClickable(true);
if (this.multipleCheck) {
onConfirmationListener.onConfirmation(listObjectData);
if (onConfirmationListener != null) {
onConfirmationListener.onConfirmation(listObjectData);
}
clearClircleMenuButtons();
}
if (stateUpdateListener != null) {
Expand All @@ -289,7 +299,6 @@ private void clearClircleMenuButtons() {
public void onItemClick(CircleMenuButton menuButton) {
centerButton.setExpanded(false);
if (multipleCheck) {
menuButton.setAlpha(0.2f);
if (verifyAlreadyChecked(menuButton.getGenerateId())) {
removeCheck(menuButton);
} else {
Expand All @@ -306,16 +315,35 @@ public void onItemClick(CircleMenuButton menuButton) {

private void addCheck(CircleMenuButton menuButton) {
menuButton.setGenerateId(UUID.randomUUID().toString());
addCheckedAnimation(menuButton);
listIndentifyChildMenuButton.put(menuButton.getGenerateId(), menuButton);
listObjectData.add(menuButton.getMetaData());
}

private void addCheckedAnimation(CircleMenuButton menuButton) {
if (alphaCheck){
menuButton.setAlpha(alphaChecked);
}
if (borderCheck){
menuButton.startCheckAnimation();
}
}

private void removeCheck(CircleMenuButton menuButton) {
menuButton.setAlpha(1f);
unCheckedAnimation(menuButton);
listObjectData.remove(menuButton.getMetaData());
listIndentifyChildMenuButton.remove(menuButton.getGenerateId());
}

private void unCheckedAnimation(CircleMenuButton menuButton) {
if (alphaCheck){
menuButton.setAlpha(alphaUnChecked);
}
if (borderCheck){
menuButton.reverseCheckAnimation();
}
}

public void setStatusDefaultCircleMenuButton() {
for(Map.Entry<String, CircleMenuButton> entry : listIndentifyChildMenuButton.entrySet()) {
CircleMenuButton cirleMenuButton = entry.getValue();
Expand Down Expand Up @@ -382,4 +410,16 @@ public void setMultipleCheck(boolean buttonConfimation) {
this.multipleCheck = buttonConfimation;
}

public void setAlphaChecked(float alphaChecked) {
this.alphaChecked = alphaChecked;
}

public void setBorderChecked(boolean borderCheck) {
this.borderCheck = borderCheck;
}

public void setAlphaUnChecked(float alphaUnChecked) {
this.alphaUnChecked = alphaUnChecked;
}

}
Loading

0 comments on commit a0f04bd

Please sign in to comment.