Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Ports/JavaSE/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ endorsed.classpath=
# unused by the simulator integration screenshot tests that drive this
# build, and the user-facing codenameone-javase jar is the Maven one.
#
# JavaSEJoglSurface/JavaSEGLDevice are the JOGL (OpenGL) 3D backend; JOGL is
# JavaSEJoglSurface/JavaSEGLDevice/JavaSEJoglFoldTarget are the JOGL (OpenGL) 3D backend; JOGL is
# only a Maven dependency, so the Ant build (no JOGL on its classpath) skips
# them. JavaSEPort loads JavaSEJoglSurface reflectively and falls back to the
# software renderer when it is absent, so the 3D API still works (software) in
# the Ant simulator and gets the real GPU backend in the Maven simulator.
excludes=com/codename1/testing/junit/**,com/codename1/impl/javase/JavaSEJoglSurface.java,com/codename1/impl/javase/JavaSEGLDevice.java
excludes=com/codename1/testing/junit/**,com/codename1/impl/javase/JavaSEJoglSurface.java,com/codename1/impl/javase/JavaSEGLDevice.java,com/codename1/impl/javase/JavaSEJoglFoldTarget.java
file.reference.Filters.jar=../../../cn1-binaries/javase/Filters.jar
file.reference.commons-codec.jar=../../../cn1-binaries/javase/commons-codec.jar
file.reference.commons-compress.jar=../../../cn1-binaries/javase/commons-compress.jar
Expand Down
54 changes: 54 additions & 0 deletions Ports/JavaSE/src/com/codename1/impl/javase/AnimationClock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package com.codename1.impl.javase;

import java.util.concurrent.atomic.AtomicLong;

/// The time the simulator's own animations (folding, turning) and fold
/// scripts run on. It is the wall clock, except during a lockstep recording,
/// where the recorder sets it to the moment of the frame it is about to
/// capture: each video frame then shows the motion exactly one frame
/// interval further on, however long the previous frame took to render.
final class AnimationClock {
private static final AtomicLong PINNED = new AtomicLong(-1);

private AnimationClock() {
}

static long now() {
long p = PINNED.get();
return p >= 0 ? p : System.currentTimeMillis();
}

static void pin(long epochMs) {
PINNED.set(epochMs);
}

static void release() {
PINNED.set(-1);
}

static boolean isPinned() {
return PINNED.get() >= 0;
}
}
165 changes: 165 additions & 0 deletions Ports/JavaSE/src/com/codename1/impl/javase/FoldController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Codename One in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if
* you need additional information or have any questions.
*/
package com.codename1.impl.javase;

import com.codename1.ui.DevicePosture;

/// Drives the hinge angle of a foldable skin between postures. An animated
/// change eases the angle toward its target one step at a time; `step`
/// takes the clock as an argument so the motion is testable without a timer.
///
/// The host learns three things: every new angle (to repaint the 3D fold),
/// a posture change when the angle crosses a `FoldableSkin` threshold (the
/// app relays out mid-motion, as on a device), and when the device reaches
/// or leaves fully closed, which is when the display moves to the cover
/// screen and back. Leaving closed is reported before the first open frame,
/// so the inner screen is in place before it is drawn.
final class FoldController {

interface Host {
/// The angle moved; repaint.
void angleChanged(int angle, boolean animating);

/// The posture category changed (a `DevicePosture` POSTURE_ constant).
void postureChanged(int posture);

/// The device became fully closed (true) or started opening (false).
void coverChanged(boolean closed);
}

static final long DEFAULT_DURATION_MS = 700;

private final Host host;
private double angle = 180;
private int posture = DevicePosture.POSTURE_FLAT;
private boolean closed;
private double fromAngle;
private double toAngle = 180;
private long startMs;
private long durationMs;
private boolean animating;

FoldController(Host host) {
this.host = host;
}

int getAngle() {
return (int) Math.round(angle);
}

double getExactAngle() {
return angle;
}

int getPosture() {
return posture;
}

boolean isClosed() {
return closed;
}

boolean isAnimating() {
return animating;
}

int getTargetAngle() {
return (int) Math.round(toAngle);
}

/// Moves to `target` degrees (0 closed, 180 flat) over `duration`
/// milliseconds, or at once when `duration` is 0 or less.
void moveTo(int target, long duration, long nowMs) {
double t = Math.max(0, Math.min(180, target));
if (duration <= 0) {
animating = false;
toAngle = t;
apply(t, false);
return;
}
fromAngle = angle;
toAngle = t;
startMs = nowMs;
// A partial move takes a proportional share of the full sweep.
durationMs = Math.max(1, (long) (duration * Math.abs(t - angle) / 180.0));
animating = Math.abs(t - angle) > 0.01;
if (animating && closed) {
// Leaving closed: back to the inner display before any open frame.
closed = false;
host.coverChanged(false);
}
if (!animating) {
apply(t, false);
}
}

/// Advances an animation to `nowMs`. Returns true while it is still running.
boolean step(long nowMs) {
if (!animating) {
return false;
}
double f = (nowMs - startMs) / (double) durationMs;
if (f >= 1) {
animating = false;
apply(toAngle, false);
return false;
}
f = Math.max(0, f);
// Ease in and out (smootherstep): zero velocity and acceleration at
// both ends, so a hinge picks up and settles without a jolt.
double e = f * f * f * (f * (f * 6 - 15) + 10);
apply(fromAngle + (toAngle - fromAngle) * e, true);
return true;
}

private void apply(double a, boolean moving) {
angle = a;
boolean nowClosed = !moving && a < 0.5;
if (closed && !nowClosed) {
// Opening: the inner display goes back first, so the posture
// event below is delivered to an app already at the inner size.
closed = false;
host.coverChanged(false);
}
int p = FoldableSkin.postureForAngle((int) Math.round(a));
if (p != posture) {
posture = p;
host.postureChanged(p);
}
if (nowClosed && !closed) {
closed = true;
host.coverChanged(true);
}
host.angleChanged(getAngle(), moving);
}

/// Puts the controller at rest at `a` without notifying the host, for a
/// newly loaded skin.
void reset(int a) {
animating = false;
angle = Math.max(0, Math.min(180, a));
toAngle = angle;
posture = FoldableSkin.postureForAngle(a);
closed = angle < 0.5;
}
}
Loading