├── .gitignore ├── README.md ├── build.gradle ├── example ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── screenshot │ ├── custom_ios_dialog_button.png │ ├── custom_ios_dialog_no_title.png │ ├── default_ios_style_dialog.png │ ├── device-2017-04-10-112933.png │ ├── device-2017-04-10-113008.png │ ├── device-2017-04-10-113032.png │ └── ios_sheet_dialog.png └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── ligl │ │ └── example │ │ └── iosdialog │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── ligl │ │ │ └── example │ │ │ └── iosdialog │ │ │ └── MainActivity.java │ └── res │ │ ├── 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 │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── ligl │ └── example │ └── iosdialog │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── iosdialog ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── ligl │ │ └── android │ │ └── widget │ │ └── iosdialog │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── ligl │ │ │ └── android │ │ │ └── widget │ │ │ └── iosdialog │ │ │ ├── IOSDialog.java │ │ │ └── IOSSheetDialog.java │ └── res │ │ ├── anim │ │ ├── iossheet_in.xml │ │ └── iossheet_out.xml │ │ ├── drawable │ │ ├── iosdialog_bg.xml │ │ ├── iosdialog_left_btn_normal.xml │ │ ├── iosdialog_left_btn_press.xml │ │ ├── iosdialog_left_btn_selector.xml │ │ ├── iosdialog_right_btn_normal.xml │ │ ├── iosdialog_right_btn_press.xml │ │ ├── iosdialog_right_btn_selector.xml │ │ ├── iosdialog_sigle_btn_normal.xml │ │ ├── iosdialog_sigle_btn_press.xml │ │ ├── iosdialog_sigle_btn_selector.xml │ │ ├── iossheet_bottom_btn_normal.xml │ │ ├── iossheet_bottom_btn_press.xml │ │ ├── iossheet_bottom_btn_selector.xml │ │ ├── iossheet_middle_btn_normal.xml │ │ ├── iossheet_middle_btn_press.xml │ │ ├── iossheet_middle_btn_selector.xml │ │ ├── iossheet_sigle_btn_normal.xml │ │ ├── iossheet_sigle_btn_press.xml │ │ ├── iossheet_sigle_btn_selector.xml │ │ ├── iossheet_top_btn_normal.xml │ │ ├── iossheet_top_btn_press.xml │ │ └── iossheet_top_btn_selector.xml │ │ ├── layout │ │ ├── ios_dialog.xml │ │ ├── ios_sheet_dialog.xml │ │ └── ios_sheet_item.xml │ │ ├── values-en │ │ └── strings.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── ligl │ └── android │ └── widget │ └── iosdialog │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IOSDialog 2 | A IOS style dialog for Android developer 3 | 4 | ## How to use 5 | Gradle 6 | ```java 7 | 8 | dependencies { 9 | compile 'com.itlgl:iosdialog:1.0.1' 10 | } 11 | ``` 12 | 13 | ## Example 14 | ### Default style Dialog 15 | ```java 16 | new IOSDialog.Builder(context) 17 | .setTitle("Tip") 18 | .setMessage("IOS style dialog").show(); 19 | ``` 20 | The default style Dialog comes with a confirmation button with the following style: 21 | 22 | ![IOS style dialog](https://github.com/itlgl/IOSDialog/raw/master/example/screenshot/default_ios_style_dialog.png) 23 | 24 | ## CUstom Dialog without title 25 | ```java 26 | new IOSDialog.Builder(context) 27 | .setMessage("IOS style dialog,have no title").show(); 28 | ``` 29 | 30 | The display is as follows: 31 | 32 | ![IOS style dialog no title](https://github.com/ligl01/IOSDialog/raw/master/example/screenshot/custom_ios_dialog_no_title.png) 33 | 34 | ### Custom Dialog button 35 | IOSDialog supports up to two buttons, such as the "confirm" and "cancel" buttons 36 | ```java 37 | new IOSDialog.Builder(context) 38 | .setTitle("title") 39 | .setMessage("message") 40 | .setPositiveButton("OK", null) 41 | .setNegativeButton("Cancel", null).show(); 42 | ``` 43 | The display is as follows: 44 | 45 | ![IOS style dialog2](https://github.com/ligl01/IOSDialog/raw/master/example/screenshot/custom_ios_dialog_button.png) 46 | 47 | ### IOS sheet style Dialog 48 | ```java 49 | IOSSheetDialog.SheetItem[] items = new IOSSheetDialog.SheetItem[2]; 50 | items[0] = new IOSSheetDialog.SheetItem("item1", IOSSheetDialog.SheetItem.RED); 51 | items[1] = new IOSSheetDialog.SheetItem("item2", IOSSheetDialog.SheetItem.BLUE); 52 | IOSSheetDialog dialog2 = new IOSSheetDialog.Builder(context) 53 | .setTitle("title").setData(items, null).show(); 54 | ``` 55 | The display is as follows: 56 | 57 | ![IOS style sheet](https://github.com/ligl01/IOSDialog/raw/master/example/screenshot/ios_sheet_dialog.png) 58 | 59 | ## 上传到远程仓库 60 | 本项目依赖Android Studio编译。 61 | 62 | 现在这个项目分别上传到了Maven和Jcenter仓库,默认情况下是上传到Maven仓库,项目不需要做修改。在Android Studio中运行`uploadArchives`的task即可上传到Maven仓库中。 63 | 64 | 如果上传到Jcenter仓库,需要修改`./iosdialog/gradle.properties`文件下的RELEASE_REPOSITORY_URL和SNAPSHOT_REPOSITORY_URL,都修改为`https://api.bintray.com/maven/itlgl/maven/iosdialog/;publish=1`即可(不知道Jcenter是否有SNAPSHOT仓库位置,都填写成正式位置仓库url),另外还需要修改`USER_HOME/.gradle/gradle.properties`中的用户名和密码。然后在Android Studio中运行`uploadArchives`的task即可上传到Jcenter仓库中。 65 | 66 | 如果想生成到本地,看一下生成的对不对,将RELEASE_REPOSITORY_URL和SNAPSHOT_REPOSITORY_URL修改为本地位置即可,比如`file://D:/temp/`。 67 | 68 | ## 参考 69 | [IOS_Dialog_Library](https://github.com/zhangjoey1984/IOS_Dialog_Library) 70 | 71 | ## 关于我 72 | 一个Android开发者 73 | 74 | 邮箱: ligl6688@gmail.com 75 | 76 | ## github Quick setup 77 | 78 | ### Quick setup — if you’ve done this kind of thing before 79 | 80 | [HTTP](https://github.com/ligl01/IOSDialog.git) or [SSH](git@github.com:ligl01/IOSDialog.git) 81 | 82 | ### …or create a new repository on the command line 83 | 84 | ```cmd 85 | echo "# IOSDialog" >> README.md 86 | git init 87 | git add README.md 88 | git commit -m "first commit" 89 | git remote add origin git@github.com:ligl01/IOSDialog.git 90 | git push -u origin master 91 | ``` 92 | 93 | ### …or push an existing repository from the command line 94 | 95 | ```cmd 96 | git remote add origin git@github.com:ligl01/IOSDialog.git 97 | git push -u origin master 98 | ``` 99 | 100 | ### …or import code from another repository 101 | 102 | ```cmd 103 | You can initialize this repository with code from a Subversion, Mercurial, or TFS project. 104 | ``` 105 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.0.0' 10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5' 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | jcenter() 17 | google() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /example/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | // buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.ligl.example.iosdialog" 9 | minSdkVersion 9 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 28 | exclude group: 'com.android.support', module: 'support-annotations' 29 | }) 30 | compile project(path: ':iosdialog') 31 | testCompile 'junit:junit:4.12' 32 | } 33 | -------------------------------------------------------------------------------- /example/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\android\adt-bundle-windows-x86-20140321\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /example/screenshot/custom_ios_dialog_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/screenshot/custom_ios_dialog_button.png -------------------------------------------------------------------------------- /example/screenshot/custom_ios_dialog_no_title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/screenshot/custom_ios_dialog_no_title.png -------------------------------------------------------------------------------- /example/screenshot/default_ios_style_dialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/screenshot/default_ios_style_dialog.png -------------------------------------------------------------------------------- /example/screenshot/device-2017-04-10-112933.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/screenshot/device-2017-04-10-112933.png -------------------------------------------------------------------------------- /example/screenshot/device-2017-04-10-113008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/screenshot/device-2017-04-10-113008.png -------------------------------------------------------------------------------- /example/screenshot/device-2017-04-10-113032.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/screenshot/device-2017-04-10-113032.png -------------------------------------------------------------------------------- /example/screenshot/ios_sheet_dialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/screenshot/ios_sheet_dialog.png -------------------------------------------------------------------------------- /example/src/androidTest/java/com/ligl/example/iosdialog/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ligl.example.iosdialog; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.ligl.example.iosdialog", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /example/src/main/java/com/ligl/example/iosdialog/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.ligl.example.iosdialog; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.view.View.OnClickListener; 9 | import android.widget.Button; 10 | import android.widget.LinearLayout; 11 | 12 | import com.ligl.android.widget.iosdialog.IOSDialog; 13 | import com.ligl.android.widget.iosdialog.IOSSheetDialog; 14 | 15 | public class MainActivity extends Activity { 16 | 17 | Context context; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | 22 | super.onCreate(savedInstanceState); 23 | context = this; 24 | LinearLayout ll = new LinearLayout(this); 25 | ll.setOrientation(LinearLayout.VERTICAL); 26 | 27 | Button btn = null; 28 | 29 | btn = new Button(this); 30 | btn.setText("ios style dialog"); 31 | btn.setOnClickListener(new OnClickListener() { 32 | @Override 33 | public void onClick(View v) { 34 | new IOSDialog.Builder(context).setTitle("Tip").setMessage("IOS style dialog").show(); 35 | } 36 | }); 37 | ll.addView(btn); 38 | 39 | btn = new Button(this); 40 | btn.setText("ios style dialog without title"); 41 | btn.setOnClickListener(new OnClickListener() { 42 | @Override 43 | public void onClick(View v) { 44 | new IOSDialog.Builder(context).setMessage("IOS style dialog,have no title").show(); 45 | } 46 | }); 47 | ll.addView(btn); 48 | 49 | btn = new Button(this); 50 | btn.setText("Custom Dialog button"); 51 | btn.setOnClickListener(new OnClickListener() { 52 | @Override 53 | public void onClick(View v) { 54 | new IOSDialog.Builder(context) 55 | .setTitle("title") 56 | .setMessage("message") 57 | .setPositiveButton("OK", null) 58 | .setNegativeButton("Cancel", null).show(); 59 | } 60 | }); 61 | ll.addView(btn); 62 | 63 | btn = new Button(this); 64 | btn.setText("ios style dialog(multiple lines of text)"); 65 | btn.setOnClickListener(new OnClickListener() { 66 | @Override 67 | public void onClick(View v) { 68 | new IOSDialog.Builder(context) 69 | .setTitle("Hello") 70 | .setMessage( 71 | "Test multiple lines of text\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222") 72 | // .setMessage("1") 73 | .setPositiveButton("OK", 74 | new DialogInterface.OnClickListener() { 75 | 76 | @Override 77 | public void onClick(DialogInterface dialog, 78 | int which) { 79 | // dialog.dismiss(); 80 | } 81 | }) 82 | .setNegativeButton("Cancel", 83 | new DialogInterface.OnClickListener() { 84 | 85 | @Override 86 | public void onClick(DialogInterface dialog, 87 | int which) { 88 | // dialog.dismiss(); 89 | } 90 | }).show(); 91 | } 92 | }); 93 | ll.addView(btn); 94 | 95 | btn = new Button(this); 96 | btn.setText("ios sheet style dialog"); 97 | btn.setOnClickListener(new OnClickListener() { 98 | @Override 99 | public void onClick(View v) { 100 | IOSSheetDialog.SheetItem[] items = new IOSSheetDialog.SheetItem[2]; 101 | items[0] = new IOSSheetDialog.SheetItem("item1", IOSSheetDialog.SheetItem.RED); 102 | items[1] = new IOSSheetDialog.SheetItem("item2", IOSSheetDialog.SheetItem.BLUE); 103 | IOSSheetDialog dialog2 = new IOSSheetDialog.Builder(context) 104 | .setTitle("Title").setData(items, null).show(); 105 | } 106 | }); 107 | ll.addView(btn); 108 | 109 | btn = new Button(this); 110 | btn.setText("ios sheet style dialog without title"); 111 | btn.setOnClickListener(new OnClickListener() { 112 | @Override 113 | public void onClick(View v) { 114 | IOSSheetDialog.SheetItem[] items = new IOSSheetDialog.SheetItem[2]; 115 | items[0] = new IOSSheetDialog.SheetItem("item1", IOSSheetDialog.SheetItem.RED); 116 | items[1] = new IOSSheetDialog.SheetItem("item2", IOSSheetDialog.SheetItem.BLUE); 117 | IOSSheetDialog dialog2 = new IOSSheetDialog.Builder(context) 118 | .setData(items, null).show(); 119 | } 120 | }); 121 | ll.addView(btn); 122 | 123 | setContentView(ll); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /example/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /example/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | IOSDialogExample 3 | 4 | -------------------------------------------------------------------------------- /example/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/src/test/java/com/ligl/example/iosdialog/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ligl.example.iosdialog; 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() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itlgl/IOSDialog/214548350da6a1e130637e7c02ad4c2aef99de92/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Nov 27 17:00:36 GMT+08:00 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /iosdialog/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /iosdialog/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 26 5 | // buildToolsVersion '26.0.2' 6 | 7 | defaultConfig { 8 | minSdkVersion 9 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0.1" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | testCompile 'junit:junit:4.12' 30 | 31 | } 32 | 33 | apply from: 'https://raw.github.com/itlgl/gradle-mvn-push/master/gradle-mvn-push-android.gradle' 34 | -------------------------------------------------------------------------------- /iosdialog/gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=1.0.1 2 | GROUP=com.itlgl 3 | 4 | POM_DESCRIPTION=A IOS style dialog for Android developer 5 | POM_URL=https://github.com/itlgl/iosdialog 6 | POM_SCM_URL=https://github.com/itlgl/iosdialog 7 | POM_SCM_CONNECTION=scm:git@github.com:itlgl/iosdialog.git 8 | POM_SCM_DEV_CONNECTION=scm:git@github.com:itlgl/iosdialog.git 9 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 10 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 11 | POM_LICENCE_DIST=repo 12 | POM_DEVELOPER_ID=itlgl 13 | POM_DEVELOPER_NAME=itlgl 14 | POM_DEVELOPER_EMAIL=itlgl@outlook.com 15 | 16 | POM_NAME=iosdialog 17 | POM_ARTIFACT_ID=iosdialog 18 | POM_PACKAGING=aar 19 | 20 | # default upload to Maven Central 21 | 22 | # generate aar in local 23 | #RELEASE_REPOSITORY_URL=file://D:/temp/ 24 | #SNAPSHOT_REPOSITORY_URL=file://D:/temp/ 25 | 26 | # upload to Jcenter 27 | #RELEASE_REPOSITORY_URL=https://api.bintray.com/maven/itlgl/maven/iosdialog/;publish=1 28 | #SNAPSHOT_REPOSITORY_URL=https://api.bintray.com/maven/itlgl/maven/iosdialog/;publish=1 -------------------------------------------------------------------------------- /iosdialog/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\android\adt-bundle-windows-x86-20140321\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /iosdialog/src/androidTest/java/com/ligl/android/widget/iosdialog/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ligl.android.widget.iosdialog; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.ligl.android.widget.iosdialog.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /iosdialog/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /iosdialog/src/main/java/com/ligl/android/widget/iosdialog/IOSDialog.java: -------------------------------------------------------------------------------- 1 | package com.ligl.android.widget.iosdialog; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.text.TextUtils; 7 | import android.util.DisplayMetrics; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.view.WindowManager; 12 | import android.widget.Button; 13 | import android.widget.LinearLayout; 14 | import android.widget.RelativeLayout; 15 | import android.widget.TextView; 16 | 17 | /** 18 | * @author itlgl 19 | * 20 | */ 21 | public class IOSDialog extends Dialog { 22 | 23 | public IOSDialog(Context context) { 24 | super(context, R.style.ios_dialog_style); 25 | } 26 | 27 | public static class Builder { 28 | private Context mContext; 29 | private IOSDialog mIosDialog; 30 | private CharSequence mTitle; 31 | private CharSequence mMessage; 32 | private CharSequence mPositiveButtonText; 33 | private CharSequence mNegativeButtonText; 34 | private View mContentView; 35 | private OnClickListener mPositiveButtonClickListener; 36 | private OnClickListener mNegativeButtonClickListener; 37 | private boolean mCancelable = true; 38 | 39 | public Builder(Context context) { 40 | mContext = context; 41 | } 42 | 43 | public Builder setTitle(int titleId) { 44 | this.mTitle = mContext.getText(titleId); 45 | return this; 46 | } 47 | 48 | public Builder setTitle(CharSequence title) { 49 | this.mTitle = title; 50 | return this; 51 | } 52 | 53 | public Builder setMessage(int messageId) { 54 | this.mMessage = mContext.getText(messageId); 55 | return this; 56 | } 57 | 58 | public Builder setMessage(CharSequence message) { 59 | this.mMessage = message; 60 | return this; 61 | } 62 | 63 | public Builder setPositiveButton(int textId, OnClickListener listener) { 64 | this.mPositiveButtonText = mContext.getText(textId); 65 | this.mPositiveButtonClickListener = listener; 66 | return this; 67 | } 68 | 69 | public Builder setPositiveButton(CharSequence text, OnClickListener listener) { 70 | this.mPositiveButtonText = text; 71 | this.mPositiveButtonClickListener = listener; 72 | return this; 73 | } 74 | 75 | public Builder setNegativeButton(int textId, OnClickListener listener) { 76 | this.mNegativeButtonText = mContext.getText(textId); 77 | this.mNegativeButtonClickListener = listener; 78 | return this; 79 | } 80 | 81 | public Builder setNegativeButton(CharSequence text, OnClickListener listener) { 82 | this.mNegativeButtonText = text; 83 | this.mNegativeButtonClickListener = listener; 84 | return this; 85 | } 86 | 87 | public Builder setCancelable(boolean cancelable) { 88 | this.mCancelable = cancelable; 89 | return this; 90 | } 91 | 92 | public Builder setContentView(View contentView) { 93 | this.mContentView = contentView; 94 | return this; 95 | } 96 | 97 | public IOSDialog create() { 98 | LayoutInflater inflater = LayoutInflater.from(mContext); 99 | View dialogView = inflater.inflate(R.layout.ios_dialog, null); 100 | mIosDialog = new IOSDialog(mContext); 101 | mIosDialog.setCancelable(mCancelable); 102 | 103 | TextView tvTitle = (TextView) dialogView.findViewById(R.id.title); 104 | TextView tvMessage = (TextView) dialogView.findViewById(R.id.message); 105 | Button btnCancel = (Button) dialogView.findViewById(R.id.cancel_btn); 106 | Button btnConfirm = (Button) dialogView.findViewById(R.id.confirm_btn); 107 | View horizontal_line = dialogView.findViewById(R.id.horizontal_line); 108 | View vertical_line = dialogView.findViewById(R.id.vertical_line); 109 | View btns_panel = dialogView.findViewById(R.id.btns_panel); 110 | 111 | // set title 112 | // fix #1,if title is null,set title visibility GONE 113 | if(TextUtils.isEmpty(mTitle)) { 114 | tvTitle.setVisibility(View.GONE); 115 | } else { 116 | tvTitle.setText(mTitle); 117 | } 118 | // set content view 119 | if (mContentView != null) { 120 | // if no message set add the contentView to the dialog body 121 | LinearLayout rl = (LinearLayout) dialogView 122 | .findViewById(R.id.message_layout); 123 | rl.removeAllViews(); 124 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( 125 | RelativeLayout.LayoutParams.MATCH_PARENT, 126 | RelativeLayout.LayoutParams.WRAP_CONTENT); 127 | rl.addView(mContentView, params); 128 | } else { 129 | tvMessage.setText(mMessage); 130 | } 131 | // set buttons 132 | if(mPositiveButtonText == null && mNegativeButtonText == null) { 133 | setPositiveButton(R.string.ios_dialog_default_ok, null); 134 | btnConfirm.setBackgroundResource(R.drawable.iosdialog_sigle_btn_selector); 135 | btnCancel.setVisibility(View.GONE); 136 | vertical_line.setVisibility(View.GONE); 137 | } else if(mPositiveButtonText != null && mNegativeButtonText == null) { 138 | btnConfirm.setBackgroundResource(R.drawable.iosdialog_sigle_btn_selector); 139 | btnCancel.setVisibility(View.GONE); 140 | vertical_line.setVisibility(View.GONE); 141 | } else if(mPositiveButtonText == null && mNegativeButtonText != null) { 142 | btnConfirm.setVisibility(View.GONE); 143 | btnCancel.setBackgroundResource(R.drawable.iosdialog_sigle_btn_selector); 144 | vertical_line.setVisibility(View.GONE); 145 | } 146 | if (mPositiveButtonText != null) { 147 | btnConfirm.setText(mPositiveButtonText); 148 | btnConfirm.setOnClickListener(new View.OnClickListener() { 149 | 150 | @Override 151 | public void onClick(View v) { 152 | if (mPositiveButtonClickListener != null) { 153 | mPositiveButtonClickListener.onClick(mIosDialog, 154 | DialogInterface.BUTTON_POSITIVE); 155 | } 156 | mIosDialog.dismiss(); 157 | } 158 | }); 159 | } 160 | if (mNegativeButtonText != null) { 161 | btnCancel.setText(mNegativeButtonText); 162 | btnCancel.setOnClickListener(new View.OnClickListener() { 163 | 164 | @Override 165 | public void onClick(View v) { 166 | if (mNegativeButtonClickListener != null) { 167 | mNegativeButtonClickListener.onClick(mIosDialog, 168 | DialogInterface.BUTTON_NEGATIVE); 169 | } 170 | mIosDialog.dismiss(); 171 | } 172 | }); 173 | } 174 | 175 | // 调整一下dialog的高度,如果高度充满屏幕不好看 176 | // Adjust the height of the dialog, if the height is full, the screen is not good. 177 | // 计算一下Dialog的高度,如果超过屏幕的4/5,则最大高度限制在4/5 178 | // Calculate the height of the Dialog. If it exceeds 4/5 of the screen, the maximum height is limited to 4/5. 179 | // 1.计算dialog的高度 180 | // 1. Calculate the height of the dialog 181 | // TODO 测试发现的问题:如果放入一大串没有换行的文本到message区域,会导致测量出来的高度偏小,从而导致实际显示出来dialog充满了整个屏幕 182 | // TODO The problem found in the test: If you put a large number of texts without line breaks into the message area, the measured height will be too small, which will cause the actual display dialog to fill the entire screen. 183 | dialogView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 184 | int dialogHeight = dialogView.getMeasuredHeight(); 185 | // 2.得到屏幕高度 186 | // 2. Get the screen height 187 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); 188 | DisplayMetrics metrics = new DisplayMetrics(); 189 | wm.getDefaultDisplay().getMetrics(metrics); 190 | int maxHeight = (int) (metrics.heightPixels * 0.8); 191 | ViewGroup.LayoutParams dialogParams = new ViewGroup.LayoutParams( 192 | ViewGroup.LayoutParams.MATCH_PARENT, 193 | ViewGroup.LayoutParams.WRAP_CONTENT); 194 | // 3.如果高度超限,限制dialog的高度 195 | // 3. Limit height of dialog if height is exceeded 196 | if(dialogHeight >= maxHeight) { 197 | dialogParams.height = maxHeight; 198 | } 199 | mIosDialog.setContentView(dialogView, dialogParams); 200 | 201 | return mIosDialog; 202 | } 203 | 204 | public IOSDialog show() { 205 | mIosDialog = create(); 206 | mIosDialog.show(); 207 | return mIosDialog; 208 | } 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /iosdialog/src/main/java/com/ligl/android/widget/iosdialog/IOSSheetDialog.java: -------------------------------------------------------------------------------- 1 | package com.ligl.android.widget.iosdialog; 2 | 3 | import java.util.List; 4 | 5 | import android.app.Dialog; 6 | import android.content.Context; 7 | import android.content.DialogInterface; 8 | import android.graphics.Color; 9 | import android.text.TextUtils; 10 | import android.util.DisplayMetrics; 11 | import android.view.Gravity; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.Window; 15 | import android.view.WindowManager; 16 | import android.view.ViewGroup.LayoutParams; 17 | import android.widget.Button; 18 | import android.widget.LinearLayout; 19 | import android.widget.TextView; 20 | 21 | /** 22 | * @author itlgl 23 | * 24 | */ 25 | public class IOSSheetDialog extends Dialog implements DialogInterface { 26 | 27 | public IOSSheetDialog(Context context) { 28 | super(context, R.style.ios_sheet_style); 29 | } 30 | 31 | public static class Builder { 32 | private IOSSheetDialog mIosSheetDialog; 33 | private Context mContext; 34 | private CharSequence mTitle; 35 | private CharSequence mCancelText; 36 | private SheetItem[] mItems; 37 | private OnClickListener mOnClickListener; 38 | 39 | public Builder(Context context) { 40 | this.mContext = context; 41 | 42 | this.mCancelText = mContext.getText(R.string.iossheet_cancel); 43 | } 44 | 45 | public Builder setTitle(CharSequence title) { 46 | this.mTitle = title; 47 | return this; 48 | } 49 | 50 | public Builder setTitle(int titleId) { 51 | this.mTitle = mContext.getText(titleId); 52 | return this; 53 | } 54 | 55 | public Builder setCancelText(CharSequence text) { 56 | this.mCancelText = text; 57 | return this; 58 | } 59 | 60 | public Builder setCancelText(int textId) { 61 | this.mCancelText = mContext.getText(textId); 62 | return this; 63 | } 64 | 65 | public Builder setData(SheetItem[] items, OnClickListener listener) { 66 | this.mItems = new SheetItem[items.length]; 67 | for (int i = 0, len = items.length; i < len; i++) { 68 | mItems[i] = new SheetItem(items[i].name, items[i].color); 69 | } 70 | this.mOnClickListener = listener; 71 | return this; 72 | } 73 | 74 | public Builder setData(List items, OnClickListener listener) { 75 | this.mItems = new SheetItem[items.size()]; 76 | for (int i = 0, len = items.size(); i < len; i++) { 77 | SheetItem item = items.get(i); 78 | mItems[i] = new SheetItem(item.name, item.color); 79 | } 80 | this.mOnClickListener = listener; 81 | return this; 82 | } 83 | 84 | public IOSSheetDialog create() { 85 | LayoutInflater inflater = LayoutInflater.from(mContext); 86 | View sheetView = inflater.inflate(R.layout.ios_sheet_dialog, null); 87 | mIosSheetDialog = new IOSSheetDialog(mContext); 88 | 89 | TextView tvTitle = (TextView) sheetView.findViewById(R.id.title); 90 | LinearLayout message_layout = (LinearLayout) sheetView.findViewById(R.id.message_layout); 91 | Button btn_cancel = (Button) sheetView.findViewById(R.id.btn_cancel); 92 | 93 | // 设置标题 94 | // fix #1, if title is null, set tvTitle visibility GONE,and set first item background as top 95 | if(TextUtils.isEmpty(mTitle)) { 96 | tvTitle.setVisibility(View.GONE); 97 | } else { 98 | tvTitle.setText(mTitle); 99 | } 100 | // 填充列表内容 101 | for (int i = 0, len = mItems.length; i < len; i++) { 102 | 103 | View itemView = inflater.inflate(R.layout.ios_sheet_item, message_layout, false); 104 | Button btnItem = (Button) itemView.findViewById(R.id.btn_item); 105 | btnItem.setText(mItems[i].name); 106 | btnItem.setTextColor(mItems[i].color); 107 | // fix #1, if title is null, set tvTitle visibility GONE,and set first item background as top 108 | if(i == 0 && TextUtils.isEmpty(mTitle)) { 109 | View line = itemView.findViewById(R.id.line); 110 | line.setVisibility(View.GONE); 111 | btnItem.setBackgroundResource(R.drawable.iossheet_top_btn_selector); 112 | } 113 | if(i == mItems.length - 1) { 114 | btnItem.setBackgroundResource(R.drawable.iossheet_bottom_btn_selector); 115 | } 116 | final int itemIndex = i; 117 | btnItem.setOnClickListener(new View.OnClickListener() { 118 | 119 | @Override 120 | public void onClick(View v) { 121 | if(mOnClickListener != null) { 122 | mOnClickListener.onClick(mIosSheetDialog, itemIndex); 123 | } 124 | mIosSheetDialog.dismiss(); 125 | } 126 | }); 127 | message_layout.addView(itemView); 128 | } 129 | btn_cancel.setText(mCancelText); 130 | // 设置取消事件 131 | btn_cancel.setOnClickListener(new View.OnClickListener() { 132 | 133 | @Override 134 | public void onClick(View v) { 135 | mIosSheetDialog.dismiss(); 136 | } 137 | }); 138 | 139 | // 获取屏幕高度 140 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); 141 | DisplayMetrics metrics = new DisplayMetrics(); 142 | wm.getDefaultDisplay().getMetrics(metrics); 143 | // 设置宽度全屏,底部弹出 144 | Window window = mIosSheetDialog.getWindow(); 145 | window.setWindowAnimations(R.style.ios_sheet_anim); 146 | window.setBackgroundDrawableResource(android.R.color.transparent); 147 | WindowManager.LayoutParams wml = window.getAttributes(); 148 | wml.width = metrics.widthPixels; 149 | wml.gravity = Gravity.BOTTOM; 150 | wml.y = 0; 151 | window.setAttributes(wml); 152 | sheetView.setMinimumWidth(metrics.widthPixels); 153 | 154 | // 设置dialog的高度不能超过屏幕的0.7 155 | LayoutParams vgl = new LayoutParams( 156 | LayoutParams.MATCH_PARENT, 157 | LayoutParams.WRAP_CONTENT); 158 | int maxHeight = (int) (metrics.heightPixels * 0.7); 159 | // 测量dialog的高度 160 | sheetView.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 161 | int dialogMeasureHeight = sheetView.getMeasuredHeight(); 162 | if(dialogMeasureHeight > maxHeight) { 163 | vgl.height = maxHeight; 164 | } 165 | mIosSheetDialog.setContentView(sheetView, vgl); 166 | return mIosSheetDialog; 167 | } 168 | 169 | public IOSSheetDialog show() { 170 | mIosSheetDialog = create(); 171 | mIosSheetDialog.show(); 172 | return mIosSheetDialog; 173 | } 174 | } 175 | 176 | public static final class SheetItem { 177 | public static final int RED = Color.parseColor("#FFFD4A2E"); 178 | public static final int BLUE = Color.parseColor("#FF037BFF"); 179 | //public static final int GREY = Color.parseColor("#FFFD4A2E"); 180 | 181 | public String name; 182 | public int color; 183 | 184 | public SheetItem() { 185 | } 186 | 187 | public SheetItem(String name, int color) { 188 | this.name = name; 189 | this.color = color; 190 | } 191 | 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/anim/iossheet_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/anim/iossheet_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_left_btn_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_left_btn_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_left_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_right_btn_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_right_btn_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_right_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_sigle_btn_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_sigle_btn_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iosdialog_sigle_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_bottom_btn_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_bottom_btn_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_bottom_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_middle_btn_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_middle_btn_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_middle_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_sigle_btn_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_sigle_btn_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_sigle_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_top_btn_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_top_btn_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/drawable/iossheet_top_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iosdialog/src/main/res/layout/ios_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | 25 | 26 | 30 | 31 | 32 | 37 | 38 | 50 | 51 | 52 | 53 | 54 | 60 | 61 | 66 | 67 |