API21 new DatePicker ShowWeekNumber Crash - java

I was testing my app with the new Android 5.0 (API21) but was getting an error with the CalendarView
Caused by: java.lang.UnsupportedOperationException: CalendarView does not exists for the new DatePicker
at android.widget.DatePickerCalendarDelegate.getCalendarView(DatePickerCalendarDelegate.java:501)
at android.widget.DatePicker.getCalendarView(DatePicker.java:365)
For my surprise the error was not because there is no CalendarView in the NEW API21 DatePicker, in fact, there is no DatePicker in API21, just CalendarView.
The error was produced because I was hidding the Week Numbers in the CalendarView
picker.getCalendarView().setShowWeekNumber(false);
This instruction throws the UnsupportedOperationException, be warned no more Week Numbers in the CalendarView, they just disappeared it, no explanation.

One problem that can cause this exception is that if your DatePicker mode is android:datePickerMode="calendar", DatePicker.getCalendarView would cause exception in post API 21, then in order to solve this, change the mode of your DatePicker to android:datePickerMode="spinner" and in java you can use from conditions to handle API greater than or equal to 21

I think you are getting confused.
your requirement is "to hide week number"
But actually there is no week Number in date picker neither in api21 nor below 21
so i suggest you skipping "picker.getCalendarView().setShowWeekNumber(false);"
line and continue with rest of code.

Related

can someone help me fix this Picker error

I am using Picker component is codename one, it was working properly before as shown in 1st screenshot, its showing the full string.
But in 2nd screenshot, its not showing some alphabets.
Screenshot 1: !https://imgur.com/m29K4f5
Screenshot 2: !https://imgur.com/RWv0klM
Picker pcle = new Picker();
Accordion acle=new Accordion();
pcle.setType(Display.PICKER_TYPE_STRINGS);
pcle.setStrings(
"Picking up a trash",
"Cleaning up a beach "+"10",
"Cleaning up a park "+"10",
"Tidying up the table after eating in a restaurant. "+"5",
"Joining a clean up operation "+"20"
);
pcle.setSelectedString("Select a Deed from Bottom of Screen");
acle.addContent("Cleaning", pcle);
where 'pcle' is my Picker,
'acle' is my Accordion
it is supposed to show whole string, but its not showing.
This looks like a regression due to the fix made here: https://github.com/codenameone/CodenameOne/issues/2774
I suggest commenting on the issue so it can be resolved by the upcoming Friday update.

Want to display a photo in the cell of day in Calendar

I would like to display a photo in cells of days in Calendar. I am new in android app development. I have looked at Calendar class, but didn't find function where I cad add photo.
Something like this should look like.
this custom android calendar could help you with your problem. Basically the standard calendar can't do what you want so you have to modify the calendar/create an own calendar.
You can use CustomCalendarView
<com.stacktips.view.CustomCalendarView
android:id="#+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/off_white"
app:calendarBackgroundColor="#color/off_white"
app:calendarTitleTextColor="#color/black"
app:currentDayOfMonthColor="#color/blue"
app:dayOfMonthTextColor="#color/black"
app:dayOfWeekTextColor="#color/black"
app:disabledDayBackgroundColor="#color/off_white"
app:disabledDayTextColor="#color/grey"
app:selectedDayBackgroundColor="#color/blue"
app:titleLayoutBackgroundColor="#color/white"
app:weekLayoutBackgroundColor="#color/white">
</com.stacktips.view.CustomCalendarView>
OUTPUT

Java EWS Reading Outlook Appointments

I would like to read all appointments from one user between some dates. And get from them the information about what, from when till when, which color (category) it has, the state if out of office.
I didn't found a sample which worked. Can you show me a sample for that.
I'm using win7 and EWS Java API 1.2 from MS
Use a CalendarView with a start and end date on the Calendar folder to get everything within a set date range. Place the properties you'd like in a PropertySet, set it in the CalendarView, and use ExchangeService.findAppointments() to get them:
CalendarView view = new CalendarView(startDate, endDate);
PropertySet p = new PropertySet(ItemSchema.Categories, AppointmentSchema.Start,
AppointmentSchema.End);
view.setPropertySet(p);
FindItemsResults<Appointment> find = service.findAppointments(
WellKnownFolderName.Calendar, view);
Iterate through the FindItemsResults and get what you need. I'm not sure if it's necessary, but various operations won't always return the information you need even if you request it with the PropertySet. If that's the case, then you'll need to use Appointment.load(PropertySet) or ExchangeService.loadPropertiesForItems(Items, PropertySet) to get them. I'm not sure what you mean by out of office on the Appointment itself. Do you mean the status of the Appoinment? The state as in province? By out of office, do you mean outside of the office of the user or if the user has a status of "Out of Office" (aka OOF) when the Appointment is scheduled?

