use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class Toolbar method constructOnTopSideMenu.
private void constructOnTopSideMenu() {
if (sidemenuDialog == null) {
permanentSideMenuContainer = constructSideNavigationComponent();
final Form parent = getComponentForm();
parent.addPointerPressedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (Display.getInstance().getImplementation().isScrollWheeling()) {
return;
}
if (sidemenuDialog.isShowing()) {
if (evt.getX() > sidemenuDialog.getWidth()) {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.FALSE);
closeSideMenu();
evt.consume();
} else {
if (evt.getX() + Display.getInstance().convertToPixels(8) > sidemenuDialog.getWidth()) {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.TRUE);
} else {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.FALSE);
}
if (!isComponentInOnTopSidemenu(parent.getComponentAt(evt.getX(), evt.getY()))) {
evt.consume();
}
}
} else {
int displayWidth = Display.getInstance().getDisplayWidth();
final int sensitiveSection = displayWidth / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
if (evt.getX() < sensitiveSection) {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.TRUE);
evt.consume();
} else {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.FALSE);
permanentSideMenuContainer.pointerPressed(evt.getX(), evt.getY());
}
}
}
});
parent.addPointerDraggedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (Display.getInstance().getImplementation().isScrollWheeling()) {
return;
}
Boolean b = (Boolean) parent.getClientProperty("cn1$sidemenuCharged");
if (b != null && b.booleanValue()) {
parent.putClientProperty("cn1$sidemenuActivated", Boolean.TRUE);
showOnTopSidemenu(evt.getX(), false);
evt.consume();
} else {
if (sidemenuDialog.isShowing()) {
permanentSideMenuContainer.pointerDragged(evt.getX(), evt.getY());
evt.consume();
}
}
}
});
parent.addPointerReleasedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (Display.getInstance().getImplementation().isScrollWheeling()) {
return;
}
Boolean b = (Boolean) parent.getClientProperty("cn1$sidemenuActivated");
if (b != null && b.booleanValue()) {
parent.putClientProperty("cn1$sidemenuActivated", null);
if (evt.getX() < parent.getWidth() / 4) {
closeSideMenu();
} else {
showOnTopSidemenu(-1, true);
}
evt.consume();
} else {
if (sidemenuDialog.isShowing()) {
if (!isComponentInOnTopSidemenu(parent.getComponentAt(evt.getX(), evt.getY()))) {
evt.consume();
}
permanentSideMenuContainer.pointerReleased(evt.getX(), evt.getY());
}
}
}
});
sidemenuDialog = new InteractionDialog(new BorderLayout());
sidemenuDialog.setFormMode(true);
sidemenuDialog.setUIID("Container");
sidemenuDialog.setDialogUIID("Container");
sidemenuDialog.getTitleComponent().remove();
sidemenuDialog.add(BorderLayout.CENTER, permanentSideMenuContainer);
if (sidemenuSouthComponent != null) {
sidemenuDialog.add(BorderLayout.SOUTH, sidemenuSouthComponent);
}
float size = 4.5f;
try {
size = Float.parseFloat(getUIManager().getThemeConstant("menuImageSize", "4.5"));
} catch (Throwable t) {
Log.e(t);
}
if (!parent.getUIManager().isThemeConstant("hideLeftSideMenuBool", false)) {
Image i = (Image) parent.getUIManager().getThemeImageConstant("sideMenuImage");
if (i != null) {
Command cmd = addCommandToLeftBar("", i, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (sidemenuDialog.isShowing()) {
closeSideMenu();
return;
}
showOnTopSidemenu(-1, false);
}
});
Image p = (Image) parent.getUIManager().getThemeImageConstant("sideMenuPressImage");
if (p != null) {
findCommandComponent(cmd).setPressedIcon(p);
}
} else {
addMaterialCommandToLeftBar("", FontImage.MATERIAL_MENU, size, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (sidemenuDialog.isShowing()) {
closeSideMenu();
return;
}
showOnTopSidemenu(-1, false);
}
});
}
}
}
}
use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class Form method pointerDragged.
/**
* {@inheritDoc}
*/
public void pointerDragged(int x, int y) {
// disable the drag stop flag if we are dragging again
boolean isScrollWheeling = Display.INSTANCE.impl.isScrollWheeling();
if (dragStopFlag) {
pointerPressed(x, y);
}
autoRelease(x, y);
if (pointerDraggedListeners != null) {
ActionEvent av = new ActionEvent(this, ActionEvent.Type.PointerDrag, x, y);
pointerDraggedListeners.fireActionEvent(av);
if (av.isConsumed()) {
return;
}
}
rippleMotion = null;
if (dragged != null) {
dragged.pointerDragged(x, y);
return;
}
if (pressedCmp != null && pressedCmp.isStickyDrag()) {
stickyDrag = pressedCmp;
}
if (stickyDrag != null) {
stickyDrag.pointerDragged(x, y);
repaint();
return;
}
Container actual = getActualPane(formLayeredPane, x, y);
if (x < actual.getX()) {
// special case for sidemenu
Component cmp = ((BorderLayout) super.getLayout()).getWest();
if (cmp != null) {
cmp = ((Container) cmp).getComponentAt(x, y);
while (cmp != null && cmp.isIgnorePointerEvents()) {
cmp = cmp.getParent();
}
if (cmp != null && cmp.isEnabled()) {
cmp.pointerDragged(x, y);
cmp.repaint();
if (cmp == pressedCmp && cmp.isStickyDrag()) {
stickyDrag = cmp;
}
}
}
return;
}
Component cmp = actual.getComponentAt(x, y);
while (cmp != null && cmp.isIgnorePointerEvents()) {
cmp = cmp.getParent();
}
if (cmp != null) {
if (!isScrollWheeling && cmp.isFocusable() && cmp.isEnabled()) {
setFocused(cmp);
}
cmp.pointerDragged(x, y);
cmp.repaint();
if (cmp == pressedCmp && cmp.isStickyDrag()) {
stickyDrag = cmp;
}
}
}
use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class SideMenuBar method validateCommandPlacement.
private void validateCommandPlacement(String placement) {
if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
((BorderLayout) getTitleAreaContainer().getLayout()).setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
if (!(getTitleComponent() instanceof Button)) {
Button b = new Button(parent.getTitle());
b.setUIID("Title");
parent.setTitleComponent(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
openMenu(COMMAND_PLACEMENT_VALUE_TOP);
}
});
}
return;
}
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
if (rightSideButton != null && rightSideButton.getParent() != null) {
return;
}
rightSideButton = new Button();
rightSideButton.setUIID("MenuButtonRight");
UIManager uim = parent.getUIManager();
Image i = (Image) uim.getThemeImageConstant("rightSideMenuImage");
if (i != null) {
rightSideButton.setIcon(i);
} else {
FontImage.setMaterialIcon(rightSideButton, FontImage.MATERIAL_MENU);
}
Image p = (Image) uim.getThemeImageConstant("rightSideMenuPressImage");
if (p != null) {
rightSideButton.setPressedIcon(p);
}
rightSideButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
openMenu(COMMAND_PLACEMENT_VALUE_RIGHT);
}
});
Container ta = getTitleAreaContainer();
ta.addComponent(BorderLayout.EAST, rightSideButton);
ta.revalidate();
return;
}
}
use of com.codename1.ui.layouts.BorderLayout 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.layouts.BorderLayout 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();
}
Aggregations