@Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    Thread.setDefaultUncaughtExceptionHandler(
        new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));

    final Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
      final Bundle data = intent.getBundleExtra(SearchManager.APP_DATA);
      if (data != null) {
        final NetworkLibrary library = NetworkLibrary.Instance();
        final NetworkTree.Key key =
            (NetworkTree.Key) data.getSerializable(NetworkLibraryActivity.TREE_KEY_KEY);
        final NetworkTree tree = library.getTreeByKey(key);
        if (tree instanceof SearchCatalogTree) {
          final SearchCatalogTree searchTree = (SearchCatalogTree) tree;
          final String pattern = intent.getStringExtra(SearchManager.QUERY);
          final MimeType mime = searchTree.getMimeType();
          if (MimeType.APP_ATOM_XML.weakEquals(mime)) {
            searchTree.startItemsLoader(new QuietNetworkContext(), pattern);
          } else if (MimeType.TEXT_HTML.weakEquals(mime)) {
            Util.openInBrowser(this, searchTree.getUrl(pattern));
          }
        }
      }
    }
    finish();
  }
 @Override
 public void run(NetworkTree tree) {
   final Intent intent = new Intent(myActivity, AddCustomCatalogActivity.class);
   Util.intentByLink(intent, tree.getLink());
   intent.setAction(Util.EDIT_CATALOG_ACTION);
   myActivity.startActivity(intent);
 }
示例#3
0
  @Override
  public boolean isVisible(NetworkTree tree) {
    if (!(tree instanceof NetworkCatalogRootTree)) {
      return false;
    }

    final INetworkLink link = tree.getLink();
    final NetworkAuthenticationManager mgr = link.authenticationManager();
    return mgr != null
        && !mgr.mayBeAuthorised(false)
        && Util.isRegistrationSupported(myActivity, link);
  }
 private static boolean runActionStatic(Activity activity, NetworkBookTree tree, int actionCode) {
   final NetworkBookItem book = tree.Book;
   switch (actionCode) {
     case ActionCode.DOWNLOAD_BOOK:
       Util.doDownloadBook(activity, book, false);
       return true;
     case ActionCode.DOWNLOAD_DEMO:
       Util.doDownloadBook(activity, book, true);
       return true;
     case ActionCode.READ_BOOK:
       doReadBook(activity, book, false);
       return true;
     case ActionCode.READ_DEMO:
       doReadBook(activity, book, true);
       return true;
     case ActionCode.DELETE_BOOK:
       tryToDeleteBook(activity, book, false);
       return true;
     case ActionCode.DELETE_DEMO:
       tryToDeleteBook(activity, book, true);
       return true;
     case ActionCode.BUY_DIRECTLY:
       doBuyDirectly(activity, tree);
       return true;
     case ActionCode.BUY_IN_BROWSER:
       doBuyInBrowser(activity, book);
       return true;
     case ActionCode.ADD_BOOK_TO_BASKET:
       book.Link.getBasketItem().add(book);
       return true;
     case ActionCode.REMOVE_BOOK_FROM_BASKET:
       book.Link.getBasketItem().remove(book);
       return true;
     case ActionCode.OPEN_BASKET:
       new OpenCatalogAction(activity)
           .run(NetworkLibrary.Instance().getFakeBasketTree(book.Link.getBasketItem()));
       return true;
   }
   return false;
 }
示例#5
0
 @Override
 public void run(NetworkTree tree) {
   Util.runAuthenticationDialog(myActivity, tree.getLink(), null);
 }
示例#6
0
 @Override
 protected void run(NetworkTree tree) {
   Util.runRegistrationDialog(myActivity, tree.getLink());
 }
 private static void doBuyInBrowser(Activity activity, final NetworkBookItem book) {
   BookUrlInfo reference = book.reference(UrlInfo.Type.BookBuyInBrowser);
   if (reference != null) {
     Util.openInBrowser(activity, reference.Url);
   }
 }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Thread.setDefaultUncaughtExceptionHandler(
        new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
    setContentView(R.layout.authentication);

    final Intent intent = getIntent();

    final String host = intent.getStringExtra(HOST_KEY);
    final String area = intent.getStringExtra(AREA_KEY);
    final String username = intent.getStringExtra(USERNAME_KEY);
    final String error = intent.getStringExtra(ERROR_KEY);
    myCustomAuthentication = intent.getBooleanExtra(CUSTOM_AUTH_KEY, false);

    if (myCustomAuthentication) {
      myLink = NetworkLibrary.Instance().getLinkByUrl(String.valueOf(intent.getData()));
      if (myLink == null) {
        finish();
        return;
      }
      setResult(RESULT_CANCELED, Util.intentByLink(new Intent(), myLink));
    } else {
      myLink = null;
      setResult(RESULT_CANCELED);
    }

    myOnSuccessRunnable = ourOnSuccessRunnableMap.remove(intent.getLongExtra(RUNNABLE_KEY, -1));

    myResource = ZLResource.resource("dialog").getResource("AuthenticationDialog");

    setTitle(host != null ? host : myResource.getResource("title").getValue());

    if (area != null && !"".equals(area)) {
      findTextView(R.id.authentication_subtitle).setText(area);
    } else {
      findTextView(R.id.authentication_subtitle).setVisibility(View.GONE);
    }
    final TextView warningView = findTextView(R.id.authentication_unencrypted_warning);
    if ("https".equalsIgnoreCase(intent.getStringExtra(SCHEME_KEY))) {
      warningView.setVisibility(View.GONE);
    } else {
      warningView.setText(myResource.getResource("unencryptedWarning").getValue());
    }
    findTextView(R.id.authentication_username_label)
        .setText(myResource.getResource("login").getValue());
    findTextView(R.id.authentication_password_label)
        .setText(myResource.getResource("password").getValue());

    myUsernameView = findTextView(R.id.authentication_username);
    myUsernameView.setText(username);

    setError(error);

    final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button");

    final View buttonsView = findViewById(R.id.authentication_buttons);
    myOkButton = (Button) buttonsView.findViewById(R.id.ok_button);
    myOkButton.setText(buttonResource.getResource("ok").getValue());
    myOkButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            final String username = myUsernameView.getText().toString();
            final String password = findTextView(R.id.authentication_password).getText().toString();
            if (myCustomAuthentication) {
              runCustomAuthentication(username, password);
            } else {
              finishOk(username, password);
            }
          }
        });

    final Button cancelButton = (Button) buttonsView.findViewById(R.id.cancel_button);
    cancelButton.setText(buttonResource.getResource("cancel").getValue());
    cancelButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            runOnUiThread(
                new Runnable() {
                  public void run() {
                    if (myLink != null) {
                      final NetworkAuthenticationManager mgr = myLink.authenticationManager();
                      if (mgr.mayBeAuthorised(false)) {
                        mgr.logOut();
                      }
                    }
                    final NetworkLibrary library = NetworkLibrary.Instance();
                    library.invalidateVisibility();
                    library.synchronize();
                  }
                });
            finish();
          }
        });
  }