use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class GameCanvasImplementation method captureAudio.
public void captureAudio(ActionListener response) {
captureResponse = response;
try {
final Form current = Display.getInstance().getCurrent();
final MMAPIPlayer player = MMAPIPlayer.createPlayer("capture://audio", null);
RecordControl record = (RecordControl) player.nativePlayer.getControl("RecordControl");
if (record == null) {
player.cleanup();
throw new RuntimeException("Capture Audio is not supported on this device");
}
final Form cam = new Form();
cam.setTransitionInAnimator(CommonTransitions.createEmpty());
cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
cam.setLayout(new BorderLayout());
cam.show();
player.play();
final Label time = new Label("0:00");
cam.addComponent(BorderLayout.SOUTH, time);
cam.revalidate();
ActionListener l = new ActionListener() {
boolean recording = false;
OutputStream out = null;
String audioPath = null;
RecordControl record;
public void actionPerformed(ActionEvent evt) {
if (!recording) {
record = (RecordControl) player.nativePlayer.getControl("RecordControl");
recording = true;
String type = record.getContentType();
String prefix = "";
if (type.endsWith("wav")) {
prefix = ".wav";
} else if (type.endsWith("amr")) {
prefix = ".amr";
} else if (type.endsWith("3gpp")) {
prefix = ".3gp";
}
audioPath = getOutputMediaFile() + prefix;
try {
out = FileSystemStorage.getInstance().openOutputStream(audioPath);
record.setRecordStream(out);
record.startRecord();
cam.registerAnimated(new Animation() {
long current = System.currentTimeMillis();
long zero = current;
int sec = 0;
public boolean animate() {
long now = System.currentTimeMillis();
if (now - current > 1000) {
current = now;
sec++;
return true;
}
return false;
}
public void paint(Graphics g) {
String txt = sec / 60 + ":" + sec % 60;
time.setText(txt);
}
});
} catch (IOException ex) {
ex.printStackTrace();
System.out.println("failed to store audio to " + audioPath);
} finally {
}
} else {
if (out != null) {
try {
record.stopRecord();
record.commit();
out.close();
player.cleanup();
} catch (Exception ex) {
ex.printStackTrace();
}
}
captureResponse.actionPerformed(new ActionEvent(audioPath));
current.showBack();
}
}
};
cam.addGameKeyListener(Display.GAME_FIRE, l);
cam.addPointerReleasedListener(l);
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException("failed to start camera");
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class Component method deinitializeImpl.
/**
* Cleansup the initialization flags in the hierachy, notice that paint calls might
* still occur after deinitilization mostly to perform transitions etc.
* <p>However interactivity, animation and event tracking code can and probably
* should be removed by this method.
*/
void deinitializeImpl() {
if (isInitialized()) {
hideNativeOverlay();
paintLockRelease();
setInitialized(false);
setDirtyRegion(null);
Style stl = getStyle();
Image i = stl.getBgImage();
if (i != null) {
i.unlock();
} else {
Border b = stl.getBorder();
if (b != null) {
b.unlock();
}
}
Painter p = stl.getBgPainter();
if (p instanceof BGPainter) {
((BGPainter) p).radialCache = null;
}
deinitialize();
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class Component method paintLock.
/**
* This method locks the component so it will always paint the given image
* instead of running through its paint logic. This is useful when running
* transitions that might be quite expensive on the device. A lock should
* be released using paintLockRelease(), it is implicitly released when
* a component is deinitialized although a component doesn't need to be initialized
* to be locked!<br>
* If the component is not opaque null is always returned!
* <p>Duplicate calls to this method won't produce duplicate locks, in case of
* a soft lock the return value will always be null.
*
* @param hardLock indicates whether the lock uses a hard or a soft reference to the image
* @return the image in case of a hard lock
*/
public Image paintLock(boolean hardLock) {
if (!paintLockEnableChecked) {
paintLockEnableChecked = true;
paintLockEnabled = Display.getInstance().getProperty("paintLockEnabled", "true").equals("true");
}
if (!paintLockEnabled || !Display.getInstance().areMutableImagesFast()) {
return null;
}
if ((getStyle().getBgTransparency() & 0xff) != 0xff) {
return null;
}
if (paintLockImage == null) {
paintLockImage = Image.createImage(getWidth(), getHeight());
int x = getX();
int y = getY();
setX(0);
setY(0);
paintInternalImpl(((Image) paintLockImage).getGraphics(), false);
setX(x);
setY(y);
if (hardLock) {
return (Image) paintLockImage;
} else {
paintLockImage = Display.getInstance().createSoftWeakRef(paintLockImage);
}
} else {
if (hardLock) {
return (Image) paintLockImage;
}
}
return null;
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class Container method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
if (enableLayoutOnPaint) {
layoutContainer();
}
g.translate(getX(), getY());
int size = components.size();
int startIter = 0;
if (size >= 30) {
int clipX1 = g.getClipX();
int clipX2 = g.getClipX() + g.getClipWidth();
int clipY1 = g.getClipY();
int clipY2 = g.getClipY() + g.getClipHeight();
startIter = calculateFirstPaintableOffset(clipX1, clipY1, clipX2, clipY2);
if (startIter < 0) {
// There was no efficient way to calculate the offset
startIter = 0;
} else if (startIter < size) {
// There was an efficient way to calculate the offset so we
// will continue this approach
size = calculateLastPaintableOffset(startIter, clipX1, clipY1, clipX2, clipY2) + 1;
}
}
CodenameOneImplementation impl = Display.impl;
if (dontRecurseContainer) {
for (int iter = startIter; iter < size; iter++) {
Component cmp = components.get(iter);
if (cmp.getClass() == Container.class) {
paintContainerChildrenForAnimation((Container) cmp, g);
} else {
cmp.paintInternal(impl.getComponentScreenGraphics(this, g), false);
}
}
} else {
for (int iter = startIter; iter < size; iter++) {
Component cmp = components.get(iter);
cmp.paintInternal(impl.getComponentScreenGraphics(this, g), false);
}
}
int tx = g.getTranslateX();
int ty = g.getTranslateY();
g.translate(-tx, -ty);
if (sidemenuBarTranslation > 0) {
g.translate(sidemenuBarTranslation, 0);
paintGlass(g);
paintTensile(g);
g.translate(-sidemenuBarTranslation, 0);
} else {
paintGlass(g);
paintTensile(g);
}
g.translate(tx, ty);
g.translate(-getX(), -getY());
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class Container method isObscuredByChildren.
/**
* Invoked internally to indicate if child components are hiding this container
* thus removing the need to invoke its own paint methods
* @return true if child components are obscuring this component
*/
boolean isObscuredByChildren() {
if (!blockOverdraw) {
return false;
}
if (!getLayout().obscuresPotential(this)) {
return false;
}
Style s = getStyle();
if (s.getPaddingTop() != 0 || s.getPaddingLeftNoRTL() != 0 || s.getPaddingRightNoRTL() != 0 || s.getPaddingBottom() != 0) {
return false;
}
int size = components.size();
for (int iter = 0; iter < size; iter++) {
Component cmp = components.get(iter);
s = cmp.getStyle();
if (cmp.getWidth() == 0 || cmp.getHeight() == 0) {
continue;
}
// need to think of a better way, this means we invoke the same logic recurisvely again and again by a factor of depth. Not good...
if (cmp instanceof Container) {
if (!((Container) cmp).getLayout().obscuresPotential(this)) {
return false;
}
if (s.getOpacity() != 0xff || s.getMarginTop() != 0 || s.getMarginLeftNoRTL() != 0 || s.getMarginRightNoRTL() != 0 || s.getMarginBottom() != 0) {
return false;
}
if ((s.getBgTransparency() & 0xff) != 0xff && !((Container) cmp).isObscuredByChildren()) {
return false;
}
} else {
if ((s.getBgTransparency() & 0xff) != 0xff || s.getOpacity() != 0xff || s.getMarginTop() != 0 || s.getMarginLeftNoRTL() != 0 || s.getMarginRightNoRTL() != 0 || s.getMarginBottom() != 0) {
return false;
}
}
}
return true;
}
Aggregations