How to customize a TimePickerDialog? - android

I'm looking to create something EXACTLY like TimePickerDialog (look and feel) in Android, but it would be for MINUTES/SECONDS, not HOURS/MINUTES. Therefore AM/PM would not be relevant and would therefore allow MINUTE to be greater than 24 (making the max 59).
Is it possible to change the TimePickerDialog instance in any way to reflect this?
Any and all suggestions would be greatly appreciated. :-)

Is it possible to change the TimePickerDialog instance in any way to reflect this?
No, but the layout and source code to TimePickerDialog are both available as a starting point for implementing your own dialog.

This might help:
TimePicker with seconds:
https://github.com/IvanKovac/TimePickerWithSeconds
Have a look.

As the links in CommonsWare's answer are now dead, you might want to know that the source for TimePickerDialog is probably already on your local machine - it is included in the SDK. Try looking in the following locations:
[SDK_HOME]/sources/android-23/android/app/TimePickerDialog.java
or
[SDK_HOME]/sources/android-23/com/android/datetimepicker/time/TimePickerDialog.java
[SDK_HOME]/platforms/android-23/data/res/layout/time_picker_dialog.xml
Of course, choose the Android version that you want to borrow from. References to R. should be to android.R. Unfortunately, there seem to be some visibility issues with ValidationCallback - even on recent SDK levels.

Related

Looking for the source code of the new Google Calendar Time and Date Picker Widgets

I would like to use the brand new Date Picker and Time Picker that is now part of the new official Google Calendar App.
http://googlesystem.blogspot.de/2013/05/new-google-calendar-controls-for-android.html
All I found so far is this source code on grepcode but I can't find the widgets or fragments or activities there.
http://grepcode.com/snapshot/repository.grepcode.com/java/ext/com.google.android/android-apps/4.2.2_r1/
Is that already public or is there something similar out there?
I think the code you are looking for can be found here:
https://android.googlesource.com/platform/frameworks/opt/datetimepicker/+/master/src/com/android/datetimepicker
There is some pretty directly usable source code snippets in this Android Developer Pages:
http://developer.android.com/guide/topics/ui/controls/pickers.html
I used it as-is and all works just fine.
Also, reference these:
DatePickerDialog
http://developer.android.com/reference/android/app/DatePickerDialog.html
TimePickerDialog
http://developer.android.com/reference/android/app/TimePickerDialog.html
DialogFragment
http://developer.android.com/reference/android/support/v4/app/DialogFragment.html

How to localize Android DatePicker?

I put the DatePicker on my Activity. Everytime I launch my app I see english version of date in the DatePicker widget: Oct 15 2012. But I want to have a local version of date (russian) when I start my Activity. I've tried to define the locale before UI initialization. But it doesn't help. Is there any possibility to make it without extending DatePicker class?
In fact there is no need to override this class. But when I started to do it, I found info about special method "reorderpickers" which is specially designed to localize datepicker (automatically). My mistake was in setting Locale to English in the previous activity (to define English locale for password). That's why the standard method didn't work. So anybody who has the same problem check your code whether you have changed Locale.
You should create your custom datepickerdialog. For make this, that link help you;
http://coffeebreak.hiq.se/2011/09/09/fixing-androids-datepickerdialog/
Additional information for DataPicker and application locale you can find here

Android: Timpicker Difference declared in xml and in java code (TimePickerDialog)

So i have this problem of not getting accurate time result from timepicker declared in xml, not the dialog thing, i just wanted to know what is the difference from the two. so that i can know which is better to use on my app, mainly i use the timepicker to set an alarm or a reminder, because i have a hunch that the timpicker declared in xml is just for UI use not really for functionality. because i keep on getting the wrong result, specially dealing with AM and PM, Scenario is that when using timepicker declared in xml (not the dialog), i change first the hour den minutes and lastly the AM and PM, but i won't correctly give me the current time, say i chose 7:30 PM supposedly the value of the hour must be 19 since its 24-hour but instead it gives me 7:30 AM i won't change the AM and PM part thus giving me a wrong result, if you go the other way around, it works, it gives me ang accurate result.
SO my question is what is the MAIN difference between the two timepickers, is it for show(timepicker xml declared) and timepicker(dialog)
Please refer to this post for this problem, i just came across this thread and it is really the same with my problem. its a bug issue in Android
Android TimePicker AM/PM button not invoking onTimeChanged

