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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
package com.android.camera.ui;
import android.graphics.Rect;
import android.view.View.MeasureSpec;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.OvershootInterpolator;
import android.view.animation.ScaleAnimation;
import javax.microedition.khronos.opengles.GL11;
public class PopupWindow extends GLView {
protected Texture mAnchor;
protected int mAnchorOffset;
protected int mAnchorPosition;
private final RotatePane mRotatePane = new RotatePane();
protected NinePatchTexture mBackground;
public PopupWindow() {
super.addComponent(mRotatePane);
}
public void setBackground(NinePatchTexture background) {
if (background == mBackground) return;
mBackground = background;
if (background != null) {
setPaddings(mBackground.getPaddings());
} else {
setPaddings(0, 0, 0, 0);
}
invalidate();
}
public void setAnchor(Texture anchor, int offset) {
mAnchor = anchor;
mAnchorOffset = offset;
}
@Override
public void addComponent(GLView component) {
throw new UnsupportedOperationException("use setContent(GLView)");
}
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
int widthMode = MeasureSpec.getMode(widthSpec);
if (widthMode != MeasureSpec.UNSPECIFIED) {
Rect p = mPaddings;
int width = MeasureSpec.getSize(widthSpec);
widthSpec = MeasureSpec.makeMeasureSpec(
Math.max(0, width - p.left - p.right
- mAnchor.getWidth() + mAnchorOffset), widthMode);
}
int heightMode = MeasureSpec.getMode(heightSpec);
if (heightMode != MeasureSpec.UNSPECIFIED) {
int height = MeasureSpec.getSize(widthSpec);
widthSpec = MeasureSpec.makeMeasureSpec(Math.max(
0, height - mPaddings.top - mPaddings.bottom), heightMode);
}
int cWidth = 0;
int cHeight = 0;
Rect p = mPaddings;
GLView child = mRotatePane;
child.measure(widthSpec, heightSpec);
setMeasuredSize(child.getMeasuredWidth()
+ p.left + p.right + mAnchor.getWidth() - mAnchorOffset,
child.getMeasuredHeight() + p.top + p.bottom);
}
@Override
protected void onLayout(
boolean change, int left, int top, int right, int bottom) {
Rect p = getPaddings();
GLView view = mRotatePane;
view.layout(p.left, p.top,
getWidth() - p.right - mAnchor.getWidth() + mAnchorOffset,
getHeight() - p.bottom);
}
public void setAnchorPosition(int yoffset) {
mAnchorPosition = yoffset;
}
@Override
protected void renderBackground(GLRootView rootView, GL11 gl) {
int width = getWidth();
int height = getHeight();
int aWidth = mAnchor.getWidth();
int aHeight = mAnchor.getHeight();
Rect p = mPaddings;
int aXoffset = width - aWidth;
int aYoffset = Math.max(p.top, mAnchorPosition - aHeight / 2);
aYoffset = Math.min(aYoffset, height - p.bottom - aHeight);
if (mAnchor != null) {
if (mAnchor.bind(rootView, gl)) {
rootView.draw2D(aXoffset, aYoffset, aWidth, aHeight);
}
}
Texture backup = null;
try {
backup = rootView.copyTexture2D(
aXoffset, aYoffset, aWidth, aHeight);
} catch (GLOutOfMemoryException e) {
e.printStackTrace();
}
if (mBackground != null) {
mBackground.setSize(width - aWidth + mAnchorOffset, height);
if (mBackground.bind(rootView, gl)) {
rootView.draw2D(
0, 0, mBackground.getWidth(), mBackground.getHeight());
}
}
if (backup.bind(rootView, gl)) {
gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ZERO);
rootView.draw2D(aXoffset, aYoffset, aWidth, aHeight, 1);
gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
}
public void setContent(GLView content) {
mRotatePane.setContent(content);
}
@Override
public void clearComponents() {
throw new UnsupportedOperationException();
}
public void popup() {
setVisibility(GLView.VISIBLE);
AnimationSet set = new AnimationSet(false);
Animation scale = new ScaleAnimation(
0.7f, 1f, 0.7f, 1f, getWidth(), getHeight() / 2);
Animation alpha = new AlphaAnimation(0.5f, 1.0f);
set.addAnimation(scale);
set.addAnimation(alpha);
scale.setDuration(200);
alpha.setDuration(200);
scale.setInterpolator(new OvershootInterpolator());
startAnimation(set);
}
public void popoff() {
setVisibility(GLView.INVISIBLE);
Animation alpha = new AlphaAnimation(0.7f, 0.0f);
alpha.setDuration(100);
startAnimation(alpha);
}
public void setOrientation(int orientation) {
switch (orientation) {
case 90:
mRotatePane.setOrientation(RotatePane.LEFT);
break;
case 180:
mRotatePane.setOrientation(RotatePane.DOWN);
break;
case 270:
mRotatePane.setOrientation(RotatePane.RIGHT);
break;
default:
mRotatePane.setOrientation(RotatePane.UP);
break;
}
}
}
|