Convert Figma logo to code with AI

square logoandroid-times-square

Standalone Android widget for picking a single date from a calendar view.

4,444
1,189
4,444
23

Top Related Projects

A Material design back port of Android's CalendarView

A highly customizable calendar view and compose library for Android and Kotlin Multiplatform.

A better calendar for Android

Pick a date or time on Android in style

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

An android library which provides a compact calendar view much like the one used in google calenders.

Quick Overview

Android Times Square is a standalone Android widget for selecting a single date or a range of dates. It provides a customizable calendar view that can be easily integrated into Android applications. The library offers a user-friendly interface for date selection with various customization options.

Pros

  • Easy integration into Android projects
  • Customizable appearance and behavior
  • Supports both single date and date range selection
  • Localization support for different languages and regions

Cons

  • Limited to Android platform only
  • May require additional customization for complex use cases
  • Documentation could be more comprehensive
  • Not actively maintained (last update was in 2020)

Code Examples

  1. Initializing a CalendarPickerView:
val calendar = Calendar.getInstance()
val nextYear = calendar.clone() as Calendar
nextYear.add(Calendar.YEAR, 1)

val calendarView = findViewById<CalendarPickerView>(R.id.calendar_view)
calendarView.init(Date(), calendar.time, nextYear.time)
    .withSelectedDate(Date())
  1. Setting up a date range selection:
calendarView.init(Date(), calendar.time, nextYear.time)
    .inMode(CalendarPickerView.SelectionMode.RANGE)
  1. Adding a date selection listener:
calendarView.setOnDateSelectedListener(object : CalendarPickerView.OnDateSelectedListener {
    override fun onDateSelected(date: Date) {
        // Handle date selection
    }

    override fun onDateUnselected(date: Date) {
        // Handle date unselection
    }
})

Getting Started

To use Android Times Square in your project, follow these steps:

  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.squareup:android-times-square:1.7.10@aar'
}
  1. Add the CalendarPickerView to your layout XML:
<com.squareup.timessquare.CalendarPickerView
    android:id="@+id/calendar_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  1. Initialize the CalendarPickerView in your Activity or Fragment:
val calendarView = findViewById<CalendarPickerView>(R.id.calendar_view)
val today = Calendar.getInstance()
val nextYear = today.clone() as Calendar
nextYear.add(Calendar.YEAR, 1)

calendarView.init(today.time, nextYear.time)
    .withSelectedDate(today.time)

Competitor Comparisons

A Material design back port of Android's CalendarView

Pros of material-calendarview

  • More modern Material Design aesthetic
  • Supports custom decorators for date cells
  • Offers more customization options for appearance

Cons of material-calendarview

  • Larger library size
  • May require more setup for basic functionality
  • Less established/mature compared to android-times-square

Code Comparison

material-calendarview:

MaterialCalendarView calendarView = findViewById(R.id.calendarView);
calendarView.setSelectionMode(MaterialCalendarView.SELECTION_MODE_MULTIPLE);
calendarView.addDecorator(new EventDecorator(Color.RED, dates));

android-times-square:

CalendarPickerView calendar = findViewById(R.id.calendar_view);
calendar.init(startDate, endDate)
    .inMode(CalendarPickerView.SelectionMode.MULTIPLE);

material-calendarview offers more built-in customization options, while android-times-square provides a simpler API for basic functionality. The former allows for easy decoration of specific dates, while the latter focuses on a straightforward date selection process.

Both libraries serve the purpose of providing a calendar view for Android applications, but material-calendarview leans more towards modern design principles and extensive customization. android-times-square, developed by Square, is known for its reliability and simplicity, making it a solid choice for projects that don't require advanced styling options.

A highly customizable calendar view and compose library for Android and Kotlin Multiplatform.

Pros of Calendar

  • More flexible and customizable, allowing for a wider range of calendar styles and layouts
  • Supports both vertical and horizontal scrolling
  • Better performance for handling large date ranges

Cons of Calendar

  • Steeper learning curve due to increased complexity and customization options
  • Requires more setup code for basic implementations
  • Less mature project with potentially fewer community resources

Code Comparison

Calendar:

val calendarView = CalendarView(context)
calendarView.dayBinder = object : DayBinder<DayViewContainer> {
    override fun create(view: View) = DayViewContainer(view)
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        container.textView.text = day.date.dayOfMonth.toString()
    }
}

TimesSquare:

CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
calendar.init(new Date(), nextYear.getTime())
    .withSelectedDate(new Date());

The Calendar library offers more granular control over day rendering and binding, while TimesSquare provides a simpler setup for basic calendar functionality. Calendar's code is in Kotlin, which may be preferred by some developers, while TimesSquare uses Java.

A better calendar for Android

Pros of Caldroid

  • More customizable appearance with support for custom cell views and backgrounds
  • Supports both date picker and date range selection modes
  • Includes built-in swipe navigation between months

Cons of Caldroid

  • Less actively maintained (last update in 2019)
  • Fewer stars and contributors on GitHub
  • May have compatibility issues with newer Android versions

Code Comparison

Caldroid:

