Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
• added support to hide components on dialog if `null` is set.
• fixed iconMode.
  • Loading branch information
kishannareshpal committed Dec 10, 2018
1 parent dd5bdee commit 1575c46
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import android.view.View;
import android.widget.Button;

import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.ERROR;
import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.SUCCESS;

public class MainActivity extends AppCompatActivity {

@Override
Expand All @@ -21,22 +24,8 @@ protected void onCreate(Bundle savedInstanceState) {
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final SuperDialog sd = new SuperDialog()
.title("Hello World")
.iconMode(AnimatedIcon.Mode.INDEFINITE)
.cancelText("Fechar");

sd.show(getSupportFragmentManager());


new Handler().postDelayed(new Runnable() {
@Override
public void run() {
sd.iconMode(SuperDialog.CUSTOM_ICON);
sd.cancelText("Close");
sd.changeTitleCaps(true);
}
}, 5000);
asi.setMode(SUCCESS);
asi2.setMode(ERROR);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions superdialog/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.kishannareshpal'
version = '0.1.0'
version = '0.1.1'

android {
compileSdkVersion 28
Expand All @@ -12,7 +12,7 @@ android {
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
versionName "0.1.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.BounceInterpolator;

import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.ERROR;
import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.INDEFINITE;
import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.STOPED;
import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.SUCCESS;
import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.CUSTOM_ICON;
import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.ERROR_ICON;
import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.PROGRESS_ICON;
import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.SUCCESS_ICON;

public class AnimatedIcon extends View {

Context ctx;

class Mode {
public static final int STOPED = -1;
public static final int SUCCESS = 0;
public static final int ERROR = 1;
public static final int INDEFINITE = 2;
public static final int CUSTOM_ICON = 0;
public static final int PROGRESS_ICON = 1;
public static final int SUCCESS_ICON = 2;
public static final int ERROR_ICON = 3;
}

private int fullWidth, fullHeight;
private int default_padding = 8;
private int circle_sweepAngle;
private int strokeWidth = 8;
private int mode = INDEFINITE;
private int mode = CUSTOM_ICON;


private RectF oval;
Expand All @@ -47,13 +47,13 @@ class Mode {
public void setMode(int mode) {
this.mode = mode;

if (mode == INDEFINITE) {
if (mode == PROGRESS_ICON) {
valueAnimator.start();

} else if (mode == STOPED){
} else if (mode == CUSTOM_ICON){
valueAnimator.end();

} else if (mode == SUCCESS){
} else if (mode == SUCCESS_ICON){
valueAnimator.end();
main_paint.setColor(ContextCompat.getColor(ctx, R.color.secondary_green));
stroke_paint.setColor(ContextCompat.getColor(ctx, R.color.secondary_green));
Expand All @@ -71,7 +71,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
});
animator.start();

} else if (mode == ERROR) {
} else if (mode == ERROR_ICON) {
valueAnimator.end();
main_paint.setColor(ContextCompat.getColor(ctx, R.color.secondary_red));
stroke_paint.setColor(ContextCompat.getColor(ctx, R.color.secondary_red));
Expand Down Expand Up @@ -171,7 +171,7 @@ protected void onDraw(Canvas canvas) {
canvas.drawCircle(cx, cy, circle_radius, main_paint);


if (mode == SUCCESS){
if (mode == SUCCESS_ICON){
float linestart_x = width/3;
float linestart_y = (height/3) + (height/5);
float lineend_x = width/2;
Expand All @@ -181,7 +181,7 @@ protected void onDraw(Canvas canvas) {
linestart_y = height/3;
canvas.drawLine(lineend_x, lineend_y, linestart_x-2, linestart_y, icon_paint);

} else if (mode == ERROR) {
} else if (mode == ERROR_ICON) {
float linestart_x = (fullWidth/2) - (fullWidth/6);
float linestart_y = (fullHeight/2) - (fullHeight/6);
float lineend_x = (fullWidth/2) + (fullWidth/6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@
import android.widget.Space;
import android.widget.TextView;

import static com.kishannareshpal.superdialog.AnimatedIcon.Mode.STOPED;

public class SuperDialog extends DialogFragment {

public static final int POSITIVE = 9;
public static final int NEGATIVE = 10;
public static final int CANCEL = 11;

public static final int CUSTOM_ICON = 0;
public static final int INDEFINITE_ICON = 0;
public static final int SUCCESS_ICON = 1;
public static final int ERROR_ICON = 2;
public static final int CUSTOM_ICON = 0;
public static final int PROGRESS_ICON = 1;
public static final int SUCCESS_ICON = 2;
public static final int ERROR_ICON = 3;

private static final int DEFAULT = -1;

Expand Down Expand Up @@ -252,6 +250,9 @@ private void changePositiveText(String positiveText){
if (positiveText != null){
btn_positive.setVisibility(View.VISIBLE);
btn_positive.setText(positiveText);

} else {
btn_positive.setVisibility(View.GONE);
}
}
private void changeOnPositive(final OnButtonClickListener onPositive){
Expand Down Expand Up @@ -286,11 +287,14 @@ private void changePositiveColor(int positiveColorRes){
}
}


// Setup Negative Button
private void changeNegativeText(String negativeText){
if (negativeText != null){
btn_negative.setVisibility(View.VISIBLE);
btn_negative.setText(negativeText);
} else {
btn_negative.setVisibility(View.GONE);
}
}
private void changeOnNegative(final OnButtonClickListener onNegative){
Expand Down Expand Up @@ -325,11 +329,14 @@ private void changeNegativeColor(int negativeColorRes){
}
}


// Setup Cancel Button
private void changeCancelText(String cancelText){
if (cancelText != null){
btn_cancel.setVisibility(View.VISIBLE);
btn_cancel.setText(cancelText);
} else {
btn_cancel.setVisibility(View.GONE);
}
}
private void changeOnCancel(final OnButtonClickListener onCancel){
Expand Down Expand Up @@ -369,11 +376,17 @@ private void changeTitle(String title){
if (title != null){
tv_title.setVisibility(View.VISIBLE);
tv_title.setText(title);

} else {
tv_title.setVisibility(View.GONE);
}
}
public void changeTitleCaps(boolean isAllCaps){
if (title != null) {
tv_title.setAllCaps(isAllCaps);

} else {
tv_title.setVisibility(View.GONE);
}
}

Expand All @@ -382,21 +395,22 @@ private void changeMessage(String message){
if (message != null) {
tv_message.setVisibility(View.VISIBLE);
tv_message.setText(message);

} else {
tv_message.setVisibility(View.GONE);
}
}
public void changeMessageGravity(int gravity){
if (message != null) {
if (gravity != DEFAULT) {
tv_message.setGravity(gravity);
}
tv_message.setGravity(gravity);
}
}

// Setup Icon
private void changeIconMode(int iconMode){
if (iconMode == CUSTOM_ICON){
ai_animatedIcon.setVisibility(View.GONE);
ai_animatedIcon.setMode(STOPED);
ai_animatedIcon.setMode(CUSTOM_ICON);

} else {
ai_animatedIcon.setVisibility(View.VISIBLE);
Expand Down

0 comments on commit 1575c46

Please sign in to comment.