Example #1
0
  /** @see blackberry.core.ScriptableFunctionBase#execute(Object, Object[]) */
  public Object execute(Object thiz, Object[] args) throws Exception {
    // Get the screen that currently owns the BrowserField
    MainScreen screen = (MainScreen) MenuExtension.getBrowserField().getScreen();
    ShowMenu thread = new ShowMenu(screen.getMenu(Menu.INSTANCE_DEFAULT));
    screen.getApplication().invokeLater(thread);

    return UNDEFINED;
  }
  /** @see blackberry.core.ScriptableFunctionBase#execute(Object, Object[]) */
  public Object execute(Object thiz, Object[] args) throws Exception {
    // Get the screen that currently owns the BrowserField
    MainScreen screen = (MainScreen) MenuExtension.getBrowserField().getScreen();
    Object[] list = MenuItemObjectManager.getMenuItemObjects();

    for (int i = 0; i < list.length; i++) {
      screen.removeMenuItem(((MenuItemObject) list[i]).getMenuItem());
    }
    MenuItemObjectManager.clearMenuItemObjects();

    return UNDEFINED;
  }
  /**
   * Display a dialog box to the user with "Goodbye!" when the application is closed.
   *
   * @see net.rim.device.api.ui.Screen#close()
   */
  public void close() {
    conCallDemo.close();

    // Display a farewell message before closing application.
    Dialog.alert("Goodbye!");

    System.exit(0);
    super.close();
  }
 /** @see net.rim.device.api.ui.Screen#onUiEngineAttached(boolean) */
 protected void onUiEngineAttached(final boolean attached) {
   super.onUiEngineAttached(attached);
   if (attached) {
     // Set the location of the map to some random
     // location and set zoom to 5 (this zoom level
     // will be overriden by this application's
     // RestrictedMapAction class).
     _map.getMapField().getAction().setCenterAndZoom(new MapPoint(0, 0), 5);
   }
 }
  /** Create a new GPSDemoAdvanced object */
  public GPSDemoAdvanced() {
    final MainScreen screen = new MainScreen();

    // Initialize UI components
    screen.setTitle("GPS Advanced Demo");
    final LabelField apiChoiceMessage =
        new LabelField("Please select an API to test:", Field.USE_ALL_WIDTH | Field.FIELD_HCENTER);
    _coreTestButton =
        new ButtonField("Core GPS API Test", ButtonField.NEVER_DIRTY | ButtonField.CONSUME_CLICK);
    _extendedTestButton =
        new ButtonField(
            "Extended GPS API Test", ButtonField.NEVER_DIRTY | ButtonField.CONSUME_CLICK);
    _coreTestButton.setChangeListener(this);
    _extendedTestButton.setChangeListener(this);

    screen.add(apiChoiceMessage);
    screen.add(_coreTestButton);
    screen.add(_extendedTestButton);
    pushScreen(screen);
  }
 /**
  * Processes a new HttpConnection object to instantiate a new browser Field (aka WebView) object,
  * and then resets the screen to the newly-created Field.
  *
  * @param connection
  * @param e
  */
 public void processConnection(HttpConnection connection, Event e) {
   // Cancel previous request.
   if (_currentConnection != null) {
     try {
       _currentConnection.close();
     } catch (IOException e1) {
     }
   }
   // Clear out pending responses.
   synchronized (pendingResponses) {
     pendingResponses.removeAllElements();
   }
   // Cancel any XHRs happening.
   commandManager.stopXHR();
   _currentConnection = connection;
   BrowserContent browserContent = null;
   Field field = null;
   try {
     browserContent = _renderingSession.getBrowserContent(connection, this, e);
     if (browserContent != null) {
       field = browserContent.getDisplayableContent();
       if (field != null) {
         synchronized (Application.getEventLock()) {
           _mainScreen.deleteAll();
           _mainScreen.add(field);
         }
       }
       browserContent.finishLoading();
     }
   } catch (RenderingException re) {
   } finally {
     browserContent = null;
     field = null;
     // Manually call the garbage collector to clean up all of leftover objects and free up the
     // nulled object handles.
     System.gc();
   }
 }
