-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCameraLensViewFragment.java
More file actions
146 lines (127 loc) · 5.6 KB
/
CameraLensViewFragment.java
File metadata and controls
146 lines (127 loc) · 5.6 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package jsc.exam.com.cameramask.fragments;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import jsc.exam.com.cameramask.R;
import jsc.exam.com.cameramask.widgets.dialog.BottomShowDialog;
import jsc.kit.cameramask.CameraLensView;
/**
* <br>Email:1006368252@qq.com
* <br>QQ:1006368252
* <br><a href="https://github.com/JustinRoom/CameraMaskDemo" target="_blank">https://github.com/JustinRoom/CameraMaskDemo</a>
*
* @author jiangshicheng
*/
public class CameraLensViewFragment extends Fragment {
private ImageView ivBackground;
private CameraLensView cameraLensView;
private Bitmap defaultCameraLensBitmap = null;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_camera_lens_view, container, false);
initView(root);
return root;
}
private void initView(View root) {
ivBackground = root.findViewById(R.id.iv_background);
cameraLensView = root.findViewById(R.id.camera_lens_view);
RadioGroup typeRadioGroup = root.findViewById(R.id.radio_group_type);
typeRadioGroup.check(R.id.radio_type_picture);
typeRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_type_picture:
if (defaultCameraLensBitmap == null)
defaultCameraLensBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.default_camera_lens);
cameraLensView.setCameraLensBitmap(defaultCameraLensBitmap);
break;
case R.id.radio_type_normal:
cameraLensView.setCameraLensBitmap(null);
break;
}
}
});
RadioGroup shapeRadioGroup = root.findViewById(R.id.radio_group_shape);
shapeRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_shape_circle:
cameraLensView.setCameraLensShape(CameraLensView.CIRCULAR);
break;
case R.id.radio_shape_square:
cameraLensView.setCameraLensShape(CameraLensView.RECTANGLE);
break;
}
}
});
RadioGroup locationRadioGroup = root.findViewById(R.id.radio_group_location);
locationRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_location_below:
cameraLensView.setTextLocation(CameraLensView.BELOW_CAMERA_LENS);
break;
case R.id.radio_location_above:
cameraLensView.setTextLocation(CameraLensView.ABOVE_CAMERA_LENS);
break;
}
}
});
SeekBar topMarginSeekBar = root.findViewById(R.id.seek_bar_top_margin);
topMarginSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
cameraLensView.setCameraLensTopMargin(progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
SeekBar textVerticalMarginSeekBar = root.findViewById(R.id.seek_bar_vertical_margin);
textVerticalMarginSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
cameraLensView.setTextVerticalMargin(progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
root.findViewById(R.id.show_camera_lens_rect_bitmap).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCameraLensRectBitmap();
}
});
}
private void showCameraLensRectBitmap() {
ivBackground.setDrawingCacheEnabled(true);
Bitmap bitmap = ivBackground.getDrawingCache(true);
bitmap = cameraLensView.cropCameraLensRectBitmap(bitmap, false);
ImageView imageView = new ImageView(getContext());
imageView.setImageBitmap(bitmap);
BottomShowDialog dialog = new BottomShowDialog(getContext());
dialog.setTitle("ShowBitmapInCameraLensRect");
dialog.setBitmap(bitmap);
dialog.show();
}
}