Skip to content
Open
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
94 changes: 94 additions & 0 deletions CodenameOne/src/com/codename1/ui/Sheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
///
/// 7.0
public class Sheet extends Container {
private static Rectangle[] sheetBoundsList = new Rectangle[0];
private static final int N = 0;
private static final int S = 1;
private static final int E = 2;
Expand Down Expand Up @@ -175,6 +176,70 @@ public void actionPerformed(ActionEvent evt) {
/// These are set the first time the sheet is shown and used as the base for safe area calculations.
private int[] originalPadding = null;
private Form form;
private final Rectangle sheetBounds = new Rectangle();
private boolean trackSheetBounds;
private Rectangle sheetEntry;

public static boolean isSheetVisibleAt(int x, int y) {
Rectangle[] boundsSnapshot = sheetBoundsList;
for (Rectangle bounds : boundsSnapshot) {
if (bounds.contains(x, y)) {
return true;
}
}
return false;
}

private static void addSheetEntry(Rectangle bounds) {
Rectangle[] current = sheetBoundsList;
Rectangle[] updated = new Rectangle[current.length + 1];
System.arraycopy(current, 0, updated, 0, current.length);
updated[current.length] = bounds;
sheetBoundsList = updated;
}

private static void removeSheetEntry(Rectangle bounds) {
Rectangle[] current = sheetBoundsList;
int matches = 0;
for (Rectangle existing : current) {
if (existing == bounds) { // NOPMD CompareObjectsWithEquals
matches++;
}
}
if (matches == 0) {
return;
}
Rectangle[] updated = new Rectangle[current.length - matches];
int index = 0;
for (Rectangle existing : current) {
if (existing != bounds) { // NOPMD CompareObjectsWithEquals
updated[index++] = existing;
}
}
sheetBoundsList = updated;
}

private void updateTrackedBounds() {
if (!trackSheetBounds) {
return;
}
sheetBounds.setBounds(getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight());
}

private void startTrackingBounds() {
trackSheetBounds = true;
sheetEntry = sheetBounds;
addSheetEntry(sheetEntry);
updateTrackedBounds();
}

private void stopTrackingBounds() {
trackSheetBounds = false;
if (sheetEntry != null) {
removeSheetEntry(sheetEntry);
sheetEntry = null;
}
}

/// Creates a new sheet with the specified parent and title.
///
Expand Down Expand Up @@ -466,6 +531,7 @@ public void run() {
cnt.revalidate();

}
startTrackingBounds();
if (cnt.getComponentCount() > 0) {
$(".Sheet", cnt).each(new ComponentClosure() {
@Override
Expand Down Expand Up @@ -503,6 +569,9 @@ public void call(Component c) {

});
Component existing = cnt.getComponentAt(0);
if (existing instanceof Sheet) {
((Sheet) existing).stopTrackingBounds();
}
cnt.replace(existing, this, null);
cnt.animateLayout(duration);
} else {
Expand Down Expand Up @@ -799,6 +868,7 @@ public void run() {
cnt.remove();
parent.getComponentForm().revalidateLater();
fireCloseEvent(true);
stopTrackingBounds();


}
Expand All @@ -808,6 +878,30 @@ public void run() {

}

@Override
public void setX(int x) {
super.setX(x);
updateTrackedBounds();
}

@Override
public void setY(int y) {
super.setY(y);
updateTrackedBounds();
}

@Override
public void setWidth(int width) {
super.setWidth(width);
updateTrackedBounds();
}

@Override
public void setHeight(int height) {
super.setHeight(height);
updateTrackedBounds();
}

/// Gets the parent sheet or null if there is none.
///
/// #### Returns
Expand Down
44 changes: 25 additions & 19 deletions Ports/Android/src/com/codename1/impl/android/CodenameOneView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
import android.view.*;
import android.view.inputmethod.EditorInfo;
import android.os.Build;
import com.codename1.ui.Component;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.PeerComponent;
import com.codename1.ui.TextArea;
import com.codename1.ui.Component;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.PeerComponent;
import com.codename1.ui.Sheet;
import com.codename1.ui.TextArea;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -561,20 +562,25 @@ public boolean onTouchEvent(MotionEvent event) {
//if (nativePeerGrabbedPointer) {
// return false;
//}
Component componentAt;
try {
if (x == null) {
componentAt = this.implementation.getCurrentForm().getComponentAt((int)event.getX(), (int)event.getY());
} else {
componentAt = this.implementation.getCurrentForm().getComponentAt((int)x[0], (int)y[0]);
}
} catch (Throwable t) {
// Since this is is an EDT violation, we may get an exception
// Just consume it
componentAt = null;
}
boolean isPeer = (componentAt instanceof PeerComponent);
boolean consumeEvent = !isPeer || cn1GrabbedPointer;
Component componentAt;
try {
if (x == null) {
componentAt = this.implementation.getCurrentForm().getComponentAt((int)event.getX(), (int)event.getY());
} else {
componentAt = this.implementation.getCurrentForm().getComponentAt((int)x[0], (int)y[0]);
}
} catch (Throwable t) {
// Since this is is an EDT violation, we may get an exception
// Just consume it
componentAt = null;
}
boolean isPeer = (componentAt instanceof PeerComponent);
if (isPeer) {
int primaryX = x == null ? (int) event.getX() : x[0];
int primaryY = y == null ? (int) event.getY() : y[0];
isPeer = !Sheet.isSheetVisibleAt(primaryX, primaryY);
}
boolean consumeEvent = !isPeer || cn1GrabbedPointer;

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.codename1.ui.Font;
import com.codename1.ui.Image;
import com.codename1.ui.PeerComponent;
import com.codename1.ui.Sheet;
import com.codename1.ui.TextArea;
import com.codename1.ui.TextField;
import com.codename1.ui.geom.Dimension;
Expand Down Expand Up @@ -1157,7 +1158,10 @@ static boolean hitTest(int x, int y) {
Form f = Display.getInstance().getCurrent();
if (f != null) {
Component cmp = f.getResponderAt(x, y);
return cmp == null || !(cmp instanceof PeerComponent);
if (cmp == null || !(cmp instanceof PeerComponent)) {
return true;
}
return Sheet.isSheetVisibleAt(x, y);
}
return true;
}
Expand Down
Binary file added scripts/android/screenshots/Sheet.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 @@ -69,6 +69,7 @@ public final class Cn1ssDeviceRunner extends DeviceRunner {
new BrowserComponentScreenshotTest(),
new MediaPlaybackScreenshotTest(),
new OrientationLockScreenshotTest(),
new SheetScreenshotTest(),
new InPlaceEditViewTest(),
new BytecodeTranslatorRegressionTest(),
new BackgroundThreadUiAccessTest(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.codenameone.examples.hellocodenameone.tests;

import com.codename1.ui.Button;
import com.codename1.ui.Container;
import com.codename1.ui.Form;
import com.codename1.ui.Label;
import com.codename1.ui.Sheet;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.util.UITimer;

public class SheetScreenshotTest extends BaseTest {
private Form form;
private Sheet sheet;
private Sheet childSheet;

@Override
public boolean runTest() {
form = createForm("Sheet Test", new BorderLayout(), "Sheet");
form.add(BorderLayout.CENTER, new Label("Tap sheet to dismiss"));
sheet = createSheet(null, "Sheet");
form.show();
return true;
}

@Override
protected void registerReadyCallback(Form parent, Runnable run) {
sheet.show();
UITimer.timer(500, false, parent, () -> {
childSheet = createSheet(sheet, "Details");
childSheet.show();
UITimer.timer(600, false, parent, run);
});
}

private Sheet createSheet(Sheet parent, String title) {
Sheet newSheet = new Sheet(parent, title);
Container content = newSheet.getContentPane();
content.setLayout(BoxLayout.y());
content.add(new Label("Sheet content"));
content.add(new Button("Primary Action"));
content.add(new Label("Secondary details"));
newSheet.getCommandsContainer().add(new Button("Edit"));
return newSheet;
}
}
Binary file added scripts/ios/screenshots/Sheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading