/* * CustomComponentsDemo.java * * Copyright � 1998-2011 Research In Motion Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Note: For the sake of simplicity, this sample application may not leverage * resource bundles and resource strings. However, it is STRONGLY recommended * that application developers make use of the localization features available * within the BlackBerry development platform to ensure a seamless application * experience across a variety of languages and geographies. For more information * on localizing your application, please refer to the BlackBerry Java Development * Environment Development Guide associated with this release. */ package com.rim.samples.device.accessibilitydemo.customcomponentsdemo; import net.rim.device.api.system.Bitmap; import net.rim.device.api.ui.Screen; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.accessibility.AccessibilityManager; import net.rim.device.api.ui.component.Dialog; import net.rim.device.api.ui.component.SeparatorField; import net.rim.device.api.ui.container.MainScreen; import com.rim.samples.device.accessibilitydemo.screenreaderdemo.ScreenReader; /** * The Accessibility Demo consists of two projects, CustomComponentsDemo and * ScreenReaderDemo. CustomComponentsDemo is a UI application featuring * customized accessible UI fields. ScreenReaderDemo is a library project * containing the ScreenReader class, which is a listener for accessible events, * and utility classes for handling the accessible events generated by the * accessible fields in the CustomComponentsDemo. */ public final class CustomComponentsDemo extends UiApplication { private static ScreenReader _screenReader; /** * Entry point for application. * * @param args * Command line arguments (not used) */ public static void main(final String[] args) { // Create a new instance of the application and make the currently // running thread the application's event dispatch thread. new CustomComponentsDemo().enterEventDispatcher(); } /** * Creates a new CustomComponentsDemo object */ public CustomComponentsDemo() { try { // Only one listener can be registered if (!AccessibilityManager.isAccessibleEventListenerRegistered()) { _screenReader = new ScreenReader(); AccessibilityManager.setAccessibleEventListener(_screenReader); } else { System.out .println("An AccessibleEventListener is already registered"); } } catch (final net.rim.device.api.system.UnsupportedOperationException uoe) { UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { Dialog.alert("Accessibilty not supported on this device"); } }); } // Push the UI screen onto the display stack pushScreen(new CustomComponentsDemoScreen()); } /** * The UI screen for the CustomComponentsDemo */ private static final class CustomComponentsDemoScreen extends MainScreen { private final IconToolbarComponent _iconToolbar; private final TableComponent _tableComponent; private final TextComponent _textComponent; private final ValueComponent _valueComponent; /** * Creates a new CustomComponentsDemoScreen object */ private CustomComponentsDemoScreen() { setTitle("Accessibility Demo"); // Initialize the IconToolbarComponent _iconToolbar = new IconToolbarComponent(); final Bitmap bitmap1 = Bitmap.getBitmapResource("1.png"); final Bitmap bitmap2 = Bitmap.getBitmapResource("2.png"); final Bitmap bitmap3 = Bitmap.getBitmapResource("3.png"); final Bitmap bitmap4 = Bitmap.getBitmapResource("4.png"); _iconToolbar.addIcon(bitmap1, " Maps "); _iconToolbar.addIcon(bitmap2, " Media "); _iconToolbar.addIcon(bitmap3, " Documents "); _iconToolbar.addIcon(bitmap4, " Applications "); // Add the IconToolbarComponent to the screen add(_iconToolbar); add(new SeparatorField()); // Create TableComponent and add to the screen _tableComponent = new TableComponent(3, 4); add(_tableComponent); add(new SeparatorField()); // Create ValueComponent and add to the screen _valueComponent = new ValueComponent(0, 50, 100); add(_valueComponent); add(new SeparatorField()); // Create TextComponent and add to the screen _textComponent = new TextComponent( "Connect to everything you love in life through the power of a BlackBerry� smartphone"); add(_textComponent); } /** * @see Screen#close() */ public void close() { // Unregister the accessible event listener when exiting the app if (AccessibilityManager.isAccessibleEventListenerRegistered()) { AccessibilityManager .removeAccessibleEventListener(_screenReader); } super.close(); } } }