diff --git a/.idea/modules.xml b/.idea/modules.xml
index 7df6841..cee0cb9 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,12 +2,10 @@
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 06942da..bce1a17 100644
--- a/README.md
+++ b/README.md
@@ -10,37 +10,38 @@ With this library you can use iOS UIAlertView on Android.
To install the library just add this line to your gradle:
- compile 'com.gdacciaro:iosdialog:1.0.2'
+ implementation 'com.gdacciaro:iosdialog:1.0.3'
And add this where you want:
- final iOSDialog iOSDialog = new iOSDialog(MainActivity.this);
- iOSDialog.setTitle( "Allow \"Calendar\" to access your location while you use the app?");
- iOSDialog.setSubtitle(" ");
- iOSDialog.setNegativeLabel("Don't Allow");
- iOSDialog.setPositiveLabel("Allow");
- iOSDialog.setBoldPositiveLabel(true);
- iOSDialog.setNegativeListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- iOSDialog.dismiss();
- }
- });
- iOSDialog.setPositiveListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Toast.makeText(MainActivity.this,"OK clicked",Toast.LENGTH_SHORT).show();
- iOSDialog.dismiss();
- }
- });
- iOSDialog.show();
+ new iOSDialogBuilder(MainActivity.this)
+ .setTitle(getString(R.string.example_title))
+ .setSubtitle(getString(R.string.example_subtitle))
+ .setBoldPositiveLabel(true)
+ .setCancelable(false)
+ .setPositiveListener(getString(R.string.ok),new iOSDialogClickListener() {
+ @Override
+ public void onClick(iOSDialog dialog) {
+ Toast.makeText(MainActivity.this,"Clicked!",Toast.LENGTH_LONG).show();
+ dialog.dismiss();
+
+ }
+ })
+ .setNegativeListener(getString(R.string.dismiss), new iOSDialogClickListener() {
+ @Override
+ public void onClick(iOSDialog dialog) {
+ dialog.dismiss();
+ }
+ })
+ .build().show();
If you liked this library, add a star to this project and feel free to make a fork!
-And of course, every donation is well accepted :D
-
A special thanks to Rofiq Setiawan who made a porting of iOSDialog for Xamarin.
Check it out here: https://github.com/rofiqsetiawan/iOSDialog
+
+Another special thanks to Francesco Borrelli who helped me with the implementation of the iOSDialogClickListener
+Here is his Linkedin profile https://www.linkedin.com/in/francesco-borrelli1/
diff --git a/app/src/main/java/com/gdacciaro/iOSDialogDemo/MainActivity.java b/app/src/main/java/com/gdacciaro/iOSDialogDemo/MainActivity.java
index f682659..0ad2a48 100644
--- a/app/src/main/java/com/gdacciaro/iOSDialogDemo/MainActivity.java
+++ b/app/src/main/java/com/gdacciaro/iOSDialogDemo/MainActivity.java
@@ -2,6 +2,7 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
@@ -18,34 +19,26 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- final iOSDialog iOSDialog = new iOSDialogBuilder(MainActivity.this)
+ new iOSDialogBuilder(MainActivity.this)
.setTitle(getString(R.string.example_title))
.setSubtitle(getString(R.string.example_subtitle))
.setBoldPositiveLabel(true)
- .setOKClick(new iOSDialogClickListener() {
+ .setCancelable(false)
+ .setPositiveListener(getString(R.string.ok),new iOSDialogClickListener() {
@Override
public void onClick(iOSDialog dialog) {
+ Toast.makeText(MainActivity.this,"Clicked!",Toast.LENGTH_LONG).show();
dialog.dismiss();
+
}
})
- .setFont(null) //add your typeface!
- .build();
-
- iOSDialog.setPositiveListener(getString(R.string.ok),new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Toast.makeText(MainActivity.this,"OK clicked",Toast.LENGTH_SHORT).show();
- iOSDialog.dismiss();
- }
- });
- iOSDialog.setNegativeListener(getString(R.string.dismiss),new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- iOSDialog.dismiss();
- }
- });
- iOSDialog.show();
-
+ .setNegativeListener(getString(R.string.dismiss), new iOSDialogClickListener() {
+ @Override
+ public void onClick(iOSDialog dialog) {
+ dialog.dismiss();
+ }
+ })
+ .build().show();
}
diff --git a/iosdialog/build.gradle b/iosdialog/build.gradle
index 104c0a8..88d8a01 100644
--- a/iosdialog/build.gradle
+++ b/iosdialog/build.gradle
@@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/MagicDog707/iOSDialog'
gitUrl = 'https://github.com/MagicDog707/iOSDialog.git'
- libraryVersion = '1.0.2'
+ libraryVersion = '1.0.3'
developerId = 'gdacciaro'
developerName = 'Gennaro Daniele Acciaro'
@@ -32,7 +32,7 @@ android {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
- versionName '1.0.2'
+ versionName '1.0.3'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -45,15 +45,6 @@ android {
}
}
-dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
- exclude group: 'com.android.support', module: 'support-annotations'
- })
- compile 'com.android.support:appcompat-v7:26.+'
- testCompile 'junit:junit:4.12'
-
-}
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
diff --git a/iosdialog/src/main/java/com/gdacciaro/iOSDialog/iOSDialog.java b/iosdialog/src/main/java/com/gdacciaro/iOSDialog/iOSDialog.java
index 23c10ea..0022a89 100644
--- a/iosdialog/src/main/java/com/gdacciaro/iOSDialog/iOSDialog.java
+++ b/iosdialog/src/main/java/com/gdacciaro/iOSDialog/iOSDialog.java
@@ -23,11 +23,11 @@ public class iOSDialog {
private View separator;
private iOSDialogClickListener positiveListener;
private iOSDialogClickListener negativeListener;
- private boolean negativeExist = false;
+ private boolean negativeExist;
private static final String LOG_ERROR = "iOSDialog_ERROR";
- public iOSDialog(Context context, String title, String subtitle, boolean bold, Typeface typeFace) {
-
+ public iOSDialog(Context context, String title, String subtitle, boolean bold, Typeface typeFace,boolean cancelable) {
+ negativeExist=false;
dialog = new Dialog(context);
dialog.setContentView(R.layout.alerts_two_buttons);
if(dialog.getWindow()!=null)
@@ -35,6 +35,7 @@ public iOSDialog(Context context, String title, String subtitle, boolean bold, T
initViews();
+ dialog.setCancelable(cancelable);
setTitle(title);
setSubtitle(subtitle);
setBoldPositiveLabel(bold);
@@ -43,18 +44,19 @@ public iOSDialog(Context context, String title, String subtitle, boolean bold, T
initEvents();
}
- public void setPositiveListener(iOSDialogClickListener listener) {
+ public void setPositive(String okLabel, iOSDialogClickListener listener) {
this.positiveListener = listener;
this.dismiss();
+ setPositiveLabel(okLabel);
}
-
- public void setNegativeListener(iOSDialogClickListener listener) throws Exception {
- if(!negativeExist)
- throw new Exception("Negative button isn't visible, set it with setNegativeLabel()");
- this.negativeListener = listener;
- this.dismiss();
+ public void setNegative(String koLabel, iOSDialogClickListener listener) {
+ if (listener != null){
+ this.negativeListener = listener;
+ this.dismiss();
+ negativeExist = true;
+ setNegativeLabel(koLabel);
+ }
}
-
public void show(){
if(!negativeExist){
dialogButtonNo.setVisibility(View.GONE);
@@ -62,7 +64,6 @@ public void show(){
}
dialog.show();
}
-
public void dismiss(){
dialog.dismiss();
}
@@ -72,20 +73,19 @@ public void setTitle(String title){
public void setSubtitle(String subtitle){
subtitle_lbl.setText(subtitle);
}
- public void setPositiveLabel(String positive){
+ private void setPositiveLabel(String positive){
dialogButtonOk.setText(positive);
}
- public void setNegativeLabel(String negative){
- negativeExist=true;
+ private void setNegativeLabel(String negative){
dialogButtonNo.setText(negative);
}
- public void setBoldPositiveLabel(boolean bold){
+ private void setBoldPositiveLabel(boolean bold){
if(bold)
dialogButtonOk.setTypeface(null, Typeface.BOLD);
else
dialogButtonOk.setTypeface(null, Typeface.NORMAL);
}
- public void setTypefaces(Typeface appleFont){
+ private void setTypefaces(Typeface appleFont){
if(appleFont!=null) {
title_lbl.setTypeface(appleFont);
subtitle_lbl.setTypeface(appleFont);
@@ -96,15 +96,14 @@ public void setTypefaces(Typeface appleFont){
private void initViews() {
- title_lbl = (TextView) dialog.findViewById(R.id.title);
- subtitle_lbl = (TextView) dialog.findViewById(R.id.subtitle);
- dialogButtonOk = (TextView) dialog.findViewById(R.id.dialogButtonOK);
- dialogButtonNo = (TextView) dialog.findViewById(R.id.dialogButtonNO);
- separator = (View) dialog.findViewById(R.id.separator);
+ title_lbl = dialog.findViewById(R.id.title);
+ subtitle_lbl = dialog.findViewById(R.id.subtitle);
+ dialogButtonOk = dialog.findViewById(R.id.dialogButtonOK);
+ dialogButtonNo = dialog.findViewById(R.id.dialogButtonNO);
+ separator = dialog.findViewById(R.id.separator);
}
private void initEvents(){
-
dialogButtonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -113,7 +112,6 @@ public void onClick(View view) {
}
}
});
-
dialogButtonNo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
diff --git a/iosdialog/src/main/java/com/gdacciaro/iOSDialog/iOSDialogBuilder.java b/iosdialog/src/main/java/com/gdacciaro/iOSDialog/iOSDialogBuilder.java
index bb88553..a9a3186 100644
--- a/iosdialog/src/main/java/com/gdacciaro/iOSDialog/iOSDialogBuilder.java
+++ b/iosdialog/src/main/java/com/gdacciaro/iOSDialog/iOSDialogBuilder.java
@@ -11,8 +11,8 @@
public class iOSDialogBuilder {
private Typeface tf;
- private boolean bold;
- private String title, subtitle;
+ private boolean bold,cancelable;
+ private String title, subtitle, okLabel, koLabel;
private Context context;
private iOSDialogClickListener positiveListener;
private iOSDialogClickListener negativeListener;
@@ -40,21 +40,27 @@ public iOSDialogBuilder setFont(Typeface font) {
this.tf=font;
return this;
}
+ public iOSDialogBuilder setCancelable(boolean cancelable){
+ this.cancelable=cancelable;
+ return this;
+ }
- public iOSDialogBuilder setNegativeListener(iOSDialogClickListener listener) {
+ public iOSDialogBuilder setNegativeListener(String koLabel,iOSDialogClickListener listener) {
this.negativeListener=listener;
+ this.koLabel=koLabel;
return this;
}
- public iOSDialogBuilder setPositiveListener(iOSDialogClickListener listener) {
+ public iOSDialogBuilder setPositiveListener(String okLabel,iOSDialogClickListener listener) {
this.positiveListener = listener;
+ this.okLabel=okLabel;
return this;
}
- public iOSDialog build() throws Exception {
- iOSDialog dialog = new iOSDialog(context,title,subtitle, bold, tf);
- dialog.setNegativeListener(negativeListener);
- dialog.setPositiveListener(positiveListener);
+ public iOSDialog build(){
+ iOSDialog dialog = new iOSDialog(context,title,subtitle, bold, tf,cancelable);
+ dialog.setNegative(koLabel,negativeListener);
+ dialog.setPositive(okLabel,positiveListener);
return dialog;
}