Picker for date and time on a BlackBerry - user-interface

I want to use a date and time picker in a BlackBerry app.

Use net.rim.device.api.ui.component.DateField.
long yourInitialDatetime = System.currentTimeMillis();
DateField dateField = new DateField("Date:", yourInitialDatetime,
DateField.DATE_TIME);
yourScreen.add(dateField);
...
long currentlySelectedDatetime = dateField.getDate();

Also, see BlackBerry - Creating custom Date Field

I don't know if you still have this problem but the solution I used is the DateTimePicker Here's how you do it:
Calendar _dateCal;
SimpleDateFormat _dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
DateTimePicker _datePicker = DateTimePicker.createInstance(_dateCal, "dd-MMM-yyyy", null);
if(_datePicker.doModal())
{
StringBuffer _dateStr = new StringBuffer();
_dateCal = _datePicker.getDateTime();
_dateFormat.format(_dateCal, _dateStr, null);
_setDateButton.setLabel(_dateStr.toString());
}
That will prompt a spinner box for date selection to the screen

Related

Xamarin get all data (events, reminders ) from Calendar

How to get all data present in my Calendar using Xamarin. I am using below code and It is only returning already present holidays list. I want to get the manually added events and reminder list also.Below is the code am using
var calendarsUri = CalendarContract.Events.ContentUri;
var cursor = Forms.Context.ContentResolver.Query(calendarsUri, null, null, null, null);
if (cursor.MoveToFirst())
{
do
{
calendarEventList.Add(new Calendar()
{
Id = cursor.GetString(cursor.GetColumnIndex(ContactsContract.Contacts.InterfaceConsts.Id)),
CalendarDisplayName = cursor.GetString(cursor.GetColumnIndex(CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName)),
AccountName = cursor.GetString(cursor.GetColumnIndex(CalendarContract.Calendars.InterfaceConsts.AccountType)),
Title = cursor.GetString(cursor.GetColumnIndex(CalendarContract.Events.InterfaceConsts.Title)),
Description = cursor.GetString(cursor.GetColumnIndex(CalendarContract.Events.InterfaceConsts.Description)),
Dtstart = cursor.GetString(cursor.GetColumnIndex(CalendarContract.Events.InterfaceConsts.Dtstart)),
Dtend = cursor.GetString(cursor.GetColumnIndex(CalendarContract.Events.InterfaceConsts.Dtend))
});
} while (cursor.MoveToNext());
}
So my 'calendarEventList' contains only the holidays event. Can anyone help me with getting all the events from my Calendar.
Thank in Advance.

make textbox value to datetime

Maybe this is to simple. If I have a textbox where I want to input a numeric value like "1300" and make it to display like datetime like this "13:00".
So what you should see is only 13:00 but it's also the days date.
anyone understand my question?
May be you need to use Day or Time Picker. This is most common way for Windows Phone to display date and time.
Check also Making a DateTimePicker
and Windows Phone 7 - DatePicker and TimePicker
But if you want to use only TextBox, you need to handled TextBox.LostFocus=OnLostFocus
private void OnLostFocus(object sender, RoutedEventArgs e)
{
//here change text of TextBox however you want.
}
UPD
If you want to place current time to TextBox as default value you can to use
tb.Text = DateTime.Now.ToShortTimeString();
when you arrive to current page or when TextBox.GotFocus=OnGotFocus
private void OnGotFocus(object sender, RoutedEventArgs e)
{
tb.Text = DateTime.Now.ToShortTimeString();
}
UPD2
When in TextBox you have value (for example 1300) you need to parse it and get newHours hours and newMinutes minutes. Then
var today = DateTime.Now;
var newDate = new DateTime(today.Year, today.Month, today.Day, newHours, newMinutes, 0);

Grails date validation

I am new to Grails/GSP and want to implement date validation in Grails. Validation should be for input text in text field as required format is mm/dd/yyyy. Any guidance is appreciated. Also please point me to some good Grails and GSP tutorials if any one knows. Thanks in advance.
To require a specific date format for date input, you can use a custom property editor.
In src/groovy/ you can add a class to register the custom editor which will be used in data binding.
class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
void registerCustomEditors(PropertyEditorRegistry registry) {
def format = 'MM/dd/yyyy'
def dateFormat = new SimpleDateFormat(format)
dateFormat.setLenient(false)
registry.registerCustomEditor(Date, new CustomDateEditor(dateFormat, true, format.size()))
}
}
and register the bean in resources.groovy
beans = {
customPropertyEditorRegistrar(CustomPropertyEditorRegistrar)
}
Grails has a default date and time picker that it uses in scaffolds, you can use that but if you want a textbox to enter the date, you can validate the format using jQuery or javascript, then parse the string into date using:
try{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
date = format.parse(stringDate);
}catch (Exception e) {
//something
}
You can use regular expression with javascript to validate the format of entered date in view. This might be useful for that.

Automated control of a Telerik RadDatePicker