Example #7
0
 public void makeMenu(Menu menu, int instance) {
   menu.add(m_editTask);
   menu.addSeparator();
   switch (task.getStatus()) {
     case Task.NOT_STARTED:
       menu.addSeparator();
       menu.add(m_markTaskInProgress);
       menu.add(m_markTaskDeferred);
       menu.add(m_markTaskWaiting);
       menu.add(m_markTaskCompleted);
       break;
     case Task.IN_PROGRESS:
       menu.addSeparator();
       menu.add(m_markTaskNotStarted);
       menu.add(m_markTaskDeferred);
       menu.add(m_markTaskWaiting);
       menu.add(m_markTaskCompleted);
       break;
     case Task.COMPLETED:
       break;
     case Task.WAITING:
       menu.addSeparator();
       menu.add(m_markTaskNotStarted);
       menu.add(m_markTaskInProgress);
       menu.add(m_markTaskDeferred);
       menu.add(m_markTaskCompleted);
       break;
     case Task.DEFERRED:
       menu.addSeparator();
       menu.add(m_markTaskNotStarted);
       menu.add(m_markTaskInProgress);
       menu.add(m_markTaskDeferred);
       menu.add(m_markTaskCompleted);
   }
   menu.addSeparator();
   menu.add(m_createTextNote);
   menu.add(m_createVoiceNote);
   if (getLeafFieldWithFocus() instanceof NoteField) {
     menu.add(m_deleteNote);
   }
   menu.addSeparator();
   menu.add(
       new MenuItem("About", 110, 1) {
         public void run() {
           UiApplication.getUiApplication().pushScreen(new AboutScreen());
         }
       });
   super.makeMenu(menu, instance);
 }
 private void init(final String url) {
   commandManager = new CommandManager(this);
   _mainScreen = new MainScreen();
   _mainScreen.addKeyListener(new PhoneGapKeyListener(this));
   pushScreen(_mainScreen);
   // Set up the browser/renderer.
   _renderingSession = RenderingSession.getNewInstance();
   _renderingSession
       .getRenderingOptions()
       .setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.JAVASCRIPT_ENABLED, true);
   _renderingSession
       .getRenderingOptions()
       .setProperty(
           RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.JAVASCRIPT_LOCATION_ENABLED, true);
   // Enable nice-looking BlackBerry browser field.
   _renderingSession
       .getRenderingOptions()
       .setProperty(RenderingOptions.CORE_OPTIONS_GUID, 17000, true);
   PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(url, null, null, null, this);
   thread.start();
   refreshTimer = new Timer();
   refreshTimer.scheduleAtFixedRate(new TimerRefresh(), 500, 500);
 }
