forked from Dimezis/BlurView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddRemoveViewBlurFragment.java
81 lines (63 loc) · 2.66 KB
/
AddRemoveViewBlurFragment.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.eightbitlab.blurview_sample;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.eightbitlab.supportrenderscriptblur.SupportRenderScriptBlur;
import eightbitlab.com.blurview.BlurView;
import eightbitlab.com.blurview.BlurViewFacade;
import eightbitlab.com.blurview.RenderScriptBlur;
public class AddRemoveViewBlurFragment extends BaseFragment {
private View decorView;
private ViewGroup rootView;
private FrameLayout container;
private Button addBlurViewBtn;
@Override
int getLayoutId() {
return R.layout.fragment_add_remove_blur_fragment;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
decorView = requireActivity().getWindow().getDecorView();
rootView = decorView.findViewById(android.R.id.content);
container = requireView().findViewById(R.id.blurContainer);
addBlurViewBtn = view.findViewById(R.id.addBlurViewBtn);
addBlurViewBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (container.getChildCount() > 0) {
container.removeAllViews();
addBlurViewBtn.setText("Add Blur View");
} else {
//While added BlurView more than once, the issue appears
addBlurView();
addBlurView();
addBlurViewBtn.setText("Remove Blur View");
}
}
});
}
void addBlurView() {
View blurItem = LayoutInflater.from(requireContext()).inflate(R.layout.item_blur_view, container, false);
container.addView(blurItem);
final BlurView blurView = blurItem.findViewById(R.id.blurView);
BlurViewFacade facade = blurView.setupWith(rootView)
.setFrameClearDrawable(decorView.getBackground())
.setBlurRadius(4f)
.setOverlayColor(Color.parseColor("#1AFFFFFF"))
.setBlurAutoUpdate(true)
.setHasFixedTransformationMatrix(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
facade.setBlurAlgorithm(new RenderScriptBlur(requireContext()));
} else {
facade.setBlurAlgorithm(new SupportRenderScriptBlur(requireContext()));
}
}
}