android-times-square
android-times-square copied to clipboard
1px artifact in middle of range selection
When I'm using custom CellDecorator with DayViewAdapter, I have a strange artefact.

@quaddef without seeing your code, it's impossible to diagnose. either share your xml+DayViewAdapter+CellDecorator code, or try to repro in the sample app and comment here with a link to your fork
@edenman Ok, no problem, here is an example. https://github.com/quaddef/android-times-square-example
i have some problem to, when i set the divider color to 0 (i want no divider) in CalenderPickerView, this thing happen
Here is my code Day view Adapter
public class MyDayViewAdapter implements DayViewAdapter {
@Override
public void makeCellView(CalendarCellView parent) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_custom_dayview,parent);
TextView textView = (TextView)v.findViewById(R.id.my_day_textview);
parent.setDayOfMonthTextView(textView);
}
CellDecorator
public class MyDecorator implements CalendarCellDecorator {
@Override
public void decorate(Context context, CalendarCellView cellView, Date date) {
ImageView image = (ImageView) cellView.getChildAt(0).findViewById(R.id.my_day_imageview);
TextView textView = (TextView)cellView.getChildAt(0).findViewById(R.id.my_day_textview);
textView.setTextColor(cellView.getContext().getColor(R.color.whiteText));
if(!cellView.isEnabled()||!cellView.isSelectable()){
textView.setTextColor(cellView.getContext().getColor(R.color.myInactive));
}
if(cellView.getRangeState().equals(RangeState.FIRST)){
image.setImageResource(R.drawable.bg_firstrange_sample);
}
else if(cellView.isSelected()&&cellView.isToday()){
image.setImageResource(R.drawable.bg_selected_sample);
}
else if(cellView.getRangeState().equals(RangeState.MIDDLE)){
image.setImageResource(R.drawable.bg_midrange_sample);
}
else if(cellView.getRangeState().equals(RangeState.LAST)){
image.setImageResource(R.drawable.bg_range_last);
}
else if(cellView.isToday()){
image.setImageResource(R.drawable.bg_today_sample);
}
else if(cellView.isSelected()){
image.setImageResource(R.drawable.bg_selected_sample);
}
else
image.setImageResource(0);
}
}
custom dayview xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null">
<ImageView
android:id="@+id/my_day_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@null"/>
<TextView
android:id="@+id/my_day_textview"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/CalendarCell.CalendarDate"
android:layout_gravity="center"
android:text=""/>
</FrameLayout>
Sorry for delayed response. I looked at this a bit on Friday but couldn't figure out why there's a 1px gap. I'll try to look again soon, but can't promise I'll get to it this week. Let me know if you figure it out.
@edenman Sometimes such artifacts happen using ViewPager
with non-standard page width, for example 7%
of the view's width.
Maybe there is another way to disable the divider except make it 0 in CalenderPickerView.class ?
I have this exact issue that I commented in #371
I have this exact issue #377
Same issue at our side https://github.com/square/android-times-square/issues/377
I was able to workaround this problem.
I checked the values for width at CalendarCellView and the generated TextView and found out, that they do not match always.
At my device (Samsung Galaxy S7) with a full width of 1080 the CalendarCellView got following width values (from left to right per row) 154,154,154,155,154,154,155 - thats fine to get the full 1080. But the TextView was always set to 154.
So I created my own DayViewTextView class inherited from TextView and just overrode the layout method in following way
override fun layout(l: Int, t: Int, r: Int, b: Int) {
super.layout(l, t, (parent as CalendarCellView).width, b)
}
After that I created my own DayViewAdapter and just adapted it from the default one but used DayViewTextView:
object dayViewAdapter : DayViewAdapter {
override fun makeCellView(parent: CalendarCellView) {
val textView = DatePickerTextView(ContextThemeWrapper(parent.context, com.squareup.timessquare.R.style.CalendarCell_CalendarDate))
textView.isDuplicateParentStateEnabled = true
parent.addView(textView)
parent.setDayOfMonthTextView(textView)
}
}
and used it
calendarPickerView.setCustomDayView(dayViewAdapter)
This solved the problem with the small gap.