├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── luck │ │ └── custom │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── luck │ │ │ └── custom │ │ │ ├── MainActivity.java │ │ │ ├── dialog │ │ │ ├── Indeterminate.java │ │ │ ├── OptAnimationLoader.java │ │ │ ├── SpinView.java │ │ │ ├── SuccessTickView.java │ │ │ └── SweetAlertDialog.java │ │ │ └── toast │ │ │ ├── T.java │ │ │ ├── TPrompt.java │ │ │ ├── TPromptError.java │ │ │ └── TPromptSuccess.java │ └── res │ │ ├── anim │ │ ├── modal_in.xml │ │ └── modal_out.xml │ │ ├── drawable │ │ ├── book_reading_toast_bg.xml │ │ └── dialog_custom_bg.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── alert_dialog.xml │ │ ├── book_reading_seekbar_toast.xml │ │ ├── book_reading_toast.xml │ │ └── book_reading_toast_error.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── jg_hud_error_3x.png │ │ ├── kprogresshud_spinner.png │ │ └── success_1x.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── luck │ └── custom │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot ├── image1.jpg ├── image2.jpg ├── image3.jpg └── image4.jpg └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | CustomView -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Android 46 | 47 | 48 | Android > Lint > Correctness 49 | 50 | 51 | Android > Lint > Performance 52 | 53 | 54 | C/C++ 55 | 56 | 57 | Class structureJava 58 | 59 | 60 | Control flow issuesJava 61 | 62 | 63 | CorrectnessLintAndroid 64 | 65 | 66 | Error handlingJava 67 | 68 | 69 | General 70 | 71 | 72 | Groovy 73 | 74 | 75 | HTML 76 | 77 | 78 | ImportsJava 79 | 80 | 81 | Internationalization issues 82 | 83 | 84 | Internationalization issuesJava 85 | 86 | 87 | J2ME issuesJava 88 | 89 | 90 | JSON 91 | 92 | 93 | Java 94 | 95 | 96 | Javadoc issuesJava 97 | 98 | 99 | LintAndroid 100 | 101 | 102 | Manifest 103 | 104 | 105 | OtherGroovy 106 | 107 | 108 | Portability issuesJava 109 | 110 | 111 | Potentially confusing code constructsGroovy 112 | 113 | 114 | Probable bugsJava 115 | 116 | 117 | Properties Files 118 | 119 | 120 | Properties FilesJava 121 | 122 | 123 | RELAX NG 124 | 125 | 126 | Resource management issuesJava 127 | 128 | 129 | Threading issuesJava 130 | 131 | 132 | Unused codeC/C++ 133 | 134 | 135 | Validity issuesGroovy 136 | 137 | 138 | XML 139 | 140 | 141 | 142 | 143 | Android 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 165 | 166 | $USER_HOME$/.subversion 167 | 168 | 169 | 170 | 171 | 172 | 1.6 173 | 174 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CustomView 2 | android仿ios弹框效果 3 | ![image](https://github.com/LuckSiege/CustomView/blob/master/screenshot/image1.jpg) 4 | ![image](https://github.com/LuckSiege/CustomView/blob/master/screenshot/image2.jpg) 5 | ![image](https://github.com/LuckSiege/CustomView/blob/master/screenshot/image3.jpg) 6 | ![image](https://github.com/LuckSiege/CustomView/blob/master/screenshot/image4.jpg) 7 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.luck.custom" 9 | minSdkVersion 16 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/luck/Documents/android-sdk-macosx-2/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/luck/custom/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.luck.custom; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.luck.custom; 2 | 3 | import android.os.Handler; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | import com.luck.custom.dialog.SweetAlertDialog; 9 | import com.luck.custom.toast.T; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | private Handler handler = new Handler(); 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | findViewById(R.id.btn_ios_dialog).setOnClickListener(new View.OnClickListener() { 20 | @Override 21 | public void onClick(View view) { 22 | final SweetAlertDialog dialog = new SweetAlertDialog(MainActivity.this); 23 | dialog.setTitleText("请稍候..."); 24 | dialog.show(); 25 | 26 | handler.postDelayed(new Runnable() { 27 | @Override 28 | public void run() { 29 | dialog.cancel(); 30 | } 31 | }, 2000); 32 | } 33 | }); 34 | 35 | findViewById(R.id.btn_ios_toast).setOnClickListener(new View.OnClickListener() { 36 | @Override 37 | public void onClick(View view) { 38 | T.showAnimToast(MainActivity.this, "恭喜您,注册成功了!"); 39 | } 40 | }); 41 | 42 | findViewById(R.id.btn_ios_toast_success).setOnClickListener(new View.OnClickListener() { 43 | @Override 44 | public void onClick(View view) { 45 | T.showAnimSuccessToast(MainActivity.this, "保存成功"); 46 | } 47 | }); 48 | 49 | findViewById(R.id.btn_ios_toast_error).setOnClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View view) { 52 | T.showAnimErrorToast(MainActivity.this, "修改失败"); 53 | } 54 | }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/dialog/Indeterminate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kaopiz Software Co., Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.luck.custom.dialog; 18 | 19 | /** 20 | * If a view implements this interface passed to the HUD as a custom view, its animation 21 | * speed can be change by calling setAnimationSpeed() on the HUD. 22 | * This interface only provides convenience, how animation speed work depends on the view implementation. 23 | */ 24 | public interface Indeterminate { 25 | void setAnimationSpeed(float scale); 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/dialog/OptAnimationLoader.java: -------------------------------------------------------------------------------- 1 | package com.luck.custom.dialog; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.content.res.XmlResourceParser; 6 | import android.util.AttributeSet; 7 | import android.util.Xml; 8 | import android.view.animation.AlphaAnimation; 9 | import android.view.animation.Animation; 10 | import android.view.animation.AnimationSet; 11 | import android.view.animation.RotateAnimation; 12 | import android.view.animation.ScaleAnimation; 13 | import android.view.animation.TranslateAnimation; 14 | 15 | import org.xmlpull.v1.XmlPullParser; 16 | import org.xmlpull.v1.XmlPullParserException; 17 | 18 | import java.io.IOException; 19 | 20 | public class OptAnimationLoader { 21 | 22 | public static Animation loadAnimation(Context context, int id) 23 | throws Resources.NotFoundException { 24 | 25 | XmlResourceParser parser = null; 26 | try { 27 | parser = context.getResources().getAnimation(id); 28 | return createAnimationFromXml(context, parser); 29 | } catch (XmlPullParserException ex) { 30 | Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + 31 | Integer.toHexString(id)); 32 | rnf.initCause(ex); 33 | throw rnf; 34 | } catch (IOException ex) { 35 | Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + 36 | Integer.toHexString(id)); 37 | rnf.initCause(ex); 38 | throw rnf; 39 | } finally { 40 | if (parser != null) parser.close(); 41 | } 42 | } 43 | 44 | private static Animation createAnimationFromXml(Context c, XmlPullParser parser) 45 | throws XmlPullParserException, IOException { 46 | 47 | return createAnimationFromXml(c, parser, null, Xml.asAttributeSet(parser)); 48 | } 49 | 50 | private static Animation createAnimationFromXml(Context c, XmlPullParser parser, 51 | AnimationSet parent, AttributeSet attrs) throws XmlPullParserException, IOException { 52 | 53 | Animation anim = null; 54 | 55 | // Make sure we are on a start tag. 56 | int type; 57 | int depth = parser.getDepth(); 58 | 59 | while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) 60 | && type != XmlPullParser.END_DOCUMENT) { 61 | 62 | if (type != XmlPullParser.START_TAG) { 63 | continue; 64 | } 65 | 66 | String name = parser.getName(); 67 | 68 | if (name.equals("set")) { 69 | anim = new AnimationSet(c, attrs); 70 | createAnimationFromXml(c, parser, (AnimationSet)anim, attrs); 71 | } else if (name.equals("alpha")) { 72 | anim = new AlphaAnimation(c, attrs); 73 | } else if (name.equals("scale")) { 74 | anim = new ScaleAnimation(c, attrs); 75 | } else if (name.equals("rotate")) { 76 | anim = new RotateAnimation(c, attrs); 77 | } else if (name.equals("translate")) { 78 | anim = new TranslateAnimation(c, attrs); 79 | } else { 80 | try { 81 | anim = (Animation) Class.forName(name).getConstructor(Context.class, AttributeSet.class).newInstance(c, attrs); 82 | } catch (Exception te) { 83 | throw new RuntimeException("Unknown animation name: " + parser.getName() + " error:" + te.getMessage()); 84 | } 85 | } 86 | 87 | if (parent != null) { 88 | parent.addAnimation(anim); 89 | } 90 | } 91 | 92 | return anim; 93 | 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/dialog/SpinView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Kaopiz Software Co., Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.luck.custom.dialog; 18 | 19 | import android.content.Context; 20 | import android.graphics.Canvas; 21 | import android.util.AttributeSet; 22 | import android.widget.ImageView; 23 | 24 | import com.luck.custom.R; 25 | 26 | class SpinView extends ImageView implements Indeterminate { 27 | 28 | private float mRotateDegrees; 29 | private int mFrameTime; 30 | private boolean mNeedToUpdateView; 31 | private Runnable mUpdateViewRunnable; 32 | 33 | public SpinView(Context context) { 34 | super(context); 35 | init(); 36 | } 37 | 38 | public SpinView(Context context, AttributeSet attrs) { 39 | super(context, attrs); 40 | init(); 41 | } 42 | 43 | private void init() { 44 | setImageResource(R.mipmap.kprogresshud_spinner); 45 | mFrameTime = 1000 / 12; 46 | mUpdateViewRunnable = new Runnable() { 47 | @Override 48 | public void run() { 49 | mRotateDegrees += 30; 50 | mRotateDegrees = mRotateDegrees < 360 ? mRotateDegrees : mRotateDegrees - 360; 51 | invalidate(); 52 | if (mNeedToUpdateView) { 53 | postDelayed(this, mFrameTime); 54 | } 55 | } 56 | }; 57 | } 58 | 59 | @Override 60 | public void setAnimationSpeed(float scale) { 61 | mFrameTime = (int) (1000 / 12 / scale); 62 | } 63 | 64 | @Override 65 | protected void onDraw(Canvas canvas) { 66 | canvas.rotate(mRotateDegrees, getWidth() / 2, getHeight() / 2); 67 | super.onDraw(canvas); 68 | } 69 | 70 | @Override 71 | protected void onAttachedToWindow() { 72 | super.onAttachedToWindow(); 73 | mNeedToUpdateView = true; 74 | post(mUpdateViewRunnable); 75 | } 76 | 77 | @Override 78 | protected void onDetachedFromWindow() { 79 | mNeedToUpdateView = false; 80 | super.onDetachedFromWindow(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/dialog/SuccessTickView.java: -------------------------------------------------------------------------------- 1 | package com.luck.custom.dialog; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Paint; 6 | import android.graphics.RectF; 7 | import android.support.v4.content.ContextCompat; 8 | import android.util.AttributeSet; 9 | import android.view.View; 10 | import android.view.animation.Animation; 11 | import android.view.animation.Transformation; 12 | 13 | import com.luck.custom.R; 14 | 15 | public class SuccessTickView extends View { 16 | private float mDensity = -1; 17 | private Paint mPaint; 18 | private final float CONST_RADIUS = dip2px(1.2f); 19 | private final float CONST_RECT_WEIGHT = dip2px(3); 20 | private final float CONST_LEFT_RECT_W = dip2px(15); 21 | private final float CONST_RIGHT_RECT_W = dip2px(25); 22 | private final float MIN_LEFT_RECT_W = dip2px(3.3f); 23 | private final float MAX_RIGHT_RECT_W = CONST_RIGHT_RECT_W + dip2px(6.7f); 24 | private Context context; 25 | private float mMaxLeftRectWidth; 26 | private float mLeftRectWidth; 27 | private float mRightRectWidth; 28 | private boolean mLeftRectGrowMode; 29 | 30 | public SuccessTickView(Context context) { 31 | super(context); 32 | this.context = context; 33 | init(); 34 | } 35 | 36 | public SuccessTickView(Context context, AttributeSet attrs) { 37 | super(context, attrs); 38 | this.context = context; 39 | init(); 40 | } 41 | 42 | private void init() { 43 | mPaint = new Paint(); 44 | mPaint.setColor(ContextCompat.getColor(context, R.color.success_stroke_color)); 45 | mLeftRectWidth = CONST_LEFT_RECT_W; 46 | mRightRectWidth = CONST_RIGHT_RECT_W; 47 | mLeftRectGrowMode = false; 48 | } 49 | 50 | @Override 51 | public void draw(Canvas canvas) { 52 | super.draw(canvas); 53 | int totalW = getWidth(); 54 | int totalH = getHeight(); 55 | // rotate canvas first 56 | canvas.rotate(45, totalW / 2, totalH / 2); 57 | 58 | totalW /= 1.2; 59 | totalH /= 1.4; 60 | mMaxLeftRectWidth = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1; 61 | 62 | RectF leftRect = new RectF(); 63 | if (mLeftRectGrowMode) { 64 | leftRect.left = 0; 65 | leftRect.right = leftRect.left + mLeftRectWidth; 66 | leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2; 67 | leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT; 68 | } else { 69 | leftRect.right = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1; 70 | leftRect.left = leftRect.right - mLeftRectWidth; 71 | leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2; 72 | leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT; 73 | } 74 | 75 | canvas.drawRoundRect(leftRect, CONST_RADIUS, CONST_RADIUS, mPaint); 76 | 77 | RectF rightRect = new RectF(); 78 | rightRect.bottom = (totalH + CONST_RIGHT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1; 79 | rightRect.left = (totalW + CONST_LEFT_RECT_W) / 2; 80 | rightRect.right = rightRect.left + CONST_RECT_WEIGHT; 81 | rightRect.top = rightRect.bottom - mRightRectWidth; 82 | canvas.drawRoundRect(rightRect, CONST_RADIUS, CONST_RADIUS, mPaint); 83 | } 84 | 85 | public float dip2px(float dpValue) { 86 | if (mDensity == -1) { 87 | mDensity = getResources().getDisplayMetrics().density; 88 | } 89 | return dpValue * mDensity + 0.5f; 90 | } 91 | 92 | public void startTickAnim() { 93 | // hide tick 94 | mLeftRectWidth = 0; 95 | mRightRectWidth = 0; 96 | invalidate(); 97 | Animation tickAnim = new Animation() { 98 | @Override 99 | protected void applyTransformation(float interpolatedTime, Transformation t) { 100 | super.applyTransformation(interpolatedTime, t); 101 | if (0.54 < interpolatedTime && 0.7 >= interpolatedTime) { // grow left and right rect to right 102 | mLeftRectGrowMode = true; 103 | mLeftRectWidth = mMaxLeftRectWidth * ((interpolatedTime - 0.54f) / 0.16f); 104 | if (0.65 < interpolatedTime) { 105 | mRightRectWidth = MAX_RIGHT_RECT_W * ((interpolatedTime - 0.65f) / 0.19f); 106 | } 107 | invalidate(); 108 | } else if (0.7 < interpolatedTime && 0.84 >= interpolatedTime) { // shorten left rect from right, still grow right rect 109 | mLeftRectGrowMode = false; 110 | mLeftRectWidth = mMaxLeftRectWidth * (1 - ((interpolatedTime - 0.7f) / 0.14f)); 111 | mLeftRectWidth = mLeftRectWidth < MIN_LEFT_RECT_W ? MIN_LEFT_RECT_W : mLeftRectWidth; 112 | mRightRectWidth = MAX_RIGHT_RECT_W * ((interpolatedTime - 0.65f) / 0.19f); 113 | invalidate(); 114 | } else if (0.84 < interpolatedTime && 1 >= interpolatedTime) { // restore left rect width, shorten right rect to const 115 | mLeftRectGrowMode = false; 116 | mLeftRectWidth = MIN_LEFT_RECT_W + (CONST_LEFT_RECT_W - MIN_LEFT_RECT_W) * ((interpolatedTime - 0.84f) / 0.16f); 117 | mRightRectWidth = CONST_RIGHT_RECT_W + (MAX_RIGHT_RECT_W - CONST_RIGHT_RECT_W) * (1 - ((interpolatedTime - 0.84f) / 0.16f)); 118 | invalidate(); 119 | } 120 | } 121 | }; 122 | tickAnim.setDuration(750); 123 | tickAnim.setStartOffset(100); 124 | startAnimation(tickAnim); 125 | } 126 | } -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/dialog/SweetAlertDialog.java: -------------------------------------------------------------------------------- 1 | package com.luck.custom.dialog; 2 | 3 | 4 | import android.app.Dialog; 5 | import android.content.Context; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.view.WindowManager; 9 | import android.view.animation.Animation; 10 | import android.view.animation.AnimationSet; 11 | import android.view.animation.Transformation; 12 | import android.widget.TextView; 13 | 14 | import com.luck.custom.R; 15 | 16 | public class SweetAlertDialog extends Dialog { 17 | private View mDialogView; 18 | private AnimationSet mModalInAnim; 19 | private AnimationSet mModalOutAnim; 20 | private Animation mOverlayOutAnim; 21 | private TextView mTitleTextView; 22 | private String mTitleText; 23 | private boolean mCloseFromCancel; 24 | public Context context; 25 | 26 | public SweetAlertDialog(Context context) { 27 | super(context, R.style.alert_dialog); 28 | this.context = context; 29 | setCancelable(true); 30 | setCanceledOnTouchOutside(false); 31 | mModalInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_in); 32 | mModalOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_out); 33 | mModalOutAnim.setAnimationListener(new Animation.AnimationListener() { 34 | @Override 35 | public void onAnimationStart(Animation animation) { 36 | 37 | } 38 | 39 | @Override 40 | public void onAnimationEnd(Animation animation) { 41 | mDialogView.setVisibility(View.INVISIBLE); 42 | mDialogView.post(new Runnable() { 43 | @Override 44 | public void run() { 45 | if (mCloseFromCancel) { 46 | SweetAlertDialog.super.cancel(); 47 | } else { 48 | SweetAlertDialog.super.dismiss(); 49 | } 50 | } 51 | }); 52 | } 53 | 54 | @Override 55 | public void onAnimationRepeat(Animation animation) { 56 | 57 | } 58 | }); 59 | // dialog overlay fade out 60 | mOverlayOutAnim = new Animation() { 61 | @Override 62 | protected void applyTransformation(float interpolatedTime, Transformation t) { 63 | WindowManager.LayoutParams wlp = getWindow().getAttributes(); 64 | wlp.alpha = 1 - interpolatedTime; 65 | getWindow().setAttributes(wlp); 66 | } 67 | }; 68 | mOverlayOutAnim.setDuration(120); 69 | } 70 | 71 | 72 | protected void onCreate(Bundle savedInstanceState) { 73 | super.onCreate(savedInstanceState); 74 | setContentView(R.layout.alert_dialog); 75 | 76 | mDialogView = getWindow().getDecorView().findViewById(android.R.id.content); 77 | mTitleTextView = (TextView) findViewById(R.id.title_text); 78 | setTitleText(mTitleText); 79 | } 80 | 81 | public String getTitleText() { 82 | return mTitleText; 83 | } 84 | 85 | public SweetAlertDialog setTitleText(String text) { 86 | mTitleText = text; 87 | if (mTitleTextView != null && mTitleText != null) { 88 | mTitleTextView.setText(mTitleText); 89 | } 90 | return this; 91 | } 92 | 93 | 94 | protected void onStart() { 95 | mDialogView.startAnimation(mModalInAnim); 96 | } 97 | 98 | /** 99 | * The real Dialog.cancel() will be invoked async-ly after the animation finishes. 100 | */ 101 | @Override 102 | public void cancel() { 103 | dismissWithAnimation(true); 104 | } 105 | 106 | /** 107 | * The real Dialog.dismiss() will be invoked async-ly after the animation finishes. 108 | */ 109 | public void dismissWithAnimation() { 110 | dismissWithAnimation(false); 111 | } 112 | 113 | private void dismissWithAnimation(boolean fromCancel) { 114 | mCloseFromCancel = fromCancel; 115 | mDialogView.startAnimation(mModalOutAnim); 116 | } 117 | } -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/toast/T.java: -------------------------------------------------------------------------------- 1 | package com.luck.custom.toast; 2 | 3 | import android.content.Context; 4 | import android.widget.Toast; 5 | 6 | /** 7 | * @author lmw 8 | * @ClassName: T 9 | * @Description: TODO(这里用一句话描述这个类的作用) 10 | * @date 2015年3月28日 下午5:34:58 11 | */ 12 | public class T { 13 | public static TPrompt tPrompt; 14 | public static TPromptSuccess tPromptSuccess; 15 | public static TPromptError tPromptError; 16 | 17 | public static void showToast(Context context, String msg) { 18 | Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); 19 | } 20 | 21 | public static void showAnimToast(Context mContext, String msg) { 22 | if (!isFastDoubleClick()) { 23 | if (tPrompt == null) { 24 | tPrompt = new TPrompt(mContext); 25 | } 26 | tPrompt.showToast(msg); 27 | } 28 | } 29 | 30 | public static void showAnimSuccessToast(Context mContext, String msg) { 31 | if (!isFastDoubleClick()) { 32 | if (tPromptSuccess == null) { 33 | tPromptSuccess = new TPromptSuccess(mContext); 34 | } 35 | tPromptSuccess.showToast(msg); 36 | } 37 | } 38 | 39 | public static void showAnimErrorToast(Context mContext, String msg) { 40 | if (!isFastDoubleClick()) { 41 | if (tPromptError == null) { 42 | tPromptError = new TPromptError(mContext); 43 | } 44 | tPromptError.showToast(msg); 45 | } 46 | } 47 | 48 | protected static long lastClickTime; 49 | 50 | protected static boolean isFastDoubleClick() { 51 | long time = System.currentTimeMillis(); 52 | if (time - lastClickTime < 500) { 53 | return true; 54 | } 55 | lastClickTime = time; 56 | return false; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/toast/TPrompt.java: -------------------------------------------------------------------------------- 1 | package com.luck.custom.toast; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.view.Gravity; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.animation.AnimationSet; 9 | import android.widget.RelativeLayout; 10 | import android.widget.TextView; 11 | import android.widget.Toast; 12 | 13 | import com.luck.custom.R; 14 | import com.luck.custom.dialog.OptAnimationLoader; 15 | 16 | /** 17 | * author:luck 18 | * project:EasyFoodBatch 19 | * package:com.luck.easyfoodbatch.util 20 | * email:893855882@qq.com 21 | * data:16/12/16 22 | */ 23 | public class TPrompt extends Toast { 24 | private Context mContext; 25 | private AnimationSet mModalInAnim; 26 | private AnimationSet mModalOutAnim; 27 | private TextView chapterNameTV; 28 | private RelativeLayout rl_root; 29 | private Handler handler = new Handler(); 30 | 31 | public TPrompt(Context context) { 32 | super(context); 33 | this.mContext = context; 34 | mModalInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(mContext, R.anim.modal_in); 35 | mModalOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(mContext, R.anim.modal_out); 36 | initView(); 37 | } 38 | 39 | protected void initView() { 40 | LayoutInflater inflater = LayoutInflater.from(mContext); 41 | View view = inflater.inflate(R.layout.book_reading_toast, null); 42 | rl_root = (RelativeLayout) view.findViewById(R.id.rl_root); 43 | chapterNameTV = (TextView) view.findViewById(R.id.chapterName); 44 | setGravity(Gravity.CENTER, 0, 0); 45 | setDuration(Toast.LENGTH_LONG); 46 | setView(view); 47 | } 48 | 49 | /** 50 | * 文字提示 51 | * 52 | * @param msg 53 | */ 54 | public void showToast(String msg) { 55 | if (chapterNameTV != null) { 56 | show(); 57 | chapterNameTV.setText(msg); 58 | mModalInAnim.setDuration(250); 59 | rl_root.setVisibility(View.VISIBLE); 60 | rl_root.startAnimation(mModalInAnim); 61 | handler.postDelayed(new Runnable() { 62 | @Override 63 | public void run() { 64 | rl_root.setVisibility(View.INVISIBLE); 65 | rl_root.startAnimation(mModalOutAnim); 66 | } 67 | }, 1000); 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/toast/TPromptError.java: -------------------------------------------------------------------------------- 1 | package com.luck.custom.toast; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.view.Gravity; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.animation.AnimationSet; 9 | import android.widget.RelativeLayout; 10 | import android.widget.TextView; 11 | import android.widget.Toast; 12 | 13 | import com.luck.custom.R; 14 | import com.luck.custom.dialog.OptAnimationLoader; 15 | 16 | /** 17 | * author:luck 18 | * project:EasyFoodBatch 19 | * package:com.luck.easyfoodbatch.util 20 | * email:893855882@qq.com 21 | * data:16/12/16 22 | */ 23 | public class TPromptError extends Toast { 24 | private Context mContext; 25 | private AnimationSet mModalInAnim; 26 | private AnimationSet mModalOutAnim; 27 | private TextView chapterNameTV; 28 | private RelativeLayout rl_root; 29 | private Handler handler = new Handler(); 30 | 31 | public TPromptError(Context context) { 32 | super(context); 33 | this.mContext = context; 34 | mModalInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(mContext, R.anim.modal_in); 35 | mModalOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(mContext, R.anim.modal_out); 36 | initView(); 37 | } 38 | 39 | protected void initView() { 40 | LayoutInflater inflater = LayoutInflater.from(mContext); 41 | View view = inflater.inflate(R.layout.book_reading_toast_error, null); 42 | rl_root = (RelativeLayout) view.findViewById(R.id.rl_root); 43 | chapterNameTV = (TextView) view.findViewById(R.id.chapterName); 44 | setGravity(Gravity.CENTER, 0, 0); 45 | setDuration(Toast.LENGTH_LONG); 46 | setView(view); 47 | 48 | } 49 | 50 | 51 | public void showToast(String msg) { 52 | if (chapterNameTV != null) { 53 | chapterNameTV.setText(msg); 54 | mModalInAnim.setDuration(250); 55 | rl_root.setVisibility(View.VISIBLE); 56 | rl_root.startAnimation(mModalInAnim); 57 | show(); 58 | handler.postDelayed(new Runnable() { 59 | @Override 60 | public void run() { 61 | rl_root.setVisibility(View.INVISIBLE); 62 | rl_root.startAnimation(mModalOutAnim); 63 | } 64 | }, 1000); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/luck/custom/toast/TPromptSuccess.java: -------------------------------------------------------------------------------- 1 | package com.luck.custom.toast; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.view.Gravity; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.animation.AnimationSet; 9 | import android.widget.RelativeLayout; 10 | import android.widget.TextView; 11 | import android.widget.Toast; 12 | 13 | import com.luck.custom.R; 14 | import com.luck.custom.dialog.OptAnimationLoader; 15 | 16 | /** 17 | * author:luck 18 | * project:EasyFoodBatch 19 | * package:com.luck.easyfoodbatch.util 20 | * email:893855882@qq.com 21 | * data:16/12/16 22 | */ 23 | public class TPromptSuccess extends Toast { 24 | private Context mContext; 25 | private AnimationSet mModalInAnim; 26 | private AnimationSet mModalOutAnim; 27 | private TextView chapterNameTV; 28 | private RelativeLayout rl_root; 29 | private Handler handler = new Handler(); 30 | 31 | public TPromptSuccess(Context context) { 32 | super(context); 33 | this.mContext = context; 34 | mModalInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(mContext, R.anim.modal_in); 35 | mModalOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(mContext, R.anim.modal_out); 36 | initView(); 37 | } 38 | 39 | protected void initView() { 40 | LayoutInflater inflater = LayoutInflater.from(mContext); 41 | View view = inflater.inflate(R.layout.book_reading_seekbar_toast, null); 42 | rl_root = (RelativeLayout) view.findViewById(R.id.rl_root); 43 | chapterNameTV = (TextView) view.findViewById(R.id.chapterName); 44 | setGravity(Gravity.CENTER, 0, 0); 45 | setDuration(Toast.LENGTH_LONG); 46 | setView(view); 47 | 48 | } 49 | 50 | 51 | public void showToast(String msg) { 52 | if (chapterNameTV != null) { 53 | chapterNameTV.setText(msg); 54 | mModalInAnim.setDuration(250); 55 | rl_root.setVisibility(View.VISIBLE); 56 | rl_root.startAnimation(mModalInAnim); 57 | show(); 58 | handler.postDelayed(new Runnable() { 59 | @Override 60 | public void run() { 61 | rl_root.setVisibility(View.INVISIBLE); 62 | rl_root.startAnimation(mModalOutAnim); 63 | } 64 | }, 1000); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/res/anim/modal_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 10 | 11 | 19 | 20 | 29 | 30 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/anim/modal_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 14 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/book_reading_toast_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/dialog_custom_bg.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |