Пример #1
0
 @Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   menu.add(0, BUTTON_ID_LOG_HTML, 0, "Log HTML")
       .setIcon(R.drawable.ic_log_html)
       .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
   super.onCreateOptionsMenu(menu, inflater);
 }
Пример #2
0
 @Override
 public void onDetach() {
   // Soft cancel (delete flag off) all media uploads currently in progress
   //        for (String mediaId : mUploadingMediaIds) {
   //            mEditorFragmentListener.onMediaUploadCancelClicked(mediaId, false);
   //        }
   super.onDetach();
 }
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   if (getArguments() != null) {
     mParamTitle = getArguments().getString(ARG_PARAM_TITLE);
     mParamContent = getArguments().getString(ARG_PARAM_CONTENT);
   }
 }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == LegacyEditorFragment.ACTIVITY_REQUEST_CODE_CREATE_LINK && data != null) {
      Bundle extras = data.getExtras();
      if (extras == null) {
        return;
      }
      String linkURL = extras.getString("linkURL");
      String linkText = extras.getString("linkText");
      createLinkFromSelection(linkURL, linkText);
    }
  }
Пример #5
0
 @Override
 public void onResume() {
   super.onResume();
   // If the editor was previously paused and the current orientation is landscape,
   // hide the actionbar because the keyboard is going to appear (even if it was hidden
   // prior to being paused).
   mWebView.setWebViewClient(new LeaWebViewClient());
   if (mEditorWasPaused
       && (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
       && !getResources().getBoolean(R.bool.is_large_tablet_landscape)) {
     mIsKeyboardOpen = true;
     mHideActionBarOnSoftKeyboardUp = true;
     hideActionBarIfNeeded();
   }
 }
  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    WPImageSpan[] spans =
        mContentEditText
            .getText()
            .getSpans(0, mContentEditText.getText().length(), WPEditImageSpan.class);

    if (spans != null && spans.length > 0) {
      outState.putParcelableArray(KEY_IMAGE_SPANS, spans);
    }

    outState.putInt(KEY_START, mContentEditText.getSelectionStart());
    outState.putInt(KEY_END, mContentEditText.getSelectionEnd());
    outState.putString(KEY_CONTENT, mContentEditText.getText().toString());
  }
Пример #7
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if ((requestCode == LinkDialogFragment.LINK_DIALOG_REQUEST_CODE_ADD
        || requestCode == LinkDialogFragment.LINK_DIALOG_REQUEST_CODE_UPDATE)) {

      if (resultCode == LinkDialogFragment.LINK_DIALOG_REQUEST_CODE_DELETE) {
        mWebView.execJavaScriptFromString("ZSSEditor.unlink();");
        return;
      }

      if (data == null) {
        return;
      }

      Bundle extras = data.getExtras();
      if (extras == null) {
        return;
      }

      String linkUrl = extras.getString("linkURL");
      String linkText = extras.getString("linkText");

      if (linkText == null || linkText.equals("")) {
        linkText = linkUrl;
      }

      if (mSourceView.getVisibility() == View.VISIBLE) {
        Editable content = mSourceViewContent.getText();
        if (content == null) {
          return;
        }

        if (mSelectionStart < mSelectionEnd) {
          content.delete(mSelectionStart, mSelectionEnd);
        }

        String urlHtml = "<a href=\"" + linkUrl + "\">" + linkText + "</a>";

        content.insert(mSelectionStart, urlHtml);
        mSourceViewContent.setSelection(mSelectionStart + urlHtml.length());
      } else {
        String jsMethod;
        if (requestCode == LinkDialogFragment.LINK_DIALOG_REQUEST_CODE_ADD) {
          jsMethod = "ZSSEditor.insertLink";
        } else {
          jsMethod = "ZSSEditor.updateLink";
        }
        mWebView.execJavaScriptFromString(
            jsMethod
                + "('"
                + Utils.escapeHtml(linkUrl)
                + "', '"
                + Utils.escapeHtml(linkText)
                + "');");
      }
    } else if (requestCode == ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_REQUEST_CODE) {
      if (data == null) {
        return;
      }

      Bundle extras = data.getExtras();
      if (extras == null) {
        return;
      }

      final String imageMeta = extras.getString("imageMeta");
      final int imageRemoteId = extras.getInt("imageRemoteId");
      final boolean isFeaturedImage = extras.getBoolean("isFeatured");

      mWebView.post(
          new Runnable() {
            @Override
            public void run() {
              mWebView.execJavaScriptFromString(
                  "ZSSEditor.updateCurrentImageMeta('" + imageMeta + "');");
            }
          });

      if (imageRemoteId != 0) {
        if (isFeaturedImage) {
          mFeaturedImageId = imageRemoteId;
          mEditorFragmentListener.onFeaturedImageChanged(mFeaturedImageId);
        } else {
          // If this image was unset as featured, clear the featured image id
          if (mFeaturedImageId == imageRemoteId) {
            mFeaturedImageId = 0;
            mEditorFragmentListener.onFeaturedImageChanged(mFeaturedImageId);
          }
        }
      }
    }
  }
