I'm using Caldroid library https://github.com/roomorama/Caldroid. I want to disable all dates earlier than today. How can I do that? There is method setDisableDates, but it requires passing as argument list of dates to disable.
I found solution - use method setMinDate.
This will work for you:
setMinDateTime(getToday());
use in customizeTextView() in CaldroidGridAdapter class
I am using an external library in my Android project. So if i want to customize it according to my needs( color, layout), shall i make direct changes in the library or is it a bad practice to do so?
One other way would be to extend its classes and make changes in my project's code itself. So which is a better way. The first method is easier and i dont see any problem with that in future.
The below code is just that SO is not letting me to submit the question without code
The library that i am using provide some functions
public void setBackgroundResourceForDates(HashMap<Date, Integer> backgroundForDateMap);
public void setBackgroundResourceForDateTimes(HashMap<DateTime, Integer> backgroundForDateTimeMap);
public void setBackgroundResourceForDate(int backgroundRes, Date date);
public void setBackgroundResourceForDateTime(int backgroundRes, DateTime dateTime);
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
I started working with CalendarView today, and to my surprise, class is very inflexible.
Only methods that CalendarView allos me to override are:
getDate()
getFirstDayOfWeek()
getMaxDate()
getMinDate()
getShowWeekNumber()
isEnabled()
setDate(long, boolean, boolean)
setDate(long)
setEnabled(boolean)
setFirstDayOfWeek(int)
setMaxDate(long)
setMinDate(long)
setOnDateChangeListener(OnDateChangeListener)
setShowWeekNumber(boolean)
However, i need to customize how certain days are displayed. For example, in my database i have events for dates 2013-10-02 and 2013-12-02 and i want to highlight these days in my calendar. How would i go about that.
You need to build your own CustomCalenderView.
Extends the Native CalendarView and build the behaviour that you want to color the background.
Or you can use this library : TimesSquare for Android.
And think it provide what you are looking for .
So I have been at this for a while, and I cannot seem to figure it out. I am fairly new at Android development, so bear with me please. I wasn't too familiar with creating a Datepicker and I learned to do it the deprecated way just to get the hang of it. Used this tutorial to get me up to speed:
http://developer.android.com/resources/tutorials/views/hello-datepicker.html
But now I need to change it, mainly to not use deprecated code, so I looked all around, and I found 2 tutorials, mainly this one though:
http://www.kylebeal.com/2011/11/android-datepickerdialog-and-the-dialogfragment/
Problem is, there is code that does not make sense. Mainly this part:
//create new DateDialogFragment
DateDialogFragment ddf = DateDialogFragment.newInstance(this, R.string.set_date, date);
ddf.setDateDialogFragmentListener(new DateDialogFragmentListener() {
#Override
public void dateDialogFragmentDateSet(Calendar date) {
// update the fragment
mDateDetailFragment.updateDate(date);
}
});
ddf.show(getSupportFragmentManager(), "date picker dialog fragment");
That is suppose to be what is running in the activity class that it runs in. So I kind of get whats happening throughout the rest of the code, and feel free to look at the rest as it will probably help. The code is essentially following almost the same route as the original showDialog() code. Implementing DatePickerDialog.onDateSetListener, and returning a new DatePickerDialog, with the obvious exception thats its using a DialogFragment. But that is where I have gotten lost.
Part of the reason is because I am not really sure where onCreateDialog() returns that new DatePickerDialog. If you look at the code I said does not make sense, both mDateDetailFragment and getSupportFragmentManager() were never instantiated or appeared anywhere else, so I cannot get the tutorial code to even work. The Android Doc also mentions that instead of using showDialog() I should be using both DialogFragment and FragmentManager, which is also not done here. Only DialogFragment.
So like the title, how exactly can I make a DatPicker in the non-depracted form? I would please ask to NOT send me to a link and just say look here. I have done that. Believe me. If not, at least explain what I have missed that makes this make sense. Also, if anyone can actually tell me where the onCreateDialog() method sends the DatePickerDialog, that would be extremely helpful as well. I am just trying to make sense of all this, rather than copy and paste code (not that it works anyways). Thanks a lot for taking the time out to read this, and if any clarifications needed, please ask.
Going in order of your post... \
1) the onCreateDialog returns the dialog to the DialogFragment.
2) I don't know about the mDateDetailFragment.updateDate(date); line... I think he might have left some code out. EDIT Found it, it's in one of the classes in the zip file for his complete demo.
3) You are using the fragment manager (it's the getSupportFragmentManager() part):
ddf.show(getSupportFragmentManager(), "date picker dialog fragment");
Ok, that said, here's how I've done it (I'm using a DateSlider, but subbing in a Datepicker in it's place should be simple enough for you).
In the fragment/activity calling the DialogFragment:
DialogFragment newFragment = new DateDialog();
newFragment.show(getFragmentManager(), "dialog");
And my DialogFragment:
public class DateDialog extends DialogFragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
private DateSlider.OnDateSetListener mDateSetListener = new DateSlider.OnDateSetListener() {
public void onDateSet(DateSlider view, Calendar selectedDate) {
MemberAddFragment.startTxt.setText(String.format("%tB %te, %tY", selectedDate, selectedDate, selectedDate));
}
};
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance(); // Get calendar instance to use in DateSlider
return new AlternativeDateSlider(getActivity(),mDateSetListener,c,null,null); // return DateSlider dialog to DialogFragment
}
}
Hope this helps clear up your confusion.
I know this question is mine and already has an answer. But I thought I'd add my own answer to others looking for help on this same issue. I have simplified the example code that I provided above into only 2 classes. Kbeal, who was gracious enough to provide the tutorial did a great job, but it was too bloated with information that was not even necessary. So using what I knew about dialogs and what I learned from what I could understand from the Kbeal's tutorial as well as the research I did on fragments, I have provided my implementation from a DatePickerDialog on my GitHub.
https://github.com/Zeroe31890/DateDialogFragment
All you honestly have to do is run it straight after only copy and pasting the 2 classes, the single layout, and modifying the Android Manifest file. Much easier than any of the other tutorials. Oh and if anybody sees anything that can be done better on it please do. Enjoy!
Author of the post here: Sounds like you have it all figured out. I replied to your questions on my post before finding this though Barak does a fine job of answering them. If you haven't done so already download the complete source for the example app. I think it will help fill any missing blanks you still have.