I want to import mp3 files as clickable labels, but i have no idea how to handle it. I am doing graphical user interface through JavaFX. Image below will explain more.
You can get all Files from a directory by doing something like this:
File myfolder = new File("path/to/directory");
File[] allFiles = folder.listFiles();
for (int i = 0; i < all.length; i++) {
if (allFiles[i].isFile()) {
System.out.println("File " + allFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + allFiles[i].getName());
}
}
But instead of printing it to the output you can add Labels with the file.
Maybe something like this is what you want:
File myfolder = new File("your/path");
File[] allFiles = folder.listFiles();
VBox yourBox = new VBox();
for (int i = 0; i < all.length; i++) {
if (allFiles[i].isFile()) {
yourBox.getChildren().add(new Label(allFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
//Do whatever you want to do with subfolders.
}
}
Edit: for selecting a folder at runtime you can use:
DirectoryChooser
https://docs.oracle.com/javase/8/javafx/api/javafx/stage/DirectoryChooser.html
Or a FileChooser, which allows selecting multiple Files.
Edit full code (tested):
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class test extends Application {
#Override
public void start(final Stage stage) {
stage.setTitle("File Chooser");
final FileChooser fileChooser = new FileChooser();
final Button openMultipleButton = new Button("Open Files...");
VBox yourBox = new VBox();
openMultipleButton.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(final ActionEvent e) {
List<File> list = fileChooser.showOpenMultipleDialog(stage);
if (list != null) {
for (File file : list) {
yourBox.getChildren().add(new Label(file.getName()));
}
}
}
});
HBox all = new HBox();
all.getChildren().addAll(openMultipleButton, yourBox);
final Pane rootGroup = new VBox(12);
rootGroup.getChildren().addAll(all);
rootGroup.setPrefSize(400, 400);
stage.setScene(new Scene(rootGroup));
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
Hope this helped,
Steffi
Related
I have a problem with DocumentsContract.copyDocument
Each time my program crashes: "java.lang.UnsupportedOperationException: Copy not supported"
The curious thing is the below-listed actions are working fine!!
DocumentsContract.moveDocument
DocumentsContract.deleteDocument
DocumentsContract.renameDocument
DocumentsContract.createDocument
Permission to SD card access is apparently granted (above actions would fail without permission)
How come document moving, deleting and renaming is supported but not copying?
Can anyone help me with this issue?
Is there a great conceptual difference between copyDocument and moveDocument. Why move does work and copy does not?
Any hint will be highly appreciated
package com.example.forum14_11_2020;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.documentfile.provider.DocumentFile;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.UriPermission;
import android.net.Uri;
import android.os.Bundle;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.provider.DocumentsContract;
import android.view.View;
import android.widget.Button;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
public class MainActivity extends AppCompatActivity {
Uri uri;
DocumentFile pickedDir;
Button Button1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button1 = new Button(MainActivity.this);
Button1 = findViewById(R.id.button1);
Button1.setOnClickListener(onClickListener_Button1);
takeCardUriPermission("storage/1619-0D07");
}
View.OnClickListener onClickListener_Button1 = new View.OnClickListener() {
#Override
public void onClick(View v) {
uri = getUri();
pickedDir = DocumentFile.fromTreeUri(getBaseContext(), uri);
DocumentFile file = pickedDir.findFile("attempt.txt");
DocumentFile folder = pickedDir.findFile("folder");
try {
//DocumentsContract.moveDocument(getContentResolver(), file.getUri(), folder.getUri(), folder.getUri()); // does work!
//DocumentsContract.deleteDocument(getContentResolver(), file.getUri()); // does work!
//DocumentsContract.renameDocument(getContentResolver(), file.getUri(), file.getName() + "_rename"); // does work!
DocumentsContract.copyDocument(getContentResolver(), file.getUri(), folder.getUri()); // does not work
} catch (UnsupportedOperationException | FileNotFoundException e) {
e.printStackTrace();
e.getMessage();
}
}
};
public void takeCardUriPermission(String sdCardRootPath) {
int stop=1;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
File sdCard = new File(sdCardRootPath);
StorageManager storageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
StorageVolume storageVolume = storageManager.getStorageVolume(sdCard);
Intent intent = storageVolume.createAccessIntent(null);
try {
startActivityForResult(intent, 4010);
} catch (ActivityNotFoundException e) {
}
}
}
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 4010) {
Uri uri = data.getData();
grantUriPermission(getPackageName(), uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
Intent.FLAG_GRANT_READ_URI_PERMISSION);
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
Intent.FLAG_GRANT_READ_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(uri, takeFlags);
}
}
public Uri getUri() {
List<UriPermission> persistedUriPermissions = getContentResolver().getPersistedUriPermissions();
if (persistedUriPermissions.size() > 0) {
UriPermission uriPermission = persistedUriPermissions.get(0);
return uriPermission.getUri();
}
return null;
}
}
This is very much a work in progress so I apologize for my code needing to be cleaned up, but I thought it best to include everything I have so far.
I'm trying to figure how to animate text by looping through an array of images. My code loops through the array and displays just the last image. I need to display one image at a time and repeat to give the desired animation effect. What am I doing wrong or not doing?
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.util.Duration;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.event.EventHandler;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
public class ImageAnimatorWithAudio extends Application {
private final static int NUMBER_OF_SLIDES = 10;
#Override // Override the start method in the Application class
public void start(Stage primaryStage) {
Image[] images = new Image[NUMBER_OF_SLIDES];
Timeline animation = new Timeline(new KeyFrame(Duration.millis(5000)));
animation.setCycleCount(Timeline.INDEFINITE);
animation.play();
HBox hBox = new HBox();
hBox.setSpacing(10);
hBox.setAlignment(Pos.TOP_RIGHT);
Button btStartPause = new Button("Start Animation");
hBox.getChildren().add(btStartPause);
//Create border pane
BorderPane borderPane = new BorderPane();
borderPane.setTop(hBox); //Add hBox to borderPane
BorderPane.setAlignment(hBox, Pos.TOP_RIGHT); //Align hBox
btStartPause.setOnAction(e -> {
if (btStartPause.getText().equals("Start Animation")) {
btStartPause.setText("Pause Animation");
animation.play();
} else {
btStartPause.setText("Start Animation");
animation.pause();
}
});
GridPane pane = new GridPane();
pane.setPadding(new Insets(5,5,5,5));
for (int i = 0; i < NUMBER_OF_SLIDES; i++) {
images[i] = new Image("image_path" + i + ".png"); //file names are numerically named(i)
pane.getChildren().add(new ImageView(images[i]));
}
pane.getChildren().add(borderPane);
Scene scene = new Scene(pane, 450, 450);
primaryStage.setTitle("TextAnimation"); //Set the stage title
primaryStage.setScene(scene); //Place the scene in the stage
primaryStage.show(); //Display the stage
}
public static void main(String[] args){
Application.launch(args);
}
}
Any help is appreciated.
Here is an app that demonstrates how to add Images to an ArrayList(similar approach for an Array). It also demonstrates how to load those Images into an ImageView and change them using Timeline.
Main
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
* #author Sedrick
*/
public class JavaFXApplication1 extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="371.0" prefWidth="607.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.60" fx:controller="javafxapplication1.FXMLDocumentController">
<children>
<Button fx:id="btnMain" layoutX="263.0" layoutY="326.0" onAction="#handleButtonAction" text="Click Me!" />
<Label fx:id="lblMain" layoutX="269.0" layoutY="28.0" minHeight="16" minWidth="69" />
<ImageView fx:id="ivMain" fitHeight="201.0" fitWidth="278.0" layoutX="165.0" layoutY="85.0" pickOnBounds="true" preserveRatio="true" />
</children>
</AnchorPane>
Controller
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.util.Duration;
/**
*
* #author Sedrick
*/
public class FXMLDocumentController implements Initializable {
#FXML private Label lblMain;
#FXML private ImageView ivMain;
#FXML private Button btnMain;
Timeline timeline;
List<Image> imageContainer;
int currentImageBeingDisplayed;
#FXML
private void handleButtonAction(ActionEvent event) {
lblMain.setText("Animation started!");
currentImageBeingDisplayed = 0;
timeline.play();
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
//Load images
imageContainer = new ArrayList();
for(int i = 1; i <= 12; i++)
{
try
{
System.out.println("/images/Slide" + i + ".PNG");
imageContainer.add(new Image(getClass().getResource("/images/Slide" + i + ".PNG").toURI().toString()));
} catch (URISyntaxException ex) {
System.out.println(ex.toString());
}
}
//Change the image every second
timeline = new Timeline(
new KeyFrame(
Duration.seconds(1),
new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent actionEvent) {
Platform.runLater(()->{
ivMain.setImage(imageContainer.get(currentImageBeingDisplayed++));
});
}
}
)
);
timeline.setCycleCount(12);
}
}
Output:(looks similar to below)
I have been playing around with the line chart tutorial here: http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/line-chart.htm#CIHGBCFI
I want to extend the tutorial and attempt to build a line chart out of data from a database, instead of setting data like this:
series.getData().add(new XYChart.Data(1, 23));
series.getData().add(new XYChart.Data(2, 14));
What I have to import data from database:
public ObservableList<Items> loadChart() {
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT cost, date FROM Items ORDER BY date ASC");
ObservableList<Items> data = FXCollections.observableArrayList();
while(rs.next()){
Items items = new Items();
items.setCost(rs.getInt(1));
items.setDate(rs.getString(2));
data.add(items);
}
return data;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
I want to plot cost and date against in a line chart... Yet don't know how to do so (based on observable list and the tutorial).
If you are using that sample, your code should look something like this.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
public class LineChartSample extends Application {
#Override public void start(Stage stage) {
stage.setTitle("Line Chart Sample");
//defining the axes
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Number of Month");
//creating the chart
final LineChart<Number,Number> lineChart =
new LineChart<Number,Number>(xAxis,yAxis);
lineChart.setTitle("Stock Monitoring, 2010");
//defining a series
XYChart.Series series = new XYChart.Series();
series.setName("My portfolio");
//populating the series with data
try
{
Connection connection = DriverManager.getConnection("...");//You can use try with resources. Establish a Connection
Statement stmt = connection.createStatement();//Create Statement
ResultSet rs = stmt.executeQuery("SELECT cost, date FROM Items ORDER BY date ASC");//Query DB and get results.
//Iterate through results.
while(rs.next())
{
series.getData().add(new XYChart.Data(rs.getInt(1), Integer.parseInt(rs.getString(2))));//Add data to Chart. Changed the second input to Integer due to LineChart<Number,Number>. This should work, though I haven't tested it.
}
}
catch (SQLException ex) {
Logger.getLogger(LineChartSample.class.getName()).log(Level.SEVERE, null, ex);
}
Scene scene = new Scene(lineChart,800,600);
lineChart.getData().add(series);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
UPDATE BELOW
You can try something like this if you want to have a database handler class.
DBHandler Class
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.scene.chart.XYChart;
/**
*
* #author blj0011
*/
public class DBHandler
{
List<List<Integer>> dataHolder;
//There is probably a better way to structure this DBHandler Class
public DBHandler()
{
dataHolder = new ArrayList();
try
{
Connection connection = DriverManager.getConnection("...");//You can use try with resources. Establish a Connection
Statement stmt = connection.createStatement();//Create Statement
ResultSet rs = stmt.executeQuery("SELECT cost, date FROM Items ORDER BY date ASC");//Query DB and get results.
//Iterate through results.
while(rs.next())
{
List<Integer> tempDataHolder = new ArrayList();
tempDataHolder.add(rs.getInt(1));
tempDataHolder.add(Integer.parseInt(rs.getString(2)));
dataHolder.add(tempDataHolder);
}
}
catch (SQLException ex) {
Logger.getLogger(DBHandler.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List<List<Integer>> getDataHolder()
{
return dataHolder;
}
}
Main Class
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
public class LineChartSample extends Application {
#Override public void start(Stage stage) {
stage.setTitle("Line Chart Sample");
//defining the axes
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Number of Month");
//creating the chart
final LineChart<Number,Number> lineChart =
new LineChart<Number,Number>(xAxis,yAxis);
lineChart.setTitle("Stock Monitoring, 2010");
//defining a series
XYChart.Series series = new XYChart.Series();
series.setName("My portfolio");
//populating the series with data
DBHandler dbHandler = new DBHandler();
List<List<Integer>> dataHolder = dbHandler.getDataHolder();
for(int i = 0; i < dataHolder.size(); i++)
{
series.getData().add(new XYChart.Data(dataHolder.get(i).get(0), dataHolder.get(i).get(1)));
}
Scene scene = new Scene(lineChart,800,600);
lineChart.getData().add(series);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Image shareIcon = FontImage.createMaterial(FontImage.MATERIAL_REPLY, s);
shareIcon = shareIcon.rotate(180);
ShareButton shareButton = new ShareButton();
shareButton.setIcon(shareIcon);
How can I flip the image here? The rotate method does nothing.
The answer below by shai doesn't work in my project
package com.mycompany.myapp;
import com.codename1.components.ShareButton;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.ui.Button;
import com.codename1.ui.FontImage;
import com.codename1.ui.Image;
import com.codename1.ui.Toolbar;
import com.codename1.ui.layouts.BoxLayout;
public class MyApplication {
private Form current;
private Resources theme;
public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature, uncomment if you have a pro subscription
// Log.bindCrashProtection(true);
}
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Rotate");
hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Image shareIcon = FontImage.createMaterial(FontImage.MATERIAL_REPLY, new Button("").getUnselectedStyle(), 5);
for (int i = 0; i < 360; i += 45) {
ShareButton s = new ShareButton();
s.setIcon(shareIcon.rotate(i));
hi.add(s);
}
hi.show();
}
public void stop() {
current = Display.getInstance().getCurrent();
if (current instanceof Dialog) {
((Dialog) current).dispose();
current = Display.getInstance().getCurrent();
}
}
public void destroy() {
}
}
If you want to see the project, heres the project:
https://drive.google.com/open?id=0B8ATnICIY2S8OEtUU2lPSlFid3M
This works for me:
Image shareIcon = FontImage.createMaterial(FontImage.MATERIAL_REPLY, new Button("").getUnselectedStyle(), 5);
for(int i = 0 ; i < 360 ; i += 45) {
ShareButton s = new ShareButton();
s.setIcon(shareIcon.rotate(i));
hi.add(s);
}
I have just started learning mgwt. After creating a Button and adding a TapHandler, the tap events are not fired. I don't know what is wrong in the code. I have deployed this on GAE and accessing the site on a Android device. Below is the code for onModuleLoad()
import com.citrix.demo.client.css.AppBundle;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
import com.google.gwt.dom.client.StyleInjector;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
import com.googlecode.mgwt.mvp.client.AnimatableDisplay;
import com.googlecode.mgwt.mvp.client.AnimatingActivityManager;
import com.googlecode.mgwt.mvp.client.Animation;
import com.googlecode.mgwt.mvp.client.AnimationMapper;
import com.googlecode.mgwt.ui.client.MGWT;
import com.googlecode.mgwt.ui.client.MGWTSettings;
import com.googlecode.mgwt.ui.client.MGWTStyle;
import com.googlecode.mgwt.ui.client.animation.AnimationHelper;
import com.googlecode.mgwt.ui.client.dialog.TabletPortraitOverlay;
import com.googlecode.mgwt.ui.client.layout.MasterRegionHandler;
import com.googlecode.mgwt.ui.client.layout.OrientationRegionHandler;
import com.googlecode.mgwt.ui.client.widget.Button;
import com.googlecode.mgwt.ui.client.widget.LayoutPanel;
/**
* #author Daniel Kurka
*
*/
public class MgwtAppEntryPoint implements EntryPoint {
private static LayoutPanel layout = new LayoutPanel();
private void start() {
//set viewport and other settings for mobile
MGWT.applySettings(MGWTSettings.getAppSetting());
final ClientFactory clientFactory = new ClientFactoryImpl();
// Start PlaceHistoryHandler with our PlaceHistoryMapper
AppPlaceHistoryMapper historyMapper = GWT.create(AppPlaceHistoryMapper.class);
final PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
historyHandler.register(clientFactory.getPlaceController(), clientFactory.getEventBus(), new com.citrix.demo.client.activities.HomePlace());
if ((MGWT.getOsDetection().isTablet())) {
// very nasty workaround because GWT does not correctly support
// #media
StyleInjector.inject(AppBundle.INSTANCE.css().getText());
createTabletDisplay(clientFactory);
} else {
createPhoneDisplay(clientFactory);
}
historyHandler.handleCurrentHistory();
}
private void createPhoneDisplay(ClientFactory clientFactory) {
AnimatableDisplay display = GWT.create(AnimatableDisplay.class);
PhoneActivityMapper appActivityMapper = new PhoneActivityMapper(clientFactory);
PhoneAnimationMapper appAnimationMapper = new PhoneAnimationMapper();
AnimatingActivityManager activityManager = new AnimatingActivityManager(appActivityMapper, appAnimationMapper, clientFactory.getEventBus());
activityManager.setDisplay(display);
RootPanel.get().add(display);
}
private void createTabletDisplay(ClientFactory clientFactory) {
SimplePanel navContainer = new SimplePanel();
navContainer.getElement().setId("nav");
navContainer.getElement().addClassName("landscapeonly");
AnimatableDisplay navDisplay = GWT.create(AnimatableDisplay.class);
final TabletPortraitOverlay tabletPortraitOverlay = new TabletPortraitOverlay();
new OrientationRegionHandler(navContainer, tabletPortraitOverlay, navDisplay);
new MasterRegionHandler(clientFactory.getEventBus(), "nav", tabletPortraitOverlay);
ActivityMapper navActivityMapper = new TabletNavActivityMapper(clientFactory);
AnimationMapper navAnimationMapper = new TabletNavAnimationMapper();
AnimatingActivityManager navActivityManager = new AnimatingActivityManager(navActivityMapper, navAnimationMapper, clientFactory.getEventBus());
navActivityManager.setDisplay(navDisplay);
RootPanel.get().add(navContainer);
SimplePanel mainContainer = new SimplePanel();
mainContainer.getElement().setId("main");
AnimatableDisplay mainDisplay = GWT.create(AnimatableDisplay.class);
TabletMainActivityMapper tabletMainActivityMapper = new TabletMainActivityMapper(clientFactory);
AnimationMapper tabletMainAnimationMapper = new TabletMainAnimationMapper();
AnimatingActivityManager mainActivityManager = new AnimatingActivityManager(tabletMainActivityMapper, tabletMainAnimationMapper, clientFactory.getEventBus());
mainActivityManager.setDisplay(mainDisplay);
mainContainer.setWidget(mainDisplay);
RootPanel.get().add(mainContainer);
}
#Override
public void onModuleLoad() {
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
#Override
public void onUncaughtException(Throwable e) {
Window.alert("uncaught: " + e.getMessage());
e.printStackTrace();
}
});
new Timer() {
#Override
public void run() {
start();
}
}.schedule(1);
//set viewport and other settings for mobile
MGWT.applySettings(MGWTSettings.getAppSetting());
MGWTStyle.getTheme().getMGWTClientBundle().getMainCss().ensureInjected();
Label label = new Label("Welcome");
label.setAutoHorizontalAlignment(Label.ALIGN_CENTER);
Button button = new Button();
button.setRound(true);
button.setText("Click");
button.addTapHandler(new TapHandler() {
#Override
public void onTap(TapEvent event) {
Window.alert("Hola !");
}
});
layout.add(label);
layout.add(button);
//build animation helper and attach it
AnimationHelper animationHelper = new AnimationHelper();
// RootPanel.get().add(layout);
RootPanel.get().add(animationHelper);
animationHelper.goTo(layout, Animation.POP);
}
}
Can somebody help me out with this ? Thanks..!
You are adding more than one AnimatableDisplays to one region. Those will overlap.
You just added some lines of code to the mgwt showcase I guess without removing the showcase code. To fix this you could remove the call to start() from the timer.