Skip to content

support included for context string #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected void onCreate(Bundle savedInstanceState) {
.setSubtitle(getString(R.string.example_subtitle))
.setBoldPositiveLabel(true)
.setCancelable(false)
.setPositiveListener(getString(R.string.ok),new iOSDialogClickListener() {
.setPositiveListener(android.R.string.ok,new iOSDialogClickListener() {
@Override
public void onClick(iOSDialog dialog) {
Toast.makeText(MainActivity.this,"Clicked!",Toast.LENGTH_LONG).show();
Expand Down
65 changes: 38 additions & 27 deletions iosdialog/src/main/java/com/gdacciaro/iOSDialog/iOSDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

Expand All @@ -18,19 +17,19 @@

public class iOSDialog {
private Dialog dialog;
private TextView dialogButtonOk ,dialogButtonNo;
private TextView dialogButtonOk, dialogButtonNo;
private TextView title_lbl, subtitle_lbl;
private View separator;
private iOSDialogClickListener positiveListener;
private iOSDialogClickListener negativeListener;
private boolean negativeExist;
private static final String LOG_ERROR = "iOSDialog_ERROR";

public iOSDialog(Context context, String title, String subtitle, boolean bold, Typeface typeFace,boolean cancelable) {
negativeExist=false;
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)
if (dialog.getWindow() != null)
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

initViews();
Expand All @@ -49,44 +48,52 @@ public void setPositive(String okLabel, iOSDialogClickListener listener) {
this.dismiss();
setPositiveLabel(okLabel);
}

public void setNegative(String koLabel, iOSDialogClickListener listener) {
if (listener != null){
this.negativeListener = listener;
this.dismiss();
negativeExist = true;
setNegativeLabel(koLabel);
}
this.negativeListener = listener;
this.dismiss();

negativeExist = koLabel != null;
setNegativeLabel(koLabel);
}
public void show(){
if(!negativeExist){

public void show() {
if (!negativeExist) {
dialogButtonNo.setVisibility(View.GONE);
separator.setVisibility(View.GONE);
}
dialog.show();
}
public void dismiss(){

public void dismiss() {
dialog.dismiss();
}
public void setTitle(String title){

public void setTitle(String title) {
title_lbl.setText(title);
}
public void setSubtitle(String subtitle){

public void setSubtitle(String subtitle) {
subtitle_lbl.setText(subtitle);
}
private void setPositiveLabel(String positive){

private void setPositiveLabel(String positive) {
dialogButtonOk.setText(positive);
}
private void setNegativeLabel(String negative){

private void setNegativeLabel(String negative) {
dialogButtonNo.setText(negative);
}
private void setBoldPositiveLabel(boolean bold){
if(bold)

private void setBoldPositiveLabel(boolean bold) {
if (bold)
dialogButtonOk.setTypeface(null, Typeface.BOLD);
else
dialogButtonOk.setTypeface(null, Typeface.NORMAL);
}
private void setTypefaces(Typeface appleFont){
if(appleFont!=null) {

private void setTypefaces(Typeface appleFont) {
if (appleFont != null) {
title_lbl.setTypeface(appleFont);
subtitle_lbl.setTypeface(appleFont);
dialogButtonOk.setTypeface(appleFont);
Expand All @@ -97,18 +104,20 @@ private void setTypefaces(Typeface appleFont){

private void initViews() {
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);
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(){
private void initEvents() {
dialogButtonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (positiveListener != null) {
positiveListener.onClick(iOSDialog.this);
} else {
dialog.dismiss();
}
}
});
Expand All @@ -117,6 +126,8 @@ public void onClick(View view) {
public void onClick(View view) {
if (negativeListener != null) {
negativeListener.onClick(iOSDialog.this);
} else {
dialog.dismiss();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.gdacciaro.iOSDialog;

import android.content.Context;
import android.graphics.Typeface;

Expand All @@ -11,7 +12,7 @@

public class iOSDialogBuilder {
private Typeface tf;
private boolean bold,cancelable;
private boolean bold, cancelable;
private String title, subtitle, okLabel, koLabel;
private Context context;
private iOSDialogClickListener positiveListener;
Expand All @@ -26,41 +27,64 @@ public iOSDialogBuilder setTitle(String title) {
return this;
}

public iOSDialogBuilder setTitle(int title) {
this.title = context.getString(title);
return this;
}

public iOSDialogBuilder setSubtitle(String subtitle) {
this.subtitle = subtitle;
return this;
}

public iOSDialogBuilder setSubtitle(int subtitle) {
this.subtitle = context.getString(subtitle);
return this;
}

public iOSDialogBuilder setBoldPositiveLabel(boolean bold) {
this.bold = bold;
return this;
}

public iOSDialogBuilder setFont(Typeface font) {
this.tf=font;
this.tf = font;
return this;
}
public iOSDialogBuilder setCancelable(boolean cancelable){
this.cancelable=cancelable;

public iOSDialogBuilder setCancelable(boolean cancelable) {
this.cancelable = cancelable;
return this;
}

public iOSDialogBuilder setNegativeListener(String koLabel, iOSDialogClickListener listener) {
this.negativeListener = listener;
this.koLabel = koLabel;
return this;
}

public iOSDialogBuilder setPositiveListener(String okLabel, iOSDialogClickListener listener) {
this.positiveListener = listener;
this.okLabel = okLabel;
return this;
}

public iOSDialogBuilder setNegativeListener(String koLabel,iOSDialogClickListener listener) {
this.negativeListener=listener;
this.koLabel=koLabel;
public iOSDialogBuilder setNegativeListener(int koLabel, iOSDialogClickListener listener) {
this.negativeListener = listener;
this.koLabel = context.getString(koLabel);
return this;
}

public iOSDialogBuilder setPositiveListener(String okLabel,iOSDialogClickListener listener) {
public iOSDialogBuilder setPositiveListener(int okLabel, iOSDialogClickListener listener) {
this.positiveListener = listener;
this.okLabel=okLabel;
this.okLabel = context.getString(okLabel);
return this;
}

public iOSDialog build(){
iOSDialog dialog = new iOSDialog(context,title,subtitle, bold, tf,cancelable);
dialog.setNegative(koLabel,negativeListener);
dialog.setPositive(okLabel,positiveListener);
public iOSDialog build() {
iOSDialog dialog = new iOSDialog(context, title, subtitle, bold, tf, cancelable);
dialog.setNegative(koLabel, negativeListener);
dialog.setPositive(okLabel, positiveListener);
return dialog;
}

Expand Down