Exemple #1
0
  @Override
  public boolean didFinishLaunchingWithOptions(
      UIApplication app, Map<String, Object> launchOptions) {
    UIWindow window = new UIWindow(UIScreen.mainScreen().getBounds());

    ArrayList<UIViewController> list = new ArrayList<UIViewController>();
    list.add(new WelcomePage());
    list.add(new NavigationPage());
    list.add(new Page1("View1", "This is Page1"));
    list.add(new Page2("View2", "This is Page2"));
    list.add(new Page3("View3", "This is Page3"));
    list.add(new ViewPage("ViewGeneric", "This is generic"));

    controller = new UITabBarController();
    controller.setViewControllers(list);

    window.addSubview(controller.getView());
    window.makeKeyAndVisible();
    return false;
  }
Exemple #2
0
  /*
   * This method is called to setup the UI required for the application
   */
  private void setupUI() {
    UIScreen screen = UIScreen.mainScreen();
    CGRect rect = screen.getApplicationFrame();
    UIWindow window = new UIWindow(rect);

    rect.origin.x = rect.origin.y = 0;
    UIView mainView = new UIView(rect);
    mainView.setBackgroundColor(UIColor.lightGrayColor);
    window.addSubview(mainView);

    rect.origin.x = 50;
    rect.origin.y = 350;
    rect.size.width = 220;
    rect.size.height = 50;

    /*
     * Create a button which allows the user to start or stop the audio playback
     */
    button = UIButton.buttonWithType(UIButtonType.RoundedRect);
    button.setFrame(rect);
    button.setTitle("Start playing ...", UIControlState.Normal);

    /*
     * Add a UIControlDelegate to the button and register for necessary events.
     * When the UIControlEvent.TouchUpInside event occurs, the raiseEvent() method
     * is invoked.
     */
    button.addTarget(
        new UIControlDelegate() {

          @Override
          public void raiseEvent(UIControl sender, int eventType) {

            /*
             * If the audio playback is playing then stop then stop the playback
             * using stop() and set the appropriate text on the button
             */
            if (playing) {
              button.setTitle("Start playing ...", UIControlState.Normal);
              playing = false;
              audioPlayer.stop();
            } else {
              /*
               * If the audio playback is not playing then start the audio playback
               * using play(). Set the number of loops that the audio stream should loop for.
               * '0' indicates no looping. Any positive number indicates the number of times the
               * audio stream should play again. Any negative number indicates indefinite looping.
               */
              button.setTitle("Stop playing ...", UIControlState.Normal);
              playing = true;
              audioPlayer.play();
              audioPlayer.setNumberOfLoops(loopSwitch.isOn() ? -1 : 0);
            }
          }
        },
        UIControlEvent.TouchUpInside);
    mainView.addSubview(button);

    /*
     * Add a label to the loop switch provided
     */
    rect.origin.x = 50;
    rect.origin.y = 280;
    rect.size.height = 20;

    UILabel loopLabel = new UILabel(rect);
    loopLabel.setBackgroundColor(UIColor.clearColor);
    loopLabel.setText("Loop file:");
    mainView.addSubview(loopLabel);

    rect.origin.x = 176;
    rect.origin.y = 277;

    /*
     * A UIswitch class provides the On/Off functionality. Here, the looping
     * of the audio playback is managed using a switch. When the switch is 'On' it
     * indicates that looping is enabled. When the Switch is 'Off' it indicates that
     * the looping is not enabled.
     */
    loopSwitch = new UISwitch(rect);
    loopSwitch.setOn(true);

    /*
     * Add an UIControlDelegate to the UISwitch object and register for the
     * UIControlEvent.ValueChanged which is generated when a user flips the
     * switch control. Set the number of loops based on whether the switch was
     * turned On/Off
     */
    loopSwitch.addTarget(
        new UIControlDelegate() {

          @Override
          public void raiseEvent(UIControl sender, int eventType) {
            audioPlayer.setNumberOfLoops(loopSwitch.isOn() ? -1 : 0);
          }
        },
        UIControlEvent.ValueChanged);
    mainView.addSubview(loopSwitch);

    initAudioPlayer("rain_thunders");

    window.makeKeyAndVisible();
  }
 public PdfViewController(UIWindow window) {
   pdfView = new UIWebView(window.getFrame());
   setView(pdfView);
   pdfView.setScalesPageToFit(true);
 }