public void addWord(String word, int freq) {
    synchronized (mDbName) {
      SQLiteDatabase db = getWritableDatabase();

      ContentValues values = new ContentValues();
      values.put(Words._ID, word.hashCode()); // ensuring that any word is inserted once
      values.put(Words.WORD, word);
      values.put(Words.FREQUENCY, freq);
      values.put(Words.LOCALE, mCurrentLocale);
      long res = db.insert(TABLE_NAME, null, values);
      if (res < 0) {
        Log.e(
            TAG,
            "Unable to insert '"
                + word
                + "' to SQLite storage ("
                + mCurrentLocale
                + "@"
                + mDbName
                + ")! Result:"
                + res);
      }
      db.close();
    }
  }
 public static int[] parseCSV(String value) {
   int count = 0;
   int lastIndex = 0;
   if (value.length() > 0) {
     count++;
     while ((lastIndex = value.indexOf(",", lastIndex + 1)) > 0) {
       count++;
     }
   }
   int[] values = new int[count];
   count = 0;
   StringTokenizer st = new StringTokenizer(value, ",");
   while (st.hasMoreTokens()) {
     String nextToken = st.nextToken();
     try {
       // Issue 395
       // default behavior
       if (nextToken.length() != 1) {
         values[count++] = Integer.parseInt(nextToken);
       } else {
         // length == 1, assume a char!
         values[count++] = (int) nextToken.charAt(0);
       }
     } catch (NumberFormatException nfe) {
       Log.e(TAG, "Error parsing keycodes " + value);
     }
   }
   return values;
 }
 public void onClick(View view) {
   try {
     String tag = getKey();
     Intent search = new Intent(Intent.ACTION_VIEW);
     search.setData(Uri.parse("market://search?q=AnySoftKeyboard " + tag));
     search.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     getContext().startActivity(search);
   } catch (Exception ex) {
     Log.e(TAG, "Could not launch Store search!", ex);
     mStoreNotFoundView.setVisibility(View.VISIBLE);
   }
 }
Пример #4
0
  public static void newSession(Context context) {
    sSessionCount++;
    sAutoSuggestCount = 0;
    sBackspaceCount = 0;
    sAutoSuggestUndoneCount = 0;
    sManualSuggestCount = 0;
    sWordNotInDictionaryCount = 0;
    sTypedChars = 0;
    sActualChars = 0;
    sState = State.START;

    if (LOGGING) {
      try {
        sKeyLocationFile = context.openFileOutput("key.txt", Context.MODE_APPEND);
        sUserActionFile = context.openFileOutput("action.txt", Context.MODE_APPEND);
      } catch (IOException ioe) {
        Log.e("TextEntryState", "Couldn't open file for output: " + ioe);
      }
    }
  }
Пример #5
0
  public void loadKeyboard(final KeyboardDimens keyboardDimens) {
    mDisplayWidth = keyboardDimens.getKeyboardMaxWidth();
    final float rowVerticalGap = keyboardDimens.getRowVerticalGap();
    final float keyHorizontalGap = keyboardDimens.getKeyHorizontalGap();

    mDefaultHorizontalGap = 0;
    mDefaultWidth = mDisplayWidth / 10;
    mDefaultHeightCode = -1;

    XmlResourceParser parser = mKeyboardContext.getResources().getXml(mLayoutResId);
    boolean inKey = false;
    boolean inRow = false;
    boolean inUnknown = false;
    int row = 0;
    float x = 0;
    float y = rowVerticalGap; // starts with a gap
    int rowHeight = 0;
    Key key = null;
    Row currentRow = null;
    Resources res = mKeyboardContext.getResources();
    boolean skipRow = false;
    int lastVerticalGap = 0;

    try {
      int event;
      while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
        if (event == XmlResourceParser.START_TAG) {
          String tag = parser.getName();
          if (TAG_ROW.equals(tag)) {
            inRow = true;
            x = 0;
            rowHeight = 0;
            currentRow = createRowFromXml(mASKContext, res, parser);
            skipRow = currentRow.mode != 0 && currentRow.mode != mKeyboardMode;
            if (skipRow) {
              skipToEndOfRow(parser);
              inRow = false;
            }
          } else if (TAG_KEY.equals(tag)) {
            inKey = true;
            x += (keyHorizontalGap / 2);
            key =
                createKeyFromXml(
                    mASKContext, res, currentRow, keyboardDimens, (int) x, (int) y, parser);
            rowHeight = Math.max(rowHeight, key.height);
            key.width -= keyHorizontalGap; // the gap is on both
            // sides
            mKeys.add(key);
            if (key.codes[0] == KeyCodes.SHIFT) {
              mShiftKey = key;
              mShiftKeyIndex = mKeys.size() - 1;
              mModifierKeys.add(key);
            } else if (key.codes[0] == KeyCodes.ALT) {
              mModifierKeys.add(key);
            }
          } else if (TAG_KEYBOARD.equals(tag)) {
            parseKeyboardAttributes(mASKContext, res, parser);
          } else {
            inUnknown = true;
            onUnknownTagStart(mKeyboardContext, res, tag, parser);
          }
        } else if (event == XmlResourceParser.END_TAG) {
          if (inKey) {
            inKey = false;
            x += key.gap + key.width;
            x += (keyHorizontalGap / 2);
            if (x > mTotalWidth) {
              mTotalWidth = (int) x;
            }
          } else if (inRow) {
            inRow = false;
            lastVerticalGap = currentRow.verticalGap;
            y += currentRow.verticalGap;
            y += rowHeight;
            y += rowVerticalGap;
            row++;
          } else if (inUnknown) {
            inUnknown = false;
            onUnknownTagEnd();
          }
        }
      }
    } catch (Exception e) {
      Log.e(TAG, "Parse error:" + e);
      e.printStackTrace();
    }
    mTotalHeight = (int) (y - lastVerticalGap);
  }