├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── helloworld
│ │ │ └── bottommenu
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── helloworld
│ │ │ └── bottommenu
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── helloworld
│ │ └── bottommenu
│ │ └── ExampleInstrumentedTest.java
├── build.gradle
└── proguard-rules.pro
├── mylibrary
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ ├── middle_shape.xml
│ │ │ │ ├── shape_et_cursor.xml
│ │ │ │ ├── edit_shape.xml
│ │ │ │ ├── bottom_menu_mid_selector.xml
│ │ │ │ ├── bottom_menu_btn_selector.xml
│ │ │ │ ├── bottom_menu_top_selector.xml
│ │ │ │ ├── bottom_menu_selector.xml
│ │ │ │ ├── bottom_menu_bottom_selector.xml
│ │ │ │ ├── left_shape.xml
│ │ │ │ ├── right_shape.xml
│ │ │ │ └── bottom_shape.xml
│ │ │ ├── anim
│ │ │ │ ├── menu_appear.xml
│ │ │ │ └── menu_disappear.xml
│ │ │ └── layout
│ │ │ │ ├── item_adapter.xml
│ │ │ │ ├── item_menu.xml
│ │ │ │ ├── fragment_bottom_menu.xml
│ │ │ │ └── dialog_middle.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── helloworld
│ │ │ └── library
│ │ │ ├── utils
│ │ │ ├── DialogEnum.java
│ │ │ ├── Tools.java
│ │ │ ├── ScreenUtils.java
│ │ │ └── DataUtils.java
│ │ │ ├── bean
│ │ │ └── CityJsonDto.java
│ │ │ ├── base
│ │ │ ├── RecyclerHolder.java
│ │ │ └── CommonRecyclerAdapter.java
│ │ │ ├── adapter
│ │ │ ├── Myadapter.java
│ │ │ └── MenuAdapter.java
│ │ │ ├── BottomMenuFragment.java
│ │ │ └── MiddleDialogConfig.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── helloworld
│ │ │ └── bottommenu
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── helloworld
│ │ └── bottommenu
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .gitattributes
├── picture
├── results1.gif
└── results2.gif
├── .idea
├── caches
│ ├── gradle_models.ser
│ └── build_file_checksums.ser
├── encodings.xml
├── vcs.xml
├── runConfigurations.xml
├── gradle.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mylibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app','mylibrary'
2 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/picture/results1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/picture/results1.gif
--------------------------------------------------------------------------------
/picture/results2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/picture/results2.gif
--------------------------------------------------------------------------------
/.idea/caches/gradle_models.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/.idea/caches/gradle_models.ser
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BottomMenu
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/mylibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BottomMenu
3 |
4 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloWordFeng/BottomMenu/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/mylibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/middle_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Mar 21 18:45:06 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/utils/DialogEnum.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library.utils;
2 |
3 | /**
4 | * 创建时间:2019/3/29 11:20
5 | * 作者:Hyman峰
6 | * 功能描述:设置样式
7 | */
8 | public enum DialogEnum {
9 | BASIC,
10 | EDIT,
11 | LIST,
12 | CITY
13 | }
14 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/shape_et_cursor.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/edit_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/bottom_menu_mid_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/anim/menu_appear.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/bottom_menu_btn_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/anim/menu_disappear.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/bottom_menu_top_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/layout/item_adapter.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/com/helloworld/bottommenu/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.bottommenu;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/mylibrary/src/test/java/com/helloworld/bottommenu/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.bottommenu;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/bottom_menu_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/bottom_menu_bottom_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/left_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/right_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | defaultConfig {
6 | applicationId "com.helloworld.bottommenu"
7 | minSdkVersion 19
8 | targetSdkVersion 29
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation project(':mylibrary')
24 | }
25 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #eeeeee
4 |
5 | #ffffff
6 | #00000000
7 | #FF0000
8 |
9 |
10 | #FF4081
11 |
12 | #454545
13 |
14 | #999999
15 |
16 | #ffffff
17 |
18 | #E9E9E9
19 |
20 | #828282
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/layout/item_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/drawable/bottom_shape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 | -
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/layout/fragment_bottom_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/mylibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/helloworld/bottommenu/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.bottommenu;
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 | * Instrumented 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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.helloworld.bottommenu", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/mylibrary/src/androidTest/java/com/helloworld/bottommenu/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.bottommenu;
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 | * Instrumented 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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.helloworld.bottommenu.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/mylibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.HelloWordFeng'
4 |
5 | android {
6 | compileSdkVersion 29
7 |
8 | defaultConfig {
9 | minSdkVersion 19
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | api 'androidx.appcompat:appcompat:1.0.2'
29 | implementation 'com.google.android.material:material:1.0.0'
30 | //数据解析
31 | implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
32 | }
33 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/bean/CityJsonDto.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library.bean;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * 创建时间:2019/4/30 14:26
7 | * 作者:Hyman峰
8 | * 功能描述:省市区实体类
9 | */
10 | public class CityJsonDto {
11 |
12 | /**
13 | * name : 省份
14 | * city : [{"name":"北京市","area":["东城区","西城区","崇文区","宣武区","朝阳区"]}]
15 | */
16 |
17 | private String name;
18 | private List city;
19 |
20 | public String getName() {
21 | return name;
22 | }
23 |
24 | public void setName(String name) {
25 | this.name = name;
26 | }
27 |
28 | public List getCityList() {
29 | return city;
30 | }
31 |
32 | public void setCityList(List city) {
33 | this.city = city;
34 | }
35 |
36 | public static class CityBean {
37 | /**
38 | * name : 城市
39 | * area : ["东城区","西城区","崇文区","昌平区"]
40 | */
41 |
42 | private String name;
43 | private List area;
44 |
45 | public String getName() {
46 | return name;
47 | }
48 |
49 | public void setName(String name) {
50 | this.name = name;
51 | }
52 |
53 | public List getArea() {
54 | return area;
55 | }
56 |
57 | public void setArea(List area) {
58 | this.area = area;
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
24 |
25 |
30 |
31 |
36 |
37 |
42 |
43 |
49 |
50 |
55 |
56 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/utils/Tools.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library.utils;
2 |
3 | import android.content.Context;
4 | import android.content.res.AssetManager;
5 |
6 | import com.google.gson.Gson;
7 | import com.helloworld.library.bean.CityJsonDto;
8 |
9 | import org.json.JSONArray;
10 |
11 | import java.io.BufferedReader;
12 | import java.io.IOException;
13 | import java.io.InputStreamReader;
14 | import java.util.ArrayList;
15 |
16 | /**
17 | * 创建时间:2019/4/30 14:28
18 | * 作者:Hyman峰
19 | * 功能描述:工具类
20 | */
21 | public class Tools {
22 |
23 | /**
24 | * 读取Json文件
25 | */
26 | public static String getJson(Context context, String fileName) {
27 | StringBuilder stringBuilder = new StringBuilder();
28 | try {
29 | AssetManager assetManager = context.getAssets();
30 | BufferedReader bf = new BufferedReader(new InputStreamReader(
31 | assetManager.open(fileName)));
32 | String line;
33 | while ((line = bf.readLine()) != null) {
34 | stringBuilder.append(line);
35 | }
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | }
39 | return stringBuilder.toString();
40 | }
41 |
42 | /**
43 | * 解析数据
44 | */
45 | public static ArrayList parseData(String result) {//Gson 解析
46 | ArrayList detail = new ArrayList<>();
47 | try {
48 | JSONArray data = new JSONArray(result);
49 | Gson gson = new Gson();
50 | for (int i = 0; i < data.length(); i++) {
51 | CityJsonDto entity = gson.fromJson(data.optJSONObject(i).toString(), CityJsonDto.class);
52 | detail.add(entity);
53 | }
54 | } catch (Exception e) {
55 | e.printStackTrace();
56 | }
57 | return detail;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/layout/dialog_middle.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
19 |
20 |
25 |
26 |
31 |
32 |
35 |
36 |
40 |
41 |
46 |
47 |
50 |
51 |
56 |
57 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/base/RecyclerHolder.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library.base;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.util.SparseArray;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import androidx.recyclerview.widget.RecyclerView;
11 |
12 | /**
13 | * Created by Administrator on 2017/11/7.
14 | */
15 |
16 | public class RecyclerHolder extends RecyclerView.ViewHolder {
17 |
18 | private SparseArray views;
19 | private Context context;
20 |
21 | private RecyclerHolder(Context context, View itemView) {
22 | super(itemView);
23 | this.context = context;
24 | this.views = new SparseArray<>();
25 | }
26 |
27 | /**
28 | * 取得一个RecyclerHolder对象
29 | *
30 | * @param context 上下文
31 | * @param itemView 子项
32 | * @return 返回一个RecyclerHolder对象
33 | */
34 | public static RecyclerHolder getRecyclerHolder(Context context, View itemView) {
35 | return new RecyclerHolder(context, itemView);
36 | }
37 |
38 | public SparseArray getViews() {
39 | return this.views;
40 | }
41 |
42 | /**
43 | * 通过view的id获取对应的控件,如果没有则加入views中
44 | *
45 | * @param viewId 控件的id
46 | * @return 返回一个控件
47 | */
48 | @SuppressWarnings("unchecked")
49 | public T getView(int viewId) {
50 | View view = views.get(viewId);
51 | if (view == null) {
52 | view = itemView.findViewById(viewId);
53 | views.put(viewId, view);
54 | }
55 | return (T) view;
56 | }
57 |
58 | /**
59 | * 设置字符串
60 | */
61 | public RecyclerHolder setText(int viewId, String text) {
62 | TextView tv = getView(viewId);
63 | tv.setText(text);
64 | return this;
65 | }
66 |
67 | /**
68 | * 设置图片
69 | */
70 | public RecyclerHolder setImageResource(int viewId, int drawableId) {
71 | ImageView iv = getView(viewId);
72 | iv.setImageResource(drawableId);
73 | return this;
74 | }
75 |
76 | /**
77 | * 设置图片
78 | */
79 | public RecyclerHolder setImageBitmap(int viewId, Bitmap bitmap) {
80 | ImageView iv = getView(viewId);
81 | iv.setImageBitmap(bitmap);
82 | return this;
83 | }
84 |
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/utils/ScreenUtils.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.util.DisplayMetrics;
6 |
7 | import java.lang.reflect.Field;
8 |
9 | /**
10 | * 创建时间:2019/3/28 18:36
11 | * 作者:Hyman峰
12 | * 功能描述:
13 | */
14 | public class ScreenUtils {
15 |
16 | /**
17 | * 网上流传
18 | */
19 | // public static int dip2px(Context context, float dpValue) {
20 | // final float scale = context.getResources().getDisplayMetrics().density;
21 | // return (int) (dpValue * scale + 0.5f);
22 | // }
23 |
24 | /**
25 | * TabLayout源码
26 | */
27 | public static int dip2px(Context context, float dpValue) {
28 | return Math.round(context.getResources().getDisplayMetrics().density * dpValue);
29 | }
30 |
31 | /**
32 | * 获取屏幕宽度
33 | *
34 | * @param context
35 | * @return
36 | */
37 | public static int getScreenWidth(Context context) {
38 | DisplayMetrics localDisplayMetrics = new DisplayMetrics();
39 | ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
40 | return localDisplayMetrics.widthPixels;
41 | }
42 |
43 | /**
44 | * 获取屏幕高度
45 | * 减去状态栏
46 | *
47 | * @param context
48 | * @return
49 | */
50 | public static int getScreenHeight(Context context) {
51 | DisplayMetrics localDisplayMetrics = new DisplayMetrics();
52 | ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
53 | return localDisplayMetrics.heightPixels - getStatusBarHeight(context);
54 | }
55 |
56 | /**
57 | * 获取状态栏高度
58 | *
59 | * @param context
60 | * @return
61 | */
62 | public static int getStatusBarHeight(Context context) {
63 | Class> c = null;
64 | Object obj = null;
65 | Field field = null;
66 | int x = 0, statusBarHeight = 0;
67 | try {
68 | c = Class.forName("com.android.internal.R$dimen");
69 | obj = c.newInstance();
70 | field = c.getField("status_bar_height");
71 | x = Integer.parseInt(field.get(obj).toString());
72 | statusBarHeight = context.getResources().getDimensionPixelSize(x);
73 | } catch (Exception e1) {
74 | e1.printStackTrace();
75 | }
76 | return statusBarHeight;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/utils/DataUtils.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library.utils;
2 |
3 | import android.content.Context;
4 |
5 | import com.helloworld.library.bean.CityJsonDto;
6 |
7 | import java.util.ArrayList;
8 |
9 | /**
10 | * 创建时间:2019/4/30 14:28
11 | * 作者:Hyman峰
12 | * 功能描述:数据源
13 | */
14 | public class DataUtils {
15 |
16 | private static ArrayList jsonBean = new ArrayList<>();
17 | private static ArrayList optionsProvinces = new ArrayList<>();
18 | private static ArrayList> optionsCitys = new ArrayList<>();
19 | private static ArrayList>> optionsAreas = new ArrayList<>();
20 |
21 | public static void initCityList(Context context) {
22 | //获取assets目录下的json文件数据
23 | String JsonData = Tools.getJson(context, "province.json");//获取assets目录下的json文件数据
24 | jsonBean = Tools.parseData(JsonData);//用Gson 转成实体
25 |
26 |
27 | for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
28 | ArrayList CityList = new ArrayList<>();//该省的城市列表(第二级)
29 | ArrayList> Province_AreaList = new ArrayList<>();//该省的所有地区列表(第三极)
30 | for (int c = 0; c < jsonBean.get(i).getCityList().size(); c++) {//遍历该省份的所有城市
31 | String CityName = jsonBean.get(i).getCityList().get(c).getName();
32 | CityList.add(CityName);//添加城市
33 | ArrayList City_AreaList = new ArrayList<>();//该城市的所有地区列表
34 | //如果无地区数据,建议添加空字符串,防止数据为null 导致三个选项长度不匹配造成崩溃
35 | if (jsonBean.get(i).getCityList().get(c).getArea() == null
36 | || jsonBean.get(i).getCityList().get(c).getArea().size() == 0) {
37 | City_AreaList.add("");
38 | } else {
39 | City_AreaList.addAll(jsonBean.get(i).getCityList().get(c).getArea());
40 | }
41 | Province_AreaList.add(City_AreaList);//添加该省所有地区数据
42 | }
43 | optionsCitys.add(CityList);
44 | optionsAreas.add(Province_AreaList);
45 | }
46 | }
47 |
48 | /**
49 | * 返回json数据
50 | */
51 | public static ArrayList returnJson() {
52 | return jsonBean;
53 | }
54 |
55 | /**
56 | * 返回二级市区数据
57 | */
58 | public static ArrayList> returnCitys() {
59 | return optionsCitys;
60 | }
61 |
62 | /**
63 | * 返回三级县级数据
64 | */
65 | public static ArrayList>> returnAreas() {
66 | return optionsAreas;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/adapter/Myadapter.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library.adapter;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.view.Gravity;
6 | import android.widget.TextView;
7 |
8 | import com.helloworld.library.R;
9 | import com.helloworld.library.base.CommonRecyclerAdapter;
10 | import com.helloworld.library.base.RecyclerHolder;
11 | import com.helloworld.library.utils.ScreenUtils;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * 创建时间:2019/3/29 16:19
17 | * 作者:Hyman峰
18 | * 功能描述:
19 | */
20 | public class Myadapter extends CommonRecyclerAdapter {
21 |
22 | private static final String TAG = "Myadapter";
23 | private Context mContext;
24 |
25 | private int itemSize = 15;
26 | private String itemColor = "#454545";
27 | private int leftPadding = 12;
28 | private int topPadding = 12;
29 | private int rightPadding = 12;
30 | private int bottomPadding = 12;
31 | private int itemGravity = Gravity.LEFT;
32 |
33 | public Myadapter(Context context, List list) {
34 | super(context, R.layout.item_adapter, list);
35 | this.mContext = context;
36 | }
37 |
38 | @Override
39 | public void convert(RecyclerHolder holder, String item, int position) {
40 | TextView textView = holder.getView(R.id.item_title);
41 | //设置文本内容
42 | textView.setText(item);
43 | //字体大小
44 | textView.setTextSize(itemSize);
45 | //文字颜色
46 | textView.setTextColor(Color.parseColor(itemColor));
47 | //距离父布局文本内容
48 | //textView.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
49 | textView.setPadding(ScreenUtils.dip2px(mContext, leftPadding),
50 | ScreenUtils.dip2px(mContext, topPadding),
51 | ScreenUtils.dip2px(mContext, rightPadding),
52 | ScreenUtils.dip2px(mContext, bottomPadding));
53 | //位置
54 | textView.setGravity(itemGravity);
55 | }
56 |
57 | /**
58 | * 字体大小
59 | */
60 | public Myadapter setItemSize(int size) {
61 | itemSize = size;
62 | return this;
63 | }
64 |
65 | /**
66 | * 字体颜色
67 | */
68 | public Myadapter setItemColor(String color) {
69 | itemColor = color;
70 | return this;
71 | }
72 |
73 | /**
74 | * 字体位置
75 | */
76 | public Myadapter setItemGravity(int gravity) {
77 | itemGravity = gravity;
78 | return this;
79 | }
80 |
81 | /**
82 | * 左、上、右、下边距
83 | */
84 | public Myadapter setItemPadding(int left, int top, int right, int bottom) {
85 | leftPadding = left;
86 | topPadding = top;
87 | rightPadding = right;
88 | bottomPadding = bottom;
89 | return this;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/mylibrary/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
14 |
15 |
20 |
21 |
27 |
28 |
36 |
37 |
46 |
47 |
56 |
57 |
58 |
67 |
68 |
73 |
90 |
91 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/adapter/MenuAdapter.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library.adapter;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.view.View;
6 | import android.widget.LinearLayout;
7 | import android.widget.TextView;
8 |
9 | import com.helloworld.library.R;
10 | import com.helloworld.library.base.CommonRecyclerAdapter;
11 | import com.helloworld.library.base.RecyclerHolder;
12 |
13 | import java.util.List;
14 |
15 |
16 | /**
17 | * 创建时间:2019/3/20 19:47
18 | * 作者:Hyman峰
19 | * 功能描述:
20 | */
21 | public class MenuAdapter extends CommonRecyclerAdapter {
22 |
23 | private int titleSize;
24 | private int contentSize;
25 | private double lineHeight;
26 | private String titleColor;
27 | private String contentColor;
28 | private String lineColor;
29 | //资源shape
30 | private int sizeShape;
31 | private int topShape;
32 | private int middleShape;
33 | private int bottomShape;
34 | //是否有辩标题
35 | private boolean isShowTitle;
36 |
37 | public MenuAdapter(Context context, List list, boolean isShowTitle) {
38 | super(context, R.layout.item_menu, list);
39 | this.isShowTitle = isShowTitle;
40 | }
41 |
42 | @Override
43 | public void convert(RecyclerHolder holder, String item, int position) {
44 |
45 | TextView textView = holder.getView(R.id.menu_item);
46 | View viewLine = holder.getView(R.id.view_line);
47 | textView.setText(item);
48 |
49 | //只有一个选项4边都要圆角
50 | if (getItemCount() == 1) {
51 | textView.setBackgroundResource(sizeShape);
52 | } else {
53 | //将第一个position上面左右圆角设置
54 | if (position == 0) {
55 | textView.setBackgroundResource(topShape);
56 | if (isShowTitle){
57 | textView.setTextColor(Color.parseColor(titleColor));
58 | textView.setTextSize(titleSize);
59 | }else {
60 | textView.setTextColor(Color.parseColor(contentColor));
61 | }
62 | //中间选项不需要圆角
63 | } else if (position < getItemCount() - 1) {
64 | textView.setBackgroundResource(middleShape);
65 | textView.setTextColor(Color.parseColor(contentColor));
66 | textView.setTextSize(contentSize);
67 | } else {
68 | //将底部也就是第一个position下面面左右圆角设置
69 | textView.setBackgroundResource(bottomShape);
70 | textView.setTextColor(Color.parseColor(contentColor));
71 | textView.setTextSize(contentSize);
72 | }
73 | //分割线
74 | if (position == getItemCount() - 1) {
75 | viewLine.setVisibility(View.GONE);
76 | } else {
77 | viewLine.setVisibility(View.VISIBLE);
78 | }
79 | //设置分割线高度
80 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
81 | LinearLayout.LayoutParams.MATCH_PARENT, (int) lineHeight);
82 | viewLine.setLayoutParams(params);
83 | //设置颜色
84 | viewLine.setBackgroundColor(Color.parseColor(lineColor));
85 | }
86 | }
87 |
88 | /**
89 | * 字体大小
90 | */
91 | public MenuAdapter setTitleSize(int size) {
92 | titleSize = size;
93 | return this;
94 | }
95 |
96 | /**
97 | * 字体颜色
98 | */
99 | public MenuAdapter setTitleColor(String color) {
100 | titleColor = color;
101 | return this;
102 | }
103 |
104 | /**
105 | * 内容大小
106 | */
107 | public MenuAdapter setContentSize(int size) {
108 | contentSize = size;
109 | return this;
110 | }
111 |
112 | /**
113 | * 内容颜色
114 | */
115 | public MenuAdapter setContentColor(String color) {
116 | contentColor = color;
117 | return this;
118 | }
119 |
120 | /**
121 | * 分割线高度
122 | */
123 | public MenuAdapter setLineHeight(double size) {
124 | lineHeight = size;
125 | return this;
126 | }
127 |
128 | /**
129 | * 分割线颜色
130 | */
131 | public MenuAdapter setLineColor(String color) {
132 | lineColor = color;
133 | return this;
134 | }
135 |
136 | /**
137 | * 背景颜色(list大小为1时)
138 | */
139 | public MenuAdapter setSizeOneShape(int resId) {
140 | sizeShape = resId;
141 | return this;
142 | }
143 |
144 | public MenuAdapter setTopShape(int resId) {
145 | topShape = resId;
146 | return this;
147 | }
148 |
149 | public MenuAdapter setMiddleShape(int resId) {
150 | middleShape = resId;
151 | return this;
152 | }
153 |
154 | public MenuAdapter setBottomShape(int resId) {
155 | bottomShape = resId;
156 | return this;
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/base/CommonRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library.base;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by Administrator on 2017/11/7.
15 | * recyclerview适配器
16 | */
17 |
18 | public abstract class CommonRecyclerAdapter extends RecyclerView.Adapter {
19 |
20 | private Context context;//上下文
21 | private List list;//数据源
22 | private LayoutInflater inflater;//布局器
23 | private int itemLayoutId;//布局id
24 | private boolean isScrolling;//是否在滚动
25 | private OnItemClickListener listener;//点击事件监听器
26 | private OnItemLongClickListener longClickListener;//长按监听器
27 | private RecyclerView recyclerView;
28 |
29 | //在RecyclerView提供数据的时候调用
30 | @Override
31 | public void onAttachedToRecyclerView(RecyclerView recyclerView) {
32 | super.onAttachedToRecyclerView(recyclerView);
33 | this.recyclerView = recyclerView;
34 | }
35 |
36 | @Override
37 | public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
38 | super.onDetachedFromRecyclerView(recyclerView);
39 | this.recyclerView = null;
40 | }
41 |
42 | /**
43 | * 定义一个点击事件接口回调
44 | */
45 | public interface OnItemClickListener {
46 | void onItemClick(RecyclerView parent, View view, int position);
47 | }
48 |
49 | public interface OnItemLongClickListener {
50 | boolean onItemLongClick(RecyclerView parent, View view, int position);
51 | }
52 |
53 | /**
54 | * 插入一项
55 | *
56 | * @param item
57 | * @param position
58 | */
59 | public void insert(T item, int position) {
60 | list.add(position, item);
61 | notifyItemInserted(position);
62 | }
63 |
64 | public void addItem(T item) {
65 | if (list == null) {
66 | list = new ArrayList<>();
67 | }
68 | list.add(item);
69 | notifyDataSetChanged();
70 | }
71 |
72 | /**
73 | * 更新
74 | *
75 | * @param item
76 | */
77 | public void setList(List item) {
78 | this.list = item;
79 | notifyDataSetChanged();
80 | }
81 |
82 | /**
83 | * 删除一项
84 | *
85 | * @param position 删除位置
86 | */
87 | public void delete(int position) {
88 | list.remove(position);
89 | notifyItemRemoved(position);
90 | notifyItemChanged(position);
91 | notifyDataSetChanged();
92 | }
93 |
94 | /**
95 | * 删除全部
96 | */
97 | public void deleteAll() {
98 | list.removeAll(list);
99 | notifyDataSetChanged();
100 | }
101 |
102 | public void clear(){
103 | if (list == null) {
104 | list = new ArrayList();
105 | }
106 | list.clear();
107 | notifyDataSetChanged();
108 | }
109 |
110 | public CommonRecyclerAdapter(Context context, int itemLayoutId, List list) {
111 | this.context = context;
112 | this.list = list;
113 | this.itemLayoutId = itemLayoutId;
114 | inflater = LayoutInflater.from(context);
115 | // recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
116 | // @Override
117 | // public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
118 | // super.onScrollStateChanged(recyclerView, newState);
119 | // isScrolling = !(newState == RecyclerView.SCROLL_STATE_IDLE);
120 | // if (!isScrolling) {
121 | // notifyDataSetChanged();
122 | // }
123 | // }
124 | // });
125 | }
126 |
127 | @Override
128 | public RecyclerHolder onCreateViewHolder(ViewGroup parent, int viewType) {
129 | View view = inflater.inflate(itemLayoutId, parent, false);
130 | return RecyclerHolder.getRecyclerHolder(context, view);
131 | }
132 |
133 | @Override
134 | public void onBindViewHolder(final RecyclerHolder holder, int position) {
135 |
136 | holder.itemView.setOnClickListener(new View.OnClickListener() {
137 | @Override
138 | public void onClick(View view) {
139 | if (listener != null && view != null && recyclerView != null) {
140 | int position = recyclerView.getChildAdapterPosition(view);
141 | listener.onItemClick(recyclerView, view, position);
142 | }
143 | }
144 | });
145 |
146 |
147 | holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
148 | @Override
149 | public boolean onLongClick(View view) {
150 | if (longClickListener != null && view != null && recyclerView != null) {
151 | int position = recyclerView.getChildAdapterPosition(view);
152 | longClickListener.onItemLongClick(recyclerView, view, position);
153 | return true;
154 | }
155 | return false;
156 | }
157 | });
158 |
159 | convert(holder, list.get(position), position);
160 |
161 | }
162 |
163 | @Override
164 | public int getItemCount() {
165 | return list == null ? 0 : list.size();
166 | }
167 |
168 | public void setOnItemClickListener(OnItemClickListener listener) {
169 | this.listener = listener;
170 | }
171 |
172 | public void setOnItemLongClickListener(OnItemLongClickListener longClickListener) {
173 | this.longClickListener = longClickListener;
174 | }
175 |
176 | /**
177 | * 填充RecyclerView适配器的方法,子类需要重写
178 | *
179 | * @param holder ViewHolder
180 | * @param item 子项
181 | * @param position 位置
182 | */
183 | public abstract void convert(RecyclerHolder holder, T item, int position);
184 | }
185 |
--------------------------------------------------------------------------------
/app/src/main/java/com/helloworld/bottommenu/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.bottommenu;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.TextView;
6 | import android.widget.Toast;
7 |
8 | import androidx.appcompat.app.AppCompatActivity;
9 |
10 | import com.helloworld.library.BottomMenuFragment;
11 | import com.helloworld.library.MiddleDialogConfig;
12 | import com.helloworld.library.utils.DataUtils;
13 | import com.helloworld.library.utils.DialogEnum;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
19 |
20 | private List list = new ArrayList<>();
21 | private TextView cityText;
22 | private ArrayList options = new ArrayList<>();
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_main);
28 |
29 | cityText = this.findViewById(R.id.city_text);
30 | findViewById(R.id.open_click1).setOnClickListener(this);
31 | findViewById(R.id.open_click2).setOnClickListener(this);
32 | findViewById(R.id.open_click3).setOnClickListener(this);
33 | findViewById(R.id.open_click4).setOnClickListener(this);
34 | findViewById(R.id.open_click5).setOnClickListener(this);
35 | findViewById(R.id.open_click6).setOnClickListener(this);
36 | findViewById(R.id.open_click7).setOnClickListener(this);
37 | //初始化省市区数据源(需要时添加)
38 | DataUtils.initCityList(this);
39 | }
40 |
41 | @Override
42 | public void onClick(View v) {
43 | switch (v.getId()) {
44 | case R.id.open_click1:
45 | showDialogType();
46 | break;
47 | case R.id.open_click2:
48 | showListDialog();
49 | break;
50 | case R.id.open_click3:
51 | showDialogBasic1();
52 | break;
53 | case R.id.open_click4:
54 | showDialogBasic2();
55 | break;
56 | case R.id.open_click5:
57 | showQQDialog();
58 | break;
59 | case R.id.open_click6:
60 | showIOSDialog();
61 | break;
62 | case R.id.open_click7:
63 | appendCity = "";//置空
64 | options.clear();
65 | //遍历省份数据
66 | for (int i = 0; i < DataUtils.returnJson().size(); i++) {
67 | options.add(DataUtils.returnJson().get(i).getName());
68 | }
69 | showCityDialog(0);
70 | break;
71 | }
72 | }
73 |
74 | /**
75 | * 城市弹框
76 | */
77 | //拼接省市区
78 | private String appendCity;
79 | private int selectPosition;
80 |
81 | private void showCityDialog(final int selectType) {
82 | //超过几个可滑动
83 | int size = 6;
84 | String title = null;
85 | if (options.size() < size) {
86 | size = options.size();
87 | }
88 | if (selectType == 0) {
89 | title = "请选择省份";
90 | } else if (selectType == 1) {
91 | title = "请选择城市";
92 | } else if (selectType == 2) {
93 | title = "请选择区县";
94 | }
95 | new MiddleDialogConfig().builder(this)
96 | .setTitle(title)
97 | .setDialogStyle(DialogEnum.CITY)
98 | .setDatas(options)
99 | .setItemSlidingCount(size, 0.7)
100 | .setCityLevel(selectType)
101 | .setLeftRightVis()
102 | .setItemCallBack(new MiddleDialogConfig.ItemCallBackListener() {
103 | @Override
104 | public void item(String str) {
105 | String[] cont = str.split(",");
106 | appendCity += cont[1] + "\u3000";
107 | cityText.setText(appendCity);
108 | //int type= Integer.parseInt(cont[2]);
109 | int position = Integer.parseInt(cont[0]);
110 | if (null != options) {
111 | options.clear();
112 | }
113 | if (selectType == 0) {
114 | for (int i = 0; i < DataUtils.returnCitys().get(position).size(); i++) {
115 | options.add(DataUtils.returnCitys().get(position).get(i));
116 | }
117 | selectPosition = position;
118 | showCityDialog(1);
119 | } else if (selectType == 1) {
120 | for (int i = 0; i < DataUtils.returnAreas().get(selectPosition).get(position).size(); i++) {
121 | options.add(DataUtils.returnAreas().get(selectPosition).get(position).get(i));
122 | }
123 | showCityDialog(2);
124 | }
125 | }
126 | })
127 | .show();
128 | }
129 |
130 | /**
131 | * 输入框弹框类型
132 | */
133 | private void showDialogType() {
134 | new MiddleDialogConfig().builder(this)
135 | .setDialogStyle(DialogEnum.EDIT)
136 | .setRightCallBack(new MiddleDialogConfig.RightCallBack() {
137 | @Override
138 | public void rightBtn(String cont) {
139 | showToast("点击了左边:"+cont);
140 | }
141 | })
142 | .setLeftCallBack(new MiddleDialogConfig.LeftCallBack() {
143 | @Override
144 | public void leftBtn(String cont) {
145 | showToast("点击了右边:" + cont);
146 | }
147 | }).show();
148 | }
149 |
150 | /**
151 | * list弹框
152 | */
153 | private void showListDialog() {
154 | List list = new ArrayList<>();
155 | for (int i = 0; i < 50; i++) {
156 | list.add("选项Item" + i);
157 | }
158 | new MiddleDialogConfig().builder(this)
159 | .setDialogStyle(DialogEnum.LIST)
160 | .setDatas(list)
161 | .setItemSlidingCount(6, 0.85)
162 | .setRightCallBack(new MiddleDialogConfig.RightCallBack() {
163 | @Override
164 | public void rightBtn(String cont) {
165 | showToast("点击了左边:");
166 | }
167 | })
168 | .setLeftCallBack(new MiddleDialogConfig.LeftCallBack() {
169 | @Override
170 | public void leftBtn(String cont) {
171 | showToast("点击了右边:");
172 | }
173 | })
174 | .setItemCallBack(new MiddleDialogConfig.ItemCallBackListener() {
175 | @Override
176 | public void item(String str) {
177 | showToast("选择了:" + str);
178 | }
179 | })
180 | .show();
181 | }
182 |
183 | /**
184 | * 输入框弹框类型
185 | */
186 | private void showDialogBasic1() {
187 | new MiddleDialogConfig().builder(this)
188 | .setRightCallBack(new MiddleDialogConfig.RightCallBack() {
189 | @Override
190 | public void rightBtn(String cont) {
191 | showToast("点击了左边:");
192 | }
193 | })
194 | .setLeftCallBack(new MiddleDialogConfig.LeftCallBack() {
195 | @Override
196 | public void leftBtn(String cont) {
197 | showToast("点击了右边:");
198 | }
199 | }).show();
200 | }
201 |
202 | /**
203 | * 输入框弹框类型
204 | */
205 | private void showDialogBasic2() {
206 | new MiddleDialogConfig().builder(this)
207 | .setTitleVis(false)
208 | .setContentColor("#ff0000")
209 | .setLeftVis(false)
210 | .setContentPadding(20, 20, 20, 20)
211 | .setContentMaxLine(2)
212 | .setContentSize(16)
213 | .setIsCancel(true)
214 | .setRightCallBack(new MiddleDialogConfig.RightCallBack() {
215 | @Override
216 | public void rightBtn(String cont) {
217 | showToast("点击了右边:");
218 | }
219 | }).show();
220 | }
221 |
222 |
223 | /**
224 | * 仿ios弹框
225 | */
226 | private void showIOSDialog() {
227 | list.clear();
228 | for (int i = 0; i < 4; i++) {
229 | list.add("文本内容" + i);
230 | }
231 | new BottomMenuFragment(this)
232 | .setTitle("标题")
233 | .addMenuItems(list)
234 | .setOnItemClickListener(new BottomMenuFragment.OnItemClickListener() {
235 | @Override
236 | public void onItemClick(TextView menu, int position) {
237 | Toast.makeText(MainActivity.this, menu.getText().toString(),
238 | Toast.LENGTH_SHORT).show();
239 |
240 | }
241 | })
242 | .show();
243 | }
244 |
245 | /**
246 | * 仿QQ图片长按弹框
247 | */
248 | private void showQQDialog() {
249 | list.clear();
250 | list.add("发送给好友");
251 | list.add("转载到空间相册");
252 | list.add("群相册");
253 | list.add("保存到手机");
254 | list.add("提取图中文字");
255 | list.add("收藏");
256 | new BottomMenuFragment(this)
257 | .setContentSize(16)
258 | .setCancelTextTitle("取消")
259 | .setCancelTextSize(16)
260 | .setCancelTextColor("#454545")
261 | .setCancelTextHeight(45)
262 | .setCancelTextMarginTop(20)
263 | .setContentColor("#454545")
264 | .addMenuItems(list)
265 | .setBackgroundColor("#ebebeb")
266 | .setCancelPadding(0, 0, 0, 0)
267 | .setSizeOneShape(R.drawable.bottom_menu_mid_selector)
268 | .setTopShape(R.drawable.bottom_menu_mid_selector)
269 | .setMiddleShape(R.drawable.bottom_menu_mid_selector)
270 | .setBottomShape(R.drawable.bottom_menu_mid_selector)
271 | .setCancelShape(R.drawable.bottom_menu_mid_selector)
272 | .setOnItemClickListener(new BottomMenuFragment.OnItemClickListener() {
273 | @Override
274 | public void onItemClick(TextView menu, int position) {
275 | Toast.makeText(MainActivity.this, menu.getText().toString(),
276 | Toast.LENGTH_SHORT).show();
277 | }
278 | })
279 | .show();
280 | }
281 |
282 | private void showToast(String msg) {
283 | Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
284 | }
285 | }
286 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/BottomMenuFragment.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.app.DialogFragment;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.ColorDrawable;
8 | import android.os.Bundle;
9 | import android.util.DisplayMetrics;
10 | import android.view.Gravity;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.view.WindowManager;
15 | import android.view.animation.AnimationUtils;
16 | import android.widget.LinearLayout;
17 | import android.widget.TextView;
18 |
19 | import androidx.appcompat.app.AppCompatActivity;
20 | import androidx.recyclerview.widget.LinearLayoutManager;
21 | import androidx.recyclerview.widget.RecyclerView;
22 |
23 | import com.helloworld.library.adapter.MenuAdapter;
24 | import com.helloworld.library.base.CommonRecyclerAdapter;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 |
30 | /**
31 | * 创建时间:2019/3/20 19:33
32 | * 作者:Hyman峰
33 | * 功能描述:特别注意DialogFragment 不要选择V4的
34 | */
35 | @SuppressLint("ValidFragment")
36 | public class BottomMenuFragment extends DialogFragment {
37 |
38 | private final String TAG = "BottomMenuFragment";
39 | private Activity context;
40 | //标题
41 | private boolean showTitle = false;
42 | //取消文字大小、颜色、文本内容
43 | private int cancelTextSize = 16;
44 | private String cancelTextColor = "#467CD4";
45 | private String cancelTextTitle = "取消";
46 | //标题文字大小、内容、分割线等
47 | private int titleSize = 16;
48 | private int contentSize = 15;
49 | private double lineHeight = 1;
50 | private String titleColor = "#ff0000";
51 | private String contentColor = "#467CD4";
52 | private String lineColor = "#ebebeb";
53 | //内容list
54 | private List menuItemList = new ArrayList<>();
55 | //取消高度
56 | private int cancelTextHeight = 45;
57 | //顶部边距
58 | private int cancelTextTopMargin = 20;
59 | //取消样式
60 | private int cancelTextShape = R.drawable.bottom_menu_selector;
61 | //距离四周边距
62 | private int leftPadding = 20;
63 | private int topPadding = 0;
64 | private int rightPadding = 20;
65 | private int bottomPadding = 20;
66 | //背景颜色
67 | private String backgroundColor = "#00000000";
68 | //资源shape
69 | private int sizeShape = R.drawable.bottom_menu_selector;
70 | private int topShape = R.drawable.bottom_menu_top_selector;
71 | private int middleShape = R.drawable.bottom_menu_mid_selector;
72 | private int bottomShape = R.drawable.bottom_menu_bottom_selector;
73 |
74 |
75 | private MenuAdapter adapter;
76 |
77 | public BottomMenuFragment(AppCompatActivity context) {
78 | this.context = context;
79 | }
80 |
81 | @Override
82 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
83 | //去除标题
84 | // getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
85 | //设置背景透明
86 | getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
87 | //添加一组进出动画
88 | getDialog().getWindow().setWindowAnimations(R.style.menu_animation);
89 | //寻找布局资源
90 | View view = inflater.inflate(R.layout.fragment_bottom_menu, container, false);
91 | TextView cancel = view.findViewById(R.id.tv_cancel);
92 | LinearLayout linear = view.findViewById(R.id.linear_view);
93 | //文本
94 | cancel.setText(cancelTextTitle);
95 | //字体大小
96 | cancel.setTextSize(cancelTextSize);
97 | //字体颜色
98 | cancel.setTextColor(Color.parseColor(cancelTextColor));
99 | //四周边距
100 | cancel.setHeight(dip2px(cancelTextHeight));
101 | //样式
102 | cancel.setBackgroundResource(cancelTextShape);
103 | //顶部边距
104 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) cancel.getLayoutParams();
105 | lp.topMargin = cancelTextTopMargin;
106 | cancel.setLayoutParams(lp);
107 | //四周边距
108 | linear.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
109 | //背景色
110 | linear.setBackgroundColor(Color.parseColor(backgroundColor));
111 | //关闭弹框事件
112 | cancel.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
113 | @Override
114 | public void onClick(View v) {
115 | //关闭弹框
116 | dismiss();
117 | }
118 | });
119 | //展示数据源
120 | RecyclerView recycler = view.findViewById(R.id.recycler);
121 | adapter = new MenuAdapter(context, menuItemList, showTitle);
122 | recycler.setLayoutManager(new LinearLayoutManager(context));
123 | recycler.setAdapter(adapter);
124 | adapter.setTitleSize(titleSize);
125 | adapter.setTitleColor(titleColor);
126 | adapter.setContentColor(contentColor);
127 | adapter.setContentSize(contentSize);
128 | adapter.setLineHeight(lineHeight);
129 | adapter.setLineColor(lineColor);
130 | //资源shape
131 | adapter.setSizeOneShape(sizeShape);
132 | adapter.setTopShape(topShape);
133 | adapter.setMiddleShape(middleShape);
134 | adapter.setBottomShape(bottomShape);
135 | adapter.setOnItemClickListener(new CommonRecyclerAdapter.OnItemClickListener() {
136 | @Override
137 | public void onItemClick(RecyclerView parent, View view, int position) {
138 | if (null != listener) {
139 | //当前设置了标题是,第0个不可点击
140 | if (showTitle) {
141 | if (position == 0) {
142 | return;
143 | }
144 | }
145 | TextView menu = view.findViewById(R.id.menu_item);
146 | listener.onItemClick(menu, position);
147 | dismiss();
148 | }
149 | }
150 | });
151 | return view;
152 | }
153 |
154 | /**
155 | * 展示
156 | */
157 | public void show() {
158 | this.show(context.getFragmentManager(), "BottomMenuFragment");
159 | }
160 |
161 | /**
162 | * 点击事件回调
163 | */
164 | private OnItemClickListener listener;
165 |
166 | public interface OnItemClickListener {
167 |
168 | void onItemClick(TextView menu_item, int position);
169 | }
170 |
171 | public BottomMenuFragment setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
172 | this.listener = mOnItemClickListener;
173 | return this;
174 | }
175 |
176 | @Override
177 | public void onStart() {
178 | super.onStart();
179 | //设置弹出框宽屏显示,适应屏幕宽度
180 | DisplayMetrics dm = new DisplayMetrics();
181 | getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
182 | getDialog().getWindow().setLayout(dm.widthPixels, getDialog().getWindow().getAttributes().height);
183 | //移动弹出菜单到底部
184 | WindowManager.LayoutParams manger = getDialog().getWindow().getAttributes();
185 | manger.gravity = Gravity.BOTTOM;
186 | //manger.width = WindowManager.LayoutParams.MATCH_PARENT;
187 | getDialog().getWindow().setAttributes(manger);
188 | }
189 |
190 | @Override
191 | public void onStop() {
192 | //设置暂停动画
193 | this.getView().setAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.menu_disappear));
194 | super.onStop();
195 | }
196 |
197 | /**
198 | * dp2px
199 | */
200 | private int dip2px(float dpValue) {
201 | final float scale = context.getResources().getDisplayMetrics().density;
202 | return (int) (dpValue * scale + 0.5f);
203 | }
204 |
205 | /**
206 | * 添加内容弹框
207 | */
208 | public BottomMenuFragment addMenuItems(List menuItems) {
209 | if (null != menuItems && menuItems.size() > 0) {
210 | for (int i = 0; i < menuItems.size(); i++) {
211 | menuItemList.add(menuItems.get(i));
212 | }
213 | }
214 | return this;
215 | }
216 |
217 | /**
218 | * 底部取消文字
219 | */
220 | public BottomMenuFragment setCancelTextTitle(String textTitle) {
221 | cancelTextTitle = textTitle;
222 | return this;
223 | }
224 |
225 | /**
226 | * 底部取消文字大小
227 | */
228 | public BottomMenuFragment setCancelTextSize(int textSize) {
229 | cancelTextSize = textSize;
230 | return this;
231 | }
232 |
233 | /**
234 | * 底部取消文字颜色
235 | */
236 | public BottomMenuFragment setCancelTextColor(String textColor) {
237 | cancelTextColor = textColor;
238 | return this;
239 | }
240 |
241 | /**
242 | * 底部取消文字高度
243 | */
244 | public BottomMenuFragment setCancelTextHeight(int height) {
245 | cancelTextHeight = height;
246 | return this;
247 | }
248 |
249 | /**
250 | * 底部取消文字边距(距离顶部)
251 | */
252 | public BottomMenuFragment setCancelTextMarginTop(int marginTop) {
253 | cancelTextTopMargin = marginTop;
254 | return this;
255 | }
256 |
257 | /**
258 | * 底部整体边距
259 | */
260 | public BottomMenuFragment setCancelPadding(int left, int top, int right, int bottom) {
261 | leftPadding = left;
262 | topPadding = top;
263 | rightPadding = right;
264 | bottomPadding = bottom;
265 | return this;
266 | }
267 |
268 | /**
269 | * 取消样式
270 | */
271 | public BottomMenuFragment setCancelShape(int resId) {
272 | cancelTextShape = resId;
273 | return this;
274 | }
275 |
276 | /**
277 | * 底部整体背景
278 | */
279 | public BottomMenuFragment setBackgroundColor(String color) {
280 | backgroundColor = color;
281 | return this;
282 | }
283 |
284 | /**
285 | * 设置标题
286 | */
287 | public BottomMenuFragment setTitle(String BottomTitle) {
288 | showTitle = true;
289 | //添加标题
290 | menuItemList.add(BottomTitle);
291 | return this;
292 | }
293 |
294 | /**
295 | * 字体大小
296 | */
297 | public BottomMenuFragment setTitleSize(int size) {
298 | titleSize = size;
299 | return this;
300 | }
301 |
302 | /**
303 | * 字体颜色
304 | */
305 | public BottomMenuFragment setTitleColor(String color) {
306 | titleColor = color;
307 | return this;
308 | }
309 |
310 | /**
311 | * 内容大小
312 | */
313 | public BottomMenuFragment setContentSize(int size) {
314 | contentSize = size;
315 | return this;
316 | }
317 |
318 | /**
319 | * 内容颜色
320 | */
321 | public BottomMenuFragment setContentColor(String color) {
322 | contentColor = color;
323 | return this;
324 | }
325 |
326 | /**
327 | * 分割线高度
328 | */
329 | public BottomMenuFragment setLineHeight(double height) {
330 | lineHeight = height;
331 | return this;
332 | }
333 |
334 | /**
335 | * 分割线颜色
336 | */
337 | public BottomMenuFragment setLineColor(String color) {
338 | lineColor = color;
339 | return this;
340 | }
341 |
342 | /**
343 | * 背景颜色(list大小为1时)
344 | */
345 | public BottomMenuFragment setSizeOneShape(int resId) {
346 | sizeShape = resId;
347 | return this;
348 | }
349 |
350 | public BottomMenuFragment setTopShape(int resId) {
351 | topShape = resId;
352 | return this;
353 | }
354 |
355 | public BottomMenuFragment setMiddleShape(int resId) {
356 | middleShape = resId;
357 | return this;
358 | }
359 |
360 | public BottomMenuFragment setBottomShape(int resId) {
361 | bottomShape = resId;
362 | return this;
363 | }
364 | }
365 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BottomMenu
2 | ## 各种简单样式的弹出框 现包含IOS、QQ底部弹出框、单个EditText输入框、List列表和提示框等效果,可以自定义多种属性效果。
3 | # 效果图
4 | 
5 | 
6 | ## 如何使用
7 | 1、项目根目录加入
8 | dependencies {
9 | ```python
10 | allprojects {
11 | repositories {
12 | google()
13 | jcenter()
14 | maven { url 'https://jitpack.io' }
15 | }
16 | }
17 | ```
18 | 2、在build.gradle加入依赖
19 |
20 | ```python
21 | implementation 'com.github.HelloWordFeng:BottomMenu:1.0.4'
22 |
23 | ```
24 |
25 | ## 更新说明
26 |
27 | ### V1.0.4 新增Android X适配 运行环境:3.4.2
28 |
29 | ### V1.0.3 新增3级城市联动弹框(数据源采用.json文件 如需动态获取可自行改造列表弹框)
30 |
31 | ### V1.0.2 新增列表弹框及部分属性方法
32 |
33 | ## 1、使用方法
34 |
35 | ### 1、输入框
36 |
37 | ```python
38 | new MiddleDialogConfig().builder(this)
39 | .setDialogStyle(DialogEnum.EDIT)
40 | .setRightCallBack(new MiddleDialogConfig.RightCallBack() {
41 | @Override
42 | public void rightBtn(String cont) {
43 | showToast("点击了左边:"+cont);
44 | }
45 | })
46 | .setLeftCallBack(new MiddleDialogConfig.LeftCallBack() {
47 | @Override
48 | public void leftBtn(String cont) {
49 | showToast("点击了右边:" + cont);
50 | }
51 | }).show();
52 | ```
53 |
54 | ### 2、列表框
55 | ```python
56 | List list = new ArrayList<>();
57 | for (int i = 0; i < 50; i++) {
58 | list.add("选项Item" + i);
59 | }
60 | new MiddleDialogConfig().builder(this)
61 | .setDialogStyle(DialogEnum.LIST)
62 | .setDatas(list)
63 | .setItemSlidingCount(6, 0.85)
64 | .setRightCallBack(new MiddleDialogConfig.RightCallBack() {
65 | @Override
66 | public void rightBtn(String cont) {
67 | showToast("点击了左边:");
68 | }
69 | })
70 | .setLeftCallBack(new MiddleDialogConfig.LeftCallBack() {
71 | @Override
72 | public void leftBtn(String cont) {
73 | showToast("点击了右边:");
74 | }
75 | })
76 | .setItemCallBack(new MiddleDialogConfig.ItemCallBackListener() {
77 | @Override
78 | public void item(String str) {
79 | showToast("选择了:" + str);
80 | }
81 | })
82 | .show();
83 | ```
84 |
85 | ### 3、提示框
86 | ```python
87 | new MiddleDialogConfig().builder(this)
88 | .setRightCallBack(new MiddleDialogConfig.RightCallBack() {
89 | @Override
90 | public void rightBtn(String cont) {
91 | showToast("点击了左边:");
92 | }
93 | })
94 | .setLeftCallBack(new MiddleDialogConfig.LeftCallBack() {
95 | @Override
96 | public void leftBtn(String cont) {
97 | showToast("点击了右边:");
98 | }
99 | }).show();
100 | ```
101 |
102 | ### 4、QQ底部弹框
103 | ```python
104 | list.clear();
105 | list.add("发送给好友");
106 | list.add("转载到空间相册");
107 | list.add("群相册");
108 | list.add("保存到手机");
109 | list.add("提取图中文字");
110 | list.add("收藏");
111 | new BottomMenuFragment(this)
112 | .setContentSize(16)
113 | .setCancelTextTitle("取消")
114 | .setCancelTextSize(16)
115 | .setCancelTextColor("#454545")
116 | .setCancelTextHeight(45)
117 | .setCancelTextMarginTop(20)
118 | .setContentColor("#454545")
119 | .addMenuItems(list)
120 | .setBackgroundColor("#ebebeb")
121 | .setCancelPadding(0, 0, 0, 0)
122 | .setSizeOneShape(R.drawable.bottom_menu_mid_selector)
123 | .setTopShape(R.drawable.bottom_menu_mid_selector)
124 | .setMiddleShape(R.drawable.bottom_menu_mid_selector)
125 | .setBottomShape(R.drawable.bottom_menu_mid_selector)
126 | .setCancelShape(R.drawable.bottom_menu_mid_selector)
127 | .setOnItemClickListener(new BottomMenuFragment.OnItemClickListener() {
128 | @Override
129 | public void onItemClick(TextView menu, int position) {
130 | Toast.makeText(MainActivity.this, menu.getText().toString(),
131 | Toast.LENGTH_SHORT).show();
132 | }
133 | })
134 | .show();
135 | ```
136 |
137 | ### 5、ios弹框
138 | ```python
139 | list.clear();
140 | for (int i = 0; i < 4; i++) {
141 | list.add("文本内容" + i);
142 | }
143 | new BottomMenuFragment(this)
144 | .setTitle("标题")
145 | .addMenuItems(list)
146 | .setOnItemClickListener(new BottomMenuFragment.OnItemClickListener() {
147 | @Override
148 | public void onItemClick(TextView menu, int position) {
149 | Toast.makeText(MainActivity.this, menu.getText().toString(),
150 | Toast.LENGTH_SHORT).show();
151 |
152 | }
153 | })
154 | .show();
155 | ```
156 |
157 | ### 6、城市弹框
158 | ```python
159 | private String appendCity;
160 | private int selectPosition;
161 |
162 | //初始化执行
163 | DataUtils.initCityList(this);
164 |
165 | //只需点击时调用即可
166 | appendCity = "";//置空
167 | options.clear();
168 | //遍历省份数据
169 | for (int i = 0; i < DataUtils.returnJson().size(); i++) {
170 | options.add(DataUtils.returnJson().get(i).getName());
171 | }
172 | showCityDialog(0);
173 |
174 | //执行方法
175 | private void showCityDialog(final int selectType) {
176 | //超过几个可滑动
177 | int size = 6;
178 | String title = null;
179 | if (options.size() < size) {
180 | size = options.size();
181 | }
182 | if (selectType == 0) {
183 | title = "请选择省份";
184 | } else if (selectType == 1) {
185 | title = "请选择城市";
186 | } else if (selectType == 2) {
187 | title = "请选择区县";
188 | }
189 | new MiddleDialogConfig().builder(this)
190 | .setTitle(title)
191 | .setDialogStyle(DialogEnum.CITY)
192 | .setDatas(options)
193 | .setItemSlidingCount(size, 0.7)
194 | .setCityLevel(selectType)
195 | .setLeftRightVis()
196 | .setItemCallBack(new MiddleDialogConfig.ItemCallBackListener() {
197 | @Override
198 | public void item(String str) {
199 | String[] cont = str.split(",");
200 | appendCity += cont[1] + "\u3000";
201 | cityText.setText(appendCity);
202 | //int type= Integer.parseInt(cont[2]);
203 | int position = Integer.parseInt(cont[0]);
204 | if (null != options) {
205 | options.clear();
206 | }
207 | if (selectType == 0) {
208 | for (int i = 0; i < DataUtils.returnCitys().get(position).size(); i++) {
209 | options.add(DataUtils.returnCitys().get(position).get(i));
210 | }
211 | selectPosition = position;
212 | showCityDialog(1);
213 | } else if (selectType == 1) {
214 | for (int i = 0; i < DataUtils.returnAreas().get(selectPosition).get(position).size(); i++) {
215 | options.add(DataUtils.returnAreas().get(selectPosition).get(position).get(i));
216 | }
217 | showCityDialog(2);
218 | }
219 | }
220 | })
221 | .show();
222 | }
223 |
224 | ```
225 |
226 | ## 2、属性说明
227 | 1、BottomMenuFragment (底部样式)
228 | ###
229 | | 方法名 | 描述 | 参数值【默认】 |
230 | | :--------: | :--------:| :--: |
231 | | addMenuItems | 数据源item选项 | (List menuItems) |
232 | | setCancelTextTitle | 底部文字文本 | 取消 |
233 | | setCancelTextSize | 底部文字大小 | 16sp |
234 | | setCancelTextColor | 底部文字颜色 | (#467CD4蓝色) |
235 | | setCancelTextHeight | 底部文字高度 | dip2px(45)) |
236 | | setCancelTextMarginTop | 底部取消文字边距(距离顶部) | 20 |
237 | | setCancelPadding | 底部文字整体边距 | int left, int top, int right, int bottom (20) |
238 | | setCancelShape | 取消文字点击样式 | int resId (例如:R.drawable.bottom_menu_selector 非图片 样式shape) |
239 | | setBackgroundColor | 底部整体背景 | (#00000000) |
240 | | setTitle | 标题 | - |
241 | | setTitleSize | 文字大小 | 16 |
242 | | setTitleColor | 文字颜色 | (#ff0000 红色) |
243 | | setContentSize | item内容文字大小 | 15sp |
244 | | setContentColor | item内容文字颜色 | (#467CD4蓝色) |
245 | | setLineHeight | item分割线高度 | 1dp |
246 | | setLineColor | item分割线颜色 | (#ebebeb 灰色) |
247 | | setSizeOneShape | 数据size为1个样式 | (例如:R.drawable.bottom_menu_selector 非图片 样式shape) |
248 | | setTopShape | item第一个样式 | (例如:R.drawable.bottom_menu_top_selector 非图片 样式shape) |
249 | | setMiddleShape | item中间样式 | (例如:R.drawable.bottom_menu_mid_selector 非图片 样式shape) |
250 | | setBottomShape | item最后一个样式 | (例如:R.drawable.bottom_menu_bottom_selector 非图片 样式shape) |
251 |
252 | 2、MiddleDialogConfig (中间样式)
253 | ###
254 | | 方法名 | 描述 | 参数值【默认】 |
255 | | :--------: | :--------:| :--: |
256 | | setDialogStyle | 弹框样式(默认BASIC) | BASIC,EDIT,LIST |
257 | | setDatas | 数据源 | List mDatas |
258 | | setItemSlidingCount | 超过个数列表可滑动、弹框宽度屏幕占比 | int count, double dialogWidth(0-1) |
259 | | setIsCancel | 点击外部是否可取消 | boolean isCancel |
260 | | setHeight | 弹框高度屏幕的百分比 | double heigh(0-1) |
261 | | setWidth | 弹框宽度屏幕的百分比 | double width(0-1) |
262 | | setHeightLineColor | 垂直分隔线颜色 | (默认:"#454545") |
263 | | setWidthLineColor | 横向分隔线颜色 | (默认:"#454545") |
264 | | setTitleVis | 是否显示标题 | boolean isVis |
265 | | setTitleBgColor | 设置标题栏背景 | int bgColor(非图片 样式shape) |
266 | | setTitlePadding | 设置标题边距 | int left, int top, int right, int bottom (15) |
267 | | setContent | 设置提示的内容 | (String类型) |
268 | | setContentBgColor | 设置内容背景 | int bgColor(非图片 样式shape) |
269 | | setContentPadding | 设置内容边距 | int left, int top, int right, int bottom (20) |
270 | | setContentMaxLine | 设置最大显示几行 | - |
271 | | setLeft | 设置左侧按钮文字 | (String类型) |
272 | | setLeftColor | 左侧按钮文字颜色 | (默认:"#454545") |
273 | | setLeftVis | 左侧是否显示 | boolean isVis |
274 | | setLeftCallBack | 左侧点击事件 | LeftCallBack leftBack |
275 | | setBottomPadding | 设置底部右边边文字边距 | int left, int top, int right, int bottom (15) |
276 | | setBackageShape | 弹框样式 | int resId(非图片 样式shape) |
277 | | setEditHint | 输入框提示文字 | (String类型) |
278 | | setEditHintNull | 输入框为空提示字 | (String类型) |
279 | | setEditHintColor | 输入框为空提示字颜色 | (默认:"#828282") |
280 | | setEditTextColor | 输入框文字颜色 | (默认:"#454545") |
281 | | setEditBackageShape | 输入框样式 | int resId(非图片 样式shape 15dp圆角)) |
282 | | setEditPadding | 输入框内边距 | int left, int top, int right, int bottom (15) |
283 | | setEditMargin | 输入框距外边距 | int left, int top, int right, int bottom (15) |
284 | | setItemCallBack | item点击事件 | ItemCallBackListener listener |
285 | | setItemSize | item字体大小 | 15sp |
286 | | setItemColor | item字体颜色 | (默认:"#454545") |
287 | | setItemPadding | item字体内边距 | int left, int top, int right, int bottom (15) |
288 | | setCityLevel | 城市等级 | 0、1、2 |
289 | | setLeftRightVis | 取消、确认按钮 | 同时隐藏 |
290 | | show | 显示底部弹框 | - |
291 |
292 | 注意:-为系统默认值
293 |
294 | ## 3、 补充说明
295 | 如果上诉属性设置均未满足需求,可自行下载源码进行修改。
296 |
--------------------------------------------------------------------------------
/mylibrary/src/main/java/com/helloworld/library/MiddleDialogConfig.java:
--------------------------------------------------------------------------------
1 | package com.helloworld.library;
2 |
3 |
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.graphics.Color;
7 | import android.text.TextUtils;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.view.Window;
13 | import android.view.WindowManager;
14 | import android.widget.EditText;
15 | import android.widget.LinearLayout;
16 | import android.widget.TextView;
17 | import android.widget.Toast;
18 |
19 | import androidx.recyclerview.widget.LinearLayoutManager;
20 | import androidx.recyclerview.widget.RecyclerView;
21 |
22 | import com.helloworld.library.adapter.Myadapter;
23 | import com.helloworld.library.base.CommonRecyclerAdapter;
24 | import com.helloworld.library.utils.DialogEnum;
25 | import com.helloworld.library.utils.ScreenUtils;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | /**
31 | * 创建时间:2019/3/28 18:03
32 | * 作者:Hyman峰
33 | * 功能描述:常见的弹出框
34 | */
35 | public class MiddleDialogConfig {
36 |
37 | private static final String TAG = "MiddleDialogConfig";
38 | private Context mContext;
39 | private Dialog dialog;
40 | //背景
41 | private LinearLayout middleLinear;
42 | //标题文字
43 | private TextView middleTitle;
44 | //提示内容
45 | private TextView middleContent;
46 | //取消文字
47 | private TextView middleCancel;
48 | //确定文字
49 | private TextView middleDetermine;
50 | //分割线
51 | private View middleLine, middleWidthLine;
52 | //输入框
53 | private EditText middleEdit;
54 | //弹框框高
55 | private WindowManager.LayoutParams params;
56 | //样式
57 | private DialogEnum dialogEnum = DialogEnum.BASIC;
58 | //提示文字
59 | private String textHint = "请输入文本内容";
60 |
61 | private RecyclerView middleRecycler;
62 | private Myadapter adapter;
63 | //数据源
64 | private List mDatas = new ArrayList<>();
65 | //省市区0、1、2
66 | private int cityType;
67 |
68 | public MiddleDialogConfig builder(Context mContext) {
69 | this.mContext = mContext;
70 | // 获取Dialog布局
71 | View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_middle, null);
72 | // 获取自定义Dialog布局中的控件
73 | middleLinear = view.findViewById(R.id.middle_linear);
74 | middleTitle = view.findViewById(R.id.middle_title);
75 | middleContent = view.findViewById(R.id.middle_content);
76 | middleCancel = view.findViewById(R.id.middle_cancel);
77 | middleDetermine = view.findViewById(R.id.middle_determine);
78 | middleLine = view.findViewById(R.id.middle_line);
79 | middleWidthLine = view.findViewById(R.id.middle_width_line);
80 | middleEdit = view.findViewById(R.id.middle_edit);
81 | middleRecycler = view.findViewById(R.id.middle_recycler);
82 | //点击事件
83 | initClick();
84 | //初始化适配器
85 | initAdapter();
86 | // 定义Dialog布局和参数
87 | dialog = new Dialog(mContext, R.style.AlertDialogStyle);
88 | //点击外部是否取消
89 | dialog.setCanceledOnTouchOutside(false);
90 | dialog.setCancelable(false);
91 | //设置View布局
92 | dialog.setContentView(view);
93 | Window window = dialog.getWindow();
94 | params = window.getAttributes();
95 | window.setAttributes(params);
96 | return this;
97 | }
98 |
99 | /**
100 | * 初始化适配器
101 | */
102 | private void initAdapter() {
103 | adapter = new Myadapter(mContext, mDatas);
104 | middleRecycler.setLayoutManager(new LinearLayoutManager(mContext));
105 | middleRecycler.setAdapter(adapter);
106 | adapter.setOnItemClickListener(new CommonRecyclerAdapter.OnItemClickListener() {
107 | @Override
108 | public void onItemClick(RecyclerView parent, View view, int position) {
109 | dialog.dismiss();
110 | if (null != listener && mDatas.size() > 0) {
111 | if (dialogEnum == DialogEnum.LIST) {
112 | listener.item(mDatas.get(position));
113 | } else if (dialogEnum == DialogEnum.CITY) {
114 | listener.item(position + "," + mDatas.get(position) + "," + cityType);
115 | }
116 | }
117 | }
118 | });
119 | }
120 |
121 | /**
122 | * 设置弹框样式(默认普通提示框)
123 | */
124 | public MiddleDialogConfig setDialogStyle(DialogEnum dialogStyle) {
125 | this.dialogEnum = dialogStyle;
126 | if (dialogStyle == DialogEnum.BASIC) {
127 | middleContent.setVisibility(View.VISIBLE);
128 | middleEdit.setVisibility(View.GONE);
129 | middleRecycler.setVisibility(View.GONE);
130 | } else if (dialogStyle == DialogEnum.EDIT) {
131 | middleContent.setVisibility(View.GONE);
132 | middleEdit.setVisibility(View.VISIBLE);
133 | middleRecycler.setVisibility(View.GONE);
134 | } else if (dialogStyle == DialogEnum.LIST || dialogStyle == DialogEnum.CITY) {
135 | middleContent.setVisibility(View.GONE);
136 | middleEdit.setVisibility(View.GONE);
137 | middleRecycler.setVisibility(View.VISIBLE);
138 | }
139 | return this;
140 | }
141 |
142 | /**
143 | * 设置数据源
144 | */
145 | public MiddleDialogConfig setDatas(List mDatas) {
146 | this.mDatas = mDatas;
147 | if (dialogEnum == DialogEnum.LIST || dialogEnum == DialogEnum.CITY) {
148 | adapter.setList(mDatas);
149 | }
150 | return this;
151 | }
152 |
153 | /**
154 | * 设置超过几个列表可滑动
155 | * 需要传dialog 宽度否则item错乱 0-1
156 | */
157 | public MiddleDialogConfig setItemSlidingCount(int count, double dialogWidth) {
158 | ViewGroup.LayoutParams params = middleRecycler.getLayoutParams();
159 | params.height = ScreenUtils.dip2px(mContext, 45) * count;
160 | params.width = (int) (ScreenUtils.getScreenWidth(mContext) * dialogWidth);
161 | Log.e(TAG, "initAdapter: " + params.height);
162 | middleRecycler.setLayoutParams(params);
163 | return this;
164 | }
165 |
166 |
167 | /**
168 | * 点击外部是否可取消
169 | */
170 | public MiddleDialogConfig setIsCancel(boolean isCancel) {
171 | dialog.setCanceledOnTouchOutside(isCancel);
172 | dialog.setCancelable(isCancel);
173 | return this;
174 | }
175 |
176 | /**
177 | * 设置弹框高度-自身控件高度
178 | * 屏幕高度的百分比(0-1)
179 | */
180 | public MiddleDialogConfig setHeight(double height) {
181 | params.height = (int) (ScreenUtils.getScreenWidth(mContext) * height);
182 | return this;
183 | }
184 |
185 | /**
186 | * 设置弹框宽度
187 | * 屏幕宽度的百分比(0-1)
188 | */
189 | public MiddleDialogConfig setWidth(double width) {
190 | params.width = (int) (ScreenUtils.getScreenWidth(mContext) * width);
191 | return this;
192 | }
193 |
194 | /**
195 | * 设置垂直分隔线颜色
196 | */
197 | public MiddleDialogConfig setHeightLineColor(String color) {
198 | middleLine.setBackgroundColor(Color.parseColor(color));
199 | return this;
200 | }
201 |
202 | /**
203 | * 设置横向分隔线颜色
204 | */
205 | public MiddleDialogConfig setWidthLineColor(String color) {
206 | middleWidthLine.setBackgroundColor(Color.parseColor(color));
207 | return this;
208 | }
209 |
210 |
211 | /**
212 | * 设置标题的内容
213 | */
214 | public MiddleDialogConfig setTitle(String title) {
215 | middleTitle.setText(title);
216 | return this;
217 | }
218 |
219 | /**
220 | * 设置标题字体颜色
221 | */
222 | public MiddleDialogConfig setTitleColor(String color) {
223 | middleTitle.setTextColor(Color.parseColor(color));
224 | return this;
225 | }
226 |
227 | /**
228 | * 是否显示标题
229 | */
230 | public MiddleDialogConfig setTitleVis(boolean isVis) {
231 | if (isVis) {
232 | middleTitle.setVisibility(View.VISIBLE);
233 | } else {
234 | middleTitle.setVisibility(View.GONE);
235 | }
236 | return this;
237 | }
238 |
239 | /**
240 | * 设置标题栏背景颜色
241 | * drawable类型
242 | */
243 | public MiddleDialogConfig setTitleBgColor(int bgColor) {
244 | middleTitle.setBackgroundResource(bgColor);
245 | return this;
246 | }
247 |
248 | /**
249 | * 设置标题边距
250 | */
251 | public MiddleDialogConfig setTitlePadding(int left, int top, int right, int bottom) {
252 | middleTitle.setPadding(ScreenUtils.dip2px(mContext, left),
253 | ScreenUtils.dip2px(mContext, top),
254 | ScreenUtils.dip2px(mContext, right),
255 | ScreenUtils.dip2px(mContext, bottom));
256 | return this;
257 | }
258 |
259 | /**
260 | * 设置提示的内容
261 | */
262 | public MiddleDialogConfig setContent(String content) {
263 | middleContent.setText(content);
264 | return this;
265 | }
266 |
267 | /**
268 | * 设置提示的内容带下
269 | */
270 | public MiddleDialogConfig setContentSize(int size) {
271 | middleContent.setTextSize(size);
272 | return this;
273 | }
274 |
275 | /**
276 | * 设置内容颜色
277 | */
278 | public MiddleDialogConfig setContentColor(String color) {
279 | middleContent.setTextColor(Color.parseColor(color));
280 | return this;
281 | }
282 |
283 | /**
284 | * 设置内容背景颜色
285 | * drawable类型
286 | */
287 | public MiddleDialogConfig setContentBgColor(int bgColor) {
288 | middleContent.setBackgroundResource(bgColor);
289 | return this;
290 | }
291 |
292 | /**
293 | * 设置内容边距
294 | */
295 | public MiddleDialogConfig setContentPadding(float left, float top, float right, float bottom) {
296 | middleContent.setPadding(ScreenUtils.dip2px(mContext, left),
297 | ScreenUtils.dip2px(mContext, top),
298 | ScreenUtils.dip2px(mContext, right),
299 | ScreenUtils.dip2px(mContext, bottom));
300 | return this;
301 | }
302 |
303 | /**
304 | * 设置最大显示几行
305 | */
306 | public MiddleDialogConfig setContentMaxLine(int line) {
307 | middleContent.setMaxLines(line);
308 | middleContent.setEllipsize(TextUtils.TruncateAt.END);
309 | return this;
310 | }
311 |
312 | /**
313 | * 设置左侧按钮文字
314 | */
315 | public MiddleDialogConfig setLeft(String leftString) {
316 | middleCancel.setText(leftString);
317 | return this;
318 | }
319 |
320 | /**
321 | * 设置左侧按钮文字颜色
322 | */
323 | public MiddleDialogConfig setLeftColor(String leftColor) {
324 | middleCancel.setTextColor(Color.parseColor(leftColor));
325 | return this;
326 | }
327 |
328 | /**
329 | * 设置左侧是否显示
330 | */
331 | public MiddleDialogConfig setLeftVis(boolean isVis) {
332 | if (isVis) {
333 | middleCancel.setVisibility(View.VISIBLE);
334 | middleLine.setVisibility(View.VISIBLE);
335 | } else {
336 | middleCancel.setVisibility(View.GONE);
337 | middleLine.setVisibility(View.GONE);
338 | middleDetermine.setBackgroundResource(R.drawable.bottom_shape);
339 | }
340 | return this;
341 | }
342 |
343 | /**
344 | * 同时隐藏取消、确认按钮
345 | */
346 | public MiddleDialogConfig setLeftRightVis() {
347 | middleCancel.setVisibility(View.GONE);
348 | middleDetermine.setVisibility(View.GONE);
349 | middleWidthLine.setVisibility(View.GONE);
350 | middleLine.setVisibility(View.GONE);
351 | return this;
352 | }
353 |
354 | /**
355 | * 设置右侧按钮文字
356 | */
357 | public MiddleDialogConfig setRight(String rightString) {
358 | middleDetermine.setText(rightString);
359 | return this;
360 | }
361 |
362 | /**
363 | * 设置右侧按钮文字颜色
364 | */
365 | public MiddleDialogConfig setRightColor(String rightColor) {
366 | middleDetermine.setTextColor(Color.parseColor(rightColor));
367 | return this;
368 | }
369 |
370 | /**
371 | * 设置右侧是否显示
372 | */
373 | public MiddleDialogConfig setRightVis(boolean isVis) {
374 | if (isVis) {
375 | middleDetermine.setVisibility(View.VISIBLE);
376 | middleLine.setVisibility(View.VISIBLE);
377 | } else {
378 | middleDetermine.setVisibility(View.GONE);
379 | middleLine.setVisibility(View.GONE);
380 | middleCancel.setBackgroundResource(R.drawable.bottom_shape);
381 |
382 | }
383 | return this;
384 | }
385 |
386 | /**
387 | * 设置底部右边边文字边距
388 | */
389 | public MiddleDialogConfig setBottomPadding(int left, int top, int right, int bottom) {
390 | middleDetermine.setPadding(ScreenUtils.dip2px(mContext, left),
391 | ScreenUtils.dip2px(mContext, top),
392 | ScreenUtils.dip2px(mContext, right),
393 | ScreenUtils.dip2px(mContext, bottom));
394 | return this;
395 | }
396 |
397 | /**
398 | * 设置弹框样式
399 | * drawable类型
400 | */
401 | public MiddleDialogConfig setBackageShape(int resId) {
402 | middleLinear.setBackgroundResource(resId);
403 | return this;
404 | }
405 |
406 |
407 | /**
408 | * 设置输入框提示字
409 | */
410 | public MiddleDialogConfig setEditHint(String hint) {
411 | middleEdit.setHint(hint);
412 | return this;
413 | }
414 |
415 | /**
416 | * 设置输入框提示字
417 | */
418 | public MiddleDialogConfig setEditHintNull(String hint) {
419 | this.textHint = hint;
420 | return this;
421 | }
422 |
423 | /**
424 | * 设置输入框提示字
425 | */
426 | public MiddleDialogConfig setEditHintColor(String hintColor) {
427 | middleEdit.setHintTextColor(Color.parseColor(hintColor));
428 | return this;
429 | }
430 |
431 | /**
432 | * 设置输入框文字颜色
433 | */
434 | public MiddleDialogConfig setEditTextColor(String hintColor) {
435 | middleEdit.setTextColor(Color.parseColor(hintColor));
436 | return this;
437 | }
438 |
439 | /**
440 | * 设置输入框样式
441 | * drawable类型
442 | */
443 | public MiddleDialogConfig setEditBackageShape(int resId) {
444 | middleEdit.setBackgroundResource(resId);
445 | return this;
446 | }
447 |
448 |
449 | /**
450 | * 设置输入框内边距
451 | */
452 | public MiddleDialogConfig setEditPadding(int left, int top, int right, int bottom) {
453 | middleEdit.setPadding(ScreenUtils.dip2px(mContext, left),
454 | ScreenUtils.dip2px(mContext, top),
455 | ScreenUtils.dip2px(mContext, right),
456 | ScreenUtils.dip2px(mContext, bottom));
457 | return this;
458 | }
459 |
460 | /**
461 | * 设置输入框距外边距
462 | */
463 | public MiddleDialogConfig setEditMargin(int left, int top, int right, int bottom) {
464 | LinearLayout.LayoutParams olp = (LinearLayout.LayoutParams) middleEdit.getLayoutParams();
465 | olp.setMargins(ScreenUtils.dip2px(mContext, left),
466 | ScreenUtils.dip2px(mContext, top),
467 | ScreenUtils.dip2px(mContext, right),
468 | ScreenUtils.dip2px(mContext, bottom));
469 | middleEdit.setLayoutParams(olp);
470 | return this;
471 | }
472 |
473 | /**
474 | * 设置省市区级数
475 | */
476 | public MiddleDialogConfig setCityLevel(int type) {
477 | this.cityType = type;
478 | return this;
479 | }
480 |
481 | /**
482 | * 左右2边点击事件
483 | */
484 | private void initClick() {
485 | middleCancel.setOnClickListener(new View.OnClickListener() {
486 | @Override
487 | public void onClick(View v) {
488 | if (leftBack != null) {
489 | String cont = middleEdit.getText().toString().trim();
490 | leftBack.leftBtn(cont);
491 | }
492 | dialog.dismiss();
493 | }
494 | });
495 | middleDetermine.setOnClickListener(new View.OnClickListener() {
496 | @Override
497 | public void onClick(View v) {
498 | if (rightBack != null) {
499 | String cont = null;
500 | //样式为输入框样式时
501 | if (dialogEnum == DialogEnum.EDIT) {
502 | cont = middleEdit.getText().toString().trim();
503 | if (TextUtils.isEmpty(cont)) {
504 | showToast(textHint);
505 | return;
506 | }
507 | }
508 | rightBack.rightBtn(cont);
509 | dialog.dismiss();
510 | }
511 | }
512 | });
513 | }
514 |
515 | /**
516 | * 左右点击事件回调
517 | *
518 | * @param leftBack
519 | * @return
520 | */
521 | public MiddleDialogConfig setLeftCallBack(LeftCallBack leftBack) {
522 | this.leftBack = leftBack;
523 | return this;
524 | }
525 |
526 | public MiddleDialogConfig setRightCallBack(RightCallBack rightBack) {
527 | this.rightBack = rightBack;
528 | return this;
529 | }
530 |
531 | /**
532 | * item点击事件
533 | */
534 | public MiddleDialogConfig setItemCallBack(ItemCallBackListener listener) {
535 | this.listener = listener;
536 | return this;
537 | }
538 |
539 | /**
540 | * 字体大小
541 | */
542 | public MiddleDialogConfig setItemSize(int size) {
543 | adapter.setItemSize(size);
544 | return this;
545 | }
546 |
547 | /**
548 | * 字体颜色
549 | */
550 | public MiddleDialogConfig setItemColor(String color) {
551 | adapter.setItemColor(color);
552 | return this;
553 | }
554 |
555 | /**
556 | * 设置item边距
557 | */
558 | public MiddleDialogConfig setItemPadding(int left, int top, int right, int bottom) {
559 | adapter.setItemPadding(left, top, right, bottom);
560 | return this;
561 | }
562 |
563 | /**
564 | * 设置item位置
565 | */
566 | public MiddleDialogConfig setItemGravity(int gravity) {
567 | adapter.setItemGravity(gravity);
568 | return this;
569 | }
570 |
571 | private LeftCallBack leftBack;
572 |
573 | public interface LeftCallBack {
574 | void leftBtn(String cont);
575 | }
576 |
577 | private RightCallBack rightBack;
578 |
579 | public interface RightCallBack {
580 | void rightBtn(String cont);
581 |
582 | }
583 |
584 | private ItemCallBackListener listener;
585 |
586 | public interface ItemCallBackListener {
587 |
588 | void item(String str);
589 | }
590 |
591 |
592 | /**
593 | * 显示底部弹框
594 | */
595 | public void show() {
596 | if (dialog != null && (!dialog.isShowing())) {
597 | dialog.show();
598 | }
599 | }
600 |
601 | /**
602 | * 提示文本
603 | */
604 | private void showToast(String msg) {
605 | Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
606 | }
607 | }
608 |
609 |
--------------------------------------------------------------------------------