diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 74aef28..2d6be5c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -35,7 +35,7 @@ - + diff --git a/build.gradle b/build.gradle index 43903de..cef4c17 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.0' + classpath 'com.android.tools.build:gradle:3.4.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/example/src/main/assets/fonts/bahianita-regular.ttf b/example/src/main/assets/fonts/bahianita-regular.ttf new file mode 100644 index 0000000..0fb3718 Binary files /dev/null and b/example/src/main/assets/fonts/bahianita-regular.ttf differ diff --git a/example/src/main/java/com/wldev/example/MainActivity.java b/example/src/main/java/com/wldev/example/MainActivity.java index d7a6227..1a7d8d7 100644 --- a/example/src/main/java/com/wldev/example/MainActivity.java +++ b/example/src/main/java/com/wldev/example/MainActivity.java @@ -16,9 +16,13 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - FancyButton button1 = (FancyButton) findViewById(R.id.btn1); - FancyButton button2 = (FancyButton) findViewById(R.id.btn2); - FancyButton button3 = (FancyButton) findViewById(R.id.btn3); + FancyButton button1 = findViewById(R.id.btn1); + FancyButton button2 = findViewById(R.id.btn2); + FancyButton button3 = findViewById(R.id.btn3); + FancyButton button4 = findViewById(R.id.btn4); + FancyButton button5 = findViewById(R.id.btn5); + FancyButton button6 = findViewById(R.id.btn6); + FancyButton button7 = findViewById(R.id.btn7); View.OnClickListener listener = new View.OnClickListener() { @Override @@ -36,5 +40,9 @@ public void onClick(View view) { button1.setOnClickListener(listener); button2.setOnClickListener(listener); button3.setOnClickListener(listener); + button4.setOnClickListener(listener); + button5.setOnClickListener(listener); + button6.setOnClickListener(listener); + button7.setOnClickListener(listener); } } diff --git a/example/src/main/res/drawable/button_border.xml b/example/src/main/res/drawable/button_border.xml new file mode 100644 index 0000000..8604033 --- /dev/null +++ b/example/src/main/res/drawable/button_border.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/example/src/main/res/drawable/button_border_stroke.xml b/example/src/main/res/drawable/button_border_stroke.xml new file mode 100644 index 0000000..6955dc9 --- /dev/null +++ b/example/src/main/res/drawable/button_border_stroke.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml index 7e7e9cd..3de1c25 100644 --- a/example/src/main/res/layout/activity_main.xml +++ b/example/src/main/res/layout/activity_main.xml @@ -1,51 +1,116 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 903c19e..1104f78 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jan 30 00:24:59 EET 2019 +#Wed Jul 03 15:46:00 EET 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/library/src/main/java/com/ekalips/fancybuttonproj/FancyButton.java b/library/src/main/java/com/ekalips/fancybuttonproj/FancyButton.java index fb36274..2515e9a 100644 --- a/library/src/main/java/com/ekalips/fancybuttonproj/FancyButton.java +++ b/library/src/main/java/com/ekalips/fancybuttonproj/FancyButton.java @@ -5,10 +5,12 @@ import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; +import android.content.res.AssetManager; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Typeface; import android.os.Build; import android.support.annotation.Nullable; import android.support.annotation.RequiresApi; @@ -21,6 +23,9 @@ import android.widget.RelativeLayout; import android.widget.TextView; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; import me.zhanghai.android.materialprogressbar.IndeterminateCircularProgressDrawable; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; @@ -30,12 +35,12 @@ public class FancyButton extends FrameLayout { interface AnimationEndListener { + void animationEnded(); } private static final String TAG = FancyButton.class.getSimpleName(); - public FancyButton(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); @@ -103,18 +108,39 @@ public void init(Context context, AttributeSet attrs) { int textColor = ta.getColor(R.styleable.FancyButton_f_textColor, Color.BLACK); int progressColor = ta.getColor(R.styleable.FancyButton_f_progressColor, Color.BLACK); int strokeWidth = ta.getInt(R.styleable.FancyButton_f_strokeWidth, -1); - if (strokeWidth == -1) - strokeWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, context.getResources().getDisplayMetrics()); + + //Adding new Attribute Background for BorderRadius + /* + * If the Background is not Null ... It must have BorderRadius and Color + * If it doesnt Have a BorderRadius then no need to add it + * if u gonna add a stroke in the background .. then u dont need to add it with_f_strokeWidth or f_strokeCollor + * */ + + int background = ta.getResourceId(R.styleable.FancyButton_f_background, -1); + //TextAppearance + int textAppearance = ta.getResourceId(R.styleable.FancyButton_f_textAppearance, -1); + + //Textfont from Assets + String textFont = ta.getString(R.styleable.FancyButton_f_textFont); + + if (strokeWidth == -1) { + strokeWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, + context.getResources().getDisplayMetrics()); + } boolean capsText = ta.getBoolean(R.styleable.FancyButton_f_capsText, true); float textSize = ta.getDimensionPixelSize(R.styleable.FancyButton_f_textSize, -1); - if (textSize == -1) - textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, context.getResources().getDisplayMetrics()); - if (capsText && text != null) + if (textSize == -1) { + textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, + context.getResources().getDisplayMetrics()); + } + if (capsText && text != null) { text = text.toUpperCase(); + } String temp = ta.getString(R.styleable.FancyButton_f_btnStyle); - if (temp != null) + if (temp != null) { style = Integer.parseInt(temp); + } hideAfterCollapse = ta.getBoolean(R.styleable.FancyButton_f_hideFillAfterCollapse, true); ta.recycle(); @@ -122,20 +148,60 @@ public void init(Context context, AttributeSet attrs) { view.setClickable(false); view.setFocusable(false); view.setTextColor(textColor); + view.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); - RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); view.setLayoutParams(params); view.setText(text); + //Checking if background is Null or not + if (background != -1) { + view.setBackground(getResources().getDrawable(background)); + } + + //Checking if textFont is Null + if (textFont != null) { + AssetManager manager = getResources().getAssets(); + InputStream inputStream = null; + try { + inputStream = manager.open(textFont); + Typeface face = Typeface.createFromAsset(context.getAssets(), + textFont); + view.setTypeface(face); + } catch (IOException ex) { + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + } + + //Checking if textAppearance is not null + if (textAppearance != -1) + try { + view.setTextAppearance(context,textAppearance); + } catch (Exception e) + { + Log.e("Error",e.getMessage()); + } + this.addView(view); bar = new MaterialProgressBar(context); - FrameLayout.LayoutParams barParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + FrameLayout.LayoutParams barParams = new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); barParams.gravity = Gravity.CENTER; bar.setLayoutParams(barParams); bar.setIndeterminate(true); // fixes pre-Lollipop progressBar indeterminateDrawable tinting - IndeterminateCircularProgressDrawable drawable = new IndeterminateCircularProgressDrawable(context); + IndeterminateCircularProgressDrawable drawable = new IndeterminateCircularProgressDrawable( + context); drawable.setTint(progressColor); bar.setIndeterminateDrawable(drawable); @@ -164,13 +230,21 @@ protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (state == State.normal) { - if (style == 0) - canvas.drawPath(Utils.composeRoundedRectPath(initPadd, initPadd, canvas.getWidth() - initPadd, canvas.getHeight() - initPadd, initPadd), strokePaint); - else if (style == 1) - canvas.drawPath(Utils.composeRoundedRectPath(initPadd, initPadd, canvas.getWidth() - initPadd, canvas.getHeight() - initPadd, initPadd), fillPaint); - else if (style == 2) { - canvas.drawPath(Utils.composeRoundedRectPath(initPadd, initPadd, canvas.getWidth() - initPadd, canvas.getHeight() - initPadd, initPadd), fillPaint); - canvas.drawPath(Utils.composeRoundedRectPath(initPadd, initPadd, canvas.getWidth() - initPadd, canvas.getHeight() - initPadd, initPadd), strokePaint); + if (style == 0) { + canvas.drawPath(Utils + .composeRoundedRectPath(initPadd, initPadd, canvas.getWidth() - initPadd, + canvas.getHeight() - initPadd, initPadd), strokePaint); + } else if (style == 1) { + canvas.drawPath(Utils + .composeRoundedRectPath(initPadd, initPadd, canvas.getWidth() - initPadd, + canvas.getHeight() - initPadd, initPadd), fillPaint); + } else if (style == 2) { + canvas.drawPath(Utils + .composeRoundedRectPath(initPadd, initPadd, canvas.getWidth() - initPadd, + canvas.getHeight() - initPadd, initPadd), fillPaint); + canvas.drawPath(Utils + .composeRoundedRectPath(initPadd, initPadd, canvas.getWidth() - initPadd, + canvas.getHeight() - initPadd, initPadd), strokePaint); } destLeft = (this.getRight() - this.getLeft()) / 2 - trueSixtee; destRight = (this.getRight() - this.getLeft()) / 2 + trueSixtee; @@ -183,8 +257,10 @@ else if (style == 2) { animator.start(); } else if (state == State.shrieked) { if (!hideAfterCollapse) { - if (style == 1 || style == 2) - canvas.drawCircle(destRight - ((destRight - destLeft) / 2), destBot - ((destBot - destTop) / 2), circleR / 2, fillPaint); + if (style == 1 || style == 2) { + canvas.drawCircle(destRight - ((destRight - destLeft) / 2), + destBot - ((destBot - destTop) / 2), circleR / 2, fillPaint); + } } ObjectAnimator animator = ObjectAnimator.ofFloat(bar, "alpha", 0, 1); @@ -192,26 +268,65 @@ else if (style == 2) { animator.start(); bar.setVisibility(VISIBLE); } else { - if (state == State.shrink) - if (style == 0) - canvas.drawPath(Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), (float) (canvas.getWidth() - nowPadW), (float) (canvas.getHeight() - nowPadH), (float) nowRad), strokePaint); - else if (style == 1) - canvas.drawPath(Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), (float) (canvas.getWidth() - nowPadW), (float) (canvas.getHeight() - nowPadH), (float) nowRad), fillPaint); - else if (style == 2) { - canvas.drawPath(Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), (float) (canvas.getWidth() - nowPadW), (float) (canvas.getHeight() - nowPadH), (float) nowRad), fillPaint); - canvas.drawPath(Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), (float) (canvas.getWidth() - nowPadW), (float) (canvas.getHeight() - nowPadH), (float) nowRad), strokePaint); + if (state == State.shrink) { + if (style == 0) { + canvas.drawPath( + Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), + (float) (canvas.getWidth() - nowPadW), + (float) (canvas.getHeight() - nowPadH), + (float) nowRad), strokePaint); + } else if (style == 1) { + canvas + .drawPath( + Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), + (float) (canvas.getWidth() - nowPadW), + (float) (canvas.getHeight() - nowPadH), + (float) nowRad), fillPaint); + } else if (style == 2) { + canvas + .drawPath( + Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), + (float) (canvas.getWidth() - nowPadW), + (float) (canvas.getHeight() - nowPadH), + (float) nowRad), fillPaint); + canvas + .drawPath( + Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), + (float) (canvas.getWidth() - nowPadW), + (float) (canvas.getHeight() - nowPadH), + (float) nowRad), strokePaint); } + } if (state == State.back) { - if (style == 0) - canvas.drawPath(Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), (float) (canvas.getWidth() - nowPadW), (float) (canvas.getHeight() - nowPadH), (float) nowRad), strokePaint); - else if (style == 1) - canvas.drawPath(Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), (float) (canvas.getWidth() - nowPadW), (float) (canvas.getHeight() - nowPadH), (float) nowRad), fillPaint); - else if (style == 2) { - canvas.drawPath(Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), (float) (canvas.getWidth() - nowPadW), (float) (canvas.getHeight() - nowPadH), (float) nowRad), fillPaint); - canvas.drawPath(Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), (float) (canvas.getWidth() - nowPadW), (float) (canvas.getHeight() - nowPadH), (float) nowRad), strokePaint); + if (style == 0) { + canvas.drawPath( + Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), + (float) (canvas.getWidth() - nowPadW), (float) (canvas.getHeight() - nowPadH), + (float) nowRad), strokePaint); + } else if (style == 1) { + canvas + .drawPath( + Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), + (float) (canvas.getWidth() - nowPadW), + (float) (canvas.getHeight() - nowPadH), + (float) nowRad), fillPaint); + } else if (style == 2) { + canvas + .drawPath( + Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), + (float) (canvas.getWidth() - nowPadW), + (float) (canvas.getHeight() - nowPadH), + (float) nowRad), fillPaint); + canvas + .drawPath( + Utils.composeRoundedRectPath((float) (0 + nowPadW), (float) (0 + nowPadH), + (float) (canvas.getWidth() - nowPadW), + (float) (canvas.getHeight() - nowPadH), + (float) nowRad), strokePaint); } - if (bar.getVisibility() != INVISIBLE) + if (bar.getVisibility() != INVISIBLE) { bar.setVisibility(INVISIBLE); + } } } } @@ -228,8 +343,9 @@ else if (style == 2) { public void expand() { // if (state == State.shrieked){ - if (state == State.normal) + if (state == State.normal) { return; + } if (animator != null) { animator.removeAllUpdateListeners(); animator.cancel(); @@ -251,10 +367,12 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) { nowPadW -= addWVal; nowRad -= addRad; if (hideAfterCollapse) { - if (strokePaint.getColor() != Color.TRANSPARENT) + if (strokePaint.getColor() != Color.TRANSPARENT) { strokePaint.setAlpha((Integer) valueAnimator.getAnimatedValue()); - if (fillPaint.getColor() != Color.TRANSPARENT) + } + if (fillPaint.getColor() != Color.TRANSPARENT) { fillPaint.setAlpha((Integer) valueAnimator.getAnimatedValue()); + } } view.setAlpha((int) valueAnimator.getAnimatedValue() / 255f); } @@ -264,8 +382,9 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) { public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); state = State.normal; - if (listener != null) + if (listener != null) { listener.animationEnded(); + } isExpanded = true; } }); @@ -275,8 +394,9 @@ public void onAnimationEnd(Animator animation) { public void collapse() { // if (state == State.normal){ - if (state == State.shrieked) + if (state == State.shrieked) { return; + } if (animator != null) { animator.removeAllUpdateListeners(); animator.cancel(); @@ -302,10 +422,12 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) { nowPadW += addWVal; nowRad += addRad; if (hideAfterCollapse) { - if (strokePaint.getColor() != Color.TRANSPARENT) + if (strokePaint.getColor() != Color.TRANSPARENT) { strokePaint.setAlpha((Integer) valueAnimator.getAnimatedValue()); - if (fillPaint.getColor() != Color.TRANSPARENT) + } + if (fillPaint.getColor() != Color.TRANSPARENT) { fillPaint.setAlpha((Integer) valueAnimator.getAnimatedValue()); + } } view.setAlpha((int) valueAnimator.getAnimatedValue() / 255f); } @@ -315,8 +437,9 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) { public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); state = State.shrieked; - if (listener != null) + if (listener != null) { listener.animationEnded(); + } } }); animator.start(); diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 178d22b..ee2f52d 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -15,5 +15,10 @@ + //Adding new Attribute Background + + + + \ No newline at end of file