├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── kotlinc.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── me
│ │ └── leefeng
│ │ └── promptdialog
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── me
│ │ │ └── leefeng
│ │ │ └── promptdialog
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── 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
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── me
│ └── leefeng
│ └── promptdialog
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── promptlibrary
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── me
│ │ └── leefeng
│ │ └── promptlibrary
│ │ ├── Builder.java
│ │ ├── OnAdClickListener.java
│ │ ├── PromptButton.java
│ │ ├── PromptButtonListener.java
│ │ ├── PromptDialog.java
│ │ └── PromptView.java
│ └── res
│ ├── drawable-xxxhdpi
│ ├── ic_prompt_alert_warn.png
│ ├── ic_prompt_close.png
│ ├── ic_prompt_error.png
│ ├── ic_prompt_info.png
│ ├── ic_prompt_loading.png
│ ├── ic_prompt_success.png
│ └── ic_prompt_warn.png
│ └── values
│ └── strings.xml
├── screen1.gif
├── screen2.jpg
├── screen3.jpg
├── screen4.jpg
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android-PromptDialog
2 | 提示窗口,正在加载中,确认对话框,广告展示,底部Sheet选项,非组合控件,感谢star
3 |
4 | 


5 |
6 | [](https://jitpack.io/#limxing/Android-PromptDialog)
7 |
8 | #### 1、添加依赖
9 |
10 | ```
11 | allprojects {
12 | repositories {
13 | ...
14 | maven { url 'https://jitpack.io' }
15 | }
16 | }
17 |
18 |
19 | ```
20 |
21 | ```
22 | dependencies {
23 | ...
24 | compile 'com.github.limxing:Android-PromptDialog:1.1.3'
25 | }
26 |
27 | ```
28 | #### 2、创建对象及使用方法
29 | ```
30 | promptDialog = new PromptDialog(this);
31 | promptDialog.showLoading("正在登录");
32 | /**
33 | /********************消息提示框*************/
34 | promptDialog.showSuccess("登陆成功");
35 | promptDialog.showError("登录失败");
36 | promptDialog.showWarn("注意");
37 | promptDialog.showInfo("成功了");
38 | promptDialog.showCustom(R.mipmap.ic_launcher, "自定义图标的");
39 | promptDialog.dismiss();
40 | promptDialog.dismissImmediately();
41 |
42 | /********************Alert弹窗*************/
43 | final PromptButton confirm = new PromptButton("确定", new PromptButtonListener() {
44 | @Override
45 | public void onClick(PromptButton button) {
46 | Toast.makeText(MainActivity.this, button.getText(), Toast.LENGTH_SHORT).show();
47 | }
48 | });
49 | confirm.setTextColor(Color.parseColor("#DAA520"));
50 | //按钮的定义
51 | PromptButton confirm = new PromptButton("确定", new PromptButtonListener() {
52 | @Override
53 | public void onClick(PromptButton button) {
54 | Toast.makeText(MainActivity.this, button.getText(), Toast.LENGTH_SHORT).show();
55 | }
56 | });
57 | confirm.setFocusBacColor(Color.parseColor("#FAFAD2"));
58 | //Alert的调用
59 | promptDialog.showWarnAlert("你确定要退出登录?", new PromptButton("取消", new PromptButtonListener() {
60 | @Override
61 | public void onClick(PromptButton button) {
62 | Toast.makeText(MainActivity.this, button.getText(), Toast.LENGTH_SHORT).show();
63 | }
64 | }), confirm);
65 |
66 | /********************底部AlertSheet*************/
67 | //可创建android效果的底部Sheet选择,默认IOS效果,sheetCellPad=0为Android效果的Sheet
68 | // promptDialog.getAlertDefaultBuilder().sheetCellPad(0).round(0);
69 | //设置按钮的特点,颜色大小什么的,具体看PromptButton的成员变量
70 | PromptButton cancle = new PromptButton("取消", null);
71 | cancle.setTextColor(Color.parseColor("#0076ff"));
72 | //设置显示的文字大小及颜色
73 | //promptDialog.getAlertDefaultBuilder().textSize(12).textColor(Color.GRAY);
74 | //默认两个按钮为Alert对话框,大于三个按钮的为底部SHeet形式展现
75 | promptDialog.showAlertSheet("", true, cancle,
76 | new PromptButton("选项1", null), new PromptButton("选项2", null),
77 | new PromptButton("选项3", null), new PromptButton("选项4", null));
78 | /********************展示广告的方法*************/
79 | promptDialog.getDefaultBuilder().backAlpha(150);
80 | Glide.with(MainActivity.this).load("https://timgsa.baidu.com/timg?image&quality=80&" +
81 | "size=b9999_10000&sec=1495518782659&di=25b120262114749ae8543652d2de5715&" +
82 | "imgtype=0&src=http%3A%2F%2Fimg.tupianzj.com%2Fuploads%2Fallimg%2F160316%2F9-160316152R5.jpg")
83 | .into(promptDialog.showAd(true, new OnAdClickListener() {
84 | @Override
85 | public void onAdClick() {
86 | Toast.makeText(MainActivity.this,"点击了广告",Toast.LENGTH_SHORT).show();
87 | }
88 | }));
89 | **/
90 | ```
91 | #### 3、自定义窗口style
92 | ```
93 | /* 均为单例,设置一次后会影响另一个,因此如果效果不同那么调用前设置一次*/
94 | //自定义提示框Style,适应于show...(消息提示框,展示广告)
95 | promptDialog.getDefaultBuilder().touchAble(true).round(3).loadingDuration(3000)..
96 | //自定义弹窗对话框Style,适应于Alert 及AlertSheet(Alert弹窗,底部AlertSheet)
97 | promptDialog.getAlertDefaultBuilder().touchAble(false).round(5)...
98 | ```
99 | #### 4、按需处理返回键
100 | ```
101 | //返回键的处理仅是Alert 或AlertSheet的关闭操作
102 | @Override
103 | public void onBackPressed() {
104 | if (promptDialog.onBackPressed())
105 | super.onBackPressed();
106 | }
107 | ```
108 | #### License
109 |
110 | ```
111 | Copyright 2017 Limxing
112 |
113 | Licensed under the Apache License, Version 2.0 (the "License");
114 | you may not use this file except in compliance with the License.
115 | You may obtain a copy of the License at
116 |
117 | http://www.apache.org/licenses/LICENSE-2.0
118 |
119 | Unless required by applicable law or agreed to in writing, software
120 | distributed under the License is distributed on an "AS IS" BASIS,
121 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
122 | See the License for the specific language governing permissions and
123 | limitations under the License.
124 | ```
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 | defaultConfig {
7 | applicationId "me.leefeng.promptdialog"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | testCompile 'junit:junit:4.12'
30 | compile project(':promptlibrary')
31 | compile 'com.github.bumptech.glide:glide:3.6.1'
32 | // compile 'com.github.limxing:Android-PromptDialog:1.0.0'
33 | // compile files('libs/MapSDK_fat.jar')
34 | }
35 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/me/leefeng/promptdialog/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.promptdialog;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("me.leefeng.promptdialog", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/me/leefeng/promptdialog/MainActivity.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.promptdialog;
2 |
3 | import android.app.AlertDialog;
4 | import android.app.ProgressDialog;
5 | import android.graphics.Color;
6 | import android.os.Handler;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.widget.Toast;
11 |
12 | import com.bumptech.glide.Glide;
13 |
14 | import me.leefeng.promptlibrary.OnAdClickListener;
15 | import me.leefeng.promptlibrary.PromptButton;
16 | import me.leefeng.promptlibrary.PromptButtonListener;
17 | import me.leefeng.promptlibrary.PromptDialog;
18 |
19 | /**
20 | * github:limxing
21 | */
22 | public class MainActivity extends AppCompatActivity {
23 |
24 | private PromptDialog promptDialog;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 |
31 | //创建对象
32 | promptDialog = new PromptDialog(this);
33 | //设置自定义属性
34 | promptDialog.getDefaultBuilder().touchAble(true).round(3).loadingDuration(3000);
35 |
36 |
37 | findViewById(R.id.main_start).setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View v) {
40 | promptDialog.showWarn("注意");
41 | }
42 | });
43 |
44 | findViewById(R.id.main_loading).setOnClickListener(new View.OnClickListener() {
45 | @Override
46 | public void onClick(View view) {
47 | // main_failview.setMode(FailView.MODE_REFRESH);
48 | promptDialog.showLoading("正在登录");
49 | }
50 | });
51 | findViewById(R.id.main_success).setOnClickListener(new View.OnClickListener() {
52 | @Override
53 | public void onClick(View v) {
54 | promptDialog.showSuccess("登陆成功");
55 | }
56 | });
57 | findViewById(R.id.main_fail).setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View v) {
60 | promptDialog.showError("登录失败");
61 | }
62 | });
63 |
64 | //按钮的定义,创建一个按钮的对象
65 | final PromptButton confirm = new PromptButton("确定", new PromptButtonListener() {
66 | @Override
67 | public void onClick(PromptButton button) {
68 | Toast.makeText(MainActivity.this, button.getText(), Toast.LENGTH_SHORT).show();
69 | }
70 | });
71 | confirm.setTextColor(Color.parseColor("#DAA520"));
72 | confirm.setFocusBacColor(Color.parseColor("#FAFAD2"));
73 | confirm.setDelyClick(true);//点击后,是否再对话框消失后响应按钮的监听事件
74 | findViewById(R.id.main_warn).setOnClickListener(new View.OnClickListener() {
75 | @Override
76 | public void onClick(View v) {
77 | promptDialog.showWarnAlert("你确定要退出登录?", new PromptButton("取消", new PromptButtonListener() {
78 | @Override
79 | public void onClick(PromptButton button) {
80 | Toast.makeText(MainActivity.this, button.getText(), Toast.LENGTH_SHORT).show();
81 | }
82 | }), confirm);
83 | }
84 | });
85 |
86 | findViewById(R.id.main_info).setOnClickListener(new View.OnClickListener() {
87 | @Override
88 | public void onClick(View v) {
89 | promptDialog.showInfo("成功了");
90 | }
91 | });
92 |
93 | findViewById(R.id.main_system).setOnClickListener(new View.OnClickListener() {
94 | @Override
95 | public void onClick(View v) {
96 | //可创建android效果的底部Sheet选择,默认IOS效果,sheetCellPad=0为Android效果的Sheet
97 | // promptDialog.getAlertDefaultBuilder().sheetCellPad(0).round(0);
98 | //设置按钮的特点,颜色大小什么的,具体看PromptButton的成员变量
99 | PromptButton cancle = new PromptButton("取消", null);
100 | cancle.setTextColor(Color.parseColor("#0076ff"));
101 | //设置显示的文字大小及颜色
102 | // promptDialog.getAlertDefaultBuilder().textSize(12).textColor(Color.GRAY);
103 | //默认两个按钮为Alert对话框,大于三个按钮的为底部SHeet形式展现
104 | promptDialog.showAlertSheet("", true, cancle,
105 | new PromptButton("选项1", null), new PromptButton("选项2", null),
106 | new PromptButton("选项3", null), new PromptButton("选项4", null));
107 |
108 | }
109 | });
110 | findViewById(R.id.main_customer).setOnClickListener(new View.OnClickListener() {
111 | @Override
112 | public void onClick(View v) {
113 | promptDialog.showCustom(R.mipmap.ic_launcher, "自定义图标的");
114 | }
115 | });
116 | // u0_a280 8011 2923 1474704 209280 SyS_epoll_ 0000000000 S me.leefeng.beida
117 |
118 | findViewById(R.id.main_ad).setOnClickListener(new View.OnClickListener() {
119 | @Override
120 | public void onClick(View v) {
121 | promptDialog.getDefaultBuilder().backAlpha(150);
122 | Glide.with(MainActivity.this).load("https://timgsa.baidu.com/timg?image&quality=80&" +
123 | "size=b9999_10000&sec=1495518782659&di=25b120262114749ae8543652d2de5715&" +
124 | "imgtype=0&src=http%3A%2F%2Fimg.tupianzj.com%2Fuploads%2Fallimg%2F160316%2F9-160316152R5.jpg")
125 | // .placeholder(getResources().getDrawable(R.drawable.ic_prompt_holder))
126 | .into(promptDialog.showAd(true, new OnAdClickListener() {
127 | @Override
128 | public void onAdClick() {
129 | Toast.makeText(MainActivity.this,"点击了广告",Toast.LENGTH_SHORT).show();
130 | }
131 | }));
132 | }
133 | });
134 |
135 | }
136 |
137 | /**
138 | * 根据需要处理返回键,这里主要针对Alert和Sheet的对话框的返回处理
139 | */
140 | @Override
141 | public void onBackPressed() {
142 | if (promptDialog.onBackPressed())
143 | super.onBackPressed();
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
19 |
20 |
25 |
26 |
31 |
32 |
37 |
38 |
43 |
44 |
45 |
49 |
50 |
55 |
56 |
61 |
62 |
67 |
68 |
73 |
74 |
75 |
76 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android-PromptDialog
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/me/leefeng/promptdialog/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.promptdialog;
2 |
3 | import org.junit.Test;
4 |
5 | import java.io.IOException;
6 |
7 | import static org.junit.Assert.*;
8 |
9 | /**
10 | * Example local unit test, which will execute on the development machine (host).
11 | *
12 | * @see Testing documentation
13 | */
14 | public class ExampleUnitTest {
15 | @Test
16 | public void addition_isCorrect() throws Exception {
17 | assertEquals(4, 2 + 2);
18 | System.out.print("asdbja\n");
19 | // boolean pins[][] = new boolean[4][];
20 | // for (int i = 0; i < pins.length; i++) pins[i] = new boolean[i + 1];
21 | // for (int i = 0; i < pins.length; i++) {
22 | // for (int k = 0; k < pins[i].length; k++) System.out.print(pins[i][k] + " ");
23 | // System.out.println("");
24 | // }
25 | test18_2();
26 | new Thread(){
27 | @Override
28 | public void run() {
29 | for (int i=0 ; i<300 ;i++){
30 | System.out.println("第"+i+"次");
31 | try {
32 | sleep(1000);
33 | Runtime.getRuntime().exec("adb shell am start -n me.leefeng.beida/me.leefeng.beida.welcome.WelcomeActivity");
34 | sleep(60000);
35 | Runtime.getRuntime().exec("adb shell am force-stop me.leefeng.beida");
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | } catch (InterruptedException e) {
39 | e.printStackTrace();
40 | }
41 | }
42 | }
43 | }.run();
44 |
45 |
46 |
47 | }
48 |
49 | static int x = 3, y = 4;
50 |
51 | static int p(int a, int b) {
52 | int w = a + b;
53 | a = x + y + b;
54 | b = x + y + w;
55 | System.out.println("w=" + w + " x=" + x + " y=" + y + " a=" + a + " b=" + b);
56 | return b;
57 | }
58 |
59 | public void test18_2() {
60 | int u = 5, v = 6;
61 | u = p(u, v) + v;
62 | System.out.println("u=" + u + " v=" + v + " x=" + x + " y=" + y);
63 | }
64 |
65 | // static int x = 4, y = 5;
66 | //
67 | // static void p(int a, int b) {
68 | // int x = 6;
69 | // a = x + y + b;
70 | // b = x + y + a;
71 | // System.out.println("\tx=" + x + " y=" + y + "\ta=" + a + " b=" + b);
72 | // }
73 |
74 | public void text18() {
75 | int u = 2, v = 3;
76 | p(u, v);
77 | System.out.println("\tu=" + u + " v=" + v + "\tx=" + x + " y=" + y);
78 | }
79 |
80 | void text13() {
81 | int i, n, k, j;
82 | int a[] = new int[9];
83 | a[0] = n = 2;
84 | i = 1;
85 | while (i < a.length) {
86 | n += 1;
87 | j = (int) Math.sqrt(n);
88 | for (k = 2; k <= j; k++) if (n % k == 0) break;
89 | if (i == j) {
90 | a[i] = n;
91 | System.out.println(i + " " + a[i]);
92 | i++;
93 | }
94 | }
95 | n = 0;
96 | // for (k = 0; k <){
97 | // int number = Integer.parseInt(args[0]);
98 | // System.out.println("the square root of " + number + "is " + Math.sqrt(number));
99 | // }
100 | }
101 |
102 | }
103 | //test13
104 | //false
105 | //false false
106 | //false false false
107 | //false false false false
108 |
109 | //1 3
110 | //2 4
111 | //3 9
112 | //4 16
113 | //5 25
114 | //6 36
115 | //7 49
116 | //8 64
117 |
118 | //test18
119 | // x=6 y=5 a=14 b=25
120 | // u=2 v=3 x=4 y=5
121 | //w=11 x=3 y=4 a=13 b=18
122 | //u=24 v=6 x=3 y=4
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 | // NOTE: Do not place your application dependencies here; they belong
10 | // in the individual module build.gradle files
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | jcenter()
17 | maven { url 'https://jitpack.io' }
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue May 09 13:49:17 CST 2017
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-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/promptlibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/promptlibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | android {
3 | compileSdkVersion 25
4 | buildToolsVersion "25.0.3"
5 |
6 | defaultConfig {
7 | minSdkVersion 15
8 | targetSdkVersion 25
9 | versionCode 1
10 | versionName "1.0"
11 |
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26 | exclude group: 'com.android.support', module: 'support-annotations'
27 | })
28 | compile 'com.android.support:appcompat-v7:25.3.1'
29 | testCompile 'junit:junit:4.12'
30 |
31 |
32 | }
--------------------------------------------------------------------------------
/promptlibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/promptlibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/promptlibrary/src/main/java/me/leefeng/promptlibrary/Builder.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.promptlibrary;
2 |
3 | import android.graphics.Color;
4 |
5 | /**
6 | * Created by FengTing on 2017/5/8.
7 | * https://www.github.com/limxing
8 | */
9 |
10 | public class Builder {
11 | private static Builder defaultBuilder;
12 | private static Builder alertDefaultBuilder;
13 | int backColor = Color.BLACK;
14 | int backAlpha = 90;
15 | int textColor = Color.WHITE;
16 | float textSize = 14;
17 | float padding = 15;
18 | float round = 8;
19 | int roundColor = Color.BLACK;
20 | int roundAlpha = 120;
21 | boolean touchAble = false;
22 | boolean withAnim = true;//
23 | long stayDuration = 1000;
24 | boolean cancleAble;
25 | int icon;
26 | String text;
27 | long loadingDuration;
28 |
29 | int sheetPressAlph=15;
30 | int sheetCellHeight=48;
31 | int sheetCellPad=13;
32 |
33 | public Builder sheetCellPad(int pad){
34 | this.sheetCellPad=pad;
35 | return this;
36 | }
37 |
38 | public Builder sheetCellHeight(int height){
39 | this.sheetCellHeight=height;
40 | return this;
41 | }
42 |
43 |
44 | public Builder sheetPressAlph(int alpha){
45 | this.sheetPressAlph=alpha;
46 | return this;
47 | }
48 |
49 | public Builder backColor(int backColor) {
50 | this.backColor = backColor;
51 | return this;
52 | }
53 |
54 | public Builder backAlpha(int backAlpha) {
55 | this.backAlpha = backAlpha;
56 | return this;
57 | }
58 |
59 | public Builder textColor(int textColor) {
60 | this.textColor = textColor;
61 | return this;
62 | }
63 |
64 | public Builder textSize(float textSize) {
65 | this.textSize = textSize;
66 | return this;
67 | }
68 |
69 | public Builder padding(float padding) {
70 | this.padding = padding;
71 | return this;
72 | }
73 |
74 | public Builder round(float round) {
75 | this.round = round;
76 | return this;
77 | }
78 |
79 | public Builder roundColor(int roundColor) {
80 | this.roundColor = roundColor;
81 | return this;
82 | }
83 |
84 | public Builder roundAlpha(int roundAlpha) {
85 | this.roundAlpha = roundAlpha;
86 | return this;
87 | }
88 |
89 | public Builder touchAble(boolean touchAble) {
90 | this.touchAble = touchAble;
91 | return this;
92 | }
93 |
94 | public Builder withAnim(boolean withAnim) {
95 | this.withAnim = withAnim;
96 | return this;
97 | }
98 |
99 | public Builder stayDuration(long time) {
100 | this.stayDuration = time;
101 | return this;
102 | }
103 |
104 | public Builder cancleAble(boolean time) {
105 | this.cancleAble = time;
106 | return this;
107 | }
108 |
109 | public Builder() {
110 | }
111 |
112 | /**
113 | * @return
114 | */
115 | static Builder getDefaultBuilder() {
116 | if (defaultBuilder == null)
117 | defaultBuilder = new Builder();
118 | return defaultBuilder;
119 | }
120 |
121 | static Builder getAlertDefaultBuilder() {
122 | if (alertDefaultBuilder == null)
123 | alertDefaultBuilder = new Builder().roundColor(Color.WHITE).roundAlpha(255).
124 | textColor(Color.GRAY).textSize(15).cancleAble(true);
125 | return alertDefaultBuilder;
126 | }
127 |
128 | public Builder icon(int icon) {
129 | this.icon = icon;
130 | return this;
131 | }
132 |
133 | public Builder text(String msg) {
134 | this.text = msg;
135 | return this;
136 | }
137 |
138 | public Builder loadingDuration(long duration) {
139 | this.loadingDuration = duration;
140 | return this;
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/promptlibrary/src/main/java/me/leefeng/promptlibrary/OnAdClickListener.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.promptlibrary;
2 |
3 | /**
4 | * Created by FengTing on 2017/5/23.
5 | * https://www.github.com/limxing
6 | */
7 |
8 | public interface OnAdClickListener {
9 | void onAdClick();
10 | }
11 |
--------------------------------------------------------------------------------
/promptlibrary/src/main/java/me/leefeng/promptlibrary/PromptButton.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.promptlibrary;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.RectF;
5 |
6 | /**
7 | * Created by FengTing on 2017/5/8.
8 | * https://www.github.com/limxing
9 | */
10 |
11 | public class PromptButton {
12 | private boolean isDelyClick;
13 | private String text = "confirm";
14 | private boolean focus;
15 | private int textColor = Color.BLACK;
16 | private float textSize = 18;
17 | private RectF rect;
18 | private PromptButtonListener listener;
19 | private int focusBacColor= Color.parseColor("#DCDCDC");
20 |
21 | private boolean dismissAfterClick=true;
22 |
23 | public PromptButton(String text, PromptButtonListener listener) {
24 | this.text = text;
25 | this.listener = listener;
26 | }
27 | public PromptButton(String text, PromptButtonListener listener,boolean delayClick) {
28 | this.text = text;
29 | this.listener = listener;
30 | this.isDelyClick=delayClick;
31 | }
32 |
33 | public boolean isFocus() {
34 | return focus;
35 | }
36 |
37 | public void setFocus(boolean focus) {
38 | this.focus = focus;
39 | }
40 |
41 | public String getText() {
42 | return text;
43 | }
44 |
45 | public void setText(String text) {
46 | this.text = text;
47 | }
48 |
49 | public int getTextColor() {
50 | return textColor;
51 | }
52 |
53 | public float getTextSize() {
54 | return textSize;
55 | }
56 |
57 | public void setTouchRect(RectF rectF) {
58 | this.rect = rectF;
59 | }
60 |
61 | public void setTextColor(int textColor) {
62 | this.textColor = textColor;
63 | }
64 |
65 | public void setTextSize(float textSize) {
66 | this.textSize = textSize;
67 | }
68 |
69 | public RectF getRect() {
70 | return rect;
71 | }
72 |
73 | public void setRect(RectF rect) {
74 | this.rect = rect;
75 | }
76 |
77 | public PromptButtonListener getListener() {
78 | return listener;
79 | }
80 |
81 | public void setListener(PromptButtonListener listener) {
82 | this.listener = listener;
83 | }
84 |
85 | public int getFocusBacColor() {
86 | return focusBacColor;
87 | }
88 |
89 | public void setFocusBacColor(int focusBacColor) {
90 | this.focusBacColor = focusBacColor;
91 | }
92 |
93 | public boolean isDismissAfterClick() {
94 | return dismissAfterClick;
95 | }
96 |
97 | public void setDismissAfterClick(boolean dismissAfterClick) {
98 | this.dismissAfterClick = dismissAfterClick;
99 | }
100 |
101 | public boolean isDelyClick() {
102 | return isDelyClick;
103 | }
104 |
105 | public void setDelyClick(boolean delyClick) {
106 | isDelyClick = delyClick;
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/promptlibrary/src/main/java/me/leefeng/promptlibrary/PromptButtonListener.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.promptlibrary;
2 |
3 | /**
4 | * Created by FengTing on 2017/5/8.
5 | * https://www.github.com/limxing
6 | */
7 |
8 | public interface PromptButtonListener {
9 | void onClick(PromptButton button);
10 | }
11 |
--------------------------------------------------------------------------------
/promptlibrary/src/main/java/me/leefeng/promptlibrary/PromptDialog.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.promptlibrary;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ValueAnimator;
5 | import android.app.Activity;
6 | import android.content.Context;
7 | import android.os.Handler;
8 | import android.util.Log;
9 | import android.view.ViewGroup;
10 | import android.view.animation.AccelerateInterpolator;
11 | import android.view.animation.AlphaAnimation;
12 | import android.view.animation.Animation;
13 | import android.view.animation.AnimationSet;
14 | import android.view.animation.DecelerateInterpolator;
15 | import android.view.animation.ScaleAnimation;
16 | import android.view.inputmethod.InputMethodManager;
17 | import android.widget.ImageView;
18 |
19 |
20 | /**
21 | * Created by limxing on 2017/5/7.
22 | * https://www.github.com/limxing
23 | */
24 |
25 | public class PromptDialog {
26 | private final String TAG = "PromptDialog";
27 |
28 | private InputMethodManager inputmanger;
29 | private Animation outAnim;
30 | private Animation inAnim;
31 | private PromptView promptView;
32 | private ViewGroup decorView;
33 | private ValueAnimator dissmissAnim;
34 | private boolean dissmissAnimCancle;
35 | private boolean outAnimRunning;
36 | public static long viewAnimDuration = 300;
37 | private boolean isShowing;
38 | private AnimationSet inSheetAnim;
39 | private AlphaAnimation outSheetAnim;
40 | private AnimationSet inDefaultAnim;
41 | private AnimationSet outDefaultAnim;
42 | private OnAdClickListener adListener;
43 | private Runnable runnable;
44 | private Handler handler;
45 |
46 | /**
47 | * 设置进入 进出动画持续的事件默认300毫秒
48 | *
49 | * @param viewAnimDuration 毫秒
50 | */
51 | public void setViewAnimDuration(long viewAnimDuration) {
52 | this.viewAnimDuration = viewAnimDuration;
53 | }
54 |
55 | public long getViewAnimDuration() {
56 | return viewAnimDuration;
57 | }
58 |
59 | public void onDetach() {
60 | isShowing = false;
61 | }
62 |
63 |
64 | public PromptDialog(Activity context) {
65 | this(Builder.getDefaultBuilder(), context);
66 | }
67 |
68 | public PromptDialog(Builder builder, Activity context) {
69 | decorView = (ViewGroup) context.getWindow().getDecorView().findViewById(android.R.id.content);
70 |
71 | promptView = new PromptView(context, builder, this);
72 | initAnim(context.getResources().getDisplayMetrics().widthPixels,
73 | context.getResources().getDisplayMetrics().heightPixels);
74 | inputmanger = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
75 | handler = new Handler();
76 | }
77 |
78 |
79 | private void initAnim(int widthPixels, int heightPixels) {
80 |
81 | inDefaultAnim = new AnimationSet(true);
82 | ScaleAnimation scaleAnimation = new ScaleAnimation(2, 1f, 2,
83 | 1f, widthPixels * 0.5f, heightPixels * 0.45f);
84 | inDefaultAnim.addAnimation(scaleAnimation);
85 |
86 | AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
87 | inDefaultAnim.addAnimation(alphaAnimation);
88 | inDefaultAnim.setDuration(viewAnimDuration);
89 | inDefaultAnim.setFillAfter(false);
90 | inDefaultAnim.setInterpolator(new DecelerateInterpolator());
91 |
92 | outDefaultAnim = new AnimationSet(true);
93 | scaleAnimation = new ScaleAnimation(1, 2, 1,
94 | 2, widthPixels * 0.5f, heightPixels * 0.45f);
95 | alphaAnimation = new AlphaAnimation(1, 0);
96 | alphaAnimation.setDuration(200);
97 | outDefaultAnim.addAnimation(scaleAnimation);
98 | outDefaultAnim.addAnimation(alphaAnimation);
99 | outDefaultAnim.setDuration(viewAnimDuration);
100 | outDefaultAnim.setFillAfter(false);
101 | outDefaultAnim.setInterpolator(new AccelerateInterpolator());
102 |
103 | alphaAnimation = new AlphaAnimation(0, 1);
104 | scaleAnimation = new ScaleAnimation(1, 1, 1,
105 | 1, widthPixels * 0.5f, heightPixels * 0.5f);
106 | inSheetAnim = new AnimationSet(true);
107 | inSheetAnim.addAnimation(alphaAnimation);
108 | inSheetAnim.addAnimation(scaleAnimation);
109 | inSheetAnim.setDuration(viewAnimDuration);
110 | inSheetAnim.setFillAfter(false);
111 |
112 |
113 | outSheetAnim = new AlphaAnimation(1, 0);
114 | outSheetAnim.setDuration(viewAnimDuration);
115 | outSheetAnim.setFillAfter(false);
116 |
117 |
118 | }
119 |
120 | public void setOutAnim(Animation outAnim) {
121 | this.outAnim = outAnim;
122 | }
123 |
124 | public void setInAnim(Animation inAnim) {
125 | this.inAnim = inAnim;
126 | }
127 |
128 | /**
129 | * 立刻关闭窗口
130 | */
131 | public void dismissImmediately() {
132 | if (isShowing && !outAnimRunning) {
133 | decorView.removeView(promptView);
134 | isShowing = false;
135 | }
136 | }
137 |
138 | /**
139 | * close
140 | */
141 | public void dismiss() {
142 |
143 | if (isShowing && !outAnimRunning) {
144 | if (promptView.getBuilder().withAnim && outAnim != null) {
145 | // outAnim.setStartOffset(delayTime);
146 | if (promptView.getCurrentType() == PromptView.PROMPT_LOADING) {
147 | outAnim.setStartOffset(promptView.getBuilder().loadingDuration);
148 | } else {
149 | outAnim.setStartOffset(0);
150 | }
151 | if (promptView.getCurrentType() == PromptView.CUSTOMER_LOADING) {
152 | promptView.stopCustomerLoading();
153 | }
154 |
155 | promptView.dismiss();
156 | promptView.startAnimation(outAnim);
157 | outAnim.setAnimationListener(new Animation.AnimationListener() {
158 | @Override
159 | public void onAnimationStart(Animation animation) {
160 | outAnimRunning = true;
161 | }
162 |
163 | @Override
164 | public void onAnimationEnd(Animation animation) {
165 | decorView.removeView(promptView);
166 | outAnimRunning = false;
167 | isShowing = false;
168 | }
169 |
170 | @Override
171 | public void onAnimationRepeat(Animation animation) {
172 |
173 | }
174 | });
175 | } else {
176 | dismissImmediately();
177 | }
178 |
179 | }
180 |
181 | }
182 |
183 | public void showError(String msg) {
184 | showError(msg, true);
185 |
186 | }
187 |
188 | public void showError(String msg, boolean withAnim) {
189 | showSomthing(R.drawable.ic_prompt_error, PromptView.PROMPT_ERROR, msg, withAnim);
190 |
191 | }
192 |
193 | public void showInfo(String msg) {
194 | showInfo(msg, true);
195 | }
196 |
197 | public void showInfo(String msg, boolean withAnim) {
198 | showSomthing(R.drawable.ic_prompt_info, PromptView.PROMPT_INFO, msg, withAnim);
199 | }
200 |
201 | public void showWarn(String msg) {
202 | showWarn(msg, true);
203 | }
204 |
205 | public void showWarn(String msg, boolean withAnim) {
206 | showSomthing(R.drawable.ic_prompt_warn, PromptView.PROMPT_WARN, msg, withAnim);
207 | }
208 |
209 | public void showSuccess(String msg) {
210 | showSuccess(msg, true);
211 | }
212 |
213 | public void showSuccess(String msg, boolean withAnim) {
214 | showSomthing(R.drawable.ic_prompt_success, PromptView.PROMPT_SUCCESS, msg, withAnim);
215 | }
216 |
217 | public void showSuccessDelay(final String msg, long delay) {
218 | decorView.postDelayed(new Runnable() {
219 | @Override
220 | public void run() {
221 | showSuccess(msg);
222 | }
223 | }, delay);
224 |
225 | }
226 |
227 | /**
228 | * show custome dialog
229 | *
230 | * @param icon
231 | * @param msg
232 | */
233 | public void showCustom(int icon, String msg) {
234 | showCustom(icon, msg, true);
235 | }
236 |
237 | public void showCustom(int icon, String msg, boolean withAnim) {
238 | showSomthing(icon, PromptView.PROMPT_CUSTOM, msg, withAnim);
239 | }
240 |
241 | private void showSomthing(int icon, int promptError, String msg, boolean withAnim) {
242 | inAnim = inDefaultAnim;
243 | outAnim = outDefaultAnim;
244 | Builder builder = Builder.getDefaultBuilder();
245 | builder.text(msg);
246 | builder.icon(icon);
247 | closeInput();
248 | checkLoadView(withAnim);
249 | if (isShowing) {
250 | promptView.setBuilder(builder);
251 | promptView.showSomthing(promptError);
252 | dissmissAni(false);
253 | }
254 | }
255 |
256 | public void showWarnAlert(String text, PromptButton button) {
257 | showWarnAlert(text, button, false);
258 | }
259 |
260 | public void showWarnAlert(String text, PromptButton button, boolean withAnim) {
261 | showAlert(text, withAnim, button);
262 | }
263 |
264 | /**
265 | * 展示警告对话框
266 | *
267 | * @param text
268 | * @param button1
269 | * @param button2
270 | * @param withAnim 是否动画进入
271 | */
272 | public void showWarnAlert(String text, PromptButton button1, PromptButton button2, boolean withAnim) {
273 | showAlert(text, withAnim, button1, button2);
274 | }
275 |
276 | public void showWarnAlert(String text, PromptButton button1, PromptButton button2) {
277 | showWarnAlert(text, button1, button2, true);
278 | }
279 |
280 | public void showAlertSheet(String title, boolean withAnim, PromptButton... button) {
281 | showAlert(title, withAnim, button);
282 | }
283 |
284 | private void showAlert(String text, boolean withAnim, PromptButton... button) {
285 | if (button.length > 2) {
286 | Log.i(TAG, "showAlert: " + promptView.getScrollY());
287 |
288 | inAnim = inSheetAnim;
289 | outAnim = outSheetAnim;
290 | } else {
291 | inAnim = inDefaultAnim;
292 | outAnim = outDefaultAnim;
293 | }
294 | Builder builder = Builder.getAlertDefaultBuilder();
295 | builder.text(text);
296 | builder.icon(R.drawable.ic_prompt_alert_warn);
297 | closeInput();
298 | promptView.setBuilder(builder);
299 | checkLoadView(withAnim);
300 | promptView.showSomthingAlert(button);
301 | dissmissAni(true);
302 |
303 |
304 | }
305 |
306 | public ImageView showAd(boolean withAnim, OnAdClickListener listener) {
307 | this.adListener = listener;
308 | inAnim = inSheetAnim;
309 | outAnim = outSheetAnim;
310 | Builder builder = Builder.getDefaultBuilder();
311 | builder.touchAble(false);
312 | // builder.text(msg);
313 | // builder.icon(icon);
314 | // builder.
315 | closeInput();
316 | checkLoadView(withAnim);
317 | promptView.setBuilder(builder);
318 | promptView.showAd();
319 | dissmissAni(true);
320 | return promptView;
321 | }
322 |
323 | /**
324 | * 展示loading
325 | *
326 | * @param msg 信息
327 | * @param withAnim 是否动画进入
328 | */
329 | public void showLoading(String msg, boolean withAnim) {
330 | inAnim = inDefaultAnim;
331 | outAnim = outDefaultAnim;
332 | if (promptView.getCurrentType() != PromptView.PROMPT_LOADING) {
333 | Builder builder = Builder.getDefaultBuilder();
334 | builder.icon(R.drawable.ic_prompt_loading);
335 | builder.text(msg);
336 | promptView.setBuilder(builder);
337 | closeInput();
338 | checkLoadView(withAnim);
339 | promptView.showLoading();
340 | dissmissAni(true);
341 | } else {
342 | promptView.setText(msg);
343 | }
344 | }
345 |
346 | /**
347 | * 展示加载中
348 | *
349 | * @param msg
350 | */
351 | public void showLoading(String msg) {
352 | showLoading(msg, true);
353 | }
354 |
355 | /** 延迟展示loading
356 | * @param msg
357 | * @param time
358 | */
359 | public void showLoadingWithDelay(final String msg, long time) {
360 | if (runnable != null) handler.removeCallbacks(runnable);
361 | runnable = new Runnable() {
362 | @Override
363 | public void run() {
364 | showLoading(msg);
365 | }
366 | };
367 | handler.postDelayed(runnable, time);
368 |
369 | }
370 |
371 | /**
372 | * promptview isshowing
373 | *
374 | * @param withAnim
375 | */
376 | private void checkLoadView(boolean withAnim) {
377 | if (!isShowing) {
378 | decorView.addView(promptView);
379 | isShowing = true;
380 | if (promptView.getBuilder().withAnim && inAnim != null && withAnim)
381 | promptView.startAnimation(inAnim);
382 | }
383 | }
384 |
385 | /**
386 | * dismiss dialog and start animation
387 | */
388 | private void dissmissAni(boolean isCancle) {
389 | if (dissmissAnim == null) {
390 | dissmissAnim = ValueAnimator.ofInt(0, 1);
391 | dissmissAnim.setDuration(promptView.getBuilder().stayDuration);
392 | dissmissAnim.addListener(new Animator.AnimatorListener() {
393 | @Override
394 | public void onAnimationStart(Animator animation) {
395 |
396 | }
397 |
398 | @Override
399 | public void onAnimationEnd(Animator animation) {
400 | if (!dissmissAnimCancle) {
401 | dismiss();
402 | }
403 | }
404 |
405 | @Override
406 | public void onAnimationCancel(Animator animation) {
407 |
408 | }
409 |
410 | @Override
411 | public void onAnimationRepeat(Animator animation) {
412 |
413 | }
414 | });
415 | } else if (dissmissAnim.isRunning()) {
416 | dissmissAnimCancle = true;
417 | dissmissAnim.end();
418 |
419 | }
420 | if (!isCancle) {
421 | dissmissAnim.start();
422 | dissmissAnimCancle = false;
423 | }
424 | }
425 |
426 | protected void closeInput() {
427 | if (decorView != null) {
428 | inputmanger.hideSoftInputFromWindow(decorView.getWindowToken(), 0);
429 |
430 | }
431 | // window.closeAllPanels();
432 | }
433 |
434 | /**
435 | * 获取提示框的配置类
436 | *
437 | * @return
438 | */
439 | public Builder getDefaultBuilder() {
440 | return Builder.getDefaultBuilder();
441 | }
442 |
443 | /**
444 | * 获取对话框的配置类
445 | *
446 | * @return
447 | */
448 | public Builder getAlertDefaultBuilder() {
449 | return Builder.getAlertDefaultBuilder();
450 | }
451 |
452 | /**
453 | * 处理返回键,需要用户自行调用
454 | *
455 | * @return
456 | */
457 | public boolean onBackPressed() {
458 | if (isShowing && promptView.getCurrentType() == PromptView.PROMPT_LOADING) {
459 | return false;
460 | }
461 | if (isShowing && (promptView.getCurrentType() == PromptView.PROMPT_ALERT_WARN ||
462 | promptView.getCurrentType() == PromptView.PROMPT_AD)) {
463 | dismiss();
464 | return false;
465 | } else {
466 | return true;
467 | }
468 | }
469 |
470 |
471 | public void onAdClick() {
472 | if (adListener != null) {
473 | adListener.onAdClick();
474 | }
475 | }
476 |
477 | /**
478 | * 加载自定义的loading
479 | *
480 | * @param logo_loading 图片数组
481 | * @param msg 展现消息
482 | */
483 | public void showCustomLoading(int logo_loading, String msg) {
484 |
485 | inAnim = inDefaultAnim;
486 | outAnim = outDefaultAnim;
487 | if (promptView.getCurrentType() != PromptView.CUSTOMER_LOADING) {
488 | Builder builder = Builder.getDefaultBuilder();
489 | builder.icon(logo_loading);
490 | builder.text(msg);
491 | promptView.setBuilder(builder);
492 | closeInput();
493 | checkLoadView(true);
494 | promptView.showCustomLoading();
495 | dissmissAni(true);
496 | } else {
497 | promptView.setText(msg);
498 | }
499 |
500 | }
501 |
502 | /**
503 | * 延迟加载自定义loading
504 | *
505 | * @param logo_loading
506 | * @param msg
507 | * @param time
508 | */
509 | public void showCustomerLoadingWithDelay(final int logo_loading, final String msg, long time) {
510 | runnable = new Runnable() {
511 | @Override
512 | public void run() {
513 | showCustomLoading(logo_loading, msg);
514 | }
515 | };
516 | handler.postDelayed(runnable, time);
517 | }
518 | }
519 |
--------------------------------------------------------------------------------
/promptlibrary/src/main/java/me/leefeng/promptlibrary/PromptView.java:
--------------------------------------------------------------------------------
1 | package me.leefeng.promptlibrary;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.annotation.SuppressLint;
6 | import android.app.Activity;
7 | import android.content.Context;
8 | import android.graphics.Bitmap;
9 | import android.graphics.BitmapFactory;
10 | import android.graphics.Canvas;
11 | import android.graphics.Color;
12 | import android.graphics.Matrix;
13 | import android.graphics.Paint;
14 | import android.graphics.PixelFormat;
15 | import android.graphics.PorterDuff;
16 | import android.graphics.PorterDuffXfermode;
17 | import android.graphics.Rect;
18 | import android.graphics.RectF;
19 | import android.graphics.drawable.AnimationDrawable;
20 | import android.graphics.drawable.BitmapDrawable;
21 | import android.graphics.drawable.Drawable;
22 | import android.graphics.drawable.ShapeDrawable;
23 | import android.graphics.drawable.shapes.RoundRectShape;
24 | import android.support.annotation.NonNull;
25 | import android.util.AttributeSet;
26 | import android.util.Log;
27 | import android.view.MotionEvent;
28 | import android.view.animation.Animation;
29 | import android.view.animation.LinearInterpolator;
30 | import android.widget.ImageView;
31 |
32 | /**
33 | * Created by limxing on 16/1/7.
34 | * https://www.github.com/limxing
35 | */
36 | @SuppressLint("AppCompatCustomView")
37 | class PromptView extends ImageView {
38 | public static final int PROMPT_SUCCESS = 101;
39 | public static final int PROMPT_LOADING = 102;
40 | public static final int PROMPT_ERROR = 103;
41 | public static final int PROMPT_NONE = 104;
42 | public static final int PROMPT_INFO = 105;
43 | public static final int PROMPT_WARN = 106;
44 | public static final int PROMPT_ALERT_WARN = 107;
45 | private static final String TAG = "LOADVIEW";
46 | public static final int PROMPT_CUSTOM = 108;
47 | public static final int PROMPT_AD = 109;
48 | public static final int CUSTOMER_LOADING = 110;
49 | private PromptDialog promptDialog;
50 | private Builder builder;
51 | private int width;
52 | private int height;
53 | private ValueAnimator animator;
54 | private Paint paint;
55 | private float density;
56 | private Rect textRect;
57 | private int canvasWidth;
58 | private int canvasHeight;
59 | private RectF roundRect;
60 | private int currentType;//当前窗口类型
61 | private PromptButton[] buttons = new PromptButton[]{};
62 | private RectF roundTouchRect;
63 | float buttonW;
64 | float buttonH;
65 | private boolean isSheet;
66 | private float bottomHeight;
67 | private float sheetHeight;
68 | private Drawable drawableClose;
69 | private int transX;
70 | private int transY;
71 | private Bitmap adBitmap;
72 |
73 | // private static final int sheetCellHeight = 54;
74 | // private static final int sheetCellPad = 13;
75 | // private final int pressAlph = 15;
76 |
77 |
78 | public PromptView(Context context) {
79 | super(context);
80 | }
81 |
82 | public PromptView(Context context, AttributeSet attrs) {
83 | super(context, attrs);
84 | }
85 |
86 | public PromptView(Context context, AttributeSet attrs, int defStyleAttr) {
87 | super(context, attrs, defStyleAttr);
88 | }
89 |
90 | public PromptView(Activity context, Builder builder, PromptDialog promptDialog) {
91 | super(context);
92 | density = getResources().getDisplayMetrics().density;
93 |
94 | this.builder = builder;
95 | this.promptDialog = promptDialog;
96 |
97 | }
98 |
99 | /**
100 | * 根据原图添加圆角
101 | *
102 | * @param source
103 | * @return
104 | */
105 | private Bitmap createRoundConerImage(Bitmap source) {
106 | final Paint paint = new Paint();
107 | paint.setAntiAlias(true);
108 | Bitmap target = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
109 | Canvas canvas = new Canvas(target);
110 | RectF rect = new RectF(0, 0, source.getWidth(), source.getHeight());
111 | float mRadius = 50;
112 | canvas.drawRoundRect(rect, mRadius, mRadius, paint);
113 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
114 | canvas.drawBitmap(source, 0, 0, paint);
115 | // source.draw(canvas);
116 | return target;
117 | }
118 |
119 |
120 | @Override
121 | protected void onDraw(Canvas canvas) {
122 | if (paint == null) return;
123 | if (canvasWidth == 0) {
124 | canvasWidth = getWidth();
125 | canvasHeight = getHeight();
126 | }
127 |
128 | paint.reset();
129 | paint.setAntiAlias(true);
130 | paint.setColor(builder.backColor);
131 | paint.setAlpha(builder.backAlpha);
132 | canvas.drawRect(0, 0, canvasWidth, canvasHeight, paint);
133 | if (currentType == PROMPT_AD) {
134 | Drawable drawable = getDrawable();
135 | if (drawable == null) return;
136 | Rect bound = drawable.getBounds();
137 | transX = canvasWidth / 2 - bound.width() / 2;
138 | transY = canvasHeight / 2 - bound.height() / 2 - bound.height() / 10;
139 | canvas.translate(transX, transY);
140 |
141 | if (adBitmap == null) {
142 | Bitmap.Config config =
143 | drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
144 | : Bitmap.Config.RGB_565;
145 | Bitmap bitmap = Bitmap.createBitmap(drawable.getMinimumWidth(), drawable.getMinimumHeight(), config);
146 | Canvas ca = new Canvas(bitmap);
147 | drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
148 | drawable.draw(ca);
149 | adBitmap = createRoundConerImage(bitmap);
150 | }
151 | canvas.drawBitmap(adBitmap, 0, 0, null);
152 | // drawable.draw(canvas);
153 | if (drawableClose == null)
154 | drawableClose = getResources().getDrawable(R.drawable.ic_prompt_close);
155 | width = drawableClose.getMinimumWidth() / 2;
156 | height = drawableClose.getMinimumHeight() / 2;
157 | int left = bound.width() / 2 - width;
158 | // int top = canvasHeight - canvasHeight / 2 + bound.height() / 2 + bound.height() / 10 + height * 4;
159 | int top = bound.height() + height;
160 | int right = left + width * 2;
161 | int bottom = top + height * 2;
162 | drawableClose.setBounds(left, top, right, bottom);
163 | drawableClose.draw(canvas);
164 | canvas.save();
165 | return;
166 | }
167 | if (isSheet) {
168 | String text = builder.text;
169 | boolean textNotNull = text != null && text.length() > 0;
170 |
171 | if (roundTouchRect == null)
172 | roundTouchRect = new RectF();
173 | roundTouchRect.set(0, canvasHeight - bottomHeight, canvasWidth, canvasHeight);
174 |
175 | canvas.translate(0, canvasHeight - bottomHeight);
176 | // paint.reset();
177 | // paint.setAntiAlias(true);
178 | // paint.setColor(Color.WHITE);
179 | // canvas.drawRect(0, 0, canvasWidth, canvasHeight - sheetHeight, paint);
180 |
181 |
182 | paint.reset();
183 | paint.setAntiAlias(true);
184 | paint.setColor(Color.WHITE);
185 | paint.setAlpha(builder.roundAlpha);
186 | int sheetCellPad = builder.sheetCellPad;
187 | float padBottom = sheetCellPad * density;
188 | float left = padBottom;
189 | float top = sheetHeight - padBottom - builder.sheetCellHeight * density;
190 | float right = canvasWidth - padBottom;
191 | float bottom = sheetHeight - padBottom;
192 | float round = builder.round * density;
193 | if (roundRect == null) roundRect = new RectF();
194 | roundRect.set(left, top, right, bottom);
195 | canvas.drawRoundRect(roundRect, round, round, paint);
196 |
197 | bottom = top - padBottom / 2;
198 | top = 0;
199 | if (textNotNull) {
200 | paint.reset();
201 | paint.setColor(builder.textColor);
202 | paint.setStrokeWidth(1 * density);
203 | paint.setTextSize(density * builder.textSize);
204 | paint.setAntiAlias(true);
205 | paint.getTextBounds(text, 0, text.length(), textRect);
206 | top = -textRect.height() - 1.5f * builder.sheetCellPad * density;
207 | }
208 | paint.reset();
209 | paint.setAntiAlias(true);
210 | paint.setColor(Color.WHITE);
211 | paint.setAlpha(builder.roundAlpha);
212 | roundRect.set(left, top, right, bottom);
213 | canvas.drawRoundRect(roundRect, round, round, paint);
214 | //画分割线
215 | paint.setColor(Color.GRAY);
216 | paint.setAlpha(100);
217 | paint.setStrokeWidth(1);
218 | paint.setAntiAlias(true);
219 | top = bottom - builder.sheetCellHeight * density;
220 | canvas.drawLine(left, top, right, top, paint);
221 | if (builder.sheetCellPad == 0) {
222 | canvas.drawLine(left, bottom, right, bottom, paint);
223 | }
224 | if (textNotNull) {
225 | canvas.drawLine(left, 0, right, 0, paint);
226 | }
227 |
228 | PromptButton button = buttons[0];
229 |
230 | String buttonText = button.getText();
231 | paint.reset();
232 | paint.setColor(button.getTextColor());
233 | paint.setStrokeWidth(1 * density);
234 | paint.setTextSize(density * button.getTextSize());
235 | paint.setAntiAlias(true);
236 | paint.getTextBounds(buttonText, 0, buttonText.length(), textRect);
237 |
238 | bottom = sheetHeight - sheetCellPad * density - builder.sheetCellHeight * density / 2 + textRect.height() / 2;
239 | left = canvasWidth / 2 - textRect.width() / 2;
240 | if (button.getRect() == null)
241 | button.setTouchRect(new RectF(sheetCellPad * density, canvasHeight -
242 | sheetCellPad * density - builder.sheetCellHeight * density,
243 | canvasWidth - sheetCellPad * density, canvasHeight - sheetCellPad * density));
244 | canvas.drawText(buttonText, left, bottom, paint);
245 | if (button.isFocus()) {
246 | paint.reset();
247 | paint.setAntiAlias(true);
248 | paint.setColor(Color.BLACK);
249 | paint.setAlpha(builder.sheetPressAlph);
250 | RectF rect = new RectF(sheetCellPad * density, sheetHeight -
251 | sheetCellPad * density - builder.sheetCellHeight * density,
252 | canvasWidth - sheetCellPad * density, sheetHeight -
253 | sheetCellPad * density);
254 | canvas.drawRoundRect(rect, round, round, paint);
255 | }
256 | //第一个选择
257 | button = buttons[1];
258 | buttonText = button.getText();
259 | paint.reset();
260 | paint.setColor(button.getTextColor());
261 | paint.setStrokeWidth(1 * density);
262 | paint.setTextSize(density * button.getTextSize());
263 | paint.setAntiAlias(true);
264 | paint.getTextBounds(buttonText, 0, buttonText.length(), textRect);
265 |
266 | bottom = sheetHeight - 1.5f * sheetCellPad * density -
267 | builder.sheetCellHeight * density * 1.5f + textRect.height() / 2;
268 | left = canvasWidth / 2 - textRect.width() / 2;
269 | if (button.getRect() == null)
270 | button.setTouchRect(new RectF(sheetCellPad * density, canvasHeight - 1.5f * sheetCellPad * density - 2f * builder.sheetCellHeight * density,
271 | canvasWidth - sheetCellPad * density, canvasHeight - 1.5f * sheetCellPad * density - builder.sheetCellHeight * density));
272 | canvas.drawText(buttonText, left, bottom, paint);
273 | if (button.isFocus()) {
274 | float[] outerR = new float[]{0, 0, 0, 0, round, round, round, round};
275 | ShapeDrawable mDrawables = new ShapeDrawable(new RoundRectShape(outerR, null, null));
276 | mDrawables.getPaint().setColor(Color.BLACK);
277 | mDrawables.getPaint().setAlpha(builder.sheetPressAlph);
278 | RectF rect = button.getRect();
279 | Rect rectPre = new Rect((int) rect.left, (int) (rect.top - canvasHeight + sheetHeight),
280 | (int) rect.right, (int) (rect.bottom - canvasHeight + sheetHeight));
281 | mDrawables.setBounds(rectPre);
282 | mDrawables.draw(canvas);
283 |
284 | }
285 |
286 | for (int i = 2; i < buttons.length; i++) {
287 | button = buttons[i];
288 | buttonText = button.getText();
289 | paint.reset();
290 | paint.setColor(button.getTextColor());
291 | paint.setStrokeWidth(1 * density);
292 | paint.setTextSize(density * button.getTextSize());
293 | paint.setAntiAlias(true);
294 | paint.getTextBounds(buttonText, 0, buttonText.length(), textRect);
295 | bottom = sheetHeight - 1.5f * sheetCellPad * density - (i + 0.5f) * builder.sheetCellHeight * density + textRect.height() / 2;
296 | left = canvasWidth / 2 - textRect.width() / 2;
297 | if (button.getRect() == null)
298 | button.setTouchRect(new RectF(sheetCellPad * density, canvasHeight - 1.5f * sheetCellPad * density - (i + 1f) * builder.sheetCellHeight * density,
299 | canvasWidth - sheetCellPad * density, canvasHeight - 1.5f * sheetCellPad * density - i * builder.sheetCellHeight * density));
300 | canvas.drawText(buttonText, left, bottom, paint);
301 |
302 | if (i != buttons.length - 1) {
303 | paint.setColor(Color.GRAY);
304 | paint.setAlpha(100);
305 | paint.setStrokeWidth(1);
306 | paint.setAntiAlias(true);
307 |
308 | top = sheetHeight - 1.5f * padBottom - (i + 1) * builder.sheetCellHeight * density;
309 |
310 | canvas.drawLine(padBottom, top, canvasWidth - padBottom, top, paint);
311 |
312 | }
313 |
314 | if (button.isFocus()) {
315 | RectF rect = button.getRect();
316 | Rect rectPre = new Rect((int) rect.left, (int) (rect.top - canvasHeight + sheetHeight),
317 | (int) rect.right, (int) (rect.bottom - canvasHeight + sheetHeight));
318 | if (i == buttons.length - 1 && !textNotNull) {
319 |
320 | float[] outerR = new float[]{round, round, round, round, 0, 0, 0, 0};
321 | ShapeDrawable mDrawables = new ShapeDrawable(new RoundRectShape(outerR, null, null));
322 | mDrawables.getPaint().setColor(Color.BLACK);
323 | mDrawables.getPaint().setAlpha(builder.sheetPressAlph);
324 | mDrawables.setBounds(rectPre);
325 | mDrawables.draw(canvas);
326 |
327 | } else {
328 | paint.reset();
329 | paint.setAntiAlias(true);
330 | paint.setColor(Color.BLACK);
331 | paint.setAlpha(builder.sheetPressAlph);
332 | canvas.drawRect(rectPre, paint);
333 | }
334 | }
335 | }
336 |
337 | if (textNotNull) {
338 | paint.reset();
339 | paint.setColor(builder.textColor);
340 | paint.setStrokeWidth(1 * density);
341 | paint.setTextSize(density * builder.textSize);
342 | paint.setAntiAlias(true);
343 | paint.getTextBounds(text, 0, text.length(), textRect);
344 | //文字背景
345 | // float[] outerR = new float[]{round, round, round, round, 0, 0, 0, 0};
346 | // ShapeDrawable mDrawables = new ShapeDrawable(new RoundRectShape(outerR, null, null));
347 | // mDrawables.getPaint().setColor(Color.WHITE);
348 | top = -textRect.height() - 1.5f * builder.sheetCellPad * density;
349 | // Rect rectPre = new Rect((int) (builder.sheetCellPad * density), (int) top,
350 | // (int) (canvasWidth - builder.sheetCellPad * density), 0);
351 | // mDrawables.setBounds(rectPre);
352 | // mDrawables.draw(canvas);
353 |
354 | canvas.drawText(text, canvasWidth / 2 - textRect.width() / 2, top / 2 + textRect.height() / 2, paint);
355 |
356 | }
357 |
358 | return;
359 | }
360 |
361 |
362 | String text = builder.text;
363 | float pad = builder.padding * density;
364 | float round = builder.round * density;
365 | paint.reset();
366 | paint.setColor(builder.textColor);
367 | paint.setStrokeWidth(1 * density);
368 | paint.setTextSize(density * builder.textSize);
369 | paint.setAntiAlias(true);
370 | paint.getTextBounds(text, 0, text.length(), textRect);
371 | // paint.getTextBounds(text, 0, text.length(), textRect);
372 | float popWidth = 0;
373 | float popHeight = 0;
374 |
375 | switch (currentType) {
376 | case PROMPT_ALERT_WARN:
377 |
378 | popWidth = Math.max(textRect.width() + pad * 2, 2 * buttonW);
379 | if (buttonW * 2 < textRect.width() + pad * 2) {
380 | buttonW = (textRect.width() + pad * 2) / 2;
381 | }
382 |
383 | popHeight = textRect.height() + 3 * pad + height * 2 + buttonH;
384 | break;
385 | default:
386 | popWidth = Math.max(100 * density, textRect.width() + pad * 2);
387 | popHeight = textRect.height() + 3 * pad + height * 2;
388 | break;
389 | }
390 |
391 |
392 | float transTop = canvasHeight / 2 - popHeight / 2;
393 | float transLeft = canvasWidth / 2 - popWidth / 2;
394 |
395 | canvas.translate(transLeft, transTop);
396 |
397 |
398 | paint.reset();
399 | paint.setAntiAlias(true);
400 | paint.setColor(builder.roundColor);
401 | paint.setAlpha(builder.roundAlpha);
402 | if (roundTouchRect == null)
403 | roundTouchRect = new RectF();
404 | roundTouchRect.set(transLeft, transTop, transLeft + popWidth, transTop + popHeight);
405 | if (roundRect == null)
406 | roundRect = new RectF(0, 0, popWidth, popHeight);
407 | roundRect.set(0, 0, popWidth, popHeight);
408 | canvas.drawRoundRect(roundRect, round, round, paint);
409 |
410 |
411 | paint.reset();
412 | paint.setColor(builder.textColor);
413 | paint.setStrokeWidth(1 * density);
414 | paint.setTextSize(density * builder.textSize);
415 | paint.setAntiAlias(true);
416 |
417 | float top = pad * 2 + height * 2 + textRect.height();
418 | float left = popWidth / 2 - textRect.width() / 2;
419 |
420 | // canvas.save();
421 | // canvas.translate(left, top);
422 | // layout.draw(canvas);
423 | // canvas.restore();//别忘了restore
424 | canvas.drawText(text, left, top, paint);
425 |
426 |
427 | if (currentType == PROMPT_ALERT_WARN) {
428 | top = top + pad;
429 | paint.setColor(Color.GRAY);
430 | paint.setStrokeWidth(1);
431 | paint.setAntiAlias(true);
432 | canvas.drawLine(0, top, popWidth, top, paint);
433 | if (buttons.length == 1) {
434 | PromptButton button = buttons[0];
435 | if (button.isFocus()) {
436 | paint.reset();
437 | paint.setAntiAlias(true);
438 | paint.setColor(button.getFocusBacColor());
439 | paint.setStyle(Paint.Style.FILL);
440 |
441 | canvas.drawRect(0, top, popWidth, top + buttonH - round, paint);
442 | canvas.drawCircle(round, top + buttonH - round, round, paint);
443 | canvas.drawCircle(popWidth - round, top + buttonH - round, round, paint);
444 | canvas.drawRect(round, top + buttonH - round, popWidth - round, top + buttonH, paint);
445 |
446 | }
447 |
448 | String buttonText = button.getText();
449 | paint.reset();
450 | paint.setColor(button.getTextColor());
451 | paint.setStrokeWidth(1 * density);
452 | paint.setTextSize(density * button.getTextSize());
453 | paint.setAntiAlias(true);
454 | paint.getTextBounds(buttonText, 0, buttonText.length(), textRect);
455 |
456 | button.setTouchRect(new RectF(transLeft, transTop + top,
457 | transLeft + popWidth, transTop + top + buttonH));
458 | canvas.drawText(buttonText, popWidth / 2 - textRect.width() / 2,
459 | top + textRect.height() / 2 + buttonH / 2, paint);
460 | }
461 | if (buttons.length > 1) {
462 |
463 | canvas.drawLine(popWidth / 2, top, popWidth / 2, popHeight, paint);
464 |
465 | for (int i = 0; i < buttons.length; i++) {
466 | PromptButton button = buttons[i];
467 | if (button.isFocus()) {
468 | paint.reset();
469 | paint.setAntiAlias(true);
470 | paint.setColor(button.getFocusBacColor());
471 | paint.setStyle(Paint.Style.FILL);
472 | // paint.setAlpha(120);
473 | canvas.drawRect(buttonW * i, top + 1, buttonW * (i + 1), top + 1 + buttonH - round, paint);
474 | if (i == 0) {
475 | canvas.drawCircle(round, top + buttonH - round, round, paint);
476 | canvas.drawRect(round, top + buttonH - round, buttonW * (i + 1), top + buttonH, paint);
477 | } else if (i == 1) {
478 | canvas.drawCircle(buttonW * 2 - round, top + buttonH - round, round, paint);
479 | canvas.drawRect(buttonW, top + buttonH - round, buttonW * 2 - round, top + buttonH, paint);
480 | }
481 | }
482 | String buttonText = button.getText();
483 | paint.reset();
484 | paint.setColor(button.getTextColor());
485 | paint.setStrokeWidth(1 * density);
486 | paint.setTextSize(density * button.getTextSize());
487 | paint.setAntiAlias(true);
488 | paint.getTextBounds(buttonText, 0, buttonText.length(), textRect);
489 |
490 | button.setTouchRect(new RectF(transLeft + i * buttonW, transTop + top,
491 | transLeft + i * buttonW + buttonW, transTop + top + buttonH));
492 | canvas.drawText(buttonText, buttonW / 2 - textRect.width() / 2 + i * buttonW,
493 | top + textRect.height() / 2 + buttonH / 2, paint);
494 |
495 | }
496 |
497 | }
498 |
499 | }
500 | canvas.translate(popWidth / 2 - width, pad);
501 | super.onDraw(canvas);
502 | }
503 |
504 | @Override
505 | protected void onAttachedToWindow() {
506 | super.onAttachedToWindow();
507 | setScaleType(ScaleType.MATRIX);
508 |
509 | if (paint == null)
510 | paint = new Paint();
511 | initData();
512 | }
513 |
514 | private void initData() {
515 | if (textRect == null)
516 | textRect = new Rect();
517 | if (roundRect == null)
518 | roundTouchRect = new RectF();
519 |
520 | buttonW = density * 120;
521 | buttonH = density * 44;
522 | }
523 |
524 | @Override
525 | protected void onDetachedFromWindow() {
526 | super.onDetachedFromWindow();
527 |
528 | if (adBitmap != null) {
529 | adBitmap.recycle();
530 | }
531 | adBitmap = null;
532 |
533 | if (animator != null)
534 | animator.cancel();
535 | animator = null;
536 | buttons = null;
537 | // textRect = null;
538 | // roundTouchRect = null;
539 | promptDialog.onDetach();
540 | // promptDialog = null;
541 | currentType = PROMPT_NONE;
542 |
543 | }
544 |
545 |
546 | private Matrix max;
547 |
548 | /**
549 | * loading start
550 | */
551 | private void start() {
552 | if (max == null || animator == null) {
553 | max = new Matrix();
554 | animator = ValueAnimator.ofInt(0, 12);
555 | animator.setDuration(12 * 80);
556 | animator.setInterpolator(new LinearInterpolator());
557 | animator.setRepeatCount(Animation.INFINITE);
558 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
559 | @Override
560 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
561 | float degrees = 30 * (Integer) valueAnimator.getAnimatedValue();
562 | max.setRotate(degrees, width, height);
563 | setImageMatrix(max);
564 | }
565 | });
566 | }
567 | if (!animator.isRunning())
568 | animator.start();
569 | }
570 |
571 |
572 | @Override
573 | public boolean onTouchEvent(MotionEvent event) {
574 | float x = event.getX();
575 | float y = event.getY();
576 | if (currentType == PROMPT_ALERT_WARN) {
577 |
578 | if (builder.cancleAble && event.getAction() == MotionEvent.ACTION_UP && !roundTouchRect.contains(x, y)) {
579 | promptDialog.dismiss();
580 | }
581 | for (final PromptButton button : buttons) {
582 | if (button.getRect() != null && button.getRect().contains(x, y)) {
583 |
584 |
585 | if (event.getAction() == MotionEvent.ACTION_DOWN) {
586 | button.setFocus(true);
587 | invalidate();
588 | }
589 | if (event.getAction() == MotionEvent.ACTION_UP) {
590 | button.setFocus(false);
591 | invalidate();
592 | if (button.isDismissAfterClick())
593 | promptDialog.dismiss();
594 | if (button.getListener() != null) {
595 | if (button.isDelyClick()) {
596 | postDelayed(new Runnable() {
597 | @Override
598 | public void run() {
599 | button.getListener().onClick(button);
600 | }
601 | }, PromptDialog.viewAnimDuration + 100);
602 | } else {
603 | button.getListener().onClick(button);
604 | }
605 |
606 | }
607 |
608 | }
609 | return true;
610 | }
611 | }
612 | if (event.getAction() == MotionEvent.ACTION_UP) {
613 | for (PromptButton button : buttons) {
614 | button.setFocus(false);
615 | invalidate();
616 | }
617 | }
618 | } else if (currentType == PROMPT_AD) {
619 | if (event.getAction() == MotionEvent.ACTION_UP) {
620 | if ((drawableClose != null && drawableClose.getBounds()
621 | .contains((int) event.getX() - transX, (int) event.getY() - transY)) || builder.cancleAble) {
622 | promptDialog.dismiss();
623 | } else if (getDrawable() !=
624 | null && getDrawable().getBounds().contains((int) event.getX() - transX, (int) event.getY() - transY)) {
625 | promptDialog.onAdClick();
626 | promptDialog.dismiss();
627 | }
628 |
629 | }
630 | }
631 | return !builder.touchAble;
632 | }
633 |
634 |
635 | /**
636 | * 停止旋转
637 | */
638 |
639 | private void endAnimator() {
640 | if (animator != null && animator.isRunning()) {
641 | animator.end();
642 | }
643 | }
644 |
645 | /**
646 | *
647 | */
648 | public void showLoading() {
649 | if (currentType == PROMPT_ALERT_WARN) {
650 | isSheet = buttons.length > 2;
651 | } else {
652 | isSheet = false;
653 | }
654 | setImageDrawable(getResources().getDrawable(builder.icon));
655 | width = getDrawable().getMinimumWidth() / 2;
656 | height = getDrawable().getMinimumHeight() / 2;
657 | start();
658 | currentType = PROMPT_LOADING;
659 |
660 | }
661 |
662 | Builder getBuilder() {
663 | return builder;
664 | }
665 |
666 | public void showSomthing(int currentType) {
667 | this.currentType = currentType;
668 | if (currentType == PROMPT_ALERT_WARN) {
669 | isSheet = buttons.length > 2;
670 | } else {
671 | isSheet = false;
672 | }
673 | endAnimator();
674 | setImageDrawable(getResources().getDrawable(builder.icon));
675 | width = getDrawable().getMinimumWidth() / 2;
676 | height = getDrawable().getMinimumHeight() / 2;
677 |
678 | if (max != null) {
679 | max.setRotate(0, width, height);
680 | setImageMatrix(max);
681 | }
682 |
683 | if (isSheet) {
684 | //计算高度
685 | sheetHeight = (1.5f * builder.sheetCellPad + builder.sheetCellHeight * buttons.length) * density;
686 | Log.i(TAG, "showSomthing: " + sheetHeight);
687 | startBottomToTopAnim();
688 | }
689 | invalidate();
690 | }
691 |
692 | /**
693 | * 底部Sheet
694 | */
695 | private void startBottomToTopAnim() {
696 | ValueAnimator bottomToTopAnim = ObjectAnimator.ofFloat(0, 1);
697 | // bottomToTopAnim.setStartDelay(100);
698 | bottomToTopAnim.setDuration(300);
699 | bottomToTopAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
700 | @Override
701 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
702 | Float value = (Float) valueAnimator.getAnimatedValue();
703 | bottomHeight = sheetHeight * value;
704 | Log.i(TAG, "onAnimationUpdate: " + bottomHeight);
705 | invalidate();
706 | }
707 | });
708 | bottomToTopAnim.start();
709 | }
710 |
711 |
712 | void showSomthingAlert(PromptButton... button) {
713 | this.buttons = button;
714 | showSomthing(PROMPT_ALERT_WARN);
715 |
716 | }
717 |
718 | public void setBuilder(Builder builder) {
719 | if (this.builder != builder)
720 | this.builder = builder;
721 | }
722 |
723 | public int getCurrentType() {
724 | return currentType;
725 | }
726 |
727 | public void setText(String msg) {
728 | builder.text(msg);
729 | invalidate();
730 | }
731 |
732 | /**
733 | * 底部Sheet 退出动画
734 | */
735 | public void dismiss() {
736 | // currentType = PROMPT_NONE;
737 | if (isSheet) {
738 |
739 | ValueAnimator bottomToTopAnim = ObjectAnimator.ofFloat(1, 0);
740 | bottomToTopAnim.setDuration(300);
741 | bottomToTopAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
742 | @Override
743 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
744 | Float value = (Float) valueAnimator.getAnimatedValue();
745 | bottomHeight = sheetHeight * value;
746 | invalidate();
747 | }
748 | });
749 | bottomToTopAnim.start();
750 | }
751 |
752 | }
753 |
754 | public void showAd() {
755 | this.currentType = PROMPT_AD;
756 | endAnimator();
757 | }
758 |
759 | /**
760 | * 展示自定义的loading
761 | */
762 | public void showCustomLoading() {
763 | if (currentType == PROMPT_ALERT_WARN) {
764 | isSheet = buttons.length > 2;
765 | } else {
766 | isSheet = false;
767 | }
768 | setImageDrawable(getResources().getDrawable(builder.icon));
769 | width = getDrawable().getMinimumWidth() / 2;
770 | height = getDrawable().getMinimumHeight() / 2;
771 | AnimationDrawable animationDrawable = (AnimationDrawable) getDrawable();
772 | animationDrawable.start();
773 | currentType = CUSTOMER_LOADING;
774 | }
775 |
776 | /**
777 | * 停止自定义的loading
778 | */
779 | public void stopCustomerLoading() {
780 | AnimationDrawable animationDrawable = (AnimationDrawable) getDrawable();
781 | animationDrawable.stop();
782 | }
783 | }
--------------------------------------------------------------------------------
/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_alert_warn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_alert_warn.png
--------------------------------------------------------------------------------
/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_close.png
--------------------------------------------------------------------------------
/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_error.png
--------------------------------------------------------------------------------
/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_info.png
--------------------------------------------------------------------------------
/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_loading.png
--------------------------------------------------------------------------------
/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_success.png
--------------------------------------------------------------------------------
/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_warn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/promptlibrary/src/main/res/drawable-xxxhdpi/ic_prompt_warn.png
--------------------------------------------------------------------------------
/promptlibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PromptLibrary
3 |
4 |
--------------------------------------------------------------------------------
/screen1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/screen1.gif
--------------------------------------------------------------------------------
/screen2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/screen2.jpg
--------------------------------------------------------------------------------
/screen3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/screen3.jpg
--------------------------------------------------------------------------------
/screen4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limxing/Android-PromptDialog/86becdc374ea4057b73aa53222b5128bc9889fc1/screen4.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':promptlibrary'
2 |
--------------------------------------------------------------------------------