Skip to content
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
26 changes: 26 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
Language: Java
AccessModifierOffset: -4
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
# class, constructor, method should be next line
BreakBeforeBraces: Linux
# Keep '=' at end of line when wrapping, but move things like '&&', '||' to beginning of newline
BreakBeforeBinaryOperators: NonAssignment
# FIXME: break for brace after synchronized block, anonymous class declarations
BreakAfterJavaFieldAnnotations: true
ColumnLimit: 120
IndentCaseLabels: true
IndentWidth: 4
MaxEmptyLinesToKeep: 1
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpacesInParentheses: false
TabWidth: 4
UseTab: ForContinuationAndIndentation
SpaceAfterCStyleCast: true
# Spaces inside {} for array literals, i.e. "new Object[] { args }"
Cpp11BracedListStyle: false
ReflowComments: false
36 changes: 36 additions & 0 deletions src/yy/tidialogs/BaseDialogProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package yy.tidialogs;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiUIHelper;

@Kroll.proxy
public abstract class BaseDialogProxy extends TiViewProxy
{

public BaseDialogProxy()
{
super();
}

@Override
protected void handleShow(KrollDict options)
{
super.handleShow(options);
// If there's a lock on the UI message queue, there's a good chance
// we're in the middle of activity stack transitions. An alert
// dialog should occur above the "topmost" activity, so if activity
// stack transitions are occurring, try to give them a chance to
// "settle"
// before determining which Activity should be the context for the
// AlertDialog.
TiUIHelper.runUiDelayedIfBlock(new Runnable() {
@Override
public void run()
{
getOrCreateView().show();
}
});
}
}
63 changes: 63 additions & 0 deletions src/yy/tidialogs/BaseUIDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package yy.tidialogs;

import android.app.AlertDialog;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;

import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;

import java.util.concurrent.atomic.AtomicInteger;

public abstract class BaseUIDialog extends TiUIView
{
protected AlertDialog dialog;

private AtomicInteger dismissCallCount = new AtomicInteger(0);
protected OnDismissListener dismissListener;

public BaseUIDialog(TiViewProxy proxy)
{
super(proxy);
dismissListener = new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog)
{
if (dismissCallCount.get() == 0) {
dismissCallCount.incrementAndGet();
KrollDict data = new KrollDict();
data.put("cancel", true);
data.put("value", null);
fireEvent("cancel", data);
}
}
};
}

abstract protected AlertDialog getDialog();

@Override
public void show()
{
getDialog().show();
}

@Override
public void hide()
{
if (dialog != null) {
dialog.hide();
}
}

@Override
public void release()
{
if (dialog != null) {
dialog.dismiss();
dialog = null;
}
}
}
161 changes: 98 additions & 63 deletions src/yy/tidialogs/DatePickerProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,102 @@

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import android.R;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.DialogInterface;
import android.os.Build;
import android.widget.DatePicker;

import ti.modules.titanium.ui.widget.picker.TiDatePickerDialog;

