Created
September 1, 2021 13:41
-
-
Save shannah/d341db06afdfb257d7a8b955315dd6d1 to your computer and use it in GitHub Desktop.
Lighter-weight InfiniteProgress dialog in Codename One
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.materialtheme; | |
import com.codename1.components.InfiniteProgress; | |
import com.codename1.ui.CN; | |
import com.codename1.ui.Component; | |
import com.codename1.ui.Container; | |
import com.codename1.ui.Form; | |
import com.codename1.ui.layouts.BorderLayout; | |
import com.codename1.ui.plaf.Border; | |
import static com.codename1.ui.ComponentSelector.$; | |
public class InfiniteProgressContainer extends Container { | |
public InfiniteProgressContainer() { | |
this(null); | |
} | |
public InfiniteProgressContainer(Component content) { | |
super(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE)); | |
if (content == null) { | |
InfiniteProgress prg = new InfiniteProgress(); | |
content = prg; | |
} | |
setGrabsPointerEvents(true); | |
$(this) | |
.setBgTransparency(128) | |
.setBorder(Border.createEmpty()) | |
.setBgColor(0x0); | |
add(BorderLayout.CENTER, content); | |
} | |
public void show() { | |
if (isInitialized()) return; | |
remove(); | |
Form form = CN.getCurrentForm(); | |
if (form == null) return; | |
Container layeredPane = form.getFormLayeredPane(InfiniteProgressContainer.class, true); | |
layeredPane.removeAll(); | |
layeredPane.setLayout(new BorderLayout()); | |
layeredPane.getAllStyles().stripMarginAndPadding(); | |
layeredPane.add(BorderLayout.CENTER, this); | |
form.revalidateWithAnimationSafety(); | |
} | |
public void dispose() { | |
if (isInitialized()) { | |
Form form = getComponentForm(); | |
remove(); | |
form.revalidateWithAnimationSafety(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InfiniteProgressContainer cnt = new InfiniteProgressContainer(); | |
cnt.show(); // Show infinite progress | |
CN.setTimeout(3000, () -> { | |
cnt.dispose(); // Dispose infinite progress 3 seconds later. | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment