private void migrate(Context context) {
    final int version = myDatabase.getVersion();
    final int currentVersion = 1;
    if (version >= currentVersion) {
      return;
    }
    UIUtil.wait(
        (version == 0) ? "creatingButtonsDatabase" : "updatingButtonsDatabase",
        new Runnable() {
          public void run() {
            myDatabase.beginTransaction();

            switch (version) {
              case 0:
                createTables();
            }
            myDatabase.setTransactionSuccessful();
            myDatabase.endTransaction();

            myDatabase.execSQL("VACUUM");
            myDatabase.setVersion(currentVersion);
          }
        },
        context);
  }
Exemplo n.º 2
0
 private void runCustomAuthentication(final String username, final String password) {
   final NetworkAuthenticationManager mgr = myLink.authenticationManager();
   final Runnable runnable =
       new Runnable() {
         public void run() {
           try {
             mgr.authorise(username, password);
             if (mgr.needsInitialization()) {
               mgr.initialize();
             }
             finishOk(username, password);
             if (myOnSuccessRunnable != null) {
               myOnSuccessRunnable.run();
             }
             final NetworkLibrary library = NetworkLibrary.Instance();
             library.invalidateVisibility();
             library.synchronize();
           } catch (final ZLNetworkException e) {
             mgr.logOut();
             runOnUiThread(
                 new Runnable() {
                   public void run() {
                     setError(e.getMessage());
                   }
                 });
           }
         }
       };
   UIUtil.wait("authentication", runnable, this);
 }
Exemplo n.º 3
0
 private void gotoBookmark(Bookmark bookmark) {
   bookmark.markAsAccessed();
   myCollection.saveBookmark(bookmark);
   final Book book = myCollection.getBookById(bookmark.getBookId());
   if (book != null) {
     FBReader.openBookActivity(this, book, bookmark);
   } else {
     UIUtil.showErrorMessage(this, "cannotOpenBook");
   }
 }
Exemplo n.º 4
0
 @Override
 protected void onNewIntent(Intent intent) {
   final Uri data = intent.getData();
   final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance();
   if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
     super.onNewIntent(intent);
   } else if (Intent.ACTION_VIEW.equals(intent.getAction())
       && data != null
       && "fbreader-action".equals(data.getScheme())) {
     fbReader.runAction(data.getEncodedSchemeSpecificPart(), data.getFragment());
   } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
     final String pattern = intent.getStringExtra(SearchManager.QUERY);
     final Runnable runnable =
         new Runnable() {
           public void run() {
             final TextSearchPopup popup =
                 (TextSearchPopup) fbReader.getPopupById(TextSearchPopup.ID);
             popup.initPosition();
             fbReader.TextSearchPatternOption.setValue(pattern);
             if (fbReader.getTextView().search(pattern, true, false, false, false) != 0) {
               runOnUiThread(
                   new Runnable() {
                     public void run() {
                       fbReader.showPopup(popup.getId());
                     }
                   });
             } else {
               runOnUiThread(
                   new Runnable() {
                     public void run() {
                       UIUtil.showErrorMessage(FBReader.this, "textNotFound");
                       popup.StartPosition = null;
                     }
                   });
             }
           }
         };
     UIUtil.wait("search", runnable, this);
   } else {
     super.onNewIntent(intent);
   }
 }
  private void refreshCatalogsList() {
    final NetworkView view = NetworkView.Instance();

    final Handler handler =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {
            if (msg.obj == null) {
              view.finishBackgroundUpdate();
            } else {
              final ZLResource dialogResource = ZLResource.resource("dialog");
              final ZLResource boxResource = dialogResource.getResource("networkError");
              final ZLResource buttonResource = dialogResource.getResource("button");
              new AlertDialog.Builder(NetworkLibraryActivity.this)
                  .setTitle(boxResource.getResource("title").getValue())
                  .setMessage((String) msg.obj)
                  .setIcon(0)
                  .setPositiveButton(buttonResource.getResource("ok").getValue(), null)
                  .create()
                  .show();
            }
          }
        };

    UIUtil.wait(
        "updatingCatalogsList",
        new Runnable() {
          public void run() {
            String error = null;
            try {
              view.runBackgroundUpdate(true);
            } catch (ZLNetworkException e) {
              error = e.getMessage();
            }
            handler.sendMessage(handler.obtainMessage(0, error));
          }
        },
        this);
  }
Exemplo n.º 6
0
  @Override
  protected void onNewIntent(Intent intent) {
    OrientationUtil.setOrientation(this, intent);

    if (!Intent.ACTION_SEARCH.equals(intent.getAction())) {
      return;
    }
    String pattern = intent.getStringExtra(SearchManager.QUERY);
    myBookmarkSearchPatternOption.setValue(pattern);

    final LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>();
    pattern = pattern.toLowerCase();
    for (Bookmark b : myAllBooksAdapter.bookmarks()) {
      if (MiscUtil.matchesIgnoreCase(b.getText(), pattern)) {
        bookmarks.add(b);
      }
    }
    if (!bookmarks.isEmpty()) {
      showSearchResultsTab(bookmarks);
    } else {
      UIUtil.showErrorMessage(this, "bookmarkNotFound");
    }
  }
Exemplo n.º 7
0
 private static void installDictionary(Activity activity) {
   if (!PackageUtil.installFromMarket(activity, "com.socialnmobile.colordict")) {
     UIUtil.showErrorMessage(activity, "cannotRunAndroidMarket", "ColorDict");
   }
 }
  private void migrate(Context context) {
    final int version = myDatabase.getVersion();
    final int currentVersion = 19;
    if (version >= currentVersion) {
      return;
    }
    UIUtil.wait(
        (version == 0) ? "creatingBooksDatabase" : "updatingBooksDatabase",
        new Runnable() {
          public void run() {
            myDatabase.beginTransaction();

            switch (version) {
              case 0:
                createTables();
              case 1:
                updateTables1();
              case 2:
                updateTables2();
              case 3:
                updateTables3();
              case 4:
                updateTables4();
              case 5:
                updateTables5();
              case 6:
                updateTables6();
              case 7:
                updateTables7();
              case 8:
                updateTables8();
              case 9:
                updateTables9();
              case 10:
                updateTables10();
              case 11:
                updateTables11();
              case 12:
                updateTables12();
              case 13:
                updateTables13();
              case 14:
                updateTables14();
              case 15:
                updateTables15();
              case 16:
                updateTables16();
              case 17:
                updateTables17();
              case 18:
                updateTables18();
            }
            myDatabase.setTransactionSuccessful();
            myDatabase.endTransaction();

            myDatabase.execSQL("VACUUM");
            myDatabase.setVersion(currentVersion);
          }
        },
        context);
  }