Пример #8
0
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if (getView() != null) {
      // Reload the format bar to make sure the correct one for the new screen width is being used
      View formatBar = getView().findViewById(R.id.format_bar);

      if (formatBar != null) {
        // Remember the currently active format bar buttons so they can be re-activated after the
        // reload
        ArrayList<String> activeTags = new ArrayList<>();
        for (Map.Entry<String, ToggleButton> entry : mTagToggleButtonMap.entrySet()) {
          if (entry.getValue().isChecked()) {
            activeTags.add(entry.getKey());
          }
        }

        ViewGroup parent = (ViewGroup) formatBar.getParent();
        parent.removeView(formatBar);

        formatBar = getActivity().getLayoutInflater().inflate(R.layout.format_bar, parent, false);
        formatBar.setId(R.id.format_bar);
        parent.addView(formatBar);

        setupFormatBarButtonMap(formatBar);

        // Restore the active format bar buttons
        for (String tag : activeTags) {
          mTagToggleButtonMap.get(tag).setChecked(true);
        }

        if (mSourceView.getVisibility() == View.VISIBLE) {
          ToggleButton htmlButton =
              (ToggleButton) formatBar.findViewById(R.id.format_bar_button_html);
          htmlButton.setChecked(true);
        }
      }

      // Reload HTML mode margins
      View sourceViewTitle = getView().findViewById(R.id.sourceview_title);
      View sourceViewContent = getView().findViewById(R.id.sourceview_content);

      if (sourceViewTitle != null && sourceViewContent != null) {
        int sideMargin =
            (int) getActivity().getResources().getDimension(R.dimen.sourceview_side_margin);

        ViewGroup.MarginLayoutParams titleParams =
            (ViewGroup.MarginLayoutParams) sourceViewTitle.getLayoutParams();
        ViewGroup.MarginLayoutParams contentParams =
            (ViewGroup.MarginLayoutParams) sourceViewContent.getLayoutParams();

        titleParams.setMargins(
            sideMargin, titleParams.topMargin, sideMargin, titleParams.bottomMargin);
        contentParams.setMargins(
            sideMargin, contentParams.topMargin, sideMargin, contentParams.bottomMargin);
      }
    }

    // Toggle action bar auto-hiding for the new orientation
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE
        && !getResources().getBoolean(R.bool.is_large_tablet_landscape)) {
      mHideActionBarOnSoftKeyboardUp = true;
      hideActionBarIfNeeded();
    } else {
      mHideActionBarOnSoftKeyboardUp = false;
      showActionBarIfNeeded();
    }
  }
Пример #9
0
 @Override
 public void onPause() {
   super.onPause();
   mEditorWasPaused = true;
   mIsKeyboardOpen = false;
 }
Пример #10
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
 }
 @Override
 public void onConfigurationChanged(Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   mFullViewBottom = mRootView.getBottom();
 }
 @Override
 public void onViewCreated(View view, Bundle savedInstanceState) {
   super.onViewCreated(view, savedInstanceState);
   mRootView = view;
   mRootView.getViewTreeObserver().addOnGlobalLayoutListener(mGlobalLayoutListener);
 }
 @Override
 public void onDetach() {
   super.onDetach();
 }