Skip to content

Commit

Permalink
Cleaning up names of new dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvavra committed Jul 14, 2014
1 parent ec3b933 commit 0c16138
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 487 deletions.
20 changes: 10 additions & 10 deletions demo/src/main/java/eu/inmite/demo/dialogs/MyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
import java.text.DateFormat;
import java.util.Date;

import eu.inmite.android.lib.dialogs.DatePickerDialogFragment;
import eu.inmite.android.lib.dialogs.IDateDialogListener;
import eu.inmite.android.lib.dialogs.IListDialogListener;
import eu.inmite.android.lib.dialogs.ISimpleDialogCancelListener;
import eu.inmite.android.lib.dialogs.ISimpleDialogDateListener;
import eu.inmite.android.lib.dialogs.ISimpleDialogListener;
import eu.inmite.android.lib.dialogs.OnListItemSelectedListener;
import eu.inmite.android.lib.dialogs.ListDialogFragment;
import eu.inmite.android.lib.dialogs.ProgressDialogFragment;
import eu.inmite.android.lib.dialogs.SimpleDatePickerDialogFragment;
import eu.inmite.android.lib.dialogs.SimpleDialogFragment;
import eu.inmite.android.lib.dialogs.SimpleListDialogFragment;
import eu.inmite.android.lib.dialogs.SimpleTimePickerDialogFragment;
import eu.inmite.android.lib.dialogs.TimePickerDialogFragment;