How to view a public Google Calendar via an Android Application

I must've gone through ever Stack Overflow question based on the Google Calendar so far with no luck what so ever. I've been trying this for hours now and got little to no results at all.
I'm a pretty new programmer with Java and Android, with quite little experience out of the field as it is. Basically the main problem I am having is with viewing another user's Google Calendar which is set to public.
At the moment, from the Google tutorials and other sites I've managed to get the calendar showing, which is pretty simple enough. It'll just load up and show the current user's calendar. Which can literally be done with (with a simple button in the layout).
public void onClick(View view) {
// A date-time specified in milliseconds since the epoch.
long startMillis = System.currentTimeMillis();
Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, startMillis);
Intent intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
startActivity(intent);
}
Obviously this doesn't pass in any user data for the public account or anything, I've been reading through the Calendar Provider Developer guides within the Google tutorials. I've tried to set up the account details thing, but it just never works. I've tried to do it as a Sync Adapter, but honestly I just know I'm not doing it right. I don't know if I really even need to use a Sync Adapter as all I want to do is literally see the events, not modify anything or update anything.
I am using API 14+ and want to user the Calendar Provider etc. It looks simple enough but I've been bashing my head against this for a few days and put a lot of hours into it and seemingly nothing I do works. At least I've got some sort of calendar opening but it's not what I want.
Is it all just down to the sync adapter? If so how will I be able to call a calendar? Another question similar had
private static Uri buildCalUri() {
return CalendarContract.Calendars.CONTENT_URI
.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(Calendars.ACCOUNT_NAME, ACCOUNT_NAME)
.appendQueryParameter(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
.build();
}
I'm hoping this is something similar to what I need but I'm very unsure. In the developer tutorial ACCOUNT_TYPE_LOCAL was important if the account wasn't on the device
Any help will be greatly appreciated!
If you are looking to integrate the public Google Calendar (www.google.com/calendar) with your Android Application, you have to use the Google Calendar API.
The easiest method would be download the Google Calendar Client Library from here and then use the API Reference here. In the Client Library Page, you want to download "Google APIs Client Library for Java (rc)" package to integrate into your Android App.
You will first need to go to API Console to create an App with Calendar API Access .
If you do not want to use the native library, you can even do it using REST API (use HTTP GET & POST Commands), example App here
Hope this helps.
For anybody that has followed the Android Developer API example, but still can't find how to add a public calendar. Try out
CalendarListEntry gracieCal = new CalendarListEntry();
gracieCal.setId("your-public-calendar-id");
mService.calendarList().insert(gracieCal);
Events events = mService.events().list(gracieCal.getId())
.setMaxResults(10)
.setTimeMin(new DateTime(System.currentTimeMillis()))
.setOrderBy("startTime")
.setSingleEvents(true)
.execute();
List<Event> items = events.getItems();
'mService' is the com.google.api.services.calendar.Calendar instance that you should have already created. (see the api tutorials mentioned by the other answer)
'your-public-calendar-id' can be found in the settings for your public google calendar.

java/nio/charset/Charsets error in Android Studio using DatePicker

I receive this error in Android Studio when I try to render a DatePicker:
Rendering Problems Exception raised during rendering: java/nio/charset/Charsets
When I delete the DataPicker from raw XML the error dissappears and I can work normally with my layout, but as soon as I try to add a DataPicker this error appears and I cannot see any component in the Component Tree, nor any activity in the activity view (where I operate with the design of my layout).
I'm using API 16 to render the layout (since APIs 17 & 18 are broken with CalendarView & DataPicker) and for locale I have es-ES.
What can I do to solve this error or, at least, be able to work in Design view with a DataPicker?

Categories