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