public class MyActivity extends FragmentActivity implements
ISimpleDialogListener,
ISimpleDialogDateListener,
IDateDialogListener,
ISimpleDialogCancelListener,
OnListItemSelectedListener {
IListDialogListener {

public static final int THEME_DEFAULT_DARK = 0;

Expand Down Expand Up @@ -100,7 +100,7 @@ public void onClick(View v) {
findViewById(R.id.list_dialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleListDialogFragment
ListDialogFragment
.createBuilder(c, getSupportFragmentManager())
.setTitle("Your favorite character:")
.setItems(new String[]{"Jayne", "Malcolm", "Kaylee",
Expand Down Expand Up @@ -142,7 +142,7 @@ public void onClick(View v) {
findViewById(R.id.time_picker).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleTimePickerDialogFragment
TimePickerDialogFragment
.createBuilder(MyActivity.this, getSupportFragmentManager())
.setDate(new Date())
.set24hour(true)
Expand All @@ -155,7 +155,7 @@ public void onClick(View v) {
findViewById(R.id.date_picker).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleDatePickerDialogFragment
DatePickerDialogFragment
.createBuilder(MyActivity.this, getSupportFragmentManager())
.setDate(new Date())
.set24hour(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
package eu.inmite.android.lib.dialogs;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
* Dialog with a date picker. Implement {@link eu.inmite.android.lib.dialogs.IDateDialogListener} or {@link eu.inmite.android.lib.dialogs.IDateDialogCancelListener} to handle events.
*/
public class DatePickerDialogFragment extends BaseDialogFragment {

protected static final String ARG_ZONE = "zone";
protected static final String ARG_TITLE = "title";
protected static final String ARG_POSITIVE_BUTTON = "positive_button";
protected static final String ARG_NEGATIVE_BUTTON = "negative_button";
protected static final String ARG_DATE = "date";
protected static final String ARG_24H = "24h";

DatePicker mDatePicker;
Calendar mCalendar;

private int mRequestCode;


public static SimpleDialogBuilder createBuilder(Context context, FragmentManager fragmentManager) {
return new SimpleDialogBuilder(context, fragmentManager, DatePickerDialogFragment.class);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Fragment targetFragment = getTargetFragment();
if (targetFragment != null) {
mRequestCode = getTargetRequestCode();
} else {
Bundle args = getArguments();
if (args != null) {
mRequestCode = args.getInt(BaseDialogBuilder.ARG_REQUEST_CODE, 0);
}
}
}

protected IDateDialogListener getDialogListener() {
final Fragment targetFragment = getTargetFragment();
if (targetFragment != null) {
if (targetFragment instanceof IDateDialogListener) {
return (IDateDialogListener) targetFragment;
}
} else {
if (getActivity() instanceof IDateDialogListener) {
return (IDateDialogListener) getActivity();
}
}
return null;
}

protected IDateDialogCancelListener getCancelListener() {
final Fragment targetFragment = getTargetFragment();
if (targetFragment != null) {
if (targetFragment instanceof IDateDialogCancelListener) {
return (IDateDialogCancelListener) targetFragment;
}
} else {
if (getActivity() instanceof IDateDialogCancelListener) {
return (IDateDialogCancelListener) getActivity();
}
}
return null;
}

@Override
protected BaseDialogFragment.Builder build(BaseDialogFragment.Builder builder) {
final String title = getTitle();
if (!TextUtils.isEmpty(title)) {
builder.setTitle(title);
}

final String positiveButtonText = getPositiveButtonText();
if (!TextUtils.isEmpty(positiveButtonText)) {
builder.setPositiveButton(positiveButtonText, new View.OnClickListener() {

@Override
public void onClick(View view) {
IDateDialogListener listener = getDialogListener();
if (listener != null) {
listener.onPositiveButtonClicked(mRequestCode, getDate());
}
dismiss();
}
});
}

final String negativeButtonText = getNegativeButtonText();
if (!TextUtils.isEmpty(negativeButtonText)) {
builder.setNegativeButton(negativeButtonText, new View.OnClickListener() {

@Override
public void onClick(View view) {
IDateDialogListener listener = getDialogListener();
if (listener != null) {
listener.onNegativeButtonClicked(mRequestCode, getDate());
}
dismiss();
}
});
}
mDatePicker = (DatePicker) LayoutInflater.from(getActivity()).inflate(R.layout.dialog_part_datepicker, null);
builder.setView(mDatePicker);

TimeZone zone = TimeZone.getTimeZone(getArguments().getString(ARG_ZONE));
mCalendar = Calendar.getInstance(zone);
mCalendar.setTimeInMillis(getArguments().getLong(ARG_DATE, System.currentTimeMillis()));
mDatePicker.updateDate(mCalendar.get(Calendar.YEAR)
, mCalendar.get(Calendar.MONTH)
, mCalendar.get(Calendar.DAY_OF_MONTH));
return builder;
}

protected String getTitle() {
return getArguments().getString(ARG_TITLE);
}

protected String getPositiveButtonText() {
return getArguments().getString(ARG_POSITIVE_BUTTON);
}

protected String getNegativeButtonText() {
return getArguments().getString(ARG_NEGATIVE_BUTTON);
}

public Date getDate() {
mCalendar.set(Calendar.YEAR, mDatePicker.getYear());
mCalendar.set(Calendar.MONTH, mDatePicker.getMonth());
mCalendar.set(Calendar.DAY_OF_MONTH, mDatePicker.getDayOfMonth());
return mCalendar.getTime();
}

public static class SimpleDialogBuilder extends BaseDialogBuilder<SimpleDialogBuilder> {
Date mDate = new Date();
String mTimeZone = null;

private String mTitle;
private String mPositiveButtonText;
private String mNegativeButtonText;

private boolean mShowDefaultButton = true;
private boolean m24h;

protected SimpleDialogBuilder(Context context, FragmentManager fragmentManager, Class<? extends DatePickerDialogFragment> clazz) {
super(context, fragmentManager, clazz);
}

public SimpleDialogBuilder setTitle(int titleResourceId) {
mTitle = mContext.getString(titleResourceId);
return this;
}


public SimpleDialogBuilder setTitle(String title) {
mTitle = title;
return this;
}

public SimpleDialogBuilder setPositiveButtonText(int textResourceId) {
mPositiveButtonText = mContext.getString(textResourceId);
return this;
}

public SimpleDialogBuilder setPositiveButtonText(String text) {
mPositiveButtonText = text;
return this;
}

public SimpleDialogBuilder setNegativeButtonText(int textResourceId) {
mNegativeButtonText = mContext.getString(textResourceId);
return this;
}

public SimpleDialogBuilder setNegativeButtonText(String text) {
mNegativeButtonText = text;
return this;
}

public SimpleDialogBuilder setDate(Date date) {
mDate = date;
return this;
}

public SimpleDialogBuilder setTimeZone(String zone) {
mTimeZone = zone;
return this;
}

public SimpleDialogBuilder set24hour(boolean state) {
m24h = state;
return this;
}

/**
* When there is neither positive nor negative button, default "close" button is created if it was enabled.<br/>
* Default is true.
*/
public SimpleDialogBuilder hideDefaultButton(boolean hide) {
mShowDefaultButton = !hide;
return this;
}


@Override
protected Bundle prepareArguments() {
if (mShowDefaultButton && mPositiveButtonText == null && mNegativeButtonText == null) {
mPositiveButtonText = mContext.getString(R.string.dialog_close);
}

Bundle args = new Bundle();
args.putString(SimpleDialogFragment.ARG_TITLE, mTitle);
args.putString(SimpleDialogFragment.ARG_POSITIVE_BUTTON, mPositiveButtonText);
args.putString(SimpleDialogFragment.ARG_NEGATIVE_BUTTON, mNegativeButtonText);

args.putLong(ARG_DATE, mDate.getTime());
args.putBoolean(ARG_24H, m24h);
if (mTimeZone != null) {
args.putString(ARG_ZONE, mTimeZone);
} else {
args.putString(ARG_ZONE, "GMT");
}
return args;
}

@Override
protected SimpleDialogBuilder self() {
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
* @author Tomáš Kypta
* @since 13/05/2013
*/
public interface ISimpleDialogDateCancelListener {
public interface IDateDialogCancelListener {
public void onCancelled(int requestCode, Date date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author David Vávra ([email protected])
*/
public interface ISimpleDialogDateListener {
public interface IDateDialogListener {
public void onPositiveButtonClicked(int requestCode, Date date);

public void onNegativeButtonClicked(int requestCode, Date date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
*
*/
public interface OnListItemSelectedListener {
public interface IListDialogListener {

public void onListItemSelected(String value, int number);
}
Loading

0 comments on commit 0c16138

Please sign in to comment.