recruit-mp / LightCalendarView

A lightweight monthly calendar view for Android, fully written in Kotlin. Designed to meet the minimum demands for typical calendars.
Apache License 2.0
445 stars 67 forks source link

Does not work with KitKat (SDK 19) #7

Closed AnthonyTjio closed 7 years ago

AnthonyTjio commented 7 years ago

E/AndroidRuntime: FATAL EXCEPTION: main Process: newage.anthony.atjara, PID: 10694 java.lang.RuntimeException: Unable to start activity ComponentInfo{newage.anthony.atjara/newage.anthony.atjara.EventCalendar.EventCalendarActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class jp.co.recruit_mp.android.lightcalendarview.LightCalendarView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) at android.app.ActivityThread.access$800(ActivityThread.java:139) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:149) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class jp.co.recruit_mp.android.lightcalendarview.LightCalendarView at android.view.LayoutInflater.createView(LayoutInflater.java:620) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at android.view.LayoutInflater.inflate(LayoutInflater.java:353) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) at newage.anthony.atjara.EventCalendar.EventCalendarActivity.onCreate(EventCalendarActivity.java:18) at android.app.Activity.performCreate(Activity.java:5411) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)  at android.app.ActivityThread.access$800(ActivityThread.java:139)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:149)  at android.app.ActivityThread.main(ActivityThread.java:5257)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)  at dalvik.system.NativeStart.main(Native Method)  Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at android.view.LayoutInflater.createView(LayoutInflater.java:594) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)  at newage.anthony.atjara.EventCalendar.EventCalendarActivity.onCreate(EventCalendarActivity.java:18)  at android.app.Activity.performCreate(Activity.java:5411)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)  at android.app.ActivityThread.access$800(ActivityThread.java:139)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:149)  at android.app.ActivityThread.main(ActivityThread.java:5257)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)  at dalvik.system.NativeStart.main(Native Method)  Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x5 at android.content.res.TypedArray.getColor(TypedArray.java:327) at jp.co.recruit_mp.android.lightcalendarview.ContextExtensionsKt.getStyledColor(ContextExtensions.kt:29) at jp.co.recruit_mp.android.lightcalendarview.CalendarSettings$DayView.initializedTodayCirclePaint(CalendarSettings.kt:139) at jp.co.recruit_mp.android.lightcalendarview.CalendarSettings$DayView.(CalendarSettings.kt:136) at jp.co.recruit_mp.android.lightcalendarview.CalendarSettings.(CalendarSettings.kt:32) at jp.co.recruit_mp.android.lightcalendarview.LightCalendarView.(LightCalendarView.kt:36) at jp.co.recruit_mp.android.lightcalendarview.LightCalendarView.(LightCalendarView.kt:74) at jp.co.recruit_mp.android.lightcalendarview.LightCalendarView.(LightCalendarView.kt:73) at java.lang.reflect.Constructor.constructNative(Native Method)  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)  at android.view.LayoutInflater.createView(LayoutInflater.java:594)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)  at newage.anthony.atjara.EventCalendar.EventCalendarActivity.onCreate(EventCalendarActivity.java:18)  at android.app.Activity.performCreate(Activity.java:5411)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)  at android.app.ActivityThread.access$800(ActivityThread.java:139)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:149)  at android.app.ActivityThread.main(ActivityThread.java:5257)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)  at dalvik.system.NativeStart.main(Native Method) 

recruit-mahayash commented 7 years ago

Hi @KenToshi,

Thank you for reporting the issue.

I've been testing using this library on Android KitKat (SDK 19), but so far I cannot reproduce the same error. It looks like the error is caused when setting the DayView background color. We need further more investigation about this.

Could you provide the layout xml file and the code that manipulates LightCalendarView if there are any?

Thank you.

AnthonyTjio commented 7 years ago

Hi @recruit-mahayash

Thanks for the reply, for the xml file I haven't do much customization from README.md

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <jp.co.recruit_mp.android.lightcalendarview.LightCalendarView
        android:id="@+id/calendarView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

By using this xml, it works properly on my Nexus 5 - Android Marshmallow (SDK 23), but not on my Zenfone 6 - Android KitKat (SDK 19)

Thank you

TomislavHorvat1 commented 7 years ago

Hi, I can confirm this issue occurring on my Samsung Tab3. I have also encountered this issue before developing my own library. The issue occurs when you try to set a color for an element using properties like ?attr/colorPrimary. The solution is fairly simple. I will use an example with two buttons requiring two colors, one from the app style and one from android:color

TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.colorAccent, typedValue, true);
int color = typedValue.data;

// coloring buttons for pre lollipop devices
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {

       ((AppCompatButton) nextBtn).setSupportBackgroundTintList(new ColorStateList(new int[][]{new int[0]}, new int[]{color}));
       ((AppCompatButton) skipBtn).setSupportBackgroundTintList(new ColorStateList(new int[][]{new int[0]}, new int[]{android.R.color.white}));

}else{

       nextBtn.setBackgroundTintList(new ColorStateList(new int[][]{new int[0]}, new int[]{color}));
       skipBtn.setBackgroundTintList(new ColorStateList(new int[][]{new int[0]}, new int[]{android.R.color.white}));

}

Hope this helps in resolving this issue

recruit-mahayash commented 7 years ago

@KenToshi and @TomislavHorvat1

Sorry for taking rather a while to reply to this.

Thanks a lot for the investigations and providing the workaround. We will be incorporating this bug fix in the next release.

Thank you.

recruit-mahayash commented 7 years ago

This issue should be fixed in Release 1.0.1.

Thanks!