@Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   if (intent == null) {
     return 0;
   }
   int cmd = intent.getIntExtra(EXTRA_CMD, 0);
   final String param = intent.getStringExtra(EXTRA_STR1);
   if (cmd == CMD_OPEN_VOCAB) {
     cancelSelect();
     m_words.open(param);
   } else if (cmd == CMD_CANCEL_VOCAB) {
     cancelSelect();
   } else if (cmd == CMD_CLOSE_VOCAB) {
     cancelSelect();
     m_words.close();
   } else if (cmd == CMD_GET_WORDS) {
     m_newWord = param;
     if (m_bRun) {
       m_words.cancelSync(true);
     } else {
       asyncOper(param);
     }
   } else if (cmd == CMD_SAVE_WORD) {
     m_words.getUserWords().addWord(param);
   }
   return super.onStartCommand(intent, flags, startId);
 }
示例#2
0
 @Override
 public void keyTyped(KeyEvent e) {
   Character typed = e.getKeyChar();
   switch (typed) {
     case KeyEvent.VK_BACK_SPACE:
       if (input.length() > 0) {
         input.deleteCharAt(input.length() - 1);
         if (!Words.isDictionaryWord(input.toString()))
           suggestion = Words.ending(input.toString());
         else suggestion = "";
       }
       word = null;
       break;
     case KeyEvent.VK_ENTER:
       if (suggestion != null && suggestion.length() > 0) {
         input.append(suggestion);
         suggestion = "";
       }
       word = Words.getWord(input.toString());
       break;
     case KeyEvent.VK_TAB:
       previous = mode;
       previousSet = System.currentTimeMillis();
       mode = Theme.next(mode);
       break;
   }
   if (allowed.matcher(typed.toString()).matches()) {
     input.append(typed);
     String focus = input.substring(input.lastIndexOf(" ") + 1);
     word = Words.getWord(focus);
     suggestion = word == null ? Words.ending(focus) : "";
   }
 }
 public void paint(Graphics g) {
   // Vault-Tech logo
   Background.drawWall(g);
   Logo.drawCircles(g);
   Logo.drawLines(g);
   Words.drawTop(g);
   Words.drawBottom(g);
 }
 public boolean canGiveWords() {
   return m_words.canGiveWords();
 }
 @Override
 public void onDestroy() {
   m_words.close();
   inst = null;
 };
 void cancelSelect() {
   if (m_bRun) {
     m_newWord = null;
     m_words.cancelSync(true);
   }
 }
示例#7
0
 public static final void delDB(Context context) {
   SQLiteDatabase wdb = Words.getWordsDb(context);
   wdb.execSQL("delete from " + WordsDBHelper.TB_W_NAME);
   wdb.execSQL("delete from " + WordsDBHelper.TB_TR_NAME);
 }
