How to create an own Calendar-structure? - android

Community,
Basically I'm working on my own Calendar App. Its a private Project to add specific functions and I wont use for example s-planner, Calendar and so on.
The Google Calendar is a great choice in my opinion but I want to learn the basics by myself.
I just started a few days ago and here we go:
The App needs 4.4 Kitkat and above versions. I started with a basic calendar view, looking like this:
So it should be possible to add Events and Reminders. It is possible to check which date is selected and working with a Date Tim Picker dialog? Or should I create an GridView and fill it. Maybe that way:
Just use the calendar api and create an Instance like this:
Calendar calendar = GregorianCalendar.getInstance();
But there is for example, no function which gives me the Dates of a Month in a Array . How its possible to fill it.
I just looked for some examples :
https://www.toptal.com/android/android-customization-how-to-build-a-ui-component-that-does-what-you-want
Is this necessary? Maybe there is an easy way. I don't understand the Calendar Api.
The Logic behind the calendar could be organized with the CalendarContract.
For example:
Intent calIntent = new Intent(Intent.ACTION_INSERT);
calIntent.setData(CalendarContract.Events.CONTENT_URI);
startActivity(calIntent);
So that's not the case now.
I just want to know how I can create the calendar structure and display it. Maybe a hint which way is possible to display dates of another Month ( for example: the first November 2016 = Tuesday so i should display the 31.10 too)
I guess there are a lot of information that I miss at this time. Hope some of you can help me. I'm sorry for my English, it isn't the best but you should understand the point. Have a great Day.
Its also my first post here, so let me know which information is missing or what I should reformat.

Are you looking for something like this. This is a fully customised calendar where you can add events to dates , can listen to date change etc :
https://github.com/khetanrajesh/CustomCalendar

Related

Use the Gregorian, Jalali and Hijiri calendars in the application

I need a Date picker to be able to set it's time types(Gregorian,Jalali or Hijiri)from setting and change it to each others too... and all the items that work by DATE will get new value...as I didn't have found any library to do this i tried to ask best Coders to help me by their libraries...if your answer is yes then how is possible to change all the dates by changing the type of calendar?
some one said "use joda time Library" but there is no tutorial.is joda time Ok?
پی نوشت : please comment up if you have same BROBLEM...to ANSWER]أۀ(in fa) sooner

Using a DatePicker in Android dev: How do I compare the date picked to today's date?

I'm really stuck with a certain problem and I'm hoping someone can help me understand the problem and come to a solution. I've looked online a fair bit but can't see an answer unless it's been staring me in the face :-/
Basically, I'm creating a very basic TV Guide app. It parses data from an RSS feed which has days offset (yesterday was -1. today is 0, tomorrow is 1, etc etc) and I'm trying to implement a DatePicker that allows the user to see what is on a particular channel when they select yesterday, today, tomorrow, etc.. but if they pick a date that is out-with the range (at the moment it's a week in advance), a simple Toast message will be displayed.
My questions I guess are, firstly, how do I use maybe an IF ELSE to either parse the specific channel data for the day the user wants or display an error Toast message, and, how do I go about converting the days from what the user has put in compared to the actual date today into integers? If they select yesterday's date it will go to URL "http://example.com/-1/channel", if they select tomorrow's date it will go to URL "http://example.com/1/channel" etc etc etc.
Code is available if anyone needs to see it, but I think if someone would be kind enough to explain the logic, I'd like to see if I can come to the answer myself...
Thanks a lot folks!!
You should use a DatePicker to allow the user to choose the when.
Time in Android is stored on a long (not an int). And the long time can easily be converted back and forth between long (always milli-seconds) and a Date object.
The Date object gives you all sorts of tools to compare before and after, look at months, minutes, hours, etc.
The current time is determined by:
long nowMs = System.currentTimeMillis();
int nowSec = (int)(nowMs / 1000);
There is also a very important Calendar object. This allows you to parse textual date formats as delivered by your http functions in and out of various dates.
For example:
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss Z");
String text = sdf.format(cal.getTime();
You will have to put all these tools together with a DatePicker example such as the one here Create a DatePicker to complete your TV Guide application.
Reference:
Date
Calendar
DatePicker
EDIT : Check David's Answer its better.
First Filter the date selected with today's date. You can compare it by date.isbefore(date) or date.isafter(date) these booleans will let you tell know if a date is of past or future or present. then to further calculate the days inbetween you can make a method with switch statement that will basically convert the selected date and the current date into miliseconds(Date.getTimeinmiliseconds)
if the date is of past take the difference of present time in miliseconds and past date in miliseconds. If the date is of future do the opposite. Take the difference and convert it to days difference with appropriate sign(negative/positive).
Please refer this link for a better coding example

Tweaked formating of date with days of week, and mounts

Well instead of 2011.10.19 10:30 I want to have something like 10:30, Wednesday or instead of 2011.09.19 10:30 I want to have something like 10:30, September. I know that I can code this somehow but I want clean and not greedy solution. The code will run on android devices so I need something that acts gracefully with resources and something that is well written. PreatyTime doesn't helps me cause it calculates distance from this moment , and there is no formatting like 12:00, Monday.
Does someone know some good pattern that I can follow when writing this kind of things ?
have a look at this
It will give you any format you want,by just passing a Calendar object.
For example:
Calendar cal=Calendar.getInstance();
String myFormat=String.format("%1$tH:%1$tM %1$tB",cal);
would give you format like "10:30 September".

Android Localization: What am I doing wrong that I can get months be displayed according to the locale?

This is very simple, I would expect the following piece of code to display Gennaio (Italian for January) but it still displays January. Even if I set the device locale to Italy. Any help will be appreciated. Thanks,W.
Calendar calendar= Calendar.getInstance(Locale.ITALIAN);
calendar.set(2011,0,1);
button.setText((calendar.getTime().toString()));
Your conclusion is logical but toString() is usually and certainly in this case a utility function, meant mainly for debugging.
For localised dates you need to use a DateFormatter, like so:
Calendar calendar=Calendar.getInstance();
calendar.set(2011,0,1);
String formatted=DateFormat.getLongDateFormat(this).format(calendar.getTime());
button.setText(formatted);
This example uses one of the three standard date formatters but you can get quite specific about the format, particularly be calling DateFormat.getInstance(context).getDateInstance which allows you to set more parameters, including the locale.
There's a litte more detail here: http://developer.android.com/reference/java/text/DateFormat.html
I hope that's what you were looking for.

How to show current week?

I'm trying to program an android app that show's the current week_of_the_year but haven't found anything similar to what I want, I've seen the date picker but that doesn't show the week numbers and I've also been on android developer site.
So is there any way to view the current week_of_the_year in a really simple way?
If there's anyone who can show me this I'll be greatly appreciated.
new GregorianCalendar().get(Calendar.WEEK_OF_YEAR);
This should give you the current week in the current time zone. If you need it for a specific date, there are alternate constructors for GregorianCalendar.
The easiest way to do this on Android is probably to use the Time class:
int currentWeek = new Time().getWeekNumber();

Categories

Resources