@Override
  protected final void loadAllResources() {
    mNextWordDictionary = new NextWordDictionary(mContext, mLocale);
    mNextWordDictionary.load();

    BTreeDictionary androidBuiltIn = null;
    try {
      // The only reason I see someone uses this, is for development or debugging.
      if (AnyApplication.getConfig().alwaysUseFallBackUserDictionary())
        throw new RuntimeException("User requested to always use fall-back user-dictionary.");

      androidBuiltIn = createAndroidUserDictionary(mContext, mLocale);
      androidBuiltIn.loadDictionary();
      mActualDictionary = androidBuiltIn;
    } catch (Exception e) {
      Logger.w(
          TAG,
          "Can not load Android's built-in user dictionary (since '%s'). FallbackUserDictionary to the rescue!",
          e.getMessage());
      if (androidBuiltIn != null) {
        try {
          androidBuiltIn.close();
        } catch (Exception buildInCloseException) {
          // it's an half-baked object, no need to worry about it
          buildInCloseException.printStackTrace();
          Logger.w(
              TAG, "Failed to close the build-in user dictionary properly, but it should be fine.");
        }
      }
      BTreeDictionary fallback = createFallbackUserDictionary(mContext, mLocale);
      fallback.loadDictionary();

      mActualDictionary = fallback;
    }
  }
示例#2
0
 @Nullable
 public final Context getPackageContext() {
   Context c = mPackageContext.get();
   if (c == null) {
     try {
       c = mAskAppContext.createPackageContext(mPackageName, Context.CONTEXT_IGNORE_SECURITY);
       mPackageContext = new WeakReference<>(c);
     } catch (NameNotFoundException e) {
       Logger.w(TAG, "Failed to find package %s!", mPackageName);
       Logger.w(TAG, "Failed to find package! ", e);
     }
   }
   return c;
 }