Пример #1
0
  @Override
  public void onColorChanged(int color) {
    MathElement begin = textSelector.getBeginObject();
    while (begin != null) {
      begin.setColor(color);

      if (begin == textSelector.getEndObject()) break;
      begin = begin.getNext();
    }
    if (mode != null) mode.finish();
  }
Пример #2
0
 /**
  * This method deletes all reference to a {@link Context} so {@link Activity} could be properly
  * recreated
  */
 @Override
 public void onDestroyView() {
   selectorBegin = textSelector.getBeginObject();
   selectorEnd = textSelector.getEndObject();
   selectorNoBegin = textSelector.isNoBegin();
   selectorNoEnd = textSelector.isNoEnd();
   if (mode != null) {
     mode.finish();
     mode = null;
   }
   super.onDestroyView();
   menu.destroyViews();
   editorScrollX = board.getEditorScrollX();
   editorScrollY = board.getEditorScrollY();
   lines = board.getLines();
   board.destroyViews();
   board = null;
   textSelector.destroy();
   textSelector = null;
 }
Пример #3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int inch = (int) (metrics.density * 160);
    final ExtendedFrameLayout layout = new ExtendedFrameLayout(getActivity());

    layout.setId(BaseActivity.generateViewId());

    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    buttonSize = (int) (inch / 3.0f);
    HorizontalScrollView scrollView = new HorizontalScrollView(getActivity());
    scrollView.setHorizontalScrollBarEnabled(false);
    layout.addView(scrollView);
    scrollView.setLayoutParams(
        new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    if (menu == null) {
      // load and build menu if necessary
      menu = new LaTeXMenu();
      EquationEditorPlugin plugin = EquationEditorPlugin.getPlugin();
      menu.setButtonBackgroundResource(R.drawable.menu_item);
      menu.setSpecialButtonBackgroundResource(R.drawable.menu_item_special);

      int pixelsValue = 4;
      float d = layout.getContext().getResources().getDisplayMetrics().density;
      menu.setMarginButton((int) (pixelsValue * d));
      File assets =
          new File(EquationEditorPlugin.getPluginDirectoryStatic(getActivity()), "assets");
      assets.mkdir();
      File out = new File(assets, "mathMenu.xml");

      plugin.loadAsset(getActivity(), out, "mathMenu.xml");
      FileReader reader = null;
      try {
        reader = new FileReader(out);
        // Creates items in menu
        menu.loadData(getActivity(), reader);
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } finally {
        if (reader != null)
          try {
            reader.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
      }
    }
    menu.setFragmentPluginListener(listener.getFragmentPluginListener());
    // set context for menu
    RelativeLayout menuLayout =
        menu.createLayout(
            getActivity(), buttonSize, buttonSize, buttonSize * 4, (int) (inch * 1.5f));

    scrollView.addView(menuLayout);
    menuLayout.setLayoutParams(
        new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    if (lines == null)
      // Creates a board for the first time
      board = new EditorBoard(this, menu, menu.getLatexMap(), menu.getUnicodeLatex());
    else {
      // Creates a board with already parsed objects. It is typically used after a rotation. For
      // faster reaction time.
      board =
          new EditorBoard(this, menu, menu.getLatexMap(), menu.getUnicodeLatex(), lines, content);
      board.setEditorScrollX(editorScrollX);
      board.setEditorScrollY(editorScrollY);
      if (isChanged) board.makeDirty();
    }
    board.setId(BaseActivity.generateViewId());
    board.setOnContentChangedListener(listener);
    board.setScreen(metrics.widthPixels, metrics.heightPixels);

    layout.addView(board, 0);
    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) board.getLayoutParams();
    params.width = LayoutParams.MATCH_PARENT;
    params.height = LayoutParams.MATCH_PARENT;
    params.topMargin = buttonSize;
    // Place equations drawing below the menu
    board.setLayoutParams(params);

    menu.setOnItemClickListener(
        new LaTeXMenu.OnItemMenuClickListener() {

          @Override
          public void onClick(LaTeXMenu menu, LaTeXMenuButton menuButton, LaTeXButton button) {
            board.addObject(button.getDataObject(), button.getAddon(), button.isNormal());
            if (mode != null) mode.finish();
          }
        });

    board.setOnContentChangedListener(
        new OnContentChangedListener() {

          @Override
          public Task requestPDF() {
            if (EditorFragment.this.listener != null)
              return EditorFragment.this.listener.requestPDF();
            return null;
          }

          @Override
          public void onContentChanged() {
            isChanged = true;
            if (listener != null) listener.onContentChanged();
          }

          @Override
          public AbstractPluginFragment getParentFragment() {
            return listener.getParentFragment();
          }

          @Override
          public FragmentPluginListener getFragmentPluginListener() {
            if (listener != null) return listener.getFragmentPluginListener();
            return null;
          }

          @Override
          public ActionMode startActionMode(Callback textSelector) {
            if (listener != null) return listener.startActionMode(textSelector);
            return null;
          }

          @Override
          public void openFile(String path) {}

          @Override
          public void openData(EditorPlugin plugin, String data, int start, int end) {}

          @Override
          public void requestInsert() {}
        });
    textSelector = new ObjectSelector(board);
    textSelector.setOnMovingHandle(
        new ObjectSelector.OnMovingHandle() {

          @Override
          public void handleStartedMoving() {
            layout.stopLongPressed();
          }
        });

    textSelector.setOnSelecting(
        new ObjectSelector.OnSelecting() {

          @Override
          public void selectingStopped() {
            board.setFocusable(false);
            board.setFocusableInTouchMode(false);
          }

          @Override
          public void selectingStarted() {
            board.setFocusable(true);
            board.setFocusableInTouchMode(true);
          }
        });
    if (selectorBegin != null && selectorEnd != null) {
      textSelector.setSelection(selectorBegin, selectorEnd, selectorNoBegin, selectorNoEnd);
      mode = listener.startActionMode(textSelector);
    }

    return layout;
  }
Пример #4
0
 @Override
 public int getColor() {
   return textSelector.getBeginObject().getColor();
 }