0

The problem is that the logs program goes inside if condition but ignoring part of the code. But on another item, it works correctly. So the logic is that in viewpager on all items which positions more than 2 they suppose to be blurred and call popup view. Now the popup appears on 3rd item BUT without blur. And on 4th item, everything works fine

Here is the code of the class

public class CardsViewPager extends PagerAdapter {

    private Context context;
    private List<CardUnit> cardList;
    private LayoutInflater layoutInflater;
    private TextView mTitle;
    private TextView mDescription;

    public CardsViewPager(Context context, List<CardUnit> cards) {
        this.context = context;
        this.cardList = cards;
        layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return cardList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((ScrollView) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        View itemView = layoutInflater.inflate(R.layout.item_card, container, false);
        mDescription = itemView.findViewById(R.id.item_card_description);
        mDescription.setText(cardList.get(position).getDescription());
        mTitle = itemView.findViewById(R.id.item_card_title);
        mTitle.setText(cardList.get(position).getTitle());
        ImageView imageView = itemView.findViewById(R.id.item_card_image);
        Glide.with(context).load(cardList.get(position).getImage()).into(imageView);
        container.addView(itemView);
        if (position > 2) {
            EventBus.getDefault().post(new BooleanEvent(true));
            AdLauncher.getInstance().launchAd();
        }

        if (SharPrefManager.getInstance().grabLockStatus().equals("")) {
            lockTheItem(position);
        }


        return itemView;
    }

    /**
     * Blur the text and show view for unlock the card
     *
     * @param position
     */
    private void lockTheItem(int position) {

        if (position > 2) {
            if (Build.VERSION.SDK_INT >= 11) {
                mDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
                mTitle.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
            }
            float descriptionRadius = mDescription.getTextSize() / 4;
            float titleRadius = mDescription.getTextSize() / 4;
            BlurMaskFilter filterDescription = new BlurMaskFilter(descriptionRadius, BlurMaskFilter.Blur.NORMAL);
            BlurMaskFilter filterTitle = new BlurMaskFilter(titleRadius, BlurMaskFilter.Blur.NORMAL);
            mDescription.getPaint().setMaskFilter(filterDescription);
            mTitle.getPaint().setMaskFilter(filterTitle);
            EventBus.getDefault().post(new UnlockEvent(false));
        } else {
            EventBus.getDefault().post(new UnlockEvent(true));
        }
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((ScrollView) object);
    }
}

Problem method is lockTheItem() When it goes inside >2 it sends the intent but not making a blur. On the next item, everything works correctly

Bo Z
  • 2,359
  • 1
  • 13
  • 31
  • You need to be a lot clearer. What is blurring? Are yiou saying aDlauncher is not being called? This is too confusing to answer and will likely get closed unless you can provide clarity – jamesc Aug 29 '19 at 19:25
  • @jamesc it is difficult to explain in words. the problem is it trigger when position of PagerAdapter is appear but programm ignore some code and some not. But if i swipe adapter until end of the list and go back to the same spot it works perfectly fine. looks like a bug. this looks like something near https://stackoverflow.com/questions/11281404/android-blurmaskfilter-has-no-effect-in-canvas-drawoval-while-text-is-blurred – Bo Z Aug 29 '19 at 19:36
  • @jamesc i guess the problem is that i am putting blur effect when view is already done. so thats why it is updating only for next item. but because call back goes separately part second part appear correctly. So i need somehow update view in pageradapter when needed and it will work. But i dont find anything about lifecycle of the views in pageradapter – Bo Z Aug 29 '19 at 20:02
  • @jamesc yes. i was right. the problem was that view is already created when i call the method. so i changed it to send callback from activity to adapter so it update views properly – Bo Z Aug 29 '19 at 20:45
  • You should answer your own question. Glad you found the solution – jamesc Aug 29 '19 at 22:26

0 Answers0