Example #9
0
  public TaskScreen(Task task) {
    super(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR);

    internalManager =
        new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR);
    super.add(internalManager);
    internalManager.add(new TitleField(TaskUtils.getPath(task)));

    manager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
    internalManager.add(manager);

    this.task = task;

    Font bold = getFont().derive(Font.BOLD);

    HeaderLabel name = new HeaderLabel(task.getName());
    name.setFont(bold);
    RichTextField description =
        new RichTextField(task.getDescription()) {
          public void paint(Graphics graphics) {
            graphics.setColor(0x00777777);
            super.paint(graphics);
          }
        };

    add(name);

    if (task.getPriority() != Task.NORMAL_PRIORITY) {
      BitmapInput priority =
          new BitmapInput(
              "Priority",
              task.getPriority() == Task.LOW_PRIORITY ? "low_priority.png" : "high_priority");
      priority.setEditable(false);
      priority.setSelected(task.getPriority());
      add(priority);
    }

    String statusRes = "";
    switch (task.getStatus()) {
      case Task.NOT_STARTED:
        statusRes = ("not_started.png");
        break;
      case Task.IN_PROGRESS:
        statusRes = ("progress.png");
        break;
      case Task.WAITING:
        statusRes = ("waiting.png");
        break;
      case Task.DEFERRED:
        statusRes = ("deferred.png");
        break;
      case Task.COMPLETED:
        statusRes = ("completed.png");
        break;
    }
    status = new BitmapInput("Status", statusRes);
    status.setEditable(false);
    status.setSelected(task.getStatus());
    add(status);

    percent_complete =
        new BitmapInput(
            "Percent Complete", task.getPercentComplete() + "% Complete", "percent_complete.png");
    percent_complete.setEditable(false);
    add(percent_complete);

    BitmapInput tags = new BitmapInput("Tags", "tags.png");
    tags.setTextQuiet(TaskUtils.getTags(task));
    tags.setEditable(false);
    add(tags);

    if (task.getDescription().length() > 0) add(description);

    Font header = getFont().derive(Font.BOLD, getFont().getHeight() - 4);
    HeaderLabel l_dr = new HeaderLabel("Due Date");
    l_dr.setFont(header);
    BitmapInput dueDate = new BitmapInput("Due Date", "soon.png");
    if (task.getDateDue() > 0) {
      dueDate.setTextQuiet(
          "Due date: "
              + new SimpleDateFormat(DateFormat.DATETIME_DEFAULT).formatLocal(task.getDateDue()));
      System.out.println("REMINDER: " + task.getDateDue());
    } else dueDate.setTextQuiet("No due date set.");
    dueDate.setEditable(false);
    BitmapInput reminder = new BitmapInput("Reminder", "reminder.png");
    if (task.getReminder() > 0) {
      reminder.setTextQuiet(
          "Reminder: "
              + new SimpleDateFormat(DateFormat.DATETIME_DEFAULT)
                  .formatLocal(task.getDateDue() - (task.getReminder() * 1000)));
      System.out.println("REMINDER: " + task.getReminder());
    } else reminder.setTextQuiet("No reminder set.");
    reminder.setEditable(false);
    add(l_dr);
    add(dueDate);
    add(reminder);
    if (task.getDateDue() > 0) {
      BitmapInput viewInCalendar = new BitmapInput("View in Calendar", "today.png");
      viewInCalendar.setTask(task);
      add(viewInCalendar);
    }

    HeaderLabel l_notes = new HeaderLabel("Notes");
    l_notes.setFont(header);
    notes = new NoteManager(task);
    add(l_notes);
    add(notes);
  }
  public Object eventOccurred(final Event event) {
    int eventId = event.getUID();
    switch (eventId) {
      case Event.EVENT_REDIRECT:
        {
          RedirectEvent e = (RedirectEvent) event;
          String referrer = e.getSourceURL();
          switch (e.getType()) {
            case RedirectEvent.TYPE_SINGLE_FRAME_REDIRECT:
              // Show redirect message.
              Application.getApplication()
                  .invokeAndWait(
                      new Runnable() {
                        public void run() {
                          Status.show(REDIRECT_MSG);
                        }
                      });
              break;

            case RedirectEvent.TYPE_JAVASCRIPT:
              break;

            case RedirectEvent.TYPE_META:
              // MSIE and Mozilla don't send a Referer for META Refresh.
              referrer = null;
              break;

            case RedirectEvent.TYPE_300_REDIRECT:
              // MSIE, Mozilla, and Opera all send the original request's Referer as the Referer for
              // the new request.
              Object eventSource = e.getSource();
              if (eventSource instanceof HttpConnection) {
                referrer = ((HttpConnection) eventSource).getRequestProperty(REFERER);
              }
              eventSource = null;
              break;
          }
          // Create the request, populate header with referrer and fire off the request.
          HttpHeaders requestHeaders = new HttpHeaders();
          requestHeaders.setProperty(REFERER, referrer);
          PrimaryResourceFetchThread thread =
              new PrimaryResourceFetchThread(e.getLocation(), requestHeaders, null, event, this);
          thread.start();
          e = null;
          referrer = null;
          requestHeaders = null;
          break;
        }
      case Event.EVENT_URL_REQUESTED:
        {
          UrlRequestedEvent urlRequestedEvent = (UrlRequestedEvent) event;
          String url = urlRequestedEvent.getURL();
          HttpHeaders header = urlRequestedEvent.getHeaders();
          PrimaryResourceFetchThread thread =
              new PrimaryResourceFetchThread(
                  url, header, urlRequestedEvent.getPostData(), event, this);
          thread.start();
          urlRequestedEvent = null;
          url = null;
          header = null;
          break;
        }
      case Event.EVENT_BROWSER_CONTENT_CHANGED:
        {
          // Browser field title might have changed update title.
          BrowserContentChangedEvent browserContentChangedEvent =
              (BrowserContentChangedEvent) event;
          if (browserContentChangedEvent.getSource() instanceof BrowserContent) {
            BrowserContent browserField = (BrowserContent) browserContentChangedEvent.getSource();
            String newTitle = browserField.getTitle();
            if (newTitle != null) {
              synchronized (getAppEventLock()) {
                _mainScreen.setTitle(newTitle);
              }
            }
            browserField = null;
            newTitle = null;
          }
          browserContentChangedEvent = null;
          break;
        }
      case Event.EVENT_CLOSE:
        // TODO: close the application
        break;

      case Event.EVENT_SET_HEADER: // No cache support.
      case Event.EVENT_SET_HTTP_COOKIE:
        String cookie = ((SetHttpCookieEvent) event).getCookie();
        if (cookie.startsWith(PHONEGAP_PROTOCOL)) {
          String response = commandManager.processInstruction(cookie);
          if ((response != null) && (response.trim().length() > 0)) {
            pendingResponses.addElement(response);
          }
          response = null;
        }
        cookie = null;
        break;
      case Event.EVENT_HISTORY: // TODO: No history support.. but we added our own history stack
        // implementation in ConnectionManager. Can we hook it up - then we'd have
        // access to window.history :o
      case Event.EVENT_EXECUTING_SCRIPT: // No progress bar is supported.
      case Event.EVENT_FULL_WINDOW: // No full window support.
      case Event.EVENT_STOP: // No stop loading support.
      default:
    }

    return null;
  }