square / android-times-square Goto Github PK
View Code? Open in Web Editor NEWStandalone Android widget for picking a single date from a calendar view.
License: Apache License 2.0
Standalone Android widget for picking a single date from a calendar view.
License: Apache License 2.0
Not sure if this is expected behavior, but given the following code, the resulting image occurs: http://i39.tinypic.com/10yqj9v.jpg
final Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
final CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Intent passedIntent = getIntent();
long passedDate;
final Date mSelectedDate;
final Date today = new Date();
if (passedIntent.hasExtra("dateToEdit")) {
passedDate = passedIntent.getLongExtra("dateToEdit", today.getTime());
mSelectedDate = new Date(passedDate);
} else {
mSelectedDate = today;
}
calendar.init(mSelectedDate, nextYear.getTime()).withSelectedDate(mSelectedDate);
The code above loads a date, in the image below December 17th gets fed in. The calendar loads with this date selected (in blue) but the 19th (today) is still selected in grey. Is this expected, or am I doing something wrong?
First of all thank you for creating this awesome widget.
I would like to suggest an enhancement since I'm missing a certain feature.
Scroll to selected date
Use-case:
This widget is used to select a date, The second time the user opens the CalendarPickerView I would like to select the previously selected date and scroll to that date.
So far I was able to restore the previous selected date with following code (using fragments). But I'm not able to reposition the ScrollView to that date.
Code to select previous date
// If a previous date was selected, restore it
if (isFirstSelection()) {
mCalendar.init(new Date(), new Date(), nextYear.getTime());
} else {
final Date currentDate = (Date) getArguments().get(KEY_CURRENTDATE);
mCalendar.init(currentDate, new Date(), nextYear.getTime());
//missing function
//mCalendar.scrollToPostion()
}
Is this behavior implemented? I personally think this feature would be a good enhancement.
First of all: thanks for creating this beautiful library.
I want to point out that i'm missing an important feature is this library and this functionality cannot be added to any project without changing the library itself. I'm creating an application where the user has the choice to select different languages but the currently the names of the month and days of the week are based on the OS-language.
Could it be possible to change the locale settings in the different initiations of the Calendar class e.g. Calendar.getInstance() / Calendar.getInstance(locale).
Any thoughts about this suggestion?
...and anything else we can think of.
I have a issue in unit testing my project, I have a fragment that loads up CalendarPickerView and then adds a OnDateSelectedListener, the code works and executes fine on actual device, However in unit testing Robolectric says its not able to ding the OnDateSelectedListener, if I comment the anonymous listener the test passes. What I'm not able to understand it If it is able to find CalendarPickerView why would it not be able to find CalendarPickerView$OnDateSelectedListener
CalendarFragment.java
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static CalendarFragment newInstance(int startMonth, int endMonth) {
CalendarFragment fragment = new CalendarFragment();
Bundle args = new Bundle();
args.putInt(ARG_START_MONTH, startMonth);
args.putInt(ARG_END_MONTH, endMonth);
fragment.setArguments(args);
return fragment;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
calendarPickerView.setOnDateSelectedListener(new OnDateSelectedListener() {
@Override
public void onDateSelected(Date date) {
Toast.makeText(getActivity(), "You selected :" + date, Toast.LENGTH_SHORT).show();
}
@Override
public void onDateUnselected(Date date) {
}
});
}
CalendarFragmentTest.java
@Test
public void newInstanceShouldAddStartMonthAndEndMonthInFragmentBundle() throws Exception {
CalendarFragment calendarFragment = CalendarFragment.newInstance(1, 2);
assertThat(1, is(calendarFragment.getArguments().get(CalendarFragment.ARG_START_MONTH)));
assertThat(2, is(calendarFragment.getArguments().get(CalendarFragment.ARG_END_MONTH)));
}
However on running this test I get
java.lang.NoClassDefFoundError: com/squareup/timessquare/CalendarPickerView$OnDateSelectedListener
at com.ccd.corrections.fragments.CalendarFragmentTest.newInstanceShouldAddStartMonthAndEndMonthInFragmentBundle(CalendarFragmentTest.java:19)
Hi there!
Is there any way to make this widget scroll infilitely? I mean, I don't want to set starting time and ending time during init() method. I need a calendar picker view which enable user to pick any date, and scroll to find any date.
Thanks.
It would be nice if we can select several dates instead of single one. Is the mutiselection feature planned ?
Sorry for my bad English, I'm newbie in Android development, could you explain, is it possible to start Activity with your calendar in DisplayOnly style? So that user can only see some highlighetened dates.
SelectionModes available: SINGLE, MULTI, RANGE, but not NONE or smth like that.
Thanks in advance
When I init the calendar with minDate 2013-02-01 and maxDate 2013-03-01, so that the user can choose any day in the month of 2013-02.
What happened:
The CalendarPickerView shows both Feb 2013 and Mar 2013, with no days in Mar 2013 that can be selected.
What should happen:
The CalendarPickerView shows only Feb 2013.
It's possible to show only one month ?
One of my users reported that the calendar (which I show in a dialog) would only show a single month (november). He tells me that a clear data for the app does not change anything. I on the other hand have been unable to reproduce the issue myself.
Any ideas on what might be causing this?
[...] I have also tried to set the clock of my phone to a past/future months,
the result is the same, only the "current" month seems to be available.
Another detail:
on landscape the screen of my smartphone is too tiny to contain an entire
table of a month, so the dialog allow me to scroll, but it scroll only for show
the entirely current month.
This happens also after a "clear data" for the app
The new Android build system (http://tools.android.com/tech-docs/new-build-system) expects libraries that contain code and resources to be in AAR format (http://tools.android.com/tech-docs/new-build-system/aar-format). apklib, the format introduced by the android-maven-plugin, is currently not supported (Conversely the android-maven-plugin does not understand AAR). Therefore it would be helpful if TimesSquare for Android would be published as apklib and as AAR as well.
The easiest way to achieve this seems to be to use the new Android build system which is apparently capable of producing an AAR and an apklib from the same build (for an example see https://github.com/googlemaps/android-maps-utils/blob/master/library/build.gradle). But this would require a switch over to Gradle. Another possibility is to keep Maven and invoke Gradle later in the build to produce the AAR (ActionBarSherlock does this). I also read somewhere that the android-maven-plugin guys plan to add AAR support but I haven't seen any results yet.
I'd be willing to prepare a pull request with the necessary changes to move over to the new Android build system. But I need to know whether such a pull request would be accepted before I invest time into it.
A common requirement for date pickers is to disable the selection of certain dates, such as weekends and holidays. This functionality could be implemented through a callback that is queried in getMonthCells
, similar to the method used by the jQuery UI Datepicker library.
just happens if first day of week is monday (see 1st September 2013)
Hello,
The first day of week isn't always Sunday, it depends of the country. So, to show the good first day of week, I replaced in getMonthCells method of CalendarPickerView :
cal.add(DATE, SUNDAY - firstDayOfWeek);
by
cal.add(DATE, cal.getFirstDayOfWeek() - firstDayOfWeek);
and I changed MonthView create method like this :
public static MonthView create(ViewGroup parent, LayoutInflater inflater, DateFormat weekdayNameFormat, Listener listener, Calendar today) {
final MonthView view = (MonthView) inflater.inflate(R.layout.month,
parent, false);
final int originalDayOfWeek = today.get(Calendar.DAY_OF_WEEK);
int firstDayOfWeek = today.getFirstDayOfWeek();
final CalendarRowView headerRow = (CalendarRowView) view.grid
.getChildAt(0);
for (int c = Calendar.SUNDAY; c <= Calendar.SATURDAY; c++) {
today.set(Calendar.DAY_OF_WEEK, firstDayOfWeek + c - 1);
final TextView textView = (TextView) headerRow.getChildAt(c - 1);
textView.setText(weekdayNameFormat.format(today.getTime()));
}
today.set(Calendar.DAY_OF_WEEK, originalDayOfWeek);
view.listener = listener;
return view;
}
Need to use this library my android project please include aar support.
If you set in the manifest's the attribute supportRtl="true" (targetSdk needs to be 17), the cells' text won't be centered because CheckedTextView ignores the Gravity setting in this case.
I created a small example with CheckedTextView and saw the text always aligned to the left if supportRtl is true. I believe it's a platform bug, so I opened an issue on the Android project site: https://code.google.com/p/android/issues/detail?id=54607
I tried overcoming this with manually setting the view or the layout to be Left-to-Right but it doesn't help. The only thing that helps is to set the supportRtl to false.
Any other ideas?
Hi
I'm in the process of integrating the control within my app (will let you know when it's out :)
Problem is that there is a slight but still noticeable delay when launching a DialogFragment that houses the control..(and only it).
I tested this on a Galaxy S2 running jellybean, no debugger attached
The dialog scenario is important for me and I'm concerned of user pushback despite
being a great control.
Can you help ?
-itai
null
It would be useful to configure arbitrary days with icons or special colors (e.g. birthday or too busy for new appointments).
With
.add(Calendar.DATE, endMonth.getActualMaximum(Calendar.DATE) - endMonth.get(Calendar.DATE) +1 );
I can add remaining days to the end of month. But I can't add one more month, because
Calendar.getInstance().getActualMaximum((Calendar.MONTH)+1)
gives some unreal data, like 52 days.
When I place times-square into an AlertDialog or DialogFragment, it's performance get worse. When you select a new date the old selection disappears some time after the new appears, which makes the experience in using it fairly bad.
Can i add some marks to the calendar?
Just like this, http://blog.csdn.net/idle_thing/article/details/17645831
Sorry for disturbance caused from my previous questions.
I'm using calendar in Multiple-DisplayOnly mode just to show some information.
Is it possible to do something when clicking some day? For example, open a Dialog with some information) without highlightening it?
mvn clean verify
will fail on a fresh checkout with the following error:
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.4.1:generate-sources (default-generate-sources) on project android-times-square: MojoExecutionException: ANDROID-040-001: Could not execute: Command = /bin/sh -c cd /Users/tad/git/android-times-square/library && /Users/tad/dev/sdk/platform-tools/aapt package -m -J /Users/tad/git/android-times-square/library/target/generated-sources/r -M /Users/tad/git/android-times-square/library/AndroidManifest.xml -S /Users/tad/git/android-times-square/library/res --auto-add-overlay -A /Users/tad/git/android-times-square/library/assets -I /Users/tad/dev/sdk/platforms/android-16/android.jar, Result = 1 -> [Help 1]
The output of that command is:
/Users/tad/git/android-times-square/library/res/values/styles.xml:13: error: Error: No resource found that matches the given name: attr 'android:textAlignment'.
The textAlignment
resource ID was added in API 17. Changing the android.platform
value to 17 in pom.xml
solves the problem.
Hello, i am trying to create a calendar witch presents one year before and after current date. i am creating the calendar with the following code but after the calendar appears it shows the second month (June 2012). Shouldn't it be showing the current month (May 2013)?
I 've also tried the .smoothScrollToPosition(position), but is scrolls the calendar by on month every time even if i try position = 1000.
Is it normal behavior or am i missing something?
Thanks in advance!
CalendarPickerView tsCalendar;
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
Calendar previousYear = Calendar.getInstance();
previousYear.add(Calendar.YEAR, -1);
ArrayList dates = new ArrayList();
Calendar today = Calendar.getInstance();
dates.add(today.getTime());
tsCalendar = (CalendarPickerView) myView.findViewById(R.id.my_view_id);
tsCalendar.init(SelectionMode.SINGLE, dates, previousYear.getTime(), nextYear.getTime());
Create state-list drawable programmatically from style attributes. Provide holo light/dark styles in the library. Have attributes so you can specify styles in the layout XML using the res-auto namespace.
(originally filed by @JakeWharton)
CalendarPickerView is one of the cleanest Android calendars I have seen.
In my attempt to use Selection Mode Multiple to show programmatically set highlighted dates without the ability to select or deselect others, I tried calling setEnabled(false). It caused the Calendar still to be scrollable, but very poorly and unresponsively.
I now realise that is what caused me to open
and
I apologize for creating issue spam with those. I know there is a real bug here somewhere.
Incidentally, I have also tried setClickable(false) and that seems to have no effect. My next idea was to overlay a transparent view on top of the calendar to intercept click events. Otherwise I will try to fork the library, but I'd prefer the library had the functionality.
You guys are really close to having an amazing calendar display, not just and amazing calendar picker. Maybe I just haven't figured out how to use it correctly. Thank you in advance.
Joseph Malone
malone.joseph .AT. gmail
Hi,
Not sure if an issue with my code or with the library. (Great library by the way). I believe this may be an issue.
Here's what I'm doing to initialise the calendar.
calendar.init(lastYear.getTime(), nextYear.getTime()).inMode(SelectionMode.SINGLE).withSelectedDate(new Date()).withHighlightedDates(dates);
When the fragment loads, it isn't highlighted by default, but when a date is clicked, then it all the dates which are to be highlighted show correctly.
Thanks.
Edit #2:
Seems to be dependent on screen size. The issue occurred when using dates, that were 1 year apart, when only 2 months apart or less no issue occurs.
For example, I'm on a Nexus 4, displaying Oct 2013 -> Feb 2014 works perfectly which is 5 months. Anything more then this for my screensize, then the highlighted dates show on the wrong months. And on higher resolution devices which can fit more calendar months on a single view, it can take more months while still displaying correctly.
Because the library uses a setMidnight convenience method, the boundary on init should be to 0:00:00:00 on the next day outside of the range otherwise you get a nice bug where the last day on your calendar isn't selectable. This wasn't inherently obvious to me when deploying the library and I wasted a day digging around trying to figure out why. The error toast didn't tell me what Date the library was using when it barfed on selecting the final day of the month which made debugging this challenging.
I am using the Calendar in a dialog and the Calendar grows when a date is selected.
Note how the OK/Cancel-buttons suddenly are slightly off-screen.
It might be important (I don't know) that I am running my app on a Galaxy Nexus.
Larger screens might not have this issue? I did not experience this before I rebased
to the latest master (was previously rebased to ddf82a9)
The images were taken with slightly different code but was reproducible with
this as well (modified from your dialog sample):
CalendarPickerView dialogView = (CalendarPickerView) layoutInflater
.inflate(R.layout.fragment_dialog_calendar_builder, null, false);
final Calendar future = Calendar.getInstance();
future.add(Calendar.YEAR, 1);
final Calendar selected = Calendar.getInstance();
if (mTask != null && mTask.due != null) {
selected.setTimeInMillis(mTask.due);
}
dialogView.init(Calendar.getInstance().getTime(), future.getTime(),
ActivityHelper.getUserLocale(getActivity())).withSelectedDate(
selected.getTime());
new AlertDialog.Builder(getActivity())
.setTitle("I'm a dialog!")
// R.string.select_date
.setView(dialogView)
.setNegativeButton("GET OUT",
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
})
.setPositiveButton("POSITIVE",
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}).create().show();
fragment_dialog_calendar_builder:
<?xml version="1.0" encoding="utf-8"?>
<com.squareup.timessquare.CalendarPickerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?CalendarPickerBackground"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:scrollbarStyle="outsideOverlay" />
Hello,
I wanna invoke a method when a date is clicked. Could you please tell me how to do it? I have check the issues and your README file, but got no answer. Thanks in advanced.
Hello,
I'm using this code
final Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
final Calendar lastYear = Calendar.getInstance();
lastYear.add(Calendar.YEAR, -1);
calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
calendar.init(lastYear.getTime(), nextYear.getTime()) //
.inMode(SelectionMode.SINGLE) //
.withSelectedDate(new Date());
but when app runs is not scrolling to the month that is the SelectedDate
Can you please export the code formatting settings of your IDE so it is easier for contributors to commit stuff? Please add the export to the project. Those settings should match with the rules defined in checkstyle.xml
.
Hi, there! thanks for your sharing.
You know, your times-square is very good and matches my style requirements. But it is still not friendly to change its face. If I want a more colorful view, do I have to change its styleable resource? Why not add some attributes to the CalendarPickerView?? like:
android:background="#111155"
android:firstDayOfWeek="1"
android:focusedMonthDateColor="#009933"
android:selectedWeekBackgroundColor="#55ffffff"
android:showWeekNumber="true"
android:shownWeekCount=""5
When I load the view (in my dialog fragment), the calendar automatically scrolls to the end of the allowed range. I don't want to restrict the date in this case so I selected a 10 year limit. The view scrolls to 2023 upon loading.
However, if you comment out the line "withSelectedDate", the calendar loads fine and does not scroll to maxDate.
Device: Galaxy Nexus, Android 4.2.2
Code:
final Calendar future = Calendar.getInstance();
future.add(Calendar.YEAR, 10);
final Calendar selected = Calendar.getInstance();
// Default to tomorrow
selected.add(Calendar.DAY_OF_YEAR, 1);
// New item hides delete button and disables OK initially
if (getArguments().getLong(SELECTED_DATE, -1) > 0) {
// TODO default date
selected.setTimeInMillis(getArguments().getLong(SELECTED_DATE, -1));
}
calendarView.init(Calendar.getInstance().getTime(), future.getTime())
.withSelectedDate(selected.getTime());
Is something like that implemented? I would rather listen to an event that constantly call calendar.getSelectedDate()
First of all: thank you for creating this awesome widget.
I want to point out that there is a small bug using a certain configuration.
I'm using fragments with the manifest configured to let the activity handle configuration changes (this being orientation,screensize and keyboardhidden)
When I rotate the device the measured areas are incorrect. Some months/days of the calendar are resized while others aren't. Is someone else having this problem? Can someone take a look at this?
Best regards,
Tobrun
There is some base code for doing multiselect and I managed to hack the code a bit to enable it, but the API for it is disabled in your current master code. Please would it be possible for you guys to do it? I think I might have broken something when I tried.
For example...
//dates in my database for example
Calendar today = Calendar.getInstance();
ArrayList dates = new ArrayList();
for (int i = 0; i < 5; i++) {
today.add(Calendar.DAY_OF_MONTH, 3);
dates.add(today.getTime());
}
calendar = (CalendarPickerView) view.findViewById(R.id.calendar_view);
calendar.init(lastYear.getTime(), nextYear.getTime()).inMode(SelectionMode.SINGLE)
.withSelectedDates(dates);
date only one has been selected in this example....why not all ?
Hi !
I just got the most updated version of the library, and it seems that styles are not working anymore.
Selecting a date doesn't highlight it anymore on the calendar, and the current date doesn't have its style anymore either.
Thanks for your sharing~
1.CellClickedListener in CalendarPickerView should be public ,so I can extends
2.in CalendarPickerView
private final MonthView.Listener listener = new CellClickedListener();
should be used in getCellListener method
then define method
public Listener getCellCilckListener() {
return listener;
}
in MonthAdapter getView methodView create by
monthView =
MonthView.create(parent, inflater, weekdayNameFormat, getCellCilckListener(), today);
in this way I can create my listener and set My listener in order to handler Cell click event
I created a Calendar View inside of a fragment inside of a TabViewPager. The calendar would still scroll up and down but not at all responsively and would tend to freeze up entirely. Have you guys seen anything similar?
Sorry for such stupid question.
In example:
Calendar today = Calendar.getInstance();
ArrayList<Date> dates = new ArrayList<Date>();
for (int i = 0; i < 5; i++) {
today.add(Calendar.DAY_OF_MONTH, 3);
dates.add(today.getTime());
}
CalendarActivity.this.calendar
.init(new Date(), nextYear.getTime()) //
.inMode(SelectionMode.MULTIPLE) //
.withSelectedDates(dates);
}
What should dates look like? In what format?
I'm trying to add DD.MM.yyyy with no luck =(
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.