CaldroidFragment caldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
Calendar cal = Calendar.getInstance();
args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
caldroidFragment.setArguments(args);

android-times-square:

Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
calendar.init(new Date(), nextYear.getTime())
    .withSelectedDate(new Date());

Both libraries offer easy-to-use calendar views for Android applications. Caldroid provides more customization options and flexibility in terms of appearance and selection modes. However, android-times-square is more actively maintained and likely to have better compatibility with recent Android versions. The code snippets show that both libraries have straightforward initialization processes, with Caldroid using a fragment-based approach and android-times-square using a view-based approach.

Pick a date or time on Android in style

Pros of MaterialDateTimePicker

  • Offers both date and time picker functionality
  • Follows Material Design guidelines for a modern, sleek appearance
  • Supports theming and customization options

Cons of MaterialDateTimePicker

  • May have a steeper learning curve due to more complex implementation
  • Potentially larger library size due to additional features

Code Comparison

MaterialDateTimePicker:

Calendar now = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
    this,
    now.get(Calendar.YEAR),
    now.get(Calendar.MONTH),
    now.get(Calendar.DAY_OF_MONTH)
);
dpd.show(getFragmentManager(), "Datepickerdialog");

android-times-square:

Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
calendar.init(new Date(), nextYear.getTime())
    .withSelectedDate(new Date());

MaterialDateTimePicker offers a more comprehensive date and time selection solution with a modern design, while android-times-square focuses on a simpler, calendar-based date selection. The code examples show that MaterialDateTimePicker uses a dialog-based approach, whereas android-times-square integrates directly into the layout. Choose based on your specific needs and design preferences.

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Pros of Android-Week-View

  • Offers a more comprehensive week view with customizable event display
  • Supports horizontal scrolling for navigating between weeks
  • Provides zoom functionality for adjusting the time scale

Cons of Android-Week-View

  • More complex implementation due to additional features
  • May have a steeper learning curve for developers
  • Potentially higher resource consumption due to advanced functionality

Code Comparison

Android-Week-View:

WeekView weekView = findViewById(R.id.weekView);
weekView.setOnEventClickListener(this);
weekView.setMonthChangeListener(this);
weekView.setEventLongPressListener(this);

android-times-square:

CalendarPickerView calendar = findViewById(R.id.calendar_view);
Date today = new Date();
calendar.init(today, nextYear.getTime())
    .withSelectedDate(today);

Android-Week-View provides a more detailed week view with event handling capabilities, while android-times-square focuses on a simpler month-based calendar picker. The code snippets demonstrate the initialization process for each library, highlighting the different approaches to calendar functionality.

An android library which provides a compact calendar view much like the one used in google calenders.

Pros of CompactCalendarView

  • More customizable appearance with options for event indicators and day labels
  • Supports horizontal scrolling for month navigation
  • Smaller footprint and easier integration into existing layouts

Cons of CompactCalendarView

  • Less comprehensive date range selection functionality
  • Fewer built-in themes and styling options
  • Limited support for custom date formats

Code Comparison

CompactCalendarView:

CompactCalendarView compactCalendarView = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
compactCalendarView.setUseThreeLetterAbbreviation(true);
compactCalendarView.setFirstDayOfWeek(Calendar.MONDAY);
compactCalendarView.setIsRtl(false);
compactCalendarView.displayOtherMonthDays(false);

android-times-square:

CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Date today = new Date();
calendar.init(today, nextYear.getTime())
    .inMode(CalendarPickerView.SelectionMode.SINGLE)
    .withSelectedDate(today);

Both libraries offer easy-to-use calendar views for Android applications. CompactCalendarView provides a more compact and customizable appearance, while android-times-square offers robust date range selection and built-in theming options. The choice between the two depends on specific project requirements and design preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

TimesSquare for Android

Standalone Android widget for picking a single date from a calendar view.

Screenshot

Usage

Include CalendarPickerView in your layout XML.

<com.squareup.timessquare.CalendarPickerView
    android:id="@+id/calendar_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

This is a fairly large control so it is wise to give it ample space in your layout. On small devices it is recommended to use a dialog, full-screen fragment, or dedicated activity. On larger devices like tablets, displaying full-screen is not recommended. A fragment occupying part of the layout or a dialog is a better choice.

In the onCreate of your activity/dialog or the onCreateView of your fragment, initialize the view with a range of valid dates as well as the currently selected date.

Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);

CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Date today = new Date();
calendar.init(today, nextYear.getTime())
    .withSelectedDate(today);

The default mode of the view is to have one selectable date. If you want the user to be able to select multiple dates or a date range, use the inMode() method:

calendar.init(today, nextYear.getTime())
    .inMode(RANGE);

Download

The latest version can be downloaded in zip and referenced by your application as a library project.

You can also depend on the library through Maven:

<dependency>
  <groupId>com.squareup</groupId>
  <artifactId>android-times-square</artifactId>
  <version>1.6.5</version>
  <type>apklib</type>
</dependency>

or Gradle:

compile 'com.squareup:android-times-square:1.6.5@aar'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2012 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.