Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1px artifact in middle of range selection #377

Open
npmrtsv opened this issue Jul 5, 2017 · 10 comments
Open

1px artifact in middle of range selection #377

npmrtsv opened this issue Jul 5, 2017 · 10 comments
Labels

Comments

@npmrtsv
Copy link

npmrtsv commented Jul 5, 2017

When I'm using custom CellDecorator with DayViewAdapter, I have a strange artefact.

screen shot 2017-07-06 at 12 44 57 am

@edenman
Copy link
Collaborator

edenman commented Jul 5, 2017

@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 edenman closed this as completed Jul 5, 2017
@npmrtsv
Copy link
Author

npmrtsv commented Jul 6, 2017

@edenman Ok, no problem, here is an example. https://github.com/quaddef/android-times-square-example

@fandyaditya
Copy link

i have some problem to, when i set the divider color to 0 (i want no divider) in CalenderPickerView, this thing happen
capture

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>

@edenman edenman reopened this Jul 10, 2017
@edenman
Copy link
Collaborator

edenman commented Jul 10, 2017

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.

@Dragas
Copy link

Dragas commented Jul 12, 2017

@edenman Sometimes such artifacts happen using ViewPager with non-standard page width, for example 7% of the view's width.

@fandyaditya
Copy link

Maybe there is another way to disable the divider except make it 0 in CalenderPickerView.class ?

@bbil
Copy link

bbil commented Aug 1, 2017

I have this exact issue that I commented in #371

@ChetnaNakum
Copy link

I have this exact issue #377

@MasterEmit
Copy link

Same issue at our side #377

@MasterEmit
Copy link

MasterEmit commented Dec 26, 2017

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.

@edenman edenman changed the title Range selection artefact 1px artifact in middle of range selection Jul 3, 2018
@edenman edenman added the bug label Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants