Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 68 additions & 15 deletions CodenameOne/src/com/codename1/ui/Sheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.codename1.ui.ComponentSelector.ComponentClosure;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import com.codename1.ui.geom.Dimension;
import com.codename1.ui.geom.Rectangle;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
Expand Down Expand Up @@ -119,6 +120,8 @@ public class Sheet extends Container {
private static final int W = 3;
private static final int C = 4;
private static final int DEFAULT_TRANSITION_DURATION = 300;
private static final String SHEET_BLOCKER_PROPERTY = "cn1$sheetBlocker";
private static final String SHEET_LAYER_PROPERTY = "cn1$sheetLayer";
private final Sheet parentSheet;
private final Label title = new Label();
private final EventDispatcher closeListeners = new EventDispatcher();
Expand Down Expand Up @@ -458,15 +461,16 @@ public void run() {
remove();
}
Container cnt = CN.getCurrentForm().getFormLayeredPane(Sheet.class, true);
if (!(cnt.getLayout() instanceof BorderLayout)) {
cnt.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
if (!(cnt.getLayout() instanceof LayeredLayout)) {
cnt.setLayout(new LayeredLayout());

cnt.getStyle().setBgPainter(new ShowPainter());

cnt.revalidate();

}
if (cnt.getComponentCount() > 0) {
Container sheetLayer = getSheetLayer(cnt);
if (sheetLayer.getComponentCount() > 0) {
$(".Sheet", cnt).each(new ComponentClosure() {
@Override
public void call(Component c) {
Expand Down Expand Up @@ -502,17 +506,17 @@ public void call(Component c) {
}

});
Component existing = cnt.getComponentAt(0);
cnt.replace(existing, this, null);
cnt.animateLayout(duration);
Component existing = sheetLayer.getComponentAt(0);
sheetLayer.replace(existing, this, null);
sheetLayer.animateLayout(duration);
} else {
cnt.add(getPosition(), this);
sheetLayer.add(getPosition(), this);

this.setWidth(getPreferredW(cnt));
this.setHeight(getPreferredH(cnt));
this.setX(getHiddenX(cnt));
this.setY(getHiddenY(cnt));
cnt.animateLayout(duration);
this.setWidth(getPreferredW(sheetLayer));
this.setHeight(getPreferredH(sheetLayer));
this.setX(getHiddenX(sheetLayer));
this.setY(getHiddenY(sheetLayer));
sheetLayer.animateLayout(duration);
}
}

Expand Down Expand Up @@ -788,9 +792,10 @@ public void back(int duration) {

private void hide(int duration) {
final Container cnt = CN.getCurrentForm().getFormLayeredPane(Sheet.class, true);
setX(getHiddenX(cnt));
setY(getHiddenY(cnt));
cnt.animateUnlayout(duration, 255, new Runnable() {
final Container sheetLayer = getSheetLayer(cnt);
setX(getHiddenX(sheetLayer));
setY(getHiddenY(sheetLayer));
sheetLayer.animateUnlayout(duration, 255, new Runnable() {
@Override
public void run() {
Container parent = cnt.getParent();
Expand Down Expand Up @@ -920,6 +925,42 @@ private void fireBackEvent() {

}

private Container getSheetLayer(Container cnt) {
Container sheetLayer = (Container) cnt.getClientProperty(SHEET_LAYER_PROPERTY);
if (sheetLayer == null) {
sheetLayer = new Container(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
sheetLayer.setName("SheetLayer");
cnt.putClientProperty(SHEET_LAYER_PROPERTY, sheetLayer);
ensureSheetBlocker(cnt, sheetLayer);
cnt.add(sheetLayer);
} else {
ensureSheetBlocker(cnt, sheetLayer);
}
return sheetLayer;
}

private void ensureSheetBlocker(Container cnt, Container sheetLayer) {
Component blocker = (Component) cnt.getClientProperty(SHEET_BLOCKER_PROPERTY);
if (Form.activePeerCount <= 0) {
if (blocker != null && blocker.getParent() == cnt) { //NOPMD CompareObjectsWithEquals
cnt.removeComponent(blocker);
}
return;
}
if (blocker == null) {
blocker = new SheetBlocker();
cnt.putClientProperty(SHEET_BLOCKER_PROPERTY, blocker);
}
if (blocker.getParent() != cnt) { //NOPMD CompareObjectsWithEquals
int sheetLayerIndex = cnt.getComponentIndex(sheetLayer);
if (sheetLayerIndex > -1) {
cnt.addComponent(sheetLayerIndex, blocker);
} else {
cnt.addComponent(0, blocker);
}
}
}


private static class ShowPainter implements Painter {
@Override
Expand All @@ -932,4 +973,16 @@ public void paint(Graphics g, Rectangle rect) {
}

}

private static class SheetBlocker extends Container {
SheetBlocker() {
setGrabsPointerEvents(true);
setUIID("SheetBlocker");
}

@Override
protected Dimension calcPreferredSize() {
return new Dimension(CN.getDisplayWidth(), CN.getDisplayHeight());
}
}
}
Binary file modified scripts/android/screenshots/BrowserComponent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.codename1.ui.BrowserComponent;
import com.codename1.ui.Form;
import com.codename1.ui.Sheet;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.util.UITimer;
import com.codename1.util.SuccessCallback;
Expand All @@ -13,6 +14,7 @@ public class BrowserComponentScreenshotTest extends BaseTest {
private Form form;
private boolean jsReady;
private boolean jsCheckPending;
private boolean sheetShown;

@Override
public boolean runTest() throws Exception {
Expand Down Expand Up @@ -56,6 +58,11 @@ public void onSucess(BrowserComponent.JSRef result) {
return;
}

if (!sheetShown) {
sheetShown = true;
Sheet sheet = new Sheet(null, "Browser Sheet");
sheet.show();
}
UITimer.timer(2000, false, form, readyRunnable);
readyRunnable = null;
}
Expand Down
Loading