Example #1
0
  /** Handle menu items selection. */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    mContext = getApplicationContext();
    mAppPrefs = new AppPrefs(mContext);

    switch (item.getItemId()) {
        // This returns to previous fragment in previous activity.
      case android.R.id.home:
        finish();
        return true;

      case R.id.action_refresh:
        mSwipeRefreshLayout.setRefreshing(true);
        initiateRefresh();
        return true;
      case R.id.action_favorite:
        mAppPrefs.setFavorite_city(mCity);
        if (mAppPrefs.getFavorite_cities() != null) {
          for (String city : mAppPrefs.getFavorite_cities()) {
            Log.i(TAG, city);
          }
        }
        Snackbar.make(
                findViewById(android.R.id.content), "Pinned To Home Menu", Snackbar.LENGTH_LONG)
            .setAction("Action", null)
            .show();
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
Example #2
0
 protected Component createRightComponent() {
   SavePane pane = (SavePane) super.createRightComponent();
   AliasTextRow row = (AliasTextRow) pane.getPropertyPane().getInfo().getRow("name");
   row.setAliasing(
       "Original", AppPrefs.getInstance().getMessages().getString("lblViewNameOriginal"));
   return pane;
 }
Example #3
0
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
   if (String.valueOf(value).equals("Original")) {
     setText(AppPrefs.getInstance().getMessages().getString("lblViewNameOriginal"));
   }
   // TODO, also remember about adding views, shouldn't allow localized original value
   return this;
 }
Example #4
0
    private boolean doUndefineGraphemeCluster() {
      Messages messages = AppPrefs.getInstance().getMessages();
      TaskDialog dialog =
          new TaskDialog(
              "lblViewsUndefineGraphemeCluster",
              new UndefineGraphemeClusterTask(_view),
              "ViewsUndefineGraphemeCluster");
      dialog.setVisible(true);

      return !dialog.isCancelled();
    }
Example #5
0
  // Update method to update the game play
  public void update(float dt, float fps) {
    FPS = fps;

    switch (GameState) {
      case 0:
        {
          // Only if game is not paused
          if (!GamePaused) {
            bgX -= ScrollSpeed * dt; // Speed of background scrolling
            // Reset once reaches 0
            if (bgX < -ScreenWidth) {
              bgX = 0;
            }

            // Only when game is active we update the following
            if (GameActive) {
              SpawnTimer += dt;
              timer += dt;

              if (timer > 5.f) {
                ScrollSpeed += 100;
                timer = 0;
              }
              if (SpawnTimer > SpawnRate) {
                FetchObstacle();
                SpawnTimer = 0.f;
              }
              stickman_anim.update(System.currentTimeMillis());

              // Adventure mode
              if (GameMode == 1) {
                Progress_bar.setPosX(Progress_bar.getPosX() + BarSpeed * 0.015f);
                if (Progress_bar.getPosX() > DestinationPoint) {
                  Win = true;
                  GameActive = false;
                }
              }
            }
            // Feedback for game over
            if (GameActive == false) {

              if (UpdateHighscore && GameMode == 0) {
                Vector<Integer> highscores = appPrefs.getHighscore();
                Vector<Integer> updatedscores = new Vector<Integer>();
                boolean scoreentered = false;
                int index = 0;

                for (int i = 0; i < highscores.size(); ++i) {
                  if (score > highscores.get(index) && !scoreentered) {
                    updatedscores.addElement(score);
                    scoreentered = true;
                  } else {
                    updatedscores.addElement(highscores.get(index));
                    ++index;
                  }
                }

                for (int i = 0; i < updatedscores.size(); ++i) {
                  appPrefs.setHighscore(i, updatedscores.get(i));
                }

                UpdateHighscore = false;
              }

              // Vibration feedback
              vibrateTime += dt;
              if (vibrateTime > MaxVibrateTime) {
                stopVibrate();
              } else {
                startVibrate();
              }
            }

            if (nearestObstacle.isActive()) {
              // Detecting user tap for tapping obstacle
              if (nearestObstacle.getType() == Obstacle.TYPE.T_TAP && Tapped == true) {
                score += 10;
                nearestObstacle.setActive(false);
                DirectionVector.SetZero();
                Tapped = false;
              }
              // Detecting user swipe direction for direction obstacle
              else if (DirectionVector.IsZero() == false
                  && Obstacle.fromInteger(ProcessSwipe(DirectionVector))
                      == nearestObstacle.getType()) {
                score += 10;
                nearestObstacle.setActive(false);
                DirectionVector.SetZero();
              }

              DirectionVector.SetZero();
            }

            // Updating game elements
            for (int i = 0; i < obstacleList.length; ++i) {
              if (obstacleList[i].isActive()) {
                obstacleList[i].setPosX(obstacleList[i].getPosX() - ScrollSpeed * dt);
                // if out of screen
                if (obstacleList[i].getPosX() < 0) {
                  obstacleList[i].setActive(false);
                }
                // Only if game is active we check these collisions
                if (GameActive == true) {
                  // Player collision against obstacles
                  if (CheckCollision(
                      stickman_anim.getX(),
                      stickman_anim.getY(),
                      stickman_anim.getSpriteWidth(),
                      stickman_anim.getSpriteHeight(),
                      (int) obstacleList[i].getPosX(),
                      (int) obstacleList[i].getPosY(),
                      obstacleList[i].getImgWidth(),
                      obstacleList[i].getImgHeight())) {
                    obstacleList[i].setActive(false);
                    GameActive = false; // Game status set to false
                    // Enable buttons
                    Restart_button.setActive(true);
                    Mainmenu_button.setActive(true);
                  }
                  // Get nearest obstacle
                  if (nearestObstacle.isActive() == false) {
                    nearestObstacle = obstacleList[i];
                  } else if (obstacleList[i].getPosX() < nearestObstacle.getPosX()) {
                    nearestObstacle = obstacleList[i];
                  }
                }
              }
            }
          }
        }
        break;
    }
  }
