OpenJDK / openjfx / 8u-dev / rt
changeset 6041:6f0901527ad0
RT-35147: [Android, Ensemble8] App should react to hardware buttons on Android
Reviewed-by: snorthov
Contributed-by: Stefan Fuchs <snfuchs@gmx.de>
author | snorthov |
---|---|
date | Fri, 03 Jan 2014 12:23:27 -0500 |
parents | 703155c18442 |
children | acc894d665a6 |
files | apps/samples/Ensemble8/src/app/java/ensemble/EnsembleApp.java apps/samples/Ensemble8/src/app/java/ensemble/PlatformFeatures.java apps/samples/Ensemble8/src/app/java/ensemble/samplepage/Description.java apps/samples/Ensemble8/src/app/java/ensemble/samplepage/SamplePageContent.java apps/samples/Ensemble8/src/app/java/ensemble/samplepage/SourceTab.java apps/samples/Ensemble8/src/app/java/ensemble/util/FeatureChecker.java modules/base/src/main/java/com/sun/javafx/PlatformUtil.java |
diffstat | 7 files changed, 73 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/apps/samples/Ensemble8/src/app/java/ensemble/EnsembleApp.java Fri Jan 03 06:00:47 2014 -0800 +++ b/apps/samples/Ensemble8/src/app/java/ensemble/EnsembleApp.java Fri Jan 03 12:23:27 2014 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. + * Copyright (c) 2008, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -56,6 +56,8 @@ import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.*; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; @@ -74,8 +76,9 @@ private static final String OS_ARCH = System.getProperty("ensemble.os.arch", System.getProperty("os.arch")); public static final boolean IS_IPHONE = false; public static final boolean IS_IOS = "iOS".equals(OS_NAME); - public static final boolean IS_EMBEDDED = "arm".equals(OS_ARCH) && !IS_IOS; - public static final boolean IS_DESKTOP = !IS_EMBEDDED && !IS_IOS; + public static final boolean IS_ANDROID = "android".equals(System.getProperty("javafx.platform")) || "Dalvik".equals(System.getProperty("java.vm.name")); + public static final boolean IS_EMBEDDED = "arm".equals(OS_ARCH) && !IS_IOS && !IS_ANDROID; + public static final boolean IS_DESKTOP = !IS_EMBEDDED && !IS_IOS && !IS_ANDROID; public static final boolean IS_MAC = OS_NAME.startsWith("Mac"); public static final boolean PRELOAD_PREVIEW_IMAGES = true; public static final boolean SHOW_HIGHLIGHTS = IS_DESKTOP; @@ -101,6 +104,7 @@ Logger.getLogger(EnsembleApp.class.getName()).finer("IS_IPHONE = " + IS_IPHONE); Logger.getLogger(EnsembleApp.class.getName()).finer("IS_MAC = " + IS_MAC); Logger.getLogger(EnsembleApp.class.getName()).finer("IS_IOS = " + IS_IOS); + Logger.getLogger(EnsembleApp.class.getName()).finer("IS_ANDROID = " + IS_ANDROID); Logger.getLogger(EnsembleApp.class.getName()).finer("IS_EMBEDDED = " + IS_EMBEDDED); Logger.getLogger(EnsembleApp.class.getName()).finer("IS_DESKTOP = " + IS_DESKTOP); } @@ -231,6 +235,52 @@ } }); + // create AndroidStyle menu handling + if (IS_ANDROID) { + root.setOnKeyReleased(new EventHandler<KeyEvent>() { + private int exitCount = 0; + + @Override + public void handle(KeyEvent event) { + if (event.getCode() == KeyCode.ESCAPE) { + if (sampleListPopover.isVisible()) { + sampleListPopover.hide(); + event.consume(); + return; + } + + if (!backButton.isDisabled()) { + pageBrowser.backward(); + event.consume(); + return; + } + exitCount++; + if (exitCount == 2) { + System.exit(0); + } + } else { + exitCount = 0; + } + + if (event.getCode() == KeyCode.CONTEXT_MENU) { + if (sampleListPopover.isVisible()) { + sampleListPopover.hide(); + } else { + sampleListPopover.clearPages(); + sampleListPopover.pushPage(rootPage); + sampleListPopover.show(new Runnable() { + @Override + public void run() { + listButton.setSelected(false); + } + }); + } + event.consume(); + } + } + }); + } + // create and setup search popover searchPopover = new SearchPopover(searchBox,pageBrowser); root.getChildren().add(searchPopover); @@ -241,7 +291,7 @@ radioMenuItem.setToggleGroup(tg); radioMenuItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { - double menuHeight = IS_IOS || IS_MAC ? 0 : menuBar.prefHeight(width); + double menuHeight = IS_IOS || IS_MAC || IS_ANDROID ? 0 : menuBar.prefHeight(width); scene.getWindow().setWidth(width + scene.getWindow().getWidth() - scene.getWidth()); scene.getWindow().setHeight(height + menuHeight + scene.getWindow().getHeight() - scene.getHeight()); if (retina) { @@ -311,7 +361,7 @@ @Override public void start(final Stage stage) throws Exception { // CREATE SCENE scene = new Scene(root, 1024, 768, Color.BLACK); - if (IS_EMBEDDED) { + if (IS_EMBEDDED || IS_ANDROID) { new ScrollEventSynthesizer(scene); } setStylesheets();
--- a/apps/samples/Ensemble8/src/app/java/ensemble/PlatformFeatures.java Fri Jan 03 06:00:47 2014 -0800 +++ b/apps/samples/Ensemble8/src/app/java/ensemble/PlatformFeatures.java Fri Jan 03 12:23:27 2014 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013 Oracle and/or its affiliates. + * Copyright (c) 2012, 2014 Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -43,14 +43,17 @@ private static final boolean WINDOWS = os.startsWith("Windows"); private static final boolean MAC = os.startsWith("Mac"); private static final boolean LINUX = os.startsWith("Linux"); - private static final boolean IOS = os.startsWith("iOS"); - private static final boolean ARM = arch.equals("arm"); + private static final boolean ANDROID = "android".equals(System.getProperty("javafx.platform")) || "Dalvik".equals(System.getProperty("java.vm.name")); + private static final boolean IOS = os.startsWith("iOS"); + private static final boolean EMBEDDED = "arm".equals(arch) && !IOS && !ANDROID; - public static final boolean SUPPORTS_BENDING_PAGES = !ARM; + public static final boolean SUPPORTS_BENDING_PAGES = !EMBEDDED; public static final boolean HAS_HELVETICA = MAC || IOS; public static final boolean USE_IOS_THEME = IOS; - public static final boolean START_FULL_SCREEN = ARM; - public static final boolean EMBEDDED = ARM || IOS; + public static final boolean START_FULL_SCREEN = EMBEDDED || IOS || ANDROID; + public static final boolean LINK_TO_SOURCE = !(EMBEDDED || IOS || ANDROID); + public static final boolean DISPLAY_PLAYGROUND = !(EMBEDDED || IOS || ANDROID); + public static final boolean USE_EMBEDDED_FILTER = EMBEDDED || IOS || ANDROID; public static final boolean WEB_SUPPORTED = Platform.isSupported(ConditionalFeature.WEB); private PlatformFeatures(){}
--- a/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/Description.java Fri Jan 03 06:00:47 2014 -0800 +++ b/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/Description.java Fri Jan 03 12:23:27 2014 -0500 @@ -84,7 +84,7 @@ samplePage.pageBrowser.goToPage(samplePage.getUrl().replaceFirst("sample://", "sample-src://")); } }); - if (!PlatformFeatures.EMBEDDED) getChildren().add(sourceBtn); + if (PlatformFeatures.LINK_TO_SOURCE) getChildren().add(sourceBtn); if (Platform.isSupported(ConditionalFeature.WEB)) { // Setup Columns GridPane gridPane = new GridPane();
--- a/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/SamplePageContent.java Fri Jan 03 06:00:47 2014 -0800 +++ b/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/SamplePageContent.java Fri Jan 03 12:23:27 2014 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013 Oracle and/or its affiliates. + * Copyright (c) 2008, 2014 Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -121,7 +121,7 @@ private void update(SampleInfo sampleInfo) { sampleContainer = new SampleContainer(samplePage.sampleRuntimeInfoProperty.get().getSampleNode()); sampleContainer.getStyleClass().add("sample-page-sample-node"); - if (PlatformFeatures.EMBEDDED) { + if (!PlatformFeatures.DISPLAY_PLAYGROUND) { needsPlayground = false; } else { needsPlayground = sampleInfo.needsPlayground();
--- a/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/SourceTab.java Fri Jan 03 06:00:47 2014 -0800 +++ b/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/SourceTab.java Fri Jan 03 12:23:27 2014 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013 Oracle and/or its affiliates. + * Copyright (c) 2008, 2014 Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -61,7 +61,7 @@ case ".css": case ".fxml": String source = Utils.loadFile(getClass().getResource(url)); - if (EnsembleApp.IS_EMBEDDED || EnsembleApp.IS_IOS || !Platform.isSupported(ConditionalFeature.WEB)) { + if (EnsembleApp.IS_EMBEDDED || EnsembleApp.IS_IOS || EnsembleApp.IS_ANDROID || !Platform.isSupported(ConditionalFeature.WEB)) { // TODO: Convert to TextFlow // TextFlow textFlow = TextFlowBuilder.create() // .build();
--- a/apps/samples/Ensemble8/src/app/java/ensemble/util/FeatureChecker.java Fri Jan 03 06:00:47 2014 -0800 +++ b/apps/samples/Ensemble8/src/app/java/ensemble/util/FeatureChecker.java Fri Jan 03 12:23:27 2014 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013 Oracle and/or its affiliates. + * Copyright (c) 2008, 2014 Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -49,7 +49,7 @@ } } - if (PlatformFeatures.EMBEDDED && !sample.runsOnEmbedded) { + if (PlatformFeatures.USE_EMBEDDED_FILTER && !sample.runsOnEmbedded) { return false; } return true;
--- a/modules/base/src/main/java/com/sun/javafx/PlatformUtil.java Fri Jan 03 06:00:47 2014 -0800 +++ b/modules/base/src/main/java/com/sun/javafx/PlatformUtil.java Fri Jan 03 12:23:27 2014 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle 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 @@ -84,7 +84,7 @@ doEGLCompositing = false; } - private static final boolean ANDROID = "android".equals(System.getProperty("javafx.platform")); + private static final boolean ANDROID = "android".equals(System.getProperty("javafx.platform")) || "Dalvik".equals(System.getProperty("java.vm.name")); private static final boolean WINDOWS = os.startsWith("Windows"); private static final boolean WINDOWS_VISTA_OR_LATER = WINDOWS && versionNumberGreaterThanOrEqualTo(6.0f); private static final boolean WINDOWS_7_OR_LATER = WINDOWS && versionNumberGreaterThanOrEqualTo(6.1f);