1

i try to use Blurry effect library in listview

i want to add blur effect when imageview clicked

        ivMemoriesImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < Title.length; i++) {
                Check[i] = false;
            }
            Check[position] = true;
            notifyDataSetChanged();
        }
    });

this is my code that i change a boolean array value to true and then

notifyDataSetChanged();

to reload items of listview

then second part of my code

if (Check[position]) {
        ivMemoriesImage.setBackgroundResource(Image[position]);
        Blurry.with(mContext)
                .radius(5)
                .sampling(2)
                .async()
                .animate(1000)
                .capture(ivMemoriesImage)
                .into(ivMemoriesImage);
        Animation fadeIn = new AlphaAnimation(0, 1);
        fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
        fadeIn.setDuration(1000);
        tvTitle.setAnimation(fadeIn);
        llButtonsAllMemories.setAnimation(fadeIn);
        tvTitle.setVisibility(View.VISIBLE);
        llButtonsAllMemories.setVisibility(View.VISIBLE);
    } else {
        Animation fadeOut = new AlphaAnimation(1, 0);
        fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
        fadeOut.setStartOffset(1000);
        fadeOut.setDuration(1000);
        tvTitle.setAnimation(fadeOut);
        llButtonsAllMemories.setAnimation(fadeOut);
        tvTitle.setVisibility(View.GONE);
        llButtonsAllMemories.setVisibility(View.GONE);
        ivMemoriesImage.setBackgroundResource(Image[position]);
    }

but the blur effect doesn't work if boolean array's value == true
at first i set original image to imageView then i add blur effect , but nothing happen !

any help please ?

UPDATE: i used the library and it works , but i think the original image set after the blur effect added or s.th like this , any other idea ? :)

my adapter class

public class AllMemoriesAdapter extends BaseAdapter {

private Context mContext;
private String[] Title;
private int[] Image;
private boolean[] Check;
private Activity Activity;

private TextView tvTitle;
private ImageView ivMemoriesImage;
private ShineButton shineButton;
private LinearLayout llButtonsAllMemories;

public AllMemoriesAdapter(Activity activity, Context context, String[] title, int[] image, boolean[] check) {
    mContext = context;
    Title = title;
    Image = image;
    Check = check;
    Activity = activity;
}

@Override
public int getCount() {
    return Title.length;
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return position;
}

@SuppressLint("ViewHolder")
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {

    final View view;

    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    view = inflater.inflate(R.layout.adapter_all_memories, parent, false);

    Typeface sansFont = Typeface.createFromAsset(mContext.getAssets(), "fonts/sans.ttf");

    tvTitle = (TextView) view.findViewById(R.id.tvSummery);
    shineButton = (ShineButton) view.findViewById(R.id.sbLoveAllMemories);
    llButtonsAllMemories = (LinearLayout) view.findViewById(R.id.llButtonsAllMemories);
    shineButton.init(Activity);

    tvTitle.setTypeface(sansFont);
    tvTitle.setText(Title[position]);

    ivMemoriesImage = (ImageView) view.findViewById(R.id.ivMemoriesPic);


    ivMemoriesImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < Title.length; i++) {
                Check[i] = false;
            }
            Check[position] = true;
            notifyDataSetChanged();
        }
    });

    if (Check[position]) {
        ivMemoriesImage.setImageResource(Image[position]);
        Blurry.with(mContext)
                .radius(5)
                .sampling(2)
                .async()
                .animate(1000)
                .capture(ivMemoriesImage)
                .into(ivMemoriesImage);
        Animation fadeIn = new AlphaAnimation(0, 1);
        fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
        fadeIn.setDuration(1000);
        tvTitle.setAnimation(fadeIn);
        llButtonsAllMemories.setAnimation(fadeIn);
        tvTitle.setVisibility(View.VISIBLE);
        llButtonsAllMemories.setVisibility(View.VISIBLE);
    } else {
        ivMemoriesImage.setImageResource(Image[position]);
        Animation fadeOut = new AlphaAnimation(1, 0);
        fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
        fadeOut.setStartOffset(1000);
        fadeOut.setDuration(1000);
        tvTitle.setAnimation(fadeOut);
        llButtonsAllMemories.setAnimation(fadeOut);
        tvTitle.setVisibility(View.GONE);
        llButtonsAllMemories.setVisibility(View.GONE);
    }

    return (view);
}

}

hassan moradnezhad
  • 455
  • 2
  • 6
  • 26
  • In demo sample of Blurry library, image is set in ImageView as source, not background https://github.com/wasabeef/Blurry/blob/master/example/src/main/res/layout/activity_main.xml Try to replace ivMemoriesImage.setBackgroundResource(Image[position]); by ivMemoriesImage.setImageResource(Image[position]); – smora Aug 26 '17 at 12:12
  • thanks for your answer , but that's for updating image of my own listview , not blur library . but i try it , and now it doesn't show an image :)))) just a white background set instead of image that means no image set to imageview!!!! – hassan moradnezhad Aug 26 '17 at 12:17
  • Maybe you can precise where your second part of code is called, could be du to adapter cycle. do you add this in bind view method ? – smora Aug 26 '17 at 12:22
  • i'm new in android , and my english language is awful , i update my post and add my complete code , if i understand your question – hassan moradnezhad Aug 26 '17 at 12:27
  • ok no problem ! You should follow the correct adapter/viewHolder pattern, take a look at https://stackoverflow.com/a/24865351/1469481 . You'd better also not getting your typeFace in getView method but in constructor, much more better for performance ! It maybe not fix your problem, but its the way to follow for using adapter. – smora Aug 26 '17 at 12:45

0 Answers0