Skip to content

Commit

Permalink
library update
Browse files Browse the repository at this point in the history
  • Loading branch information
samwelnyandoro committed May 31, 2024
1 parent dff06ae commit f709441
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 229 deletions.
8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,13 @@ public class OptAnimationLoader {
public static Animation loadAnimation(Context context, int id)
throws Resources.NotFoundException {

XmlResourceParser parser = null;
try {
parser = context.getResources().getAnimation(id);
try (XmlResourceParser parser = context.getResources().getAnimation(id)) {
return createAnimationFromXml(context, parser);
} catch (XmlPullParserException ex) {
} catch (XmlPullParserException | IOException ex) {
Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" +
Integer.toHexString(id));
rnf.initCause(ex);
throw rnf;
} catch (IOException ex) {
Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" +
Integer.toHexString(id));
rnf.initCause(ex);
throw rnf;
} finally {
if (parser != null) parser.close();
}
}

Expand Down Expand Up @@ -65,23 +56,30 @@ private static Animation createAnimationFromXml(Context c, XmlPullParser parser,

String name = parser.getName();

if (name.equals("set")) {
anim = new AnimationSet(c, attrs);
createAnimationFromXml(c, parser, (AnimationSet)anim, attrs);
} else if (name.equals("alpha")) {
anim = new AlphaAnimation(c, attrs);
} else if (name.equals("scale")) {
anim = new ScaleAnimation(c, attrs);
} else if (name.equals("rotate")) {
anim = new RotateAnimation(c, attrs);
} else if (name.equals("translate")) {
anim = new TranslateAnimation(c, attrs);
} else {
try {
anim = (Animation) Class.forName(name).getConstructor(Context.class, AttributeSet.class).newInstance(c, attrs);
} catch (Exception te) {
throw new RuntimeException("Unknown animation name: " + parser.getName() + " error:" + te.getMessage());
}
switch (name) {
case "set":
anim = new AnimationSet(c, attrs);
createAnimationFromXml(c, parser, (AnimationSet) anim, attrs);
break;
case "alpha":
anim = new AlphaAnimation(c, attrs);
break;
case "scale":
anim = new ScaleAnimation(c, attrs);
break;
case "rotate":
anim = new RotateAnimation(c, attrs);
break;
case "translate":
anim = new TranslateAnimation(c, attrs);
break;
default:
try {
anim = (Animation) Class.forName(name).getConstructor(Context.class, AttributeSet.class).newInstance(c, attrs);
} catch (Exception te) {
throw new RuntimeException("Unknown animation name: " + parser.getName() + " error:" + te.getMessage());
}
break;
}

if (parent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class Rotate3dAnimation extends Animation {
private float mPivotXValue = 0.0f;
private float mPivotYValue = 0.0f;

private float mFromDegrees;
private float mToDegrees;
private final float mFromDegrees;
private final float mToDegrees;
private float mPivotX;
private float mPivotY;
private Camera mCamera;
private int mRollType;
private final int mRollType;

public static final int ROLL_BY_X = 0;
public static final int ROLL_BY_Y = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.view.animation.Animation;
import android.view.animation.Transformation;

import androidx.annotation.NonNull;

public class SuccessTickView extends View {
private float mDensity = -1;
private Paint mPaint;
Expand Down Expand Up @@ -43,29 +45,25 @@ private void init () {
}

@Override
public void draw(Canvas canvas) {
public void draw(@NonNull Canvas canvas) {
super.draw(canvas);
int totalW = getWidth();
int totalH = getHeight();
// rotate canvas first
canvas.rotate(45, totalW / 2, totalH / 2);
canvas.rotate(45, (float) totalW / 2, (float) totalH / 2);

totalW /= 1.2;
totalH /= 1.4;
mMaxLeftRectWidth = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;

RectF leftRect = new RectF();
if (mLeftRectGrowMode) {
leftRect.left = 0;
leftRect.right = leftRect.left + mLeftRectWidth;
leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
} else {
leftRect.right = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
leftRect.left = leftRect.right - mLeftRectWidth;
leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
}
leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;

canvas.drawRoundRect(leftRect, CONST_RADIUS, CONST_RADIUS, mPaint);

Expand Down Expand Up @@ -103,7 +101,7 @@ protected void applyTransformation(float interpolatedTime, Transformation t) {
} else if (0.7 < interpolatedTime && 0.84 >= interpolatedTime) { // shorten left rect from right, still grow right rect
mLeftRectGrowMode = false;
mLeftRectWidth = mMaxLeftRectWidth * (1 - ((interpolatedTime - 0.7f) / 0.14f));
mLeftRectWidth = mLeftRectWidth < MIN_LEFT_RECT_W ? MIN_LEFT_RECT_W : mLeftRectWidth;
mLeftRectWidth = Math.max(mLeftRectWidth, MIN_LEFT_RECT_W);
mRightRectWidth = MAX_RIGHT_RECT_W * ((interpolatedTime - 0.65f) / 0.19f);
invalidate();
} else if (0.84 < interpolatedTime && 1 >= interpolatedTime) { // restore left rect width, shorten right rect to const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,26 @@
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.Transformation;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.materialprogress.mylibrary.ProgressWheel;

import java.util.List;

public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private View mDialogView;
private AnimationSet mModalInAnim;
private AnimationSet mModalOutAnim;
private Animation mOverlayOutAnim;
private Animation mErrorInAnim;
private AnimationSet mErrorXInAnim;
private AnimationSet mSuccessLayoutAnimSet;
private Animation mSuccessBowAnim;
private final AnimationSet mModalInAnim;
private final AnimationSet mModalOutAnim;
private final Animation mOverlayOutAnim;
private final Animation mErrorInAnim;
private final AnimationSet mErrorXInAnim;
private final AnimationSet mSuccessLayoutAnimSet;
private final Animation mSuccessBowAnim;
private TextView mTitleTextView;
private TextView mContentTextView;
private String mTitleText;
Expand All @@ -48,7 +43,7 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private ImageView mCustomImage;
private Button mConfirmButton;
private Button mCancelButton;
private ProgressHelper mProgressHelper;
private final ProgressHelper mProgressHelper;
private FrameLayout mWarningFrame;
private OnSweetClickListener mCancelClickListener;
private OnSweetClickListener mConfirmClickListener;
Expand Down Expand Up @@ -79,18 +74,6 @@ public SweetAlertDialog(Context context, int alertType) {
mErrorXInAnim = (AnimationSet)OptAnimationLoader.loadAnimation(getContext(), R.anim.error_x_in);
// 2.3.x system don't support alpha-animation on layer-list drawable
// remove it from animation set
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
List<Animation> childAnims = mErrorXInAnim.getAnimations();
int idx = 0;
for (;idx < childAnims.size();idx++) {
if (childAnims.get(idx) instanceof AlphaAnimation) {
break;
}
}
if (idx < childAnims.size()) {
childAnims.remove(idx);
}
}
mSuccessBowAnim = OptAnimationLoader.loadAnimation(getContext(), R.anim.success_bow_roate);
mSuccessLayoutAnimSet = (AnimationSet)OptAnimationLoader.loadAnimation(getContext(), R.anim.success_mask_layout);
mModalInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_in);
Expand All @@ -104,14 +87,11 @@ public void onAnimationStart(Animation animation) {
@Override
public void onAnimationEnd(Animation animation) {
mDialogView.setVisibility(View.GONE);
mDialogView.post(new Runnable() {
@Override
public void run() {
if (mCloseFromCancel) {
SweetAlertDialog.super.cancel();
} else {
SweetAlertDialog.super.dismiss();
}
mDialogView.post(() -> {
if (mCloseFromCancel) {
SweetAlertDialog.super.cancel();
} else {
SweetAlertDialog.super.dismiss();
}
});
}
Expand All @@ -138,20 +118,20 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.alert_dialog);

mDialogView = getWindow().getDecorView().findViewById(android.R.id.content);
mTitleTextView = (TextView)findViewById(R.id.title_text);
mContentTextView = (TextView)findViewById(R.id.content_text);
mErrorFrame = (FrameLayout)findViewById(R.id.error_frame);
mErrorX = (ImageView)mErrorFrame.findViewById(R.id.error_x);
mSuccessFrame = (FrameLayout)findViewById(R.id.success_frame);
mProgressFrame = (FrameLayout)findViewById(R.id.progress_dialog);
mSuccessTick = (SuccessTickView)mSuccessFrame.findViewById(R.id.success_tick);
mTitleTextView = findViewById(R.id.title_text);
mContentTextView = findViewById(R.id.content_text);
mErrorFrame = findViewById(R.id.error_frame);
mErrorX = mErrorFrame.findViewById(R.id.error_x);
mSuccessFrame = findViewById(R.id.success_frame);
mProgressFrame = findViewById(R.id.progress_dialog);
mSuccessTick = mSuccessFrame.findViewById(R.id.success_tick);
mSuccessLeftMask = mSuccessFrame.findViewById(R.id.mask_left);
mSuccessRightMask = mSuccessFrame.findViewById(R.id.mask_right);
mCustomImage = (ImageView)findViewById(R.id.custom_image);
mWarningFrame = (FrameLayout)findViewById(R.id.warning_frame);
mConfirmButton = (Button)findViewById(R.id.confirm_button);
mCancelButton = (Button)findViewById(R.id.cancel_button);
mProgressHelper.setProgressWheel((ProgressWheel)findViewById(R.id.progressWheel));
mCustomImage = findViewById(R.id.custom_image);
mWarningFrame = findViewById(R.id.warning_frame);
mConfirmButton = findViewById(R.id.confirm_button);
mCancelButton = findViewById(R.id.cancel_button);
mProgressHelper.setProgressWheel(findViewById(R.id.progressWheel));
mConfirmButton.setOnClickListener(this);
mCancelButton.setOnClickListener(this);

Expand Down Expand Up @@ -225,19 +205,11 @@ private void changeAlertType(int alertType, boolean fromCreate) {
}
}

public int getAlerType () {
return mAlertType;
}

public void changeAlertType(int alertType) {
changeAlertType(alertType, false);
}


public String getTitleText () {
return mTitleText;
}

public SweetAlertDialog setTitleText (String text) {
mTitleText = text;
if (mTitleTextView != null && mTitleText != null) {
Expand All @@ -259,10 +231,6 @@ public SweetAlertDialog setCustomImage (int resourceId) {
return setCustomImage(getContext().getResources().getDrawable(resourceId));
}

public String getContentText () {
return mContentText;
}

public SweetAlertDialog setContentText (String text) {
mContentText = text;
if (mContentTextView != null && mContentText != null) {
Expand All @@ -272,10 +240,6 @@ public SweetAlertDialog setContentText (String text) {
return this;
}

public boolean isShowCancelButton () {
return mShowCancel;
}

public SweetAlertDialog showCancelButton (boolean isShow) {
mShowCancel = isShow;
if (mCancelButton != null) {
Expand All @@ -284,20 +248,11 @@ public SweetAlertDialog showCancelButton (boolean isShow) {
return this;
}

public boolean isShowContentText () {
return mShowContent;
}

public SweetAlertDialog showContentText (boolean isShow) {
public void showContentText (boolean isShow) {
mShowContent = isShow;
if (mContentTextView != null) {
mContentTextView.setVisibility(mShowContent ? View.VISIBLE : View.GONE);
}
return this;
}

public String getCancelText () {
return mCancelText;
}

public SweetAlertDialog setCancelText (String text) {
Expand All @@ -309,10 +264,6 @@ public SweetAlertDialog setCancelText (String text) {
return this;
}

public String getConfirmText () {
return mConfirmText;
}

public SweetAlertDialog setConfirmText (String text) {
mConfirmText = text;
if (mConfirmButton != null && mConfirmText != null) {
Expand Down
Loading

0 comments on commit f709441

Please sign in to comment.