I'm using WatIn to create an automated test for a Web App that uses Telerik controls: my first challenge is to drive a Telerik date control - a RadDatePicker.
Simply entering the text in the likeliest input field doesn't work: the value is reset to blank as the form is posted. So I imagine I need a more complex set of automated interactions -- for example, I found this thread on the Telerik site discussing how to automated a selection from a Telerik combo box.
Can anyone supply the magic combination of interactions I need?
(I'm sure that the answer would help anyone using any automated test tool, hence I've also flagged this question with a couple of other test frameworks too :-))
I'm using Selenium RC and had a similar problem few days ago. It took me ages to find the right way of doing it so I thought I will share the solution that worked for me:
(NOTE: I couldn't use $find)
The javascript to set the date on the RadDatePicker is:
var appBrowser = this.browserbot.getCurrentWindow();
var datepicker = appBrowser.yourDatePickerId; //note: no quotes
var selectDate=new Date();
selectDate.setFullYear(yourYear,yourMonth,yourDay);
datepicker.SetDate(selectDate);
datepicker.DateInput.SetDate(selectDate);
and then use selenium GetEval in your test to call javascript code to set the date:
selenium.GetEval("javascript here");
You should definitely wrap it around some parametrised helper class that will generate the javascript code for you each time you want to set the date in the test by passing id of the control and date.
I finally have a solution that works. The key is to use javascript to call the client-side API for the telerik control. The same technique is required for all complex Telerik controls, e.g. RadInput.
I used the technique recommended on the WatiN website for writing your own control http://watinandmore.blogspot.com/2009/12/wrapping-complex-logic-in-control.html to come up with this:
public class TelerikDatePicker : Control<TextField>
{
public DateTime? Value
{
get
{
var jScript = string.Format(#"$find(""{0}"").get_selectedDate();", Element.Id);
var selectedDateStr = Eval(jScript);
return TranslateJavascriptDateStringIntoDateTime(selectedDateStr);
}
set
{
var jScript = string.Format(#"$find(""{0}"").set_selectedDate(new Date(""{1:MMMM dd,yyyy}""));", Element.Id, value);
Eval(jScript);
}
}
public void SetValue(DateTime? value)
{
if (value.HasValue)
Value = value.Value;
else
Clear();
}
public void Clear()
{
var jScript = string.Format(#"$find(""{0}"").clear();", Element.Id);
Eval(jScript);
}
private string Eval(string script)
{
return Element.DomContainer.Eval(script);
}
public bool IsEnabled()
{
var jScript = string.Format(#"$find(""{0}"").get_enabled();", Element.Id);
return Eval(jScript) == "true";
}
private DateTime? TranslateJavascriptDateStringIntoDateTime(string jsDateStr /*E.g. Mon Mar 12 00:00:00 UTC+0100 2012*/)
{
if (String.IsNullOrEmpty(jsDateStr) || jsDateStr == "null") return null;
var abbreviatedMonth = jsDateStr.Substring(4, 3);
var dayOfTheMonth = jsDateStr.Substring(8, 2).TrimEnd(' ');
var year = jsDateStr.Substring(jsDateStr.Length-4, 4);
const string format = "d MMM yyyy";
var dateStr = dayOfTheMonth + " " + abbreviatedMonth + " " + year;
return DateTime.ParseExact(dateStr, format, CultureInfo.InvariantCulture);
}
}
I had the same issue with a RadDatePicker that would post back empty after typing in values.
I managed to automate typing in the date into the input field with these steps:
Select the dateInput text box associated with the control.
Do a dateInput.MouseClick() on it
Type the date into the field Manager.Desktop.KeyBoard.TypeText("1/1/1990")
Do a .MouseClick() on any other element on the page, e.g. some div
I found that #4 was needed to fire the events to make the control blur therefore "saving" its value.
Then you can submit and the value should go along with it.
Solved that problem for SeleniumIDE - you have to use "fireEvent" method with value "blur" for "ControlID" after you've set value using "sendKeys" or "type" methods. Strange that this problem does not occur when automating with WebDriver.

Telerik Scheduler - drag and drop

I use Telerik demo scheduler as my base, as it seen in http://www.telerik.com/community/forums/wpf/scheduler/uniqueid-property-how-to-access-it.aspx
So i have implemented data loading from SQL to this scheduler. Now I want to implement drag and drop. So, how can I get my appointment values in old place and values in new place on scheduler and what the best technique to do that? I would use these values, to implement update of appointment dates in SQL.
private void OnAppointmentEdited(object sender, AppointmentEditedEventArgs e)
{
Appointment eAppo = e.Appointment as Appointment;
SessionAppointment ses = e.Appointment as SessionAppointment;
if(eAppo != null && ses != null)
{
DateTime dateStart = eAppo.Start; //new datestart
DateTime dateEnd = eAppo.End;//new dateend
string id = ses.UniqueId;//id
}
}

Resources