roomorama / Caldroid

A better calendar for Android
Other
1.42k stars 532 forks source link

how to set cell shape circular #398

Open Sumanth-istar opened 8 years ago

shyamsam commented 8 years ago

@sumanth Did you find any solution for the same ?

Chris59160 commented 8 years ago

I had managed to have the selection highlight circular...but the Square Cell just screws every thing up. Having your own style is far from being as easy as being claimed

dexion commented 7 years ago

You should use custom adapter like this:

public class CaldroidCustomAdapter extends CaldroidGridAdapter {

    public CaldroidCustomAdapter(Context context, int month, int year,
                                       Map<String, Object> caldroidData,
                                       Map<String, Object> extraData) {
        super(context, month, year, caldroidData, extraData);
    }

    @SuppressWarnings("unchecked")
    @Override
    protected void setCustomResources(DateTime dateTime, View backgroundView,
                                      TextView textView) {
        // Set custom background resource
        Map<DateTime, Drawable> backgroundForDateTimeMap = (Map<DateTime, Drawable>) caldroidData
                .get(CaldroidFragment._BACKGROUND_FOR_DATETIME_MAP);
        if (backgroundForDateTimeMap != null) {
            // Get background resource for the dateTime
            ColorDrawable drawable = (ColorDrawable) backgroundForDateTimeMap.get(dateTime);

            // Set it
            if (drawable != null) {
                backgroundView.setBackgroundResource(R.drawable.bg_circle);
                GradientDrawable gd = (GradientDrawable) backgroundView.getBackground();
                //gd.setColor(drawable.getColor());
                gd.setStroke(10, drawable.getColor());
            }
        }
    }
}

in onClickListener set drawable

caldroidFragment.setBackgroundDrawableForDate(new ColorDrawable(0xffff0000), mDate);
caldroidFragment.refreshView();

.../res/drawable/bg_circle.xml may be like this

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <stroke
        android:width="4dp"
        android:color="@color/colorPrimaryDark"/>
</shape>

hide unness colors you may in your style file .../res/cell_bg.xml with @android:color/transparent:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:caldroid="http://schemas.android.com/apk/res-auto">

    <item android:drawable="@drawable/red_border_gray_bg"        android:state_pressed="false" caldroid:state_date_disabled="true" caldroid:state_date_today="true"/>
    <item android:drawable="@drawable/bg_circle"                 android:state_pressed="false" caldroid:state_date_today="true"/>
    <item android:drawable="@android:color/transparent"          android:state_pressed="false" caldroid:state_date_prev_next_month="true"/>
    <item android:drawable="@drawable/disable_cell"                                            caldroid:state_date_disabled="true"/>
    <item android:drawable="@color/bg_swipe_group_item_dismiss"  android:state_pressed="false" caldroid:state_date_selected="true"/>
    <item android:drawable="@android:color/transparent"          android:state_pressed="true"/>
    <item android:drawable="@android:color/transparent"          android:state_pressed="false"/>

</selector>

So it's very simple and useful but not proper documented :(

saiyeshwanth commented 5 years ago

how to set this custom adapter in caldroid?