@Kroll.proxy(creatableInModule = TidialogsModule.class)
public class DatePickerProxy extends TiViewProxy {
private class BasicDatePicker extends TiUIView {
public class DatePickerProxy extends BaseDialogProxy
{
private class BasicDatePicker extends BaseUIDialog
{

private int year;
private int month;
private int day;

private Date maxDate;
private Date minDate;

private String okButtonTitle;
private String cancelButtonTitle;

public BasicDatePicker(TiViewProxy proxy) {
public BasicDatePicker(TiViewProxy proxy)
{
super(proxy);

}

private DatePickerDialog getDialog() {
DatePickerDialog picker = new DatePickerDialog(this.proxy.getActivity(),
new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be
// called.
public void onDateSet(DatePicker view,
int selectedYear, int selectedMonth,
int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;

KrollDict data = new KrollDict();

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
Date value = calendar.getTime();

data.put("value", value);
data.put("year", year);
data.put("month", month);
data.put("day", day);
fireEvent("click", data);

}
}, year, month, day);
picker.setCanceledOnTouchOutside(false);
protected DatePickerDialog getDialog()
{
if (dialog != null) {
return (DatePickerDialog) dialog;
}
OnDateSetListener dateSetListener = new OnDateSetListener() {
// when dialog box is closed, below method will be
// called.
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay)
{
year = selectedYear;
month = selectedMonth;
day = selectedDay;

KrollDict data = new KrollDict();

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
Date value = calendar.getTime();

data.put("value", value);
data.put("year", year);
data.put("month", month);
data.put("day", day);
fireEvent("click", data);
}
};
DatePickerDialog picker;

picker.setButton(DialogInterface.BUTTON_POSITIVE, okButtonTitle, picker);
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
&& (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)) {
picker =
new TiDatePickerDialog(TiApplication.getAppCurrentActivity(), dateSetListener, year, month, day);
} else {
picker = new DatePickerDialog(TiApplication.getAppCurrentActivity(), dateSetListener, year, month, day);
}

if (minDate != null) {
picker.getDatePicker().setMinDate(trimDate(minDate).getTime());
}

if (maxDate != null) {
picker.getDatePicker().setMaxDate(trimDate(maxDate).getTime());
}

picker.setOnDismissListener(dismissListener);

picker.setButton(DialogInterface.BUTTON_NEGATIVE, cancelButtonTitle,
new DialogInterface.OnClickListener() {
picker.setCanceledOnTouchOutside(false);

@Override
public void onClick(DialogInterface dialog, int which) {
fireEvent("cancel", new KrollDict());
}
});
picker.setButton(DialogInterface.BUTTON_POSITIVE, okButtonTitle, picker);

dialog = picker;
return picker;
}

@Override
public void processProperties(KrollDict d) {
public void processProperties(KrollDict d)
{
super.processProperties(d);
Calendar c = Calendar.getInstance();
if (d.containsKey("value")) {
Expand All @@ -102,47 +126,58 @@ public void processProperties(KrollDict d) {
}
}

if (d.containsKey(TiC.PROPERTY_MIN_DATE)) {
minDate = (Date) d.get(TiC.PROPERTY_MIN_DATE);
}
if (d.containsKey(TiC.PROPERTY_MAX_DATE)) {
maxDate = (Date) d.get(TiC.PROPERTY_MAX_DATE);
}

if (d.containsKey("okButtonTitle")) {
okButtonTitle = d.getString("okButtonTitle");
} else {
okButtonTitle = this.proxy.getActivity().getApplication().getResources().getString(R.string.ok);
okButtonTitle =
TiApplication.getAppCurrentActivity().getApplication().getResources().getString(R.string.ok);
}
if (d.containsKey("cancelButtonTitle")) {
cancelButtonTitle = d.getString("cancelButtonTitle");
} else {
cancelButtonTitle = this.proxy.getActivity().getApplication().getResources().getString(R.string.cancel);
cancelButtonTitle =
TiApplication.getAppCurrentActivity().getApplication().getResources().getString(R.string.cancel);
}
}

public void show() {
getDialog().show();
}

}

public DatePickerProxy() {
public DatePickerProxy()
{
super();
}

@Override
public TiUIView createView(Activity activity) {
public TiUIView createView(Activity activity)
{
return new BasicDatePicker(this);
}

@Override
public void handleCreationDict(KrollDict options) {
public void handleCreationDict(KrollDict options)
{
super.handleCreationDict(options);
}

@Override
protected void handleShow(KrollDict options) {
super.handleShow(options);
TiUIHelper.runUiDelayedIfBlock(new Runnable() {
@Override
public void run() {
BasicDatePicker d = (BasicDatePicker) getOrCreateView();
d.show();
}
});
/**
* Trim hour, minute, second and millisecond from the date
* @param inDate input date
* @return return the trimmed date
*/
public static Date trimDate(Date inDate)
{
Calendar cal = Calendar.getInstance();
cal.setTime(inDate);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
}
Loading