Skip to content

Commit 2d7d61d

Browse files
committed
Move GPUImageView to library
1 parent d436c5f commit 2d7d61d

1 file changed

Lines changed: 21 additions & 46 deletions

File tree

library/src/main/java/jp/co/cyberagent/android/gpuimage/GPUImageView.java

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
public class GPUImageView extends FrameLayout {
5454

55-
private int surfaceType = SURFACE_TYPE_SURFACE_VIEW;
55+
private int surfaceType = SURFACE_TYPE_TEXTURE_VIEW;
5656
private View surfaceView;
5757
private GPUImage gpuImage;
5858
private boolean isShowLoading = true;
@@ -100,46 +100,11 @@ private void init(Context context, AttributeSet attrs) {
100100
addView(surfaceView, surfaceViewLayoutParams);
101101
}
102102

103-
// @Override
104-
// protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
105-
// if (ratio != 0.0f) {
106-
// int width = MeasureSpec.getSize(widthMeasureSpec);
107-
// int height = MeasureSpec.getSize(heightMeasureSpec);
108-
//
109-
// int newHeight;
110-
// int newWidth;
111-
// if (width / ratio < height) {
112-
// newWidth = width;
113-
// newHeight = Math.round(width / ratio);
114-
// } else {
115-
// newHeight = height;
116-
// newWidth = Math.round(height * ratio);
117-
// }
118-
//
119-
// LayoutParams layoutParams = (LayoutParams) surfaceView.getLayoutParams();
120-
// layoutParams.width = newWidth;
121-
// layoutParams.height = newHeight;
122-
// surfaceView.setLayoutParams(layoutParams);
123-
//
124-
// Log.d("GPUImageView", "onMeasure: " + newWidth + "x" + newHeight);
125-
//
126-
//// int newWidthSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
127-
//// int newHeightSpec = MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY);
128-
//// super.onMeasure(newWidthSpec, newHeightSpec);
129-
// super.onMeasure(widthMeasureSpec, heightMeasureSpec);
130-
// } else {
131-
// super.onMeasure(widthMeasureSpec, heightMeasureSpec);
132-
// }
133-
// }
134-
135103
@Override
136-
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
137-
super.onSizeChanged(w, h, oldw, oldh);
138-
refreshSurfaceViewSize(w, h);
139-
}
140-
141-
private void refreshSurfaceViewSize(int width, int height) {
104+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
142105
if (ratio != 0.0f) {
106+
int width = MeasureSpec.getSize(widthMeasureSpec);
107+
int height = MeasureSpec.getSize(heightMeasureSpec);
143108

144109
int newHeight;
145110
int newWidth;
@@ -151,13 +116,11 @@ private void refreshSurfaceViewSize(int width, int height) {
151116
newWidth = Math.round(height * ratio);
152117
}
153118

154-
LayoutParams layoutParams = (LayoutParams) surfaceView.getLayoutParams();
155-
layoutParams.width = newWidth;
156-
layoutParams.height = newHeight;
157-
surfaceView.setLayoutParams(layoutParams);
158-
requestLayout();
159-
160-
Log.d("GPUImageView", "onMeasure: " + newWidth + "x" + newHeight);
119+
int newWidthSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
120+
int newHeightSpec = MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY);
121+
super.onMeasure(newWidthSpec, newHeightSpec);
122+
} else {
123+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
161124
}
162125
}
163126

@@ -316,6 +279,18 @@ public void setImage(final File file) {
316279
gpuImage.setImage(file);
317280
}
318281

282+
public boolean isFlipHorizontally() {
283+
return gpuImage.getRenderer().isFlippedHorizontally();
284+
}
285+
286+
public boolean isFlipVertically() {
287+
return gpuImage.getRenderer().isFlippedVertically();
288+
}
289+
290+
public Rotation getCurrentRotation() {
291+
return gpuImage.getRenderer().getRotation();
292+
}
293+
319294
public void requestRender() {
320295
if (surfaceView instanceof GLSurfaceView) {
321296
((GLSurfaceView) surfaceView).requestRender();

0 commit comments

Comments
 (0)