Help with Android MonthDisplayHelper

How exactly do we use Android's MonthDisplayHelper? Ive been searching for possible widgets/views that would help me simplify my work as I would need to create a calendar. but it is just so hard. at least for me. So i saw this MonthDisplayHelper. from its members, i think i know what it can do..but what i don't get is how are we going to use it as i dont see it extending the view class nor is it an adapter. i know the question might be confusing. im heck confused right now. i hope somebody could help.
enlighten the confused :D
im sorry this came late..i have figured it out myself that MonthDisplayHelper will not make a Calendar for me. Well i hope it did. Creating a calendar functionality is not an easy task. we are faced with relatively complex algorithm.
so MonthDispalyHelper, again, will not make a calendar for you. Rather, it provides utility functionalities that would help you build your own calendar. a very good example of that is
MonthDisplayHelper mdh = new MonthDisplayHelper(viewedYear, viewedMonth);
int temp[] = mdh.getDigitsForRow(countRows);
which basically gives us as an integer array representation of which dates(digits) should go to each cell of the calendar. say for example, the first rows of the calendar of the supplied month and year(July 2011), would be {26,27,28,29,30,1,2}. from there, the job to position those digits to your layouts would be yours.
it also provides methods such as getting the number of days that the month specified have, the day of the week that the month starts, among other things.
i hope this helps.
This project uses MonthDisplayHelper, which might help understand how it works.

Android Calendar View for Date Picker

I'm writing my first app, and I have a question about DatePicker.
My app requires the user to input a date. The most user-friendly way would be to popup a calendar-like widget that displays the current month like a calendar grid - something like this:
I want to use that in place of the DatePicker interface - which has Month, Day, and Year fields, each with an up and down button to increment/decrement.
Is this type of functionality built into any Android widget or view, or would I have to design my own custom component to do this? I figured this would already exist, seeing how much this type of UI is used so frequently in non-mobile apps and web pages.
Thanks!
Now, in 2014, even the native DatePicker (link) contains small Holo looking CalendarView (link) to pick a day in month.
You can choose, if both spinners and CalendarView or just one of them is displayed by setting:
android:calendarViewShown
android:spinnersShown
I'm not sure if it's just API level 16+ or if it was even in Ice Cream Sandwich, but it's there. This is how it looks by default:
Moreover, on API level 21 and higher there is a new Material themed DatePicker that looks like following:
This is default on API 21+ and there are no spinners anymore, but you can switch back to the Holo one by setting
android:datePickerMode="spinner"
in your XML.
Since the API 11 there natively: CalendarView
This View is in HoloEverywhere since API 7.
Is this type of functionality built into any android widget or view, or would I have to design my own custom > component to do this?
There is no component for that in the Android SDK, sorry. The widget you illustrate is too small for a touchscreen. You can implement something larger (see the Calendar app), but you are largely on your own for that.
what i found so far:
http://code.google.com/p/android-calendar-view
http://code.google.com/p/openintents/wiki/CalendarPickerAPI
I have recently written exactly this as a modular app. Here is some sample code, documentation with screenshots, and .apk download.
Found a good implemetation in http://caughtinthemobileweb.wordpress.com/2011/06/20/how-to-implement-calendarview-in-android/
Also Since API level 11 (Android 3.0) there has been the native implementation of the CalendarView http://developer.android.com/reference/android/widget/CalendarView.html
Try to use this component:
https://github.com/truefedex/android-date-picker
If you want to use it like popup write on your onclick:
if (calendarPopup == null) {
calendarPopup = new PopupWindow(getContext());
CalendarPickerView calendarView = new CalendarPickerView(getContext());
CalendarNumbersView calendar = (CalendarNumbersView) calendarView.findViewById(com.phlox.datepick.R.id.calendar);
calendar.setShowDayNames(false);
calendarView.setListener(onDateSelectionListener);
calendarPopup.setContentView(calendarView);
calendarPopup.setWindowLayoutMode(
MeasureSpec.makeMeasureSpec(llCalendar.getWidth(), MeasureSpec.EXACTLY),
ViewGroup.LayoutParams.WRAP_CONTENT);
calendarPopup.setHeight(1);
calendarPopup.setWidth(llCalendar.getWidth());
calendarPopup.setOutsideTouchable(true);
}
calendarPopup.showAsDropDown(llCalendar);
you can use this lib for date selection
https://github.com/square/android-times-square/

Categories

Resources