use of com.codename1.ui.Label 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");
}
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class ComponentSelector method setIcon.
/**
* Sets the icon of all elements in this set to a material icon. This will use
* the foreground color of the label.
* @param materialIcon The material icon charcode.
* @return Self for chaining.
*/
public ComponentSelector setIcon(char materialIcon) {
for (Component c : this) {
if (c instanceof Label) {
Label l = (Label) c;
Style style = new Style();
Style cStyle = c.getUnselectedStyle();
style.setBgTransparency(0);
style.setFgColor(cStyle.getFgColor());
l.setIcon(FontImage.createMaterial(materialIcon, style, 3));
if (c instanceof Button) {
Button b = (Button) c;
style = new Style();
cStyle = c.getPressedStyle();
style.setBgTransparency(0);
style.setFgColor(cStyle.getFgColor());
b.setPressedIcon(FontImage.createMaterial(materialIcon, style, 3));
}
}
}
return this;
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class SMSShare method share.
/**
* {@inheritDoc}
*/
public void share(final String toShare) {
final Form currentForm = Display.getInstance().getCurrent();
final Form contactsForm = new Form("Contacts");
contactsForm.setScrollable(false);
contactsForm.setLayout(new BorderLayout());
contactsForm.addComponent(BorderLayout.CENTER, new Label("Please wait..."));
contactsForm.show();
Display.getInstance().startThread(new Runnable() {
public void run() {
String[] ids = ContactsManager.getAllContacts();
if (ids == null || ids.length == 0) {
Display.getInstance().callSerially(new Runnable() {
public void run() {
Dialog.show("Failed to Share", "No Contacts Found", "Ok", null);
currentForm.showBack();
}
});
return;
}
ContactsModel model = new ContactsModel(ids);
final List contacts = new List(model);
contacts.setRenderer(createListRenderer());
Display.getInstance().callSerially(new Runnable() {
public void run() {
contacts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
final ShareForm[] f = new ShareForm[1];
final Hashtable contact = (Hashtable) contacts.getSelectedItem();
f[0] = new ShareForm(contactsForm, "Send SMS", (String) contact.get("phone"), toShare, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
Display.getInstance().sendSMS(f[0].getTo(), f[0].getMessage());
} catch (IOException ex) {
Log.e(ex);
System.out.println("failed to send sms to " + (String) contact.get("phone"));
}
finish();
}
});
f[0].show();
}
});
contactsForm.addComponent(BorderLayout.CENTER, contacts);
Command back = new Command("Back") {
public void actionPerformed(ActionEvent evt) {
currentForm.showBack();
}
};
contactsForm.addCommand(back);
contactsForm.setBackCommand(back);
contactsForm.revalidate();
}
});
}
}, "SMS Thread").start();
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class TestUtils method clickButtonByLabel.
/**
* Clicks the button with the given label
* @param text the text on the button
*/
public static void clickButtonByLabel(String text) {
if (verbose) {
log("clickButtonByLabel(" + text + ")");
}
Button b = (Button) findLabelText(text);
waitFor(20);
b.pressed();
waitFor(20);
b.released();
waitFor(20);
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class TestUtils method setText.
/**
* Sets the text for the given component
* @param path the path to the component
* @param text the text to set
*/
public static void setText(int[] path, String text) {
if (verbose) {
log("setText(" + toString(path) + ", " + text + ")");
}
Component c = getComponentByPath(path);
if (c instanceof Label) {
((Label) c).setText(text);
return;
}
((TextArea) c).setText(text);
}
Aggregations