├── .classpath
├── .project
├── AndroidManifest.xml
├── README.md
├── ic_launcher-web.png
├── images
└── 0.gif
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── drawable
│ └── operate_background.xml
├── layout
│ ├── activity_main.xml
│ └── dialog_operate2.xml
├── menu
│ └── main.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
├── values-w820dp
│ └── dimens.xml
└── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── example
├── android_dialog
└── MainActivity.java
└── dialog
├── AnimDialog.java
└── DialogFactory.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Android_Dialog_fade_inandout
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # fade_in_out_dialog
2 | Android Dialog which has fade-in and fade-out animation (带有淡入淡出动画的Android Dialog)
3 | 效果图:
4 | 
5 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/fade_in_out_dialog/ff229b29c31359c91cde51e1537e9cd40c6ddc76/ic_launcher-web.png
--------------------------------------------------------------------------------
/images/0.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/fade_in_out_dialog/ff229b29c31359c91cde51e1537e9cd40c6ddc76/images/0.gif
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/fade_in_out_dialog/ff229b29c31359c91cde51e1537e9cd40c6ddc76/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/fade_in_out_dialog/ff229b29c31359c91cde51e1537e9cd40c6ddc76/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/fade_in_out_dialog/ff229b29c31359c91cde51e1537e9cd40c6ddc76/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/fade_in_out_dialog/ff229b29c31359c91cde51e1537e9cd40c6ddc76/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/fade_in_out_dialog/ff229b29c31359c91cde51e1537e9cd40c6ddc76/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/operate_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/res/layout/dialog_operate2.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Android_Dialog
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/com/example/android_dialog/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.android_dialog;
2 |
3 | import android.app.Activity;
4 | import android.app.Dialog;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import com.example.dialog.DialogFactory;
10 |
11 | public class MainActivity extends Activity {
12 |
13 | private Button mButton;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_main, null);
19 | setContentView(view);
20 |
21 | mButton = (Button)findViewById(R.id.button);
22 | mButton.setOnClickListener(new View.OnClickListener() {
23 |
24 | @Override
25 | public void onClick(View v) { //创建淡入淡出的dialog,R.layout.dialog_operate2为dialog的显示布局
26 |
27 | Dialog dialog = DialogFactory.createAnimDialog(MainActivity.this, R.layout.dialog_operate2, null, android.R.anim.fade_in, android.R.anim.fade_out);
28 | dialog.show();
29 | }
30 | });
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/example/dialog/AnimDialog.java:
--------------------------------------------------------------------------------
1 | package com.example.dialog;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.view.animation.Animation;
8 | import android.view.animation.Animation.AnimationListener;
9 | import android.view.animation.AnimationUtils;
10 |
11 | /**
12 | * 可以在 “显示” 和 “隐藏” 时添加动画效果的dialog
13 | * @author Jack
14 | * @version 创建时间:2014年5月27日 下午3:26:50
15 | */
16 | public class AnimDialog extends Dialog {
17 |
18 | /** 显示时加载的动画 */
19 | private Animation anim_in;
20 | /** 隐藏时加载的动画 */
21 | private Animation anim_out;
22 | /** 显示动画监听器 */
23 | private AnimInListener animInListener;
24 | /** 隐藏动画监听器 */
25 | private AnimOutListener animOutListener;
26 |
27 | public interface IAnimDialogListener {
28 |
29 | public void onDialogInStart();
30 |
31 | public void onDialogInEnd();
32 |
33 | public void onDialogOutStart();
34 |
35 | public void onDialogOutEnd();
36 | }
37 |
38 | private IAnimDialogListener mListener;
39 |
40 | /**
41 | * @param mListener the mListener to set
42 | */
43 | public void setAnimDialogListener(IAnimDialogListener listener) {
44 | mListener = listener;
45 | }
46 |
47 | /**
48 | * @return the mListener
49 | */
50 | public IAnimDialogListener getAnimDialogListener() {
51 | return mListener;
52 | }
53 |
54 | private class AnimInListener implements AnimationListener {
55 |
56 | @Override
57 | public void onAnimationEnd(Animation animation) {
58 | if (null != mListener) {
59 | mListener.onDialogInEnd();
60 | }
61 | }
62 |
63 | @Override
64 | public void onAnimationRepeat(Animation animation) {
65 | }
66 |
67 | @Override
68 | public void onAnimationStart(Animation animation) {
69 | if (null != mListener) {
70 | mListener.onDialogInStart();
71 | }
72 | }
73 | }
74 |
75 | private class AnimOutListener implements AnimationListener {
76 |
77 | @Override
78 | public void onAnimationEnd(Animation animation) {
79 | superDismiss();
80 | if (null != mListener) {
81 | mListener.onDialogOutEnd();
82 | }
83 | }
84 |
85 | @Override
86 | public void onAnimationRepeat(Animation animation) {
87 | }
88 |
89 | @Override
90 | public void onAnimationStart(Animation animation) {
91 | if (null != mListener) {
92 | mListener.onDialogOutStart();
93 | }
94 | }
95 | }
96 |
97 | public AnimDialog(Context context, int style) {
98 | super(context, style);
99 | setCancelable(true);
100 | animInListener = new AnimInListener();
101 | animOutListener = new AnimOutListener();
102 | }
103 |
104 | public AnimDialog(Context context, int style, int anim_in, int anim_out) {
105 | this(context, style);
106 | setAnimationIn(AnimationUtils.loadAnimation(context, anim_in));
107 | setAnimationOut(AnimationUtils.loadAnimation(context, anim_out));
108 | }
109 |
110 | public void setAnimationIn(Animation in) {
111 | if (in != null) {
112 | this.anim_in = in;
113 |
114 | if (animInListener != null) {
115 | anim_in.setAnimationListener(animInListener);
116 | }
117 | }
118 | }
119 |
120 | public void setAnimationOut(Animation out) {
121 | if (null != out) {
122 | this.anim_out = out;
123 |
124 | if (animOutListener != null) {
125 | anim_out.setAnimationListener(animOutListener);
126 | }
127 | }
128 | }
129 |
130 | @Override
131 | public void show() {
132 | super.show();
133 | View dialog_root = ((ViewGroup) getWindow().getDecorView().getRootView()).getChildAt(0);
134 | if (anim_in != null) {
135 | dialog_root.startAnimation(anim_in);
136 | }
137 | }
138 |
139 | private void superDismiss() {
140 | super.dismiss();
141 | }
142 |
143 | @Override
144 | public void dismiss() {
145 | View dialog_root = ((ViewGroup) getWindow().getDecorView().getRootView()).getChildAt(0);
146 | if (anim_out != null) {
147 | dialog_root.startAnimation(anim_out);
148 | } else {
149 | superDismiss();
150 | }
151 | }
152 | }
--------------------------------------------------------------------------------
/src/com/example/dialog/DialogFactory.java:
--------------------------------------------------------------------------------
1 | package com.example.dialog;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | public class DialogFactory {
7 |
8 |
9 | /**
10 | * 根据布局文件创建支持动画的Dialog
11 | * @param ctx 上下文对象
12 | * @param layoutResID 布局文件的id
13 | * @param anim_in 进入动画的xml
14 | * @param anim_out 划出动画的xml
15 | * @return
16 | */
17 | public static AnimDialog createAnimDialog(Context ctx, int layoutResID, View view, int anim_in, int anim_out) {
18 | AnimDialog animDialog = new AnimDialog(ctx, android.R.style.Theme_Translucent_NoTitleBar, anim_in, anim_out);
19 | if (layoutResID != 0) {
20 |
21 | animDialog.setContentView(layoutResID);
22 | } else {
23 |
24 | animDialog.setContentView(view);
25 | }
26 | return animDialog;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------