示例#8
0
  @Override
  public void paint(Graphics g) {
    BufferedImage buffer =
        new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g2 = (Graphics2D) buffer.getGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    if (Words.isLoaded()) {

      int tX = 0;
      if (previous != null) {
        g2.setColor(previous.getBackground());
        long lapse = System.currentTimeMillis() - previousSet;
        if (lapse > TRANSISTION_TIME) {
          previous = null;
        } else {
          double percentage = (TRANSISTION_TIME - (double) lapse) / TRANSISTION_TIME;
          tX = (int) (getWidth() * percentage);
        }
        g2.fillRect(getWidth() - tX, 0, getWidth(), getHeight());
      }
      g2.setColor(mode.getBackground());
      g2.fillRect(tX, 0, getWidth(), getHeight());
    } else {

      g2.setColor(
          new Color(
              mode.getBackground().getRed(),
              (int) (mode.getBackground().getGreen() * Words.getPercent()),
              (int) (mode.getBackground().getBlue() * Words.getPercent())));
      g2.fillRect(0, 0, getWidth(), getHeight());
      g2.setColor(
          new Color(
              mode.getBackground().getRed(),
              mode.getBackground().getGreen(),
              (int) (mode.getBackground().getBlue() * Words.getPercent())));
      int tX = (int) (getWidth() * Words.getPercent());
      setSize((int) (width * Words.getPercent()) + 1, getHeight());
      g2.fillRect(getWidth() - tX, 0, getWidth(), getHeight());
    }
    g2.setColor(Color.WHITE);
    int y = COLLAPSE_LENGTH - PADDING;
    if (word != null) {
      FontMetrics metrics = g2.getFontMetrics();
      y = COLLAPSE_LENGTH + PADDING;
      int x = PADDING * 2;
      int maxX = getWidth() - PADDING * 2;
      if (word.getPronunciation() != null) {
        g2.drawString(
            word.getPronunciation(),
            getWidth() / 2 - metrics.stringWidth(word.getPronunciation()) / 2,
            y);
        x = PADDING * 2;
        y += metrics.getHeight() + PADDING;
      }
      if (mode.equals(Theme.DICT)) {
        for (String string : word.getDefinitions()) {
          String[] division = string.split(" ");
          for (String append : division) {
            int width = metrics.stringWidth(append + " ");
            if (x + width >= maxX) {
              x = PADDING * 2;
              y += metrics.getHeight();
            }
            g2.drawString(append, x, y);
            x += width;
          }
          x = PADDING * 2;
          y += metrics.getHeight() + PADDING;
        }
      } else if (mode.equals(Theme.THES)) {
        if (!word.getSynonyms().isEmpty()) {
          x = PADDING * 4 + metrics.stringWidth(word.getText());
        }
        int storedY = y;
        int height = 0;
        int count = 0;
        for (String string : word.getSynonyms()) {
          if (count == 10) {
            break;
          }
          int width = metrics.stringWidth(string + "->");
          if (x + width >= maxX) {
            x = PADDING * 4 + metrics.stringWidth(word.getText());
            y += metrics.getHeight();
            height += metrics.getHeight();
          }
          g2.drawString(string, x, y);
          x += width;
          count++;
        }

        if (!word.getSynonyms().isEmpty()) {
          y += metrics.getHeight() + PADDING;
          x = PADDING * 2;
          int tY = (storedY += height / 2) - metrics.getHeight() / 2;
          g2.drawString(word.getText(), x, tY);
          g2.setColor(Color.YELLOW);
          g2.drawLine(
              x + metrics.stringWidth(word.getText()),
              tY - metrics.getHeight() / 4,
              x + metrics.stringWidth(word.getText()) + PADDING,
              tY);
          g2.drawLine(
              x + metrics.stringWidth(word.getText()),
              tY - metrics.getHeight() / 4,
              x + metrics.stringWidth(word.getText()) + PADDING,
              tY - metrics.getHeight() / 2);
        }
      } else {
        y -= word.getPronunciation() != null ? PADDING : 0;
      }
    }
    if (!(Math.max(y, getHeight()) - Math.min(y, getHeight()) <= (INTERVAL + 1))) {
      setSize(getWidth(), (int) (getHeight() + Math.abs(INTERVAL) * (y >= getHeight() ? 1 : -1)));
    }
    g2.setColor(Color.WHITE);
    g2.fill(tBounds);
    g2.setColor(Color.BLACK);
    g2.draw(tBounds);
    g2.setFont(INPUT_FONT);
    String text = input.toString() + "";
    float sY = (float) (tBounds.getY() + 22);
    float x = (float) (tBounds.getX() + PADDING / 2D);
    Rectangle2D bounds = g2.getFontMetrics().getStringBounds(text, g2);
    g2.drawString(text, x, sY);
    g2.setColor(Color.BLUE);
    if (suggestion != null) g2.drawString(suggestion, (float) (x + bounds.getWidth()), sY);
    g.drawImage(buffer, 0, 0, null);
  }