Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slide out animation #2703

Merged
merged 1 commit into from
Apr 12, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public class DaoLaunchWindow extends Overlay<DaoLaunchWindow> {
private ArrayList<Section> sections = new ArrayList<>();
private IntegerProperty currentSectionIndex = new SimpleIntegerProperty(0);
private Label sectionDescriptionLabel;
private Timeline autoPlayTimeline;
private Timeline slideTimeline;
private Timeline autoPlayTimeline, slideInTimeline, slideOutTimeline;
private Section selectedSection;
private boolean showSlideInAnimation = true;


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -124,15 +124,18 @@ protected void addMessage() {

addListeners();

createSlideAnimation();
createSlideAnimations();
startAutoSectionChange();
}

@Override
protected void onShow() {
display();

slideTimeline.playFrom(Duration.millis(2 * DURATION));
new Timeline(new KeyFrame(
Duration.millis(2000),
ae -> slideInTimeline.playFrom(Duration.millis(DURATION))
)).play();
}

@Override
Expand All @@ -150,6 +153,7 @@ private void addListeners() {
currentSectionIndex.addListener((observable, oldValue, newValue) -> {
if (!newValue.equals(oldValue)) {
ObservableList<Toggle> toggles = sectionButtonsGroup.getToggles();

Toggle toggleToSelect = toggles.get(newValue.intValue() % toggles.size());
if (sectionButtonsGroup.getSelectedToggle() != toggleToSelect)
sectionButtonsGroup.selectToggle(toggleToSelect);
Expand All @@ -161,7 +165,10 @@ private void addListeners() {
int index = ((SectionButton) newValue).index;
selectedSection = sections.get(index);

slideTimeline.playFromStart();
if (showSlideInAnimation)
slideInTimeline.playFromStart();
else
slideOutTimeline.playFromStart();

currentSectionIndex.set(index);
}
Expand Down Expand Up @@ -208,10 +215,7 @@ private void createContent() {
Button prevButton = getIconButton(MaterialDesignIcon.ARROW_LEFT, "dao-launch-paging-button");
prevButton.setOnAction(event -> {
autoPlayTimeline.stop();
if (currentSectionIndex.get() == 0)
currentSectionIndex.set(sections.size() - 1);
else
currentSectionIndex.set(currentSectionIndex.get() - 1);
goToPrevSection();
});
Button nextButton = getIconButton(MaterialDesignIcon.ARROW_RIGHT, "dao-launch-paging-button");
nextButton.setOnAction(event -> {
Expand Down Expand Up @@ -245,17 +249,34 @@ private void createContent() {
gridPane.getChildren().add(slidingContentWithPagingBox);
}

private void goToPrevSection() {
showSlideInAnimation = false;

if (currentSectionIndex.get() == 0)
currentSectionIndex.set(sections.size() - 1);
else
currentSectionIndex.set(currentSectionIndex.get() - 1);
}

private void goToNextSection() {
showSlideInAnimation = true;
currentSectionIndex.set(currentSectionIndex.get() + 1);
}

private void createSlideAnimation() {
slideTimeline = new Timeline();
private void createSlideAnimations() {
slideInTimeline = new Timeline();
slideOutTimeline = new Timeline();

double imageWidth = 534;

createSlideAnimation(slideInTimeline, imageWidth);
createSlideAnimation(slideOutTimeline, -imageWidth);
}

private void createSlideAnimation(Timeline timeline, double imageWidth) {
Interpolator interpolator = Interpolator.EASE_OUT;
ObservableList<KeyFrame> keyFrames = slideTimeline.getKeyFrames();
ObservableList<KeyFrame> keyFrames = timeline.getKeyFrames();

double imageWidth = 534;
double endX = -imageWidth;
keyFrames.add(new KeyFrame(Duration.millis(0),
new KeyValue(sectionScreenshot.opacityProperty(), 1, interpolator),
Expand Down Expand Up @@ -284,6 +305,7 @@ protected double getDuration(double duration) {

private class SectionButton extends AutoTooltipToggleButton {
int index;

SectionButton(String title, int index) {
super(title);
this.index = index;
Expand All @@ -293,7 +315,10 @@ private class SectionButton extends AutoTooltipToggleButton {

this.selectedProperty().addListener((ov, oldValue, newValue) -> this.setMouseTransparent(newValue));

this.setOnAction(event -> autoPlayTimeline.stop());
this.setOnAction(event -> {
autoPlayTimeline.stop();
showSlideInAnimation = true;
});
}
}

Expand Down