├── app
├── .gitignore
├── apk
│ └── app-debug.apk
├── image
│ ├── ItemDialog.png
│ ├── AlertDialog.png
│ ├── ErrorDialog.png
│ ├── ProgressDialog.png
│ └── SuccessDialog.png
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── icon_share_wx_friends.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ ├── icon_dialog_error.png
│ │ │ │ ├── icon_dialog_success.png
│ │ │ │ ├── icon_share_wx_collect.png
│ │ │ │ ├── icon_share_wx_friends.png
│ │ │ │ └── icon_share_wx_circle_of_friends.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── anim
│ │ │ │ ├── anim_bottom_in.xml
│ │ │ │ └── anim_bottom_out.xml
│ │ │ ├── drawable
│ │ │ │ ├── background_alert_dialog.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── layout
│ │ │ │ ├── content_main.xml
│ │ │ │ ├── dialog_item.xml
│ │ │ │ ├── item_item_dialog.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── dialog_status.xml
│ │ │ │ └── dialog_alert.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── android
│ │ │ │ └── dialog
│ │ │ │ ├── base
│ │ │ │ ├── BaseAdapter.java
│ │ │ │ ├── BaseViewHolder.java
│ │ │ │ └── BaseViewHolderAdapter.java
│ │ │ │ ├── widgets
│ │ │ │ ├── itemdialog
│ │ │ │ │ ├── ItemType.java
│ │ │ │ │ ├── ItemDialogAdapter.java
│ │ │ │ │ ├── ItemBean.java
│ │ │ │ │ └── ItemDialog.java
│ │ │ │ ├── AlertDialog.java
│ │ │ │ ├── StatusDialog.java
│ │ │ │ └── Dialog.java
│ │ │ │ ├── App.java
│ │ │ │ ├── utils
│ │ │ │ └── Utils.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── android
│ │ │ └── dialog
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── android
│ │ └── dialog
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /build/
3 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/apk/app-debug.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/apk/app-debug.apk
--------------------------------------------------------------------------------
/app/image/ItemDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/image/ItemDialog.png
--------------------------------------------------------------------------------
/app/image/AlertDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/image/AlertDialog.png
--------------------------------------------------------------------------------
/app/image/ErrorDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/image/ErrorDialog.png
--------------------------------------------------------------------------------
/app/image/ProgressDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/image/ProgressDialog.png
--------------------------------------------------------------------------------
/app/image/SuccessDialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/image/SuccessDialog.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon_dialog_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xxhdpi/icon_dialog_error.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon_dialog_success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xxhdpi/icon_dialog_success.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_share_wx_friends.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xhdpi/icon_share_wx_friends.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon_share_wx_collect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xxhdpi/icon_share_wx_collect.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon_share_wx_friends.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xxhdpi/icon_share_wx_friends.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon_share_wx_circle_of_friends.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lvTravler/Android-Dialog/HEAD/app/src/main/res/mipmap-xxhdpi/icon_share_wx_circle_of_friends.png
--------------------------------------------------------------------------------
/app/src/main/res/anim/anim_bottom_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/anim_bottom_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background_alert_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Aug 24 20:20:39 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | /.idea/
15 | /.gradle/
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android Dialog
3 | Settings
4 |
5 | 微信好友
6 | 微信收藏
7 | 朋友圈
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 | #ffffff
8 | #000000
9 | #e6cdb8
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/base/BaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.base;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.annotation.Nullable;
6 |
7 | /**
8 | * BaseAdapter
9 | *
10 | * @param
11 | */
12 | public abstract class BaseAdapter extends BaseViewHolderAdapter {
13 |
14 | public BaseAdapter(Context context, int itemLayoutRes, @Nullable Object type) {
15 | super(context, itemLayoutRes, type);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/test/java/com/android/dialog/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 | 16dp
5 | 12dp
6 |
7 | 18sp
8 | 15sp
9 | 0.5sp
10 | 25dp
11 | 8dp
12 |
13 | 60dp
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/widgets/itemdialog/ItemType.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.widgets.itemdialog;
2 |
3 | /**
4 | * @Copyright (C)seengene
5 | * @Package: open.ui.widgets.itemdialog
6 | * @ClassName: ItemType
7 | * @Description: $DESC$
8 | * @Author: seengene_lvTravler
9 | * @CreateDate: 2019/8/28 16:52
10 | * @UpdateUser: 更新者:
11 | * @UpdateDate: 2019/8/28 16:52
12 | * @UpdateRemark: 更新说明:
13 | * @Version: 1.0
14 | */
15 | public @interface ItemType {
16 | /**
17 | * 微信好友
18 | */
19 | int WECHAT_FRIENDS = 0x00000001;
20 |
21 | /**
22 | * 微信朋友圈
23 | */
24 | int WECHAT_CIRCLE_OF_FRIENDS = 0x00000002;
25 |
26 | /**
27 | * 微信收藏
28 | */
29 | int WECHAT_COLLECT=0x00000003;
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/App.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | /**
7 | * @Copyright (C)seengene
8 | * @Package: com.android.dialog
9 | * @ClassName: App
10 | * @Description: $DESC$
11 | * @Author: seengene_lvTravler
12 | * @CreateDate: 2019/8/28 22:00
13 | * @UpdateUser: 更新者:
14 | * @UpdateDate: 2019/8/28 22:00
15 | * @UpdateRemark: 更新说明:
16 | * @Version: 1.0
17 | */
18 | public class App extends Application {
19 | private static Context context;
20 |
21 | @Override
22 | public void onCreate() {
23 | super.onCreate();
24 | context = this;
25 | }
26 |
27 | public static Context getContext() {
28 | return context;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/android/dialog/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.android.dialog", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
22 |
23 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | defaultConfig {
6 | applicationId "com.android.dialog"
7 | minSdkVersion 19
8 | targetSdkVersion 29
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'androidx.appcompat:appcompat:1.0.2'
24 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
25 | implementation 'com.google.android.material:material:1.0.0'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation 'androidx.test:runner:1.2.0'
28 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
29 | }
30 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/widgets/itemdialog/ItemDialogAdapter.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.widgets.itemdialog;
2 |
3 | import android.content.Context;
4 |
5 | import com.android.dialog.R;
6 | import com.android.dialog.base.BaseAdapter;
7 | import com.android.dialog.base.BaseViewHolder;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.annotation.Nullable;
11 |
12 | /**
13 | * @Copyright (C)seengene
14 | * @Package: open.ui.widgets.itemdialog
15 | * @ClassName: ItemDialogAdapter
16 | * @Description: $DESC$
17 | * @Author: seengene_lvTravler
18 | * @CreateDate: 2019/8/28 11:51
19 | * @UpdateUser: 更新者:
20 | * @UpdateDate: 2019/8/28 11:51
21 | * @UpdateRemark: 更新说明:
22 | * @Version: 1.0
23 | */
24 | public class ItemDialogAdapter extends BaseAdapter {
25 | public ItemDialogAdapter(Context context, int itemLayoutRes, @Nullable Object type) {
26 | super(context, itemLayoutRes, type);
27 | }
28 |
29 | @Override
30 | public void bind(@NonNull BaseViewHolder viewHolder, ItemBean itemData, int position) {
31 | viewHolder.setImageResource(R.id.img_item_item_dialog_icon,itemData.getIcon());
32 | viewHolder.setText(R.id.tv_item_item_dialog_name, itemData.getName());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/widgets/itemdialog/ItemBean.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.widgets.itemdialog;
2 |
3 | /**
4 | * @Copyright (C)seengene
5 | * @Package: open.ui.widgets.itemdialog
6 | * @ClassName: ItemBean
7 | * @Description: $DESC$
8 | * @Author: seengene_lvTravler
9 | * @CreateDate: 2019/8/28 11:51
10 | * @UpdateUser: 更新者:
11 | * @UpdateDate: 2019/8/28 11:51
12 | * @UpdateRemark: 更新说明:
13 | * @Version: 1.0
14 | */
15 | public class ItemBean {
16 | /**
17 | * 可用来区分点击事件对应的类型,例如分享时微信、QQ等
18 | */
19 | private int type;
20 | private String id;
21 | private int icon;
22 | private String name;
23 |
24 | public int getType() {
25 | return type;
26 | }
27 |
28 | public void setType(int type) {
29 | this.type = type;
30 | }
31 |
32 | public String getId() {
33 | return id;
34 | }
35 |
36 | public void setId(String id) {
37 | this.id = id;
38 | }
39 |
40 | public int getIcon() {
41 | return icon;
42 | }
43 |
44 | public void setIcon(int icon) {
45 | this.icon = icon;
46 | }
47 |
48 | public String getName() {
49 | return name;
50 | }
51 |
52 | public void setName(String name) {
53 | this.name = name;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_item_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.utils;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.text.TextUtils;
5 |
6 | import com.android.dialog.App;
7 | import com.android.dialog.R;
8 | import com.android.dialog.widgets.itemdialog.ItemBean;
9 | import com.android.dialog.widgets.itemdialog.ItemType;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import androidx.annotation.ColorRes;
15 | import androidx.annotation.DimenRes;
16 | import androidx.annotation.DrawableRes;
17 | import androidx.annotation.StringRes;
18 |
19 |
20 | public class Utils {
21 |
22 | public static boolean isNonEmpty(String text) {
23 | return !TextUtils.isEmpty(text);
24 | }
25 |
26 | public static String getString(@StringRes int strRes) {
27 | return App.getContext().getString(strRes);
28 | }
29 |
30 | public static Drawable getDrawable(@DrawableRes int drawableRes) {
31 | return App.getContext().getResources().getDrawable(drawableRes);
32 | }
33 |
34 | public static int getColor(@ColorRes int colorRes) {
35 | return App.getContext().getResources().getColor(colorRes);
36 | }
37 |
38 | public static float getDimen(@DimenRes int dimenRes) {
39 | return App.getContext().getResources().getDimension(dimenRes);
40 | }
41 |
42 | public static List getItemBeanList() {
43 | List data = new ArrayList<>(3);
44 |
45 | ItemBean itemBeanWxFriends = new ItemBean();
46 | itemBeanWxFriends.setIcon(R.mipmap.icon_share_wx_friends);
47 | itemBeanWxFriends.setName(getString(R.string.wechat_friends));
48 | itemBeanWxFriends.setType(ItemType.WECHAT_FRIENDS);
49 |
50 | ItemBean itemBeanCircleOfFriends = new ItemBean();
51 | itemBeanCircleOfFriends.setIcon(R.mipmap.icon_share_wx_circle_of_friends);
52 | itemBeanCircleOfFriends.setName(getString(R.string.wechat_of_circle_friends));
53 | itemBeanCircleOfFriends.setType(ItemType.WECHAT_CIRCLE_OF_FRIENDS);
54 |
55 | ItemBean itemBeanWechatCollect = new ItemBean();
56 | itemBeanWechatCollect.setIcon(R.mipmap.icon_share_wx_collect);
57 | itemBeanWechatCollect.setName(getString(R.string.wechat_collect));
58 | itemBeanWechatCollect.setType(ItemType.WECHAT_COLLECT);
59 | data.add(itemBeanWxFriends);
60 | data.add(itemBeanCircleOfFriends);
61 | data.add(itemBeanWechatCollect);
62 | return data;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android-Dialog
2 |
3 | 基于DialogFragment实现的Dialog,有以下几点优势:
4 | 1. 异常情况状态自动保存
5 | 2. show、dismiss等严格被Fragment生命周期托管,不会出现内存泄露
6 | 3. 支持自定义,扩展性高
7 |
8 | **Show**
9 |
10 | ***AlertDialog:***
11 |
12 | 
13 |
14 | ***ProgressDialog:***
15 |
16 | 
17 |
18 | ***SuccessDialog:***
19 |
20 | 
21 |
22 | ***ErrorDialog:***
23 |
24 | 
25 |
26 | ***BottomDialog:***
27 |
28 | 
29 | **Usage**
30 | ```
31 | public void showAlertDialog() {
32 | AlertDialog.with(MainActivity.this)
33 | .setCancelable(true)
34 | .setContent("Android Alert DialogFragment Content")
35 | .setTitle("AlertDialog Title")
36 | .setPositiveButton("success", new View.OnClickListener() {
37 | @Override
38 | public void onClick(View view) {
39 | showSuccessDialog();
40 | }
41 | }).setNegativeButton("error", new View.OnClickListener() {
42 | @Override
43 | public void onClick(View view) {
44 | showErrorDialog();
45 | }
46 | }).show();
47 | }
48 |
49 | public void showErrorDialog() {
50 | StatusDialog.with(MainActivity.this)
51 | .setCancelable(false)
52 | .setPrompt("load error")
53 | .setType(StatusDialog.Type.ERROR)
54 | .show();
55 | }
56 |
57 | public void showSuccessDialog() {
58 | StatusDialog.with(MainActivity.this)
59 | .setCancelable(false)
60 | .setPrompt("load success")
61 | .setType(StatusDialog.Type.SUCCESS)
62 | .show();
63 | }
64 |
65 | public void showProgressDialog() {
66 | StatusDialog.with(MainActivity.this)
67 | .setCancelable(false)
68 | .setPrompt("loading…")
69 | .setType(StatusDialog.Type.PROGRESS)
70 | .show();
71 | }
72 |
73 | public void showItemDialog() {
74 | List itemBeanList = Utils.getItemBeanList();
75 | ItemDialog.with(MainActivity.this)
76 | .setCancelable(true)
77 | .setData(itemBeanList)
78 | .setOnItemClickListener(new ItemDialog.OnItemClickListener() {
79 | @Override
80 | public void onItemClick(int position, ItemBean itemData) {
81 | showSuccessDialog();
82 | }
83 | })
84 | .setSpanCount(itemBeanList.size())
85 | .setAnimations(R.style.Dialog_Anim_Bottom_In_Bottom_Out)
86 | .setGravity(Gravity.BOTTOM)
87 | .setShowType(ItemDialog.ShowType.GRID)
88 | .show();
89 | }
90 | ```
91 |
92 | **It feels good,Please Star,Thank you!**
93 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_status.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
29 |
30 |
43 |
44 |
50 |
51 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/base/BaseViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.base;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Typeface;
5 | import android.util.SparseArray;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import com.android.dialog.utils.Utils;
11 |
12 | import androidx.annotation.ColorRes;
13 | import androidx.annotation.DimenRes;
14 | import androidx.annotation.DrawableRes;
15 | import androidx.annotation.IdRes;
16 | import androidx.annotation.IntRange;
17 | import androidx.annotation.StringRes;
18 | import androidx.recyclerview.widget.RecyclerView;
19 |
20 | /**
21 | * BaseViewHolder
22 | */
23 | public class BaseViewHolder extends RecyclerView.ViewHolder {
24 | private SparseArray mViewSparseArray;
25 |
26 | public BaseViewHolder(View itemView) {
27 | super(itemView);
28 | }
29 |
30 | public interface OnItemClickListener {
31 | void onItemClick(BaseViewHolder viewHolder, int position, T itemData, Object type);
32 |
33 | void onItemLongClick(BaseViewHolder viewHolder, int position, T itemData, Object type);
34 | }
35 |
36 | public interface OnItemViewClickListener {
37 | void onItemViewClick(BaseViewHolder viewHolder, View view, int position, T itemData, Object type);
38 |
39 | void onItemViewLongClick(BaseViewHolder viewHolder, View view, int position, T itemData, Object type);
40 | }
41 |
42 | /**
43 | * 获取Item里的控件
44 | *
45 | * @param viewId
46 | * @param
47 | * @return
48 | */
49 | public V getView(@IdRes int viewId) {
50 | if (mViewSparseArray == null) {
51 | mViewSparseArray = new SparseArray<>();
52 | }
53 | View view = mViewSparseArray.get(viewId);
54 | if (view == null) {
55 | view = itemView.findViewById(viewId);
56 | mViewSparseArray.put(viewId, view);
57 | }
58 | return (V) view;
59 | }
60 |
61 | /****************************************各种设置方法******************************************************/
62 | public void setText(@IdRes int viewId, @StringRes int text) {
63 | this.getView(viewId).setText(text);
64 | }
65 |
66 | public void setText(@IdRes int viewId, String text) {
67 | this.getView(viewId).setText(text);
68 | }
69 |
70 | public void setTextType(@IdRes int viewId, Typeface typeface) {
71 | this.getView(viewId).setTypeface(typeface);
72 | }
73 |
74 | public void setTextSize(@IdRes int viewId, @DimenRes int dimenRes) {
75 | this.getView(viewId).setTextSize(Utils.getDimen(dimenRes));
76 | }
77 |
78 | public void setTextColor(@IdRes int viewId, @ColorRes int colorRes) {
79 | this.getView(viewId).setTextColor(Utils.getColor(colorRes));
80 | }
81 |
82 | public void setImageBitmap(@IdRes int viewId, Bitmap bitmap) {
83 | this.getView(viewId).setImageBitmap(bitmap);
84 | }
85 |
86 | public void setImageResource(@IdRes int viewId, @DrawableRes int resId) {
87 | this.getView(viewId).setImageResource(resId);
88 | }
89 |
90 | public void setBackgroundColor(@IdRes int viewId, @ColorRes int colorRes) {
91 | this.getView(viewId).setBackgroundColor(Utils.getColor(colorRes));
92 | }
93 |
94 | public void setBackground(@IdRes int viewId, @DrawableRes int resId) {
95 | this.getView(viewId).setBackground(Utils.getDrawable(resId));
96 | }
97 |
98 | public void setBackgroundAlpha(@IdRes int viewId, @IntRange(from = 0, to = 255) int alpha) {
99 | this.getView(viewId).getBackground().mutate().setAlpha(alpha);
100 | }
101 |
102 | public void setCompoundDrawablesRelativeWithIntrinsicBounds(@IdRes int viewId, @DrawableRes int start,
103 | @DrawableRes int top, @DrawableRes int end, @DrawableRes int bottom) {
104 | this.getView(viewId).setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
105 | }
106 |
107 | public void setVisibility(@IdRes int viewId, boolean isShow) {
108 | if (isShow) {
109 | this.getView(viewId).setVisibility(View.VISIBLE);
110 | } else {
111 | this.getView(viewId).setVisibility(View.GONE);
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_alert.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
19 |
20 |
31 |
32 |
49 |
50 |
56 |
57 |
71 |
72 |
80 |
81 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.view.Gravity;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.View;
9 |
10 | import com.android.dialog.utils.Utils;
11 | import com.android.dialog.widgets.AlertDialog;
12 | import com.android.dialog.widgets.StatusDialog;
13 | import com.android.dialog.widgets.itemdialog.ItemBean;
14 | import com.android.dialog.widgets.itemdialog.ItemDialog;
15 | import com.google.android.material.floatingactionbutton.FloatingActionButton;
16 |
17 | import java.util.List;
18 |
19 | import androidx.appcompat.app.AppCompatActivity;
20 | import androidx.appcompat.widget.Toolbar;
21 |
22 | public class MainActivity extends AppCompatActivity {
23 |
24 | private Handler mHandler = new Handler();
25 | private StatusDialog mProgressDialog;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_main);
31 | Toolbar toolbar = findViewById(R.id.toolbar);
32 | setSupportActionBar(toolbar);
33 |
34 | FloatingActionButton fab = findViewById(R.id.fab);
35 | fab.setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View view) {
38 | showProgressDialog();
39 | }
40 | });
41 | findViewById(R.id.tv_act_main_click).setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View view) {
44 | showItemDialog();
45 | }
46 | });
47 | }
48 |
49 | private void showItemDialog() {
50 | List itemBeanList = Utils.getItemBeanList();
51 | ItemDialog.with(MainActivity.this)
52 | .setCancelable(true)
53 | .setData(itemBeanList)
54 | .setOnItemClickListener(new ItemDialog.OnItemClickListener() {
55 | @Override
56 | public void onItemClick(int position, ItemBean itemData) {
57 | showSuccessDialog();
58 | }
59 | })
60 | .setSpanCount(itemBeanList.size())
61 | .setAnimations(R.style.Dialog_Anim_Bottom_In_Bottom_Out)
62 | .setGravity(Gravity.BOTTOM)
63 | .setShowType(ItemDialog.ShowType.GRID)
64 | .show();
65 | }
66 |
67 | private void showAlertDialog() {
68 | AlertDialog.with(MainActivity.this)
69 | .setCancelable(true)
70 | .setContent("Android Alert DialogFragment Content")
71 | .setTitle("AlertDialog Title")
72 | .setPositiveButton("success", new View.OnClickListener() {
73 | @Override
74 | public void onClick(View view) {
75 | showSuccessDialog();
76 | }
77 | }).setNegativeButton("error", new View.OnClickListener() {
78 | @Override
79 | public void onClick(View view) {
80 | showErrorDialog();
81 | }
82 | }).show();
83 | }
84 |
85 | private void showErrorDialog() {
86 | StatusDialog.with(MainActivity.this)
87 | .setCancelable(false)
88 | .setPrompt("load error")
89 | .setType(StatusDialog.Type.ERROR)
90 | .show();
91 | }
92 |
93 | private void showSuccessDialog() {
94 | StatusDialog.with(MainActivity.this)
95 | .setCancelable(false)
96 | .setPrompt("success")
97 | .setType(StatusDialog.Type.SUCCESS)
98 | .show();
99 | }
100 |
101 | private void showProgressDialog() {
102 | mProgressDialog = StatusDialog.with(MainActivity.this)
103 | .setCancelable(false)
104 | .setPrompt("loading…")
105 | .setType(StatusDialog.Type.PROGRESS)
106 | .show();
107 | mHandler.postDelayed(new Runnable() {
108 | @Override
109 | public void run() {
110 | mProgressDialog.dismiss();
111 | showAlertDialog();
112 | }
113 | }, 3000);
114 | }
115 |
116 | @Override
117 | public boolean onCreateOptionsMenu(Menu menu) {
118 | // Inflate the menu; this adds items to the action bar if it is present.
119 | getMenuInflater().inflate(R.menu.menu_main, menu);
120 | return true;
121 | }
122 |
123 | @Override
124 | public boolean onOptionsItemSelected(MenuItem item) {
125 | // Handle action bar item clicks here. The action bar will
126 | // automatically handle clicks on the Home/Up button, so long
127 | // as you specify a parent activity in AndroidManifest.xml.
128 | int id = item.getItemId();
129 |
130 | //noinspection SimplifiableIfStatement
131 | if (id == R.id.action_settings) {
132 | return true;
133 | }
134 |
135 | return super.onOptionsItemSelected(item);
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/widgets/AlertDialog.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.widgets;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.TextView;
6 |
7 | import com.android.dialog.R;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.annotation.Nullable;
11 | import androidx.annotation.StringRes;
12 | import androidx.appcompat.app.AppCompatActivity;
13 |
14 | /**
15 | * @Copyright (C)open
16 | * @ClassName: AlertDialog
17 | * @Description: $DESC$
18 | * @Author: seengene_lvTravler
19 | * @CreateDate: 2019/8/23 19:11
20 | * @UpdateUser: 更新者:
21 | * @UpdateDate: 2019/8/23 19:11
22 | * @UpdateRemark: 更新说明:
23 | * @Version: 1.0
24 | */
25 | public class AlertDialog extends Dialog {
26 | private DialogParams mDialogParams;
27 |
28 | public AlertDialog() {
29 | mDialogParams = new DialogParams();
30 | }
31 |
32 | @Override
33 | protected int setLayoutRes() {
34 | return R.layout.dialog_alert;
35 | }
36 |
37 | public static Builder with(AppCompatActivity activity) {
38 | return new Builder(activity);
39 | }
40 |
41 | @Override
42 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
43 | TextView tvDialogCommonTitle = view.findViewById(R.id.tv_dialog_common_title);
44 | TextView tvDialogCommonContent = view.findViewById(R.id.tv_dialog_common_content);
45 | TextView tvDialogCommonPositive = view.findViewById(R.id.tv_dialog_common_positive);
46 | TextView tvDialogCommonNegative = view.findViewById(R.id.tv_dialog_common_negative);
47 |
48 | //填充数据
49 | if (isNonEmpty(mDialogParams.title)) {
50 | tvDialogCommonTitle.setText(mDialogParams.title);
51 | }
52 | if (isNonEmpty(mDialogParams.content)) {
53 | tvDialogCommonContent.setText(mDialogParams.content);
54 | }
55 | if (isNonEmpty(mDialogParams.positive)) {
56 | tvDialogCommonPositive.setText(mDialogParams.positive);
57 | }
58 | if (isNonEmpty(mDialogParams.negative)) {
59 | tvDialogCommonNegative.setText(mDialogParams.negative);
60 | }
61 |
62 | //监听
63 | tvDialogCommonPositive.setOnClickListener(this);
64 | tvDialogCommonNegative.setOnClickListener(this);
65 | }
66 |
67 | @Override
68 | public void onClick(View v) {
69 | switch (v.getId()) {
70 | case R.id.tv_dialog_common_positive:
71 | dismiss();
72 | if (mDialogParams.onPositiveClickListener != null) {
73 | mDialogParams.onPositiveClickListener.onClick(v);
74 | }
75 | break;
76 | case R.id.tv_dialog_common_negative:
77 | dismiss();
78 | if (mDialogParams.onNegativeClickListener != null) {
79 | mDialogParams.onNegativeClickListener.onClick(v);
80 | }
81 | break;
82 | }
83 | }
84 |
85 | @Override
86 | protected boolean setCancelable() {
87 | return mDialogParams.isCancelable;
88 | }
89 |
90 | public class DialogParams {
91 | String title;
92 | String positive;
93 | String negative;
94 | String content;
95 | boolean isCancelable = true;
96 | View.OnClickListener onPositiveClickListener;
97 | View.OnClickListener onNegativeClickListener;
98 | }
99 |
100 | public static class Builder {
101 | AppCompatActivity activity;
102 | DialogParams P;
103 | AlertDialog alertDialog;
104 |
105 | public Builder(AppCompatActivity activity) {
106 | alertDialog = new AlertDialog();
107 | this.P = alertDialog.mDialogParams;
108 | this.activity = activity;
109 | }
110 |
111 | public Builder setTitle(String val) {
112 | P.title = val;
113 | return this;
114 | }
115 |
116 | public Builder setContent(String val) {
117 | P.content = val;
118 | return this;
119 | }
120 |
121 | public Builder setCancelable(boolean val) {
122 | P.isCancelable = val;
123 | return this;
124 | }
125 |
126 | public Builder setPositiveButton(String positive, View.OnClickListener onClickListener) {
127 | P.onPositiveClickListener = onClickListener;
128 | P.positive = positive;
129 | return this;
130 | }
131 |
132 | public Builder setNegativeButton(String negative, View.OnClickListener onClickListener) {
133 | P.onNegativeClickListener = onClickListener;
134 | P.negative = negative;
135 | return this;
136 | }
137 |
138 | public Builder setPositiveButton(@StringRes int positive, View.OnClickListener onClickListener) {
139 | P.onPositiveClickListener = onClickListener;
140 | P.positive = activity.getString(positive);
141 | return this;
142 | }
143 |
144 | public Builder setNegativeButton(@StringRes int negative, View.OnClickListener onClickListener) {
145 | P.onNegativeClickListener = onClickListener;
146 | P.negative = activity.getString(negative);
147 | return this;
148 | }
149 |
150 | public AlertDialog show() {
151 | alertDialog.show(activity);
152 | return alertDialog;
153 | }
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/widgets/StatusDialog.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.widgets;
2 |
3 | import android.graphics.PorterDuff;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 | import android.widget.ProgressBar;
9 | import android.widget.TextView;
10 |
11 | import com.android.dialog.R;
12 |
13 | import java.util.Timer;
14 | import java.util.TimerTask;
15 |
16 | import androidx.annotation.NonNull;
17 | import androidx.annotation.Nullable;
18 | import androidx.appcompat.app.AppCompatActivity;
19 |
20 | /**
21 | * @Copyright (C)open
22 | * @ClassName: StatusDialog
23 | * @Description: $DESC$
24 | * @Author: seengene_lvTravler
25 | * @CreateDate: 2019/8/25 22:57
26 | * @UpdateUser: 更新者:
27 | * @UpdateDate: 2019/8/25 22:57
28 | * @UpdateRemark: 更新说明:
29 | * @Version: 1.0
30 | */
31 | public class StatusDialog extends Dialog {
32 |
33 | private Handler mMainHandler = new Handler();
34 | /**
35 | * 成功或错误2s后dismiss
36 | */
37 | public static final int DELAY_TIME = 2000;
38 | private DialogParams mDialogParams;
39 | private Timer mDelayTimer;
40 |
41 | public StatusDialog() {
42 | mDialogParams = new DialogParams();
43 | }
44 |
45 | public static Builder with(AppCompatActivity activity) {
46 | return new Builder(activity);
47 | }
48 |
49 | @Override
50 | protected int setLayoutRes() {
51 | return R.layout.dialog_status;
52 | }
53 |
54 | @Override
55 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
56 | TextView tvDialogStatusContent = view.findViewById(R.id.tv_dialog_status_prompt);
57 | ImageView imgDialogStatusShow = view.findViewById(R.id.img_dialog_status_show);
58 | ProgressBar pbDialogStatusShow = view.findViewById(R.id.pb_dialog_status_show);
59 |
60 | //更换圆形进度条颜色
61 | pbDialogStatusShow.getIndeterminateDrawable()
62 | .setColorFilter(getResources().getColor(R.color.colorPrimaryDark), PorterDuff.Mode.SRC_ATOP);
63 |
64 | //填充数据
65 | if (isNonEmpty(mDialogParams.prompt)) {
66 | tvDialogStatusContent.setText(mDialogParams.prompt);
67 | }
68 |
69 | switch (mDialogParams.type) {
70 | case Type.ERROR:
71 | pbDialogStatusShow.setVisibility(View.GONE);
72 | imgDialogStatusShow.setVisibility(View.VISIBLE);
73 | imgDialogStatusShow.setImageResource(R.mipmap.icon_dialog_error);
74 | break;
75 | case Type.SUCCESS:
76 | pbDialogStatusShow.setVisibility(View.GONE);
77 | imgDialogStatusShow.setVisibility(View.VISIBLE);
78 | imgDialogStatusShow.setImageResource(R.mipmap.icon_dialog_success);
79 | break;
80 | case Type.PROGRESS:
81 | imgDialogStatusShow.setVisibility(View.GONE);
82 | pbDialogStatusShow.setVisibility(View.VISIBLE);
83 | break;
84 | }
85 | }
86 |
87 | @Override
88 | protected boolean setCancelable() {
89 | return mDialogParams.isCancelable;
90 | }
91 |
92 | @Override
93 | public void onStart() {
94 | super.onStart();
95 | /**
96 | * 显示定时间后自动dismiss
97 | */
98 | if (mDialogParams.type == Type.SUCCESS || mDialogParams.type == Type.ERROR) {
99 | cancelTimer();
100 | mDelayTimer = new Timer();
101 | mDelayTimer.schedule(new TimerTask() {
102 | @Override
103 | public void run() {
104 | mMainHandler.post(new Runnable() {
105 | @Override
106 | public void run() {
107 | dismiss();
108 | }
109 | });
110 | }
111 | }, DELAY_TIME);
112 | }
113 | }
114 |
115 | private void cancelTimer() {
116 | if (mDelayTimer != null) {
117 | mDelayTimer.cancel();
118 | }
119 | }
120 |
121 | @Override
122 | public void dismiss() {
123 | super.dismiss();
124 | cancelTimer();
125 | }
126 |
127 | @Override
128 | public void onPause() {
129 | super.onPause();
130 | cancelTimer();
131 | }
132 |
133 | public class DialogParams {
134 | String prompt;
135 | boolean isCancelable;
136 | int type = -1;
137 | }
138 |
139 | public static class Builder {
140 | AppCompatActivity activity;
141 | DialogParams P;
142 | StatusDialog progressDialog;
143 |
144 | public Builder(AppCompatActivity activity) {
145 | progressDialog = new StatusDialog();
146 | this.P = progressDialog.mDialogParams;
147 | this.activity = activity;
148 | }
149 |
150 | public Builder setPrompt(String val) {
151 | P.prompt = val;
152 | return this;
153 | }
154 |
155 | public Builder setCancelable(boolean val) {
156 | P.isCancelable = val;
157 | return this;
158 | }
159 |
160 | public Builder setType(int val) {
161 | P.type = val;
162 | return this;
163 | }
164 |
165 | public StatusDialog show() {
166 | if (P.type == -1) {
167 | throw new IllegalArgumentException("Please set type");
168 | }
169 | progressDialog.show(activity);
170 | return progressDialog;
171 | }
172 | }
173 |
174 | public interface Type {
175 |
176 | int PROGRESS = 0x000000000211;
177 |
178 | int ERROR = 0x000000000985;
179 |
180 | int SUCCESS = 0x00000000011;
181 |
182 | }
183 | }
184 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/widgets/Dialog.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.widgets;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.res.Configuration;
5 | import android.graphics.Color;
6 | import android.graphics.drawable.ColorDrawable;
7 | import android.os.Bundle;
8 | import android.text.TextUtils;
9 | import android.view.Gravity;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.view.Window;
14 | import android.view.WindowManager;
15 |
16 | import androidx.annotation.LayoutRes;
17 | import androidx.annotation.NonNull;
18 | import androidx.annotation.Nullable;
19 | import androidx.annotation.StyleRes;
20 | import androidx.appcompat.app.AppCompatActivity;
21 | import androidx.appcompat.app.AppCompatDialogFragment;
22 |
23 | /**
24 | * @Copyright (C)open
25 | * @Package: open.ui.widgets
26 | * @ClassName: Dialog
27 | * @Description: Dialog
28 | * @Author: seengene_lvTravler
29 | * @CreateDate: 2019/8/2 20:14
30 | * @UpdateUser: 更新者:
31 | * @UpdateDate: 2019/8/2 20:14
32 | * @UpdateRemark: 更新说明:
33 | * @Version: 1.0
34 | */
35 | public class Dialog extends AppCompatDialogFragment implements View.OnClickListener {
36 | private DialogParams mDialogParams;
37 |
38 | public Dialog() {
39 | this.mDialogParams = new DialogParams();
40 | }
41 |
42 | protected void show(AppCompatActivity activity, String tag) {
43 | if (!TextUtils.isEmpty(tag)) {
44 | show(activity.getSupportFragmentManager(), tag);
45 | } else {
46 | show(activity);
47 | }
48 | }
49 |
50 | public static Builder newBuilder(AppCompatActivity activity) {
51 | return new Builder(activity);
52 | }
53 |
54 | protected void show(AppCompatActivity activity) {
55 | show(activity.getSupportFragmentManager(), activity.getClass().getSimpleName());
56 | }
57 |
58 |
59 | protected boolean isNonEmpty(String content) {
60 | return !TextUtils.isEmpty(content);
61 | }
62 |
63 | @Nullable
64 | @Override
65 | public final View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
66 | //getDialog().setCancelable(setCancelable());
67 | getDialog().setCanceledOnTouchOutside(setCancelable());
68 | Window window = getDialog().getWindow();
69 | int animationsRes = setAnimations();
70 | if (animationsRes != 0 && animationsRes != -1) {
71 | window.setWindowAnimations(animationsRes);
72 | }
73 | setCancelable(setCancelable());
74 | //设置背景透明
75 | window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
76 | int gravity = setGravity();
77 | if (gravity != -1 && gravity != 0) {//即未设置
78 | window.setGravity(gravity);
79 | }
80 | return super.onCreateView(inflater, container, savedInstanceState);
81 | }
82 |
83 | @Override
84 | public void onStart() {
85 | super.onStart();
86 | Window window = getDialog().getWindow();
87 | WindowManager.LayoutParams params = window.getAttributes();
88 | params.width = WindowManager.LayoutParams.MATCH_PARENT;
89 | params.height = WindowManager.LayoutParams.WRAP_CONTENT;
90 | window.setAttributes(params);
91 | }
92 |
93 | @Override
94 | public void onConfigurationChanged(Configuration newConfig) {
95 | dismiss();
96 | super.onConfigurationChanged(newConfig);
97 | }
98 |
99 | /**
100 | * @return
101 | * @see Gravity
102 | */
103 | protected int setGravity() {
104 | return Gravity.CENTER;
105 | }
106 |
107 | protected boolean setCancelable() {
108 | return mDialogParams.isCancelable;
109 | }
110 |
111 | @StyleRes
112 | protected int setAnimations() {
113 | return mDialogParams.animations;
114 | }
115 |
116 | @NonNull
117 | @Override
118 | public final android.app.Dialog onCreateDialog(Bundle savedInstanceState) {
119 | AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
120 | View dialogLayout = LayoutInflater.from(getContext()).inflate(setLayoutRes(), null);
121 | builder.setView(dialogLayout);
122 | onViewCreated(dialogLayout, null);
123 | return builder.create();
124 | }
125 |
126 | protected int setLayoutRes() {
127 | return mDialogParams.contentView;
128 | }
129 |
130 | @Override
131 | public void onClick(View v) {
132 |
133 | }
134 |
135 | public class DialogParams {
136 | AppCompatActivity activity;
137 | int style;
138 | int animations;
139 | int contentView;
140 | String tag;
141 | boolean isCancelable;
142 | }
143 |
144 | public static class Builder {
145 | private DialogParams P;
146 | private Dialog dialog;
147 |
148 | private Builder(AppCompatActivity activity) {
149 | dialog = new Dialog();
150 | P = dialog.mDialogParams;
151 | P.activity = activity;
152 | }
153 |
154 | public Builder setStyle(int val) {
155 | P.style = val;
156 | return this;
157 | }
158 |
159 | public Builder setAnimations(int val) {
160 | P.animations = val;
161 | return this;
162 | }
163 |
164 | public Builder setContentView(@LayoutRes int val) {
165 | P.contentView = val;
166 | return this;
167 | }
168 |
169 | public Builder setCancelable(boolean val) {
170 | P.isCancelable = val;
171 | return this;
172 | }
173 |
174 | public Dialog build() {
175 | if (P.contentView == -1) {
176 | throw new IllegalArgumentException("Please set setContentView");
177 | }
178 | dialog.show(P.activity, P.tag);
179 | return dialog;
180 | }
181 | }
182 |
183 | }
184 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/widgets/itemdialog/ItemDialog.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.widgets.itemdialog;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import com.android.dialog.R;
7 | import com.android.dialog.base.BaseViewHolder;
8 | import com.android.dialog.widgets.Dialog;
9 |
10 | import java.util.List;
11 |
12 | import androidx.annotation.ColorRes;
13 | import androidx.annotation.NonNull;
14 | import androidx.annotation.Nullable;
15 | import androidx.annotation.StyleRes;
16 | import androidx.appcompat.app.AppCompatActivity;
17 | import androidx.recyclerview.widget.GridLayoutManager;
18 | import androidx.recyclerview.widget.LinearLayoutManager;
19 | import androidx.recyclerview.widget.RecyclerView;
20 |
21 | /**
22 | * @Copyright (C)seengene
23 | * @Package: open.ui.widgets
24 | * @ClassName: ItemDialog
25 | * @Description: 适用于重复性数据展示,例如使用RecyclerView展示
26 | * @Author: seengene_lvTravler
27 | * @CreateDate: 2019/8/28 11:34
28 | * @UpdateUser: 更新者:
29 | * @UpdateDate: 2019/8/28 11:34
30 | * @UpdateRemark: 更新说明:
31 | * @Version: 1.0
32 | */
33 | public class ItemDialog extends Dialog implements BaseViewHolder.OnItemClickListener {
34 | private DialogParams mDialogParams;
35 |
36 | public ItemDialog() {
37 | mDialogParams = new DialogParams();
38 | }
39 |
40 | public static Builder with(AppCompatActivity activity) {
41 | return new Builder(activity);
42 | }
43 |
44 | @Override
45 | protected int setLayoutRes() {
46 | return R.layout.dialog_item;
47 | }
48 |
49 | @Override
50 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
51 | if (mDialogParams.backgroundColor != -1 && mDialogParams.backgroundColor != 0) {
52 | view.setBackgroundColor(getContext().getResources().getColor(mDialogParams.backgroundColor));
53 | }
54 | RecyclerView recDialogItemShow = view.findViewById(R.id.rec_dialog_item_show);
55 | recDialogItemShow.setHasFixedSize(true);
56 | switch (mDialogParams.showType) {
57 | case ShowType.LIST:
58 | recDialogItemShow.setLayoutManager(new LinearLayoutManager(getContext()));
59 | break;
60 | case ShowType.GRID:
61 | recDialogItemShow.setLayoutManager(new GridLayoutManager(getContext(), mDialogParams.spanCount));
62 | break;
63 | }
64 | ItemDialogAdapter adapter = new ItemDialogAdapter(getContext(), R.layout.item_item_dialog, null);
65 | recDialogItemShow.setAdapter(adapter);
66 | adapter.setOnItemClickListener(this);
67 | adapter.refreshAdapter(mDialogParams.data);
68 | }
69 |
70 | @Override
71 | protected boolean setCancelable() {
72 | return mDialogParams.isCancelable;
73 | }
74 |
75 | @Override
76 | protected int setGravity() {
77 | return mDialogParams.gravity;
78 | }
79 |
80 | @Override
81 | protected int setAnimations() {
82 | return mDialogParams.animations;
83 | }
84 |
85 | @Override
86 | public void onItemClick(BaseViewHolder viewHolder, int position, ItemBean itemData, Object type) {
87 | if (mDialogParams.onItemClickListener != null) {
88 | dismiss();
89 | mDialogParams.onItemClickListener.onItemClick(position, itemData);
90 | }
91 | }
92 |
93 | @Override
94 | public void onItemLongClick(BaseViewHolder viewHolder, int position, ItemBean itemData, Object type) {
95 |
96 | }
97 |
98 | public class DialogParams {
99 | /**
100 | * 是否可以点击外部dismiss
101 | */
102 | boolean isCancelable = true;
103 | /**
104 | * 展示类型
105 | */
106 | @ShowType
107 | int showType = -1;
108 | /**
109 | * Grid形式展示时每行显示的数量
110 | */
111 | int spanCount = -1;
112 | /**
113 | * 展示数据
114 | */
115 | List data;
116 | /**
117 | * 监听
118 | */
119 | OnItemClickListener onItemClickListener;
120 | /**
121 | * 位置
122 | *
123 | * @see android.view.Gravity
124 | */
125 | int gravity = -1;
126 | /**
127 | * 背景颜色
128 | */
129 | int backgroundColor = -1;
130 | /**
131 | * 动画
132 | */
133 | int animations = -1;
134 | }
135 |
136 | public static class Builder {
137 | AppCompatActivity activity;
138 | DialogParams P;
139 | ItemDialog dialog;
140 |
141 | public Builder(AppCompatActivity activity) {
142 | dialog = new ItemDialog();
143 | this.P = dialog.mDialogParams;
144 | this.activity = activity;
145 | }
146 |
147 | public Builder setShowType(@ShowType int val) {
148 | P.showType = val;
149 | return this;
150 | }
151 |
152 | public Builder setSpanCount(int val) {
153 | P.spanCount = val;
154 | return this;
155 | }
156 |
157 | public Builder setData(@NonNull List val) {
158 | P.data = val;
159 | return this;
160 | }
161 |
162 | public Builder setOnItemClickListener(@NonNull OnItemClickListener val) {
163 | P.onItemClickListener = val;
164 | return this;
165 | }
166 |
167 | public Builder setCancelable(boolean val) {
168 | P.isCancelable = val;
169 | return this;
170 | }
171 |
172 | public Builder setGravity(int val) {
173 | P.gravity = val;
174 | return this;
175 | }
176 |
177 | public Builder setBackgroundColor(@ColorRes int val) {
178 | P.backgroundColor = val;
179 | return this;
180 | }
181 |
182 | public Builder setAnimations(@StyleRes int val) {
183 | P.animations = val;
184 | return this;
185 | }
186 |
187 | public ItemDialog show() {
188 | if (P.data == null) {
189 | throw new IllegalArgumentException("Please set data");
190 | }
191 |
192 | if (P.showType == -1) {
193 | throw new IllegalArgumentException("Please set showType");
194 | }
195 |
196 | dialog.show(activity);
197 | return dialog;
198 | }
199 | }
200 |
201 | public @interface ShowType {
202 |
203 | int LIST = 0x000000051;
204 |
205 | int GRID = 0x000000061;
206 |
207 | }
208 |
209 | public interface OnItemClickListener {
210 | void onItemClick(int position, ItemBean itemData);
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/dialog/base/BaseViewHolderAdapter.java:
--------------------------------------------------------------------------------
1 | package com.android.dialog.base;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | import androidx.annotation.IntRange;
13 | import androidx.annotation.LayoutRes;
14 | import androidx.annotation.NonNull;
15 | import androidx.annotation.Nullable;
16 | import androidx.recyclerview.widget.RecyclerView;
17 |
18 | /**
19 | * BaseAdapter
20 | *
21 | * @param
22 | */
23 | public abstract class BaseViewHolderAdapter extends RecyclerView.Adapter {
24 |
25 | public static final int LOAD_PAGE_SIZE = 10;
26 | protected List mDataList;
27 | protected Context mContext;
28 | @LayoutRes
29 | protected int mItemLayoutRes;
30 | /**
31 | * 为了在一个Activity/Fragment有多个Adapter时区分不同类型
32 | */
33 | protected Object mType;
34 | private BaseViewHolder.OnItemClickListener mOnItemClickListener;
35 | private BaseViewHolder.OnItemViewClickListener mOnItemViewClickListener;
36 | protected LayoutInflater mLayoutInflater;
37 |
38 | public BaseViewHolderAdapter(Context context, @LayoutRes int itemLayoutRes, @Nullable Object type) {
39 | mContext = context;
40 | mItemLayoutRes = itemLayoutRes;
41 | mType = type;
42 | mDataList = new ArrayList<>();
43 | mLayoutInflater = LayoutInflater.from(context);
44 | }
45 |
46 | /**
47 | * 设置监听
48 | *
49 | * @param onItemClickListener
50 | */
51 | public void setOnItemClickListener(BaseViewHolder.OnItemClickListener onItemClickListener) {
52 | mOnItemClickListener = onItemClickListener;
53 | }
54 |
55 | public void setOnItemViewClickListener(BaseViewHolder.OnItemViewClickListener onItemViewClickListener) {
56 | mOnItemViewClickListener = onItemViewClickListener;
57 | }
58 |
59 | /**
60 | * 适合分页加载
61 | *
62 | * @param dataList
63 | * @param isFirst
64 | */
65 | public void refreshAdapter(@NonNull List dataList, boolean isFirst) {
66 | if (isFirst) {//第一次添加
67 | mDataList.clear();
68 | mDataList.addAll(dataList);
69 | notifyDataSetChanged();
70 | } else {
71 | int preSize = mDataList.size();
72 | mDataList.addAll(dataList);
73 | notifyItemRangeInserted(preSize, LOAD_PAGE_SIZE);
74 | }
75 | }
76 |
77 |
78 | /**
79 | * 适合初始加载
80 | *
81 | * @param dataList
82 | */
83 | public void refreshAdapter(@NonNull List dataList) {
84 | if (dataList == null) return;
85 | mDataList.clear();
86 | mDataList.addAll(dataList);
87 | notifyDataSetChanged();
88 | }
89 |
90 | public void removeItem(int position) {
91 | mDataList.remove(position);
92 | notifyItemRemoved(position);
93 | }
94 |
95 | public void clearAdaper() {
96 | mDataList.clear();
97 | notifyDataSetChanged();
98 | }
99 |
100 | protected boolean isNonEmpty(String content) {
101 | return !TextUtils.isEmpty(content);
102 | }
103 |
104 | public boolean isNonEmpty() {
105 | return !mDataList.isEmpty();
106 | }
107 |
108 | public List getDataList() {
109 | return mDataList;
110 | }
111 |
112 | public void refreshAdapter(int position) {
113 | notifyItemChanged(position);
114 | }
115 |
116 | public void refreshAdapter() {
117 | notifyDataSetChanged();
118 | }
119 |
120 | public T getItemDataByPosition(@IntRange(from = 0) int position) {
121 | return mDataList.get(position);
122 | }
123 |
124 | protected Context getContext() {
125 | return mContext;
126 | }
127 |
128 | @NonNull
129 | @Override
130 | public VH onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
131 | return (VH) new BaseViewHolder(getItemLayout(viewGroup));
132 | }
133 |
134 | protected View getItemLayout(@NonNull ViewGroup viewGroup) {
135 | return mLayoutInflater.inflate(mItemLayoutRes, viewGroup, false);
136 | }
137 |
138 | @Override
139 | public void onBindViewHolder(@NonNull VH t, int i) {
140 | T itemData = mDataList.get(i);
141 | setOnItemClickListener(t, itemData, i);
142 | bind(t, itemData, i);
143 | }
144 |
145 |
146 | protected void setOnItemClickListener(@NonNull final BaseViewHolder viewHolder, final T itemData, final int position) {
147 | /**
148 | * 为了避免单独设置监听,只要Activity设置了监听这里就直接转换设置了
149 | */
150 | if (mContext instanceof BaseViewHolder.OnItemClickListener) {
151 | mOnItemClickListener = (BaseViewHolder.OnItemClickListener) mContext;
152 | }
153 | if (mOnItemClickListener != null) {
154 | viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
155 | @Override
156 | public void onClick(View view) {
157 | mOnItemClickListener.onItemClick(viewHolder, position, itemData, mType);
158 | }
159 | });
160 | viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
161 | @Override
162 | public boolean onLongClick(View view) {
163 | mOnItemClickListener.onItemLongClick(viewHolder, position, itemData, mType);
164 | return true;
165 | }
166 | });
167 | }
168 | }
169 |
170 | protected void setOnItemViewClickListener(@NonNull final BaseViewHolder viewHolder, View view, final T itemData, final int position) {
171 | if (mContext instanceof BaseViewHolder.OnItemViewClickListener) {
172 | mOnItemViewClickListener = (BaseViewHolder.OnItemViewClickListener) mContext;
173 | }
174 | if (mOnItemViewClickListener != null) {
175 | view.setOnClickListener(new View.OnClickListener() {
176 | @Override
177 | public void onClick(View view) {
178 | mOnItemViewClickListener.onItemViewClick(viewHolder, view, position, itemData, mType);
179 | }
180 | });
181 | view.setOnLongClickListener(new View.OnLongClickListener() {
182 | @Override
183 | public boolean onLongClick(View view) {
184 | mOnItemViewClickListener.onItemViewLongClick(viewHolder, view, position, itemData, mType);
185 | return true;
186 | }
187 | });
188 |
189 | }
190 | }
191 |
192 | @Override
193 | public int getItemCount() {
194 | return mDataList.size();
195 | }
196 |
197 | /**
198 | * 子类实现并在里填充数据
199 | *
200 | * @param viewHolder
201 | * @param itemData
202 | * @param position
203 | */
204 | public abstract void bind(@NonNull VH viewHolder, T itemData, int position);
205 | }
206 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------