use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class Graphics method setClip.
/**
* Clips the Graphics context to the Shape.
* <p>This is not supported on all platforms and contexts currently.
* Use {@link #isShapeClipSupported} to check if the current
* context supports clipping shapes.</p>
*
* <script src="https://gist.github.com/codenameone/65f531adae2e8c22afc8.js"></script>
* <img src="https://www.codenameone.com/img/blog/shaped-clipping.png" alt="Shaped clipping in action" />
*
* @param shape The shape to clip.
* @see #isShapeClipSupported
*/
public void setClip(Shape shape) {
if (xTranslate != 0 || yTranslate != 0) {
GeneralPath p = tmpClipShape();
p.setShape(shape, translation());
shape = p;
}
impl.setClip(nativeGraphics, shape);
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class Graphics method drawShape.
// --------------------------------------------------------------------------
// START SHAPE DRAWING STUFF
// --------------------------------------------------------------------------
/**
* Draws a outline shape inside the specified bounding box. The bounding box will resize the shape to fit in its dimensions.
* <p>This is not supported on
* all platforms and contexts currently. Use {@link #isShapeSupported} to check if the current
* context supports drawing shapes.</p>
*
* <script src="https://gist.github.com/codenameone/3f2f8cdaabb7780eae6f.js"></script>
* <img src="https://www.codenameone.com/img/developer-guide/graphics-shape-fill.png" alt="Fill a shape general path" />
*
* @param shape The shape to be drawn.
* @param stroke the stroke to use
*
* @see #setStroke
* @see #isShapeSupported
*/
public void drawShape(Shape shape, Stroke stroke) {
if (isShapeSupported()) {
if (xTranslate != 0 || yTranslate != 0) {
GeneralPath p = tmpClipShape();
p.setShape(shape, translation());
shape = p;
}
impl.drawShape(nativeGraphics, shape, stroke);
}
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class Graphics method fillShape.
/**
* Fills the given shape using the current alpha and color settings.
* <p>This is not supported on
* all platforms and contexts currently. Use {@link #isShapeSupported} to check if the current
* context supports drawing shapes.</p>
*
* <script src="https://gist.github.com/codenameone/3f2f8cdaabb7780eae6f.js"></script>
* <img src="https://www.codenameone.com/img/developer-guide/graphics-shape-fill.png" alt="Fill a shape general path" />
*
* @param shape The shape to be filled.
*
* @see #isShapeSupported
*/
public void fillShape(Shape shape) {
if (isShapeSupported()) {
if (xTranslate != 0 || yTranslate != 0) {
GeneralPath p = tmpClipShape();
p.setShape(shape, translation());
shape = p;
}
impl.fillShape(nativeGraphics, shape);
}
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class SideMenuBar method setMenuGlassPane.
private void setMenuGlassPane(Form m, final String placement) {
boolean isRTLValue = m.isRTL();
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
isRTLValue = !isRTLValue;
}
final boolean isRTL = isRTLValue;
final Image image = rightPanel.getStyle().getBgImage();
UIManager uim = rightPanel.getUIManager();
Image sh = (Image) uim.getThemeImageConstant("sideMenuShadowImage");
if (sh == null) {
sh = Resources.getSystemResource().getImage("sidemenu-shadow.png");
}
if (isRTL) {
sh = sh.flipHorizontally(true);
}
final Image shadow = sh;
if (m.getGlassPane() == null) {
m.setGlassPane(new Painter() {
Image img = image;
public void paint(Graphics g, Rectangle rect) {
if (img == null) {
// will happen for areMutableImagesFast returning false on iOS and Windows Phone
Component c = (Component) rightPanel.getClientProperty("$parent");
// not sure what is happening here
if (c == null) {
return;
}
boolean b = c.isVisible();
c.setVisible(true);
if (isRTL) {
int x = Math.max(draggedX, rightPanel.getWidth()) - c.getWidth();
g.translate(x, 0);
Container.sidemenuBarTranslation = x;
if (shadow != null) {
g.tileImage(shadow, x + c.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
c.paintComponent(g, true);
Container.sidemenuBarTranslation = 0;
g.translate(-x, 0);
} else {
int x = Math.min(draggedX, rightPanel.getX());
g.translate(x, 0);
Container.sidemenuBarTranslation = x;
if (shadow != null) {
g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
c.paintComponent(g, true);
Container.sidemenuBarTranslation = 0;
g.translate(-x, 0);
}
c.setVisible(b);
} else {
if (Display.getInstance().areMutableImagesFast()) {
if (img.getHeight() != Display.getInstance().getDisplayHeight()) {
img = updateRightPanelBgImage(placement, parent);
}
}
if (isRTL) {
int x = Math.max(draggedX, rightPanel.getWidth()) - img.getWidth();
if (shadow != null) {
g.tileImage(shadow, x + img.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
g.drawImage(img, x, 0);
} else {
int x = Math.min(draggedX, rightPanel.getX());
if (shadow != null) {
g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
g.drawImage(img, x, 0);
}
}
}
});
}
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class AndroidImplementation method captureAudio.
public void captureAudio(final ActionListener response) {
if (!checkForPermission(Manifest.permission.RECORD_AUDIO, "This is required to record the audio")) {
return;
}
try {
final Form current = Display.getInstance().getCurrent();
final File temp = File.createTempFile("mtmp", ".3gpp");
temp.deleteOnExit();
if (recorder != null) {
recorder.release();
}
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
recorder.setOutputFile(temp.getAbsolutePath());
final Form recording = new Form("Recording");
recording.setTransitionInAnimator(CommonTransitions.createEmpty());
recording.setTransitionOutAnimator(CommonTransitions.createEmpty());
recording.setLayout(new BorderLayout());
recorder.prepare();
recorder.start();
final Label time = new Label("00:00");
time.getAllStyles().setAlignment(Component.CENTER);
Font f = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);
f = f.derive(getDisplayHeight() / 10, Font.STYLE_PLAIN);
time.getAllStyles().setFont(f);
recording.addComponent(BorderLayout.CENTER, time);
recording.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) {
int seconds = sec % 60;
int minutes = sec / 60;
String secStr = seconds < 10 ? "0" + seconds : "" + seconds;
String minStr = minutes < 10 ? "0" + minutes : "" + minutes;
String txt = minStr + ":" + secStr;
time.setText(txt);
}
});
Container south = new Container(new com.codename1.ui.layouts.GridLayout(1, 2));
Command cancel = new Command("Cancel") {
@Override
public void actionPerformed(ActionEvent evt) {
if (recorder != null) {
recorder.stop();
recorder.release();
recorder = null;
}
current.showBack();
response.actionPerformed(null);
}
};
recording.setBackCommand(cancel);
south.add(new com.codename1.ui.Button(cancel));
south.add(new com.codename1.ui.Button(new Command("Save") {
@Override
public void actionPerformed(ActionEvent evt) {
if (recorder != null) {
recorder.stop();
recorder.release();
recorder = null;
}
current.showBack();
response.actionPerformed(new ActionEvent(temp.getAbsolutePath()));
}
}));
recording.addComponent(BorderLayout.SOUTH, south);
recording.show();
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException("failed to start audio recording");
}
}
Aggregations