From 0e3849999b7ed3398255b1312fa28d7d38b23306 Mon Sep 17 00:00:00 2001 From: SiberiaDante <994537867@qq.com> Date: Tue, 19 Sep 2017 14:45:04 +0800 Subject: [PATCH] v1.0.1 --- .idea/compiler.xml | 22 ++ .idea/copyright/profiles_settings.xml | 3 + .idea/markdown-navigator.xml | 72 ++++ .../markdown-navigator/profiles_settings.xml | 3 + .idea/misc.xml | 62 ++++ .idea/modules.xml | 10 + .idea/runConfigurations.xml | 12 + .idea/vcs.xml | 6 + README.md | 166 +++++++++ app/.gitignore | 1 + app/build.gradle | 31 ++ app/proguard-rules.pro | 25 ++ .../customdialog/ExampleInstrumentedTest.java | 26 ++ app/src/main/AndroidManifest.xml | 21 ++ .../customdialog/MainActivity.java | 207 +++++++++++ app/src/main/res/layout/activity_main.xml | 83 +++++ app/src/main/res/layout/dialog_layout.xml | 55 +++ app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4208 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2555 bytes app/src/main/res/mipmap-mdpi/tip_icon.png | Bin 0 -> 1404 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6114 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10056 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 14696 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 15 + .../customdialog/ExampleUnitTest.java | 17 + build.gradle | 23 ++ customdialoglib/.gitignore | 1 + customdialoglib/build.gradle | 31 ++ customdialoglib/proguard-rules.pro | 25 ++ .../ExampleInstrumentedTest.java | 26 ++ customdialoglib/src/main/AndroidManifest.xml | 1 + .../customdialoglib/BottomPopupWindow.java | 218 ++++++++++++ .../customdialoglib/CustomDialog.java | 165 +++++++++ .../customdialoglib/EditDialog.java | 209 +++++++++++ .../customdialoglib/EnsureDialog.java | 328 ++++++++++++++++++ .../main/res/anim/actionsheet_dialog_in.xml | 5 + .../main/res/anim/actionsheet_dialog_out.xml | 5 + .../src/main/res/anim/bottom_enter.xml | 6 + .../src/main/res/anim/bottom_exit.xml | 6 + .../main/res/anim/nice_dialog_enter_anim.xml | 11 + .../main/res/anim/nice_dialog_exit_anim.xml | 13 + .../res/anim/photo_activity_before_enter.xml | 12 + .../res/anim/photo_activity_before_exit.xml | 12 + .../main/res/anim/photo_activity_enter.xml | 12 + .../src/main/res/anim/photo_activity_exit.xml | 12 + .../src/main/res/drawable/bac_white_one.xml | 8 + .../res/drawable/bottom_menu_btn_selector.xml | 9 + .../src/main/res/drawable/corners_bg.xml | 5 + .../main/res/drawable/corners_bg_press.xml | 5 + .../main/res/drawable/edit_cursor_line.xml | 5 + .../main/res/drawable/edit_select_handle.xml | 5 + .../res/drawable/shape_alert_dialog_edit.xml | 12 + .../src/main/res/layout/dialog_alert_edit.xml | 73 ++++ .../main/res/layout/dialog_ensure_layout.xml | 101 ++++++ .../res/layout/popup_window_bottom_layout.xml | 62 ++++ .../src/main/res/values/colors.xml | 12 + .../src/main/res/values/strings.xml | 3 + .../src/main/res/values/styles.xml | 59 ++++ .../customdialoglib/ExampleUnitTest.java | 17 + gradle.properties | 17 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 +++++++++ gradlew.bat | 90 +++++ settings.gradle | 1 + 72 files changed, 2617 insertions(+) create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/markdown-navigator.xml create mode 100644 .idea/markdown-navigator/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/siberiadante/customdialog/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/siberiadante/customdialog/MainActivity.java create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/dialog_layout.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/tip_icon.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/siberiadante/customdialog/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 customdialoglib/.gitignore create mode 100644 customdialoglib/build.gradle create mode 100644 customdialoglib/proguard-rules.pro create mode 100644 customdialoglib/src/androidTest/java/com/siberiadante/customdialoglib/ExampleInstrumentedTest.java create mode 100644 customdialoglib/src/main/AndroidManifest.xml create mode 100644 customdialoglib/src/main/java/com/siberiadante/customdialoglib/BottomPopupWindow.java create mode 100644 customdialoglib/src/main/java/com/siberiadante/customdialoglib/CustomDialog.java create mode 100644 customdialoglib/src/main/java/com/siberiadante/customdialoglib/EditDialog.java create mode 100644 customdialoglib/src/main/java/com/siberiadante/customdialoglib/EnsureDialog.java create mode 100644 customdialoglib/src/main/res/anim/actionsheet_dialog_in.xml create mode 100644 customdialoglib/src/main/res/anim/actionsheet_dialog_out.xml create mode 100644 customdialoglib/src/main/res/anim/bottom_enter.xml create mode 100644 customdialoglib/src/main/res/anim/bottom_exit.xml create mode 100644 customdialoglib/src/main/res/anim/nice_dialog_enter_anim.xml create mode 100644 customdialoglib/src/main/res/anim/nice_dialog_exit_anim.xml create mode 100644 customdialoglib/src/main/res/anim/photo_activity_before_enter.xml create mode 100644 customdialoglib/src/main/res/anim/photo_activity_before_exit.xml create mode 100644 customdialoglib/src/main/res/anim/photo_activity_enter.xml create mode 100644 customdialoglib/src/main/res/anim/photo_activity_exit.xml create mode 100644 customdialoglib/src/main/res/drawable/bac_white_one.xml create mode 100644 customdialoglib/src/main/res/drawable/bottom_menu_btn_selector.xml create mode 100644 customdialoglib/src/main/res/drawable/corners_bg.xml create mode 100644 customdialoglib/src/main/res/drawable/corners_bg_press.xml create mode 100644 customdialoglib/src/main/res/drawable/edit_cursor_line.xml create mode 100644 customdialoglib/src/main/res/drawable/edit_select_handle.xml create mode 100644 customdialoglib/src/main/res/drawable/shape_alert_dialog_edit.xml create mode 100644 customdialoglib/src/main/res/layout/dialog_alert_edit.xml create mode 100644 customdialoglib/src/main/res/layout/dialog_ensure_layout.xml create mode 100644 customdialoglib/src/main/res/layout/popup_window_bottom_layout.xml create mode 100644 customdialoglib/src/main/res/values/colors.xml create mode 100644 customdialoglib/src/main/res/values/strings.xml create mode 100644 customdialoglib/src/main/res/values/styles.xml create mode 100644 customdialoglib/src/test/java/com/siberiadante/customdialoglib/ExampleUnitTest.java create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml new file mode 100644 index 0000000..d819570 --- /dev/null +++ b/.idea/markdown-navigator.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml new file mode 100644 index 0000000..57927c5 --- /dev/null +++ b/.idea/markdown-navigator/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7158618 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ee66873 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index c573b89..53abec0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,168 @@ # CustomDialog 一个万能的通用支持多功能的Dialog +## 依赖 +``` + +``` +## 说明 +### [CustomDialog]: +一个万能的通用支持多功能的Dialog,简单两步即可实现 +* 只需要传入自定义的CustomDialog布局和需要设置点击事件的控件的id即可 +``` + CustomDialog customDialog=new CustomDialog(this,R.layout.dialog_layout,new int[]{R.id.dialog_sure}); +``` +* CustomDialog按钮的监听 +``` + customDialog.setOnDialogItemClickListener(new CustomDialog.OnCustomDialogItemClickListener() { + @Override + public void OnCustomDialogItemClick(CustomDialog dialog, View view) { + Toast.makeText(MainActivity.this, "确定按钮被点击了", Toast.LENGTH_LONG).show(); + } + }); +``` +* CustomDialog显示与隐藏 + + ```customDialog.show();``` + + ```customDialog.dismiss();``` + +#### 如果你想改变CustomDialog的显示位置、动画、控制按钮点击是否取消显示CustomDialog,可以使用一下构造 +* 改变CustomDialog动画 +``` + /** + * @param context + * @param layoutResID 自己定义的布局 + * @param listenedItems 需要设置点击事件的资源id + * @param animationResId dialog 动画,如果不使用自己的,则传0 + */ + public CustomDialog(Context context, int layoutResID, int[] listenedItems, int animationResId) { + super(context, R.style.Custom_Dialog_Style); //dialog的样式 + this.context = context; + this.mLayoutResId = layoutResID; + this.mListenedItems = listenedItems; + this.mAnimationResId = animationResId; + } +``` +* 控制点击CustomDialog后是否自动取消显示CustomDialog +``` + /** + * @param context + * @param layoutResID 自己定义的布局 + * @param listenedItems 需要设置点击事件的资源id + * @param isDismiss 按钮点击后是否默认取消dialog {@code true}取消 {@code false} 不取消 + */ + public CustomDialog(Context context, int layoutResID, int[] listenedItems, boolean isDismiss) { + super(context, R.style.Custom_Dialog_Style); //dialog的样式 + this.context = context; + this.mLayoutResId = layoutResID; + this.mListenedItems = listenedItems; + this.mIsDismiss = isDismiss; + } +``` +* 改变CustomDialog的显示位置,同时可以控制点击CustomDialog后是否自动取消显示CustomDialog +``` + /** + * @param context + * @param layoutResID 自己定义的布局 + * @param listenedItems 需要设置点击事件的资源id + * @param isDismiss 按钮点击后是否默认取消dialog {@code true}取消 {@code false} 不取消 + * @param position dialog 显示位置,默认CENTER,不设置时可以传0 + */ + public CustomDialog(Context context, int layoutResID, int[] listenedItems, boolean isDismiss, int position) { + super(context, R.style.Custom_Dialog_Style); //dialog的样式 + this.context = context; + this.mLayoutResId = layoutResID; + this.mListenedItems = listenedItems; + this.mPosition = position; + } +``` +* 可以同时改变CustomDialog动画、显示位置、按钮点击是否取消显示CustomDialog +``` + /** + * 满足你各种需求 + * + * @param context + * @param layoutResID 自己定义的布局 + * @param listenedItems 需要设置点击事件的资源id + * @param animationResId dialog 动画,如果不使用自己的,则传0 + * @param isDismiss 按钮点击后是否默认取消dialog {@code true}取消 {@code false} 不取消 + * @param position dialog 显示位置,默认CENTER,不设置时可以传0 + */ + public CustomDialog(Context context, int layoutResID, int[] listenedItems, int animationResId, boolean isDismiss, int position) { + super(context, R.style.Custom_Dialog_Style); //dialog的样式 + this.context = context; + this.mLayoutResId = layoutResID; + this.mListenedItems = listenedItems; + this.mAnimationResId = animationResId; + this.mIsDismiss = isDismiss; + this.mPosition = position; + } +``` + +### 其他几个常用Dialog + +* [EnsureDialog] +``` +EnsureDialog ensureDialog = new EnsureDialog(this).builder() + .setGravity(Gravity.CENTER)//默认居中,可以不设置 + .setTitle("这里是一个标题", getResources().getColor(R.color.black))//可以不设置标题颜色,默认系统颜色 + .setCancelable(false) + .setSubTitle("这是一个副标题") + .setIncon(R.mipmap.tip_icon)//不设置图标,默认没有图标 + .setNegativeButton("取消", new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法 + @Override + public void onClick(View view) { + + } + }) + .setPositiveButton("确认", getResources().getColor(R.color.red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法 + @Override + public void onClick(View view) { + ensureDialog.dismiss(); + + } + }); + ensureDialog.show(); +``` +* [BottomPopupWindow]: +``` +new BottomPopupWindow(this).builder() + .setTitle("选择").setCancelable(false).setCanceled(true) + .addSheetItem("相机", BottomPopupWindow.SheetItemColor.Blue, new BottomPopupWindow.OnSheetItemClickListener() { + @Override + public void onClick(int which) { + } + }) + ...//可以addSheetItem多个item + .addSheetItem("相册", BottomPopupWindow.SheetItemColor.Blue, new BottomPopupWindow.OnSheetItemClickListener() { + @Override + public void onClick(int which) { + } + }).show(); +``` + +* [EditDialog] +``` + final EditDialog dialog = new EditDialog(this).builder(); + dialog.setTitle("可编辑Dialog"); + dialog.setCancelable(false); + dialog.setNegativeButton("取消", new View.OnClickListener() { + @Override + public void onClick(View view) { + } + }); + dialog.setPositiveButton("确定", new View.OnClickListener() { + @Override + public void onClick(View view) { + final String msg = dialog.getMsg(); + Toast.makeText(MainActivity.this, "输入内容为:" + msg, Toast.LENGTH_LONG).show(); + dialog.dismiss(); + } + }); + dialog.show(); +``` + +[CustomDialog]: +[EditDialog]: +[BottomPopupWindow]: +[EnsureDialog]: diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..6568d29 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + buildToolsVersion "26.0.0" + defaultConfig { + applicationId "com.siberiadante.customdialog" + minSdkVersion 14 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:26.+' + compile 'com.android.support.constraint:constraint-layout:1.0.1' + testCompile 'junit:junit:4.12' + compile project(':customdialoglib') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..c81a1f1 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\shuinsen05\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/siberiadante/customdialog/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/siberiadante/customdialog/ExampleInstrumentedTest.java new file mode 100644 index 0000000..8191e3a --- /dev/null +++ b/app/src/androidTest/java/com/siberiadante/customdialog/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.siberiadante.customdialog; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.siberiadante.customdialog", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ef60e4f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/siberiadante/customdialog/MainActivity.java b/app/src/main/java/com/siberiadante/customdialog/MainActivity.java new file mode 100644 index 0000000..e04a371 --- /dev/null +++ b/app/src/main/java/com/siberiadante/customdialog/MainActivity.java @@ -0,0 +1,207 @@ +package com.siberiadante.customdialog; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.Gravity; +import android.view.View; +import android.widget.Toast; + +import com.siberiadante.customdialoglib.BottomPopupWindow; +import com.siberiadante.customdialoglib.CustomDialog; +import com.siberiadante.customdialoglib.EditDialog; +import com.siberiadante.customdialoglib.EnsureDialog; + +public class MainActivity extends AppCompatActivity implements View.OnClickListener { + private EnsureDialog ensureDialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + initView(); + } + + private void initView() { + findViewById(R.id.btn_general_dialog_one).setOnClickListener(this); + findViewById(R.id.btn_general_dialog_two).setOnClickListener(this); + findViewById(R.id.btn_general_dialog_three).setOnClickListener(this); + findViewById(R.id.btn_general_dialog_four).setOnClickListener(this); + findViewById(R.id.btn_bottom_popup_widow).setOnClickListener(this); + findViewById(R.id.btn_edit_dialog).setOnClickListener(this); + findViewById(R.id.btn_custom_dialog).setOnClickListener(this); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.btn_general_dialog_one: + showEnsureDialogOne(); + break; + case R.id.btn_general_dialog_two: + showEnsureDialogTwo(); + break; + case R.id.btn_general_dialog_three: + showEnsureDialogThree(); + break; + case R.id.btn_general_dialog_four: + showEnsureDialogFour(); + break; + case R.id.btn_bottom_popup_widow: + showBottomPopupWindow(); + break; + case R.id.btn_edit_dialog: + showEditDialog(); + break; + case R.id.btn_custom_dialog: + showCustomDialog(); + break; + } + } + + /** + * EditDialog + */ + private void showEditDialog() { + final EditDialog dialog = new EditDialog(this).builder(); + dialog.setTitle("可编辑Dialog"); + dialog.setCancelable(false); + dialog.setNegativeButton("取消", new View.OnClickListener() { + @Override + public void onClick(View view) { + } + }); + dialog.setPositiveButton("确定", new View.OnClickListener() { + @Override + public void onClick(View view) { + final String msg = dialog.getMsg(); + Toast.makeText(MainActivity.this, "输入内容为:" + msg, Toast.LENGTH_LONG).show(); + dialog.dismiss(); + } + }); + dialog.show(); + } + + /** + * BottomPopupWindow + */ + private void showBottomPopupWindow() { + new BottomPopupWindow(this).builder() + .setTitle("选择").setCancelable(false).setCanceled(true) + .addSheetItem("相机", BottomPopupWindow.SheetItemColor.Blue, new BottomPopupWindow.OnSheetItemClickListener() { + @Override + public void onClick(int which) { + //需要对相机进行运行时权限的申请 + } + }) + .addSheetItem("相册", BottomPopupWindow.SheetItemColor.Blue, new BottomPopupWindow.OnSheetItemClickListener() { + @Override + public void onClick(int which) { + //调用手机相册的方法,该方法在下面有具体实现 + } + }).show(); + } + + /** + * EnsureDialog + */ + private void showEnsureDialogOne() { + ensureDialog = new EnsureDialog(this).builder() + .setGravity(Gravity.CENTER)//默认居中,可以不设置 + .setTitle("这里是一个标题", getResources().getColor(R.color.black))//可以不设置标题颜色,默认系统颜色 + .setCancelable(false) + .setNegativeButton("取消", new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法 + @Override + public void onClick(View view) { + + } + }) + .setPositiveButton("确认", getResources().getColor(R.color.red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法 + @Override + public void onClick(View view) { + ensureDialog.dismiss(); + + } + }); + ensureDialog.show(); + + } + + private void showEnsureDialogTwo() { + ensureDialog = new EnsureDialog(this).builder() + .setGravity(Gravity.CENTER)//默认居中,可以不设置 + .setTitle("这里是一个标题", getResources().getColor(R.color.black))//可以不设置标题颜色,默认系统颜色 + .setSubTitle("这是一个副标题") + .setCancelable(false) + .setNegativeButton("取消", new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法 + @Override + public void onClick(View view) { + + } + }) + .setPositiveButton("确认", getResources().getColor(R.color.red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法 + @Override + public void onClick(View view) { + ensureDialog.dismiss(); + + } + }); + ensureDialog.show(); + + } + + private void showEnsureDialogThree() { + ensureDialog = new EnsureDialog(this).builder() + .setGravity(Gravity.CENTER)//默认居中,可以不设置 + .setTitle("这里是一个标题", getResources().getColor(R.color.black))//可以不设置标题颜色,默认系统颜色 + .setIncon(R.mipmap.tip_icon)//不设置图标,默认没有图标 + .setCancelable(false) + .setNegativeButton("取消", new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法 + @Override + public void onClick(View view) { + + } + }) + .setPositiveButton("确认", getResources().getColor(R.color.red), new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法 + @Override + public void onClick(View view) { + ensureDialog.dismiss(); + + } + }); + ensureDialog.show(); + + } + + private void showEnsureDialogFour() { + ensureDialog = new EnsureDialog(this).builder() + .setGravity(Gravity.CENTER)//默认居中,可以不设置 + .setTitle("这里是一个标题", R.color.black)//可以不设置标题颜色,默认系统颜色 + .setCancelable(false) + .setCenterButton("取消", new View.OnClickListener() {//可以选择设置颜色和不设置颜色两个方法 + @Override + public void onClick(View view) { + + } + }) + ; + ensureDialog.show(); + } + + private void showCustomDialog() { + final CustomDialog customDialog = new CustomDialog(this, R.layout.dialog_layout, new int[]{R.id.dialog_sure}, 0, true, Gravity.CENTER); + customDialog.setOnDialogItemClickListener(new CustomDialog.OnCustomDialogItemClickListener() { + @Override + public void OnCustomDialogItemClick(CustomDialog dialog, View view) { +// customDialog.dismiss(); + Toast.makeText(MainActivity.this, "确定按钮被点击了", Toast.LENGTH_LONG).show(); + } + }); + customDialog.show(); + + } + + @Override + public void onPointerCaptureChanged(boolean hasCapture) { + + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b1f55b3 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,83 @@ + + + + + + +