Example #6
0
  ViewsPane(WordCollection collection) {
    super(null, true, true, false);
    final Messages messages = AppPrefs.getInstance().getMessages();

    // change find label
    setFindButtonLabel(messages.getString("btnFindViews"));

    _collection = collection;
    getList().setModel(new BasicListModel());

    final MainFrame mf = MainFrame.getInstance();
    ListSelectionModel model = getList().getSelectionModel();
    model.addListSelectionListener(
        new ListSelectionListener() {
          public synchronized void valueChanged(ListSelectionEvent evt) {
            try {
              View view = (View) getList().getSelectedValue();
              if (view != null) {
                Setting setting = _collection.getDatabase().getCurrentSetting();
                setting.setViewID(view.getID());
                setting.save();
                mf.updateStatus();
              }
            } catch (DatabaseException e) {
              Dialogs.genericError(e);
            }
          }
        });

    addAddEditDeleteListener(
        new AddEditDeleteListener() {
          public void doAdd(ActionEvent evt) throws DatabaseException {
            final View view = _collection.makeView();
            AddDialog dialog = new AddDialog("lblAddView", view);
            dialog.setVisible(true);
            if (!dialog.isCancelled()) {
              // add default groups and alignments
              AddRunnable task =
                  new AddRunnable() {
                    public void run() {
                      try {
                        ViewDuplicator.makeGroupsAndAlignments(view, view, _collection, false);

                        // update collection view list
                        List views = _collection.getViews();
                        views.add(view);

                        _collection.getDatabase().getCurrentSetting().setViewID(view.getID());
                        refresh();
                      } catch (DatabaseException ex) {
                        exception = ex;
                      }
                    }

                    DatabaseException exception = null;

                    public DatabaseException getException() {
                      return exception;
                    }
                  };
              Messages m = AppPrefs.getInstance().getMessages();
              Dialogs.indeterminateProgressDialog(
                  task,
                  m.getString("pgbWaitString"),
                  m.getString("pgbCurrentTask") + m.getString("lblAddView"));
              if (task.getException()
                  != null) { // so we don't swallow the exception from the other thread.
                throw task.getException();
              }
            }
          }

          public void doCopy(ActionEvent evt) throws DatabaseException {
            ViewDuplicator duplicator =
                new ViewDuplicator((View) getList().getSelectedValue(), _collection);
            TaskDialog dialog = new TaskDialog("lblViewCopy", duplicator);
            dialog.setVisible(true);
            if (!dialog.isCancelled()) {
              // update collection view list
              List views = _collection.getViews();
              View view = duplicator.getDuplicate();
              if (view != null) { // view will be null if attempted duplicate view name.
                views.add(view);
                _collection.getDatabase().getCurrentSetting().setViewID(view.getID());
                refresh();
              }
            }
          }

          public void doDelete(ActionEvent evt) throws DatabaseException {
            View view = (View) getList().getSelectedValue();

            // check for Original view
            View original = _collection.getOriginalView();
            if (view.equals(original)) {
              Dialogs.error(messages.getString("msgErrDeletingOriginalView"));
            } else {
              view.delete();

              // update collection view list
              List views = _collection.getViews();
              views.remove(view);
              changeView(original);

              JSplitPane split = (JSplitPane) getMainComponent();
              int loc = split.getDividerLocation();
              split.setRightComponent(new JLabel(""));
              split.setDividerLocation(loc);
              refresh();
            }
          }

          public void doValidate(ActionEvent evt) {}

          public void doMoveUp(ActionEvent evt) {}

          public void doMoveDown(ActionEvent evt) {}
        });

    getList().setCellRenderer(new ViewNameListCellRenderer());
  }