示例#1
0
  private boolean menuClick(View v, boolean longClick) {
    boolean goToTOC = longClick;
    longClick = false;
    MenuButton mb = (MenuButton) v;
    MenuState newMenuState = menuState.goForward(mb.getNode(), mb.getSectionNode());
    Intent intent;
    if (mb.isBook()) {
      Book book = null;
      try {
        if (!Settings.getUseAPI()
            && !Database.hasOfflineDB()) { // There's no DB //TODO make it work with API
          Settings.setUseAPI(true);
        }
        book = new Book(newMenuState.getCurrNode().getTitle(Util.Lang.EN));
        if (goToTOC) {
          intent = TOCActivity.getStartTOCActivityIntent(context, book, null);
          /// intent = new Intent(context, TOCActivity.class);
          // intent.putExtra("currBook", book);
          // intent.putExtra("lang", newMenuState.getLang());
          context.startActivity(intent);
          return true;
        } else {
          SuperTextActivity.startNewTextActivityIntent(context, book, longClick);
        }
      } catch (Book.BookNotFoundException e) {
        Toast.makeText(context, MyApp.getRString(R.string.sorry_book_not_found), Toast.LENGTH_SHORT)
            .show();
      }

    } else {
      intent = new Intent(context, MenuActivity.class);
      Bundle options = null;
      if (longClick) {
        intent = MyApp.startNewTab(intent);
        options =
            ActivityOptionsCompat.makeCustomAnimation(
                    context, R.animator.activity_zoom_in, R.animator.activity_zoom_out)
                .toBundle();
      }
      intent.putExtra("menuState", newMenuState);
      intent.putExtra("hasSectionBack", mb.getSectionNode() != null);
      intent.putExtra("hasTabBack", hasTabs);

      if (longClick) {
        ActivityCompat.startActivityForResult((Activity) context, intent, 0, options);
      } else {
        ((Activity) context).startActivityForResult(intent, 0);
      }
    }

    return false;
  }
示例#2
0
 @Override
 protected void onPostExecute(Boolean success) {
   super.onPostExecute(success);
   isWorking = false;
   if (success == false) {
     if (APIError)
       Toast.makeText(
               superTextActivity,
               MyApp.getRString(R.string.not_avil_in_online_mode),
               Toast.LENGTH_SHORT)
           .show();
     if (finishedEverything)
       Toast.makeText(
               superTextActivity,
               MyApp.getRString(R.string.didnt_find_query_in_book),
               Toast.LENGTH_SHORT)
           .show();
     return;
   }
   superTextActivity.postFindOnPageBackground();
   if (goingToNode != null) {
     Log.d("findOnPage", "node:" + goingToNode);
     superTextActivity.lastLoadedNode = null;
     superTextActivity.firstLoadedNode = goingToNode;
     superTextActivity.openToSegment = goingToSegment;
     if (superTextActivity.openToSegment != null) {
       if (snackbar == null || !snackbar.isShown())
         snackbar =
             Snackbar.make(
                 superTextActivity.searchActionBarRoot,
                 superTextActivity.openToSegment.getLocationString(superTextActivity.menuLang),
                 Snackbar.LENGTH_SHORT);
       else {
         snackbar.setText(
             superTextActivity.openToSegment.getLocationString(superTextActivity.menuLang));
       }
       snackbar.show();
     }
     superTextActivity.init();
   }
 }
 // segment is used to update segment list
 public void setCurrLinkCount(LinkFilter linkCount, Segment segment) {
   // try not to update too often
   if (!linkCount.equals(currLinkCount)) {
     currLinkCount = linkCount;
     if (segment
         != null) // o/w no need to update itemList. You probably just initialized LinkTextAdapter
     try {
         setItemList(Link.getLinkedTexts(segment, currLinkCount));
       } catch (API.APIException e) {
         setItemList(new ArrayList<Segment>());
         API.makeAPIErrorToast(activity);
       } catch (Exception e) {
         setItemList(new ArrayList<Segment>());
         try {
           Toast.makeText(
                   activity, MyApp.getRString(R.string.error_getting_links), Toast.LENGTH_SHORT)
               .show();
         } catch (Exception e1) {
           e1.printStackTrace();
         }
       }
   }
 }