Exemplo n.º 1
0
  @Override
  public void onNotesSelected(NoteInfo note) {
    if (!isAdded()) return;

    if (note == null) {
      ToastUtils.showToast(getActivity(), R.string.note_not_found);
      return;
    }

    ActivityLauncher.previewNoteForResult(getActivity(), note.getId());
  }
Exemplo n.º 2
0
  @Override
  public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.format_bar_button_html) {
      // Don't switch to HTML mode if currently uploading media
      //            if (!mUploadingMediaIds.isEmpty()) {
      //                ((ToggleButton) v).setChecked(false);
      //
      //                if (isAdded()) {
      //                    ToastUtils.showToast(getActivity(),
      // R.string.alert_html_toggle_uploading, ToastUtils.Duration.LONG);
      //                }
      //                return;
      //            }

      clearFormatBarButtons();
      updateFormatBarEnabledState(true);

      if (((ToggleButton) v).isChecked()) {
        mSourceViewTitle.setText(getTitle());

        SpannableString spannableContent = new SpannableString(getContent());
        HtmlStyleUtils.styleHtmlForDisplay(spannableContent);
        mSourceViewContent.setText(spannableContent);

        mWebView.setVisibility(View.GONE);
        mSourceView.setVisibility(View.VISIBLE);

        mSourceViewContent.requestFocus();
        mSourceViewContent.setSelection(0);

        InputMethodManager imm =
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE));
        imm.showSoftInput(mSourceViewContent, InputMethodManager.SHOW_IMPLICIT);
      } else {
        mWebView.setVisibility(View.VISIBLE);
        mSourceView.setVisibility(View.GONE);

        mTitle = mSourceViewTitle.getText().toString();
        mContentHtml = mSourceViewContent.getText().toString();
        updateVisualEditorFields();

        mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').focus();");
      }
    } else if (id == R.id.format_bar_button_media) {
      ((ToggleButton) v).setChecked(false);

      if (mSourceView.getVisibility() == View.VISIBLE) {
        ToastUtils.showToast(
            getActivity(), R.string.alert_insert_image_html_mode, ToastUtils.Duration.LONG);
      } else {
        mEditorFragmentListener.onAddMediaClicked();
        if (isAdded()) {
          getActivity().openContextMenu(mTagToggleButtonMap.get(TAG_FORMAT_BAR_BUTTON_MEDIA));
        }
      }
    } else if (id == R.id.format_bar_button_link) {
      if (!((ToggleButton) v).isChecked()) {
        // The link button was checked when it was pressed; remove the current link
        mWebView.execJavaScriptFromString("ZSSEditor.unlink();");
        return;
      }

      ((ToggleButton) v).setChecked(false);

      LinkDialogFragment linkDialogFragment = new LinkDialogFragment();
      linkDialogFragment.setTargetFragment(this, LinkDialogFragment.LINK_DIALOG_REQUEST_CODE_ADD);

      Bundle dialogBundle = new Bundle();

      // Pass selected text to dialog
      if (mSourceView.getVisibility() == View.VISIBLE) {
        // HTML mode
        mSelectionStart = mSourceViewContent.getSelectionStart();
        mSelectionEnd = mSourceViewContent.getSelectionEnd();

        String selectedText =
            mSourceViewContent.getText().toString().substring(mSelectionStart, mSelectionEnd);
        dialogBundle.putString("linkText", selectedText);
      } else {
        // Visual mode
        mGetSelectedTextCountDownLatch = new CountDownLatch(1);
        mWebView.execJavaScriptFromString("ZSSEditor.execFunctionForResult('getSelectedText');");
        try {
          if (mGetSelectedTextCountDownLatch.await(1, TimeUnit.SECONDS)) {
            dialogBundle.putString("linkText", mJavaScriptResult);
          }
        } catch (InterruptedException e) {
          AppLog.d(AppLog.T.EDITOR, "Failed to obtain selected text from JS editor.");
        }
      }

      linkDialogFragment.setArguments(dialogBundle);
      linkDialogFragment.show(getFragmentManager(), "LinkDialogFragment");
    } else {
      if (v instanceof ToggleButton) {
        onFormattingButtonClicked((ToggleButton) v);
      }
    }
  }