Ejemplo n.º 1
0
  @Override
  public void appendMediaFile(
      final MediaFile mediaFile, final String mediaUrl, ImageLoader imageLoader) {
    if (!mDomHasLoaded) {
      // If the DOM hasn't loaded yet, we won't be able to add media to the ZSSEditor
      // Place them in a queue to be handled when the DOM loaded callback is received
      mWaitingMediaFiles.put(mediaUrl, mediaFile);
      return;
    }

    mWebView.post(
        new Runnable() {
          @Override
          public void run() {
            if (URLUtil.isNetworkUrl(mediaUrl)) {
              String mediaId = mediaFile.getMediaId();
              mWebView.execJavaScriptFromString(
                  "ZSSEditor.insertImage('" + mediaUrl + "', '" + mediaId + "');");
            } else {
              String id = mediaFile.getMediaId();
              // String id = mediaFile.getId();
              // 报错在这里
              // 需要把本地url替换成leanote url
              // http://leanote.com/api/file/getImage?fileId=5503537b38f4111dcb0000d1

              String imageUrl = mediaFile.getFileURL();
              mWebView.execJavaScriptFromString(
                  "ZSSEditor.insertLocalImage(" + id + ", '" + imageUrl + "');");
              // mWebView.execJavaScriptFromString("ZSSEditor.setProgressOnImage(" + id + ", " + 0 +
              // ");");
              // mUploadingMediaIds.add(id);
            }
          }
        });
  }
Ejemplo n.º 2
0
  public void onDomLoaded() {
    mWebView.post(
        new Runnable() {
          public void run() {
            mDomHasLoaded = true;

            mWebView.execJavaScriptFromString(
                "ZSSEditor.getField('zss_field_content').setMultiline('true');");

            // Set title and content placeholder text
            mWebView.execJavaScriptFromString(
                "ZSSEditor.getField('zss_field_title').setPlaceholderText('"
                    + mTitlePlaceholder
                    + "');");
            mWebView.execJavaScriptFromString(
                "ZSSEditor.getField('zss_field_content').setPlaceholderText('"
                    + mContentPlaceholder
                    + "');");

            // Load title and content into ZSSEditor
            updateVisualEditorFields();

            // If there are images that are still in progress (because the editor exited before they
            // completed),
            // set them to failed, so the user can restart them (otherwise they will stay stuck in
            // 'uploading' mode)
            // mWebView.execJavaScriptFromString("ZSSEditor.markAllUploadingImagesAsFailed();");

            // Update the list of failed media uploads
            // mWebView.execJavaScriptFromString("ZSSEditor.getFailedImages();");

            hideActionBarIfNeeded();

            // Reset all format bar buttons (in case they remained active through activity
            // re-creation)
            ToggleButton htmlButton =
                (ToggleButton) getActivity().findViewById(R.id.format_bar_button_html);
            htmlButton.setChecked(false);
            for (ToggleButton button : mTagToggleButtonMap.values()) {
              button.setChecked(false);
            }

            // Add any media files that were placed in a queue due to the DOM not having loaded yet
            if (mWaitingMediaFiles.size() > 0) {
              // Image insertion will only work if the content field is in focus
              // (for a new post, no field is in focus until user action)
              mWebView.execJavaScriptFromString("ZSSEditor.getField('zss_field_content').focus();");

              for (Map.Entry<String, MediaFile> entry : mWaitingMediaFiles.entrySet()) {
                appendMediaFile(entry.getValue(), entry.getKey(), null);
              }
              mWaitingMediaFiles.clear();
            }
          }
        });
  }
Ejemplo n.º 3
0
 public void onSelectionStyleChanged(final Map<String, Boolean> changeMap) {
   mWebView.post(
       new Runnable() {
         public void run() {
           for (Map.Entry<String, Boolean> entry : changeMap.entrySet()) {
             // Handle toggling format bar style buttons
             ToggleButton button = mTagToggleButtonMap.get(entry.getKey());
             if (button != null) {
               button.setChecked(entry.getValue());
             }
           }
         }
       });
 }
Ejemplo n.º 4
0
 public void onSelectionChanged(final Map<String, String> selectionArgs) {
   final String focusedFieldId = selectionArgs.get("id"); // The field now in focus
   mWebView.post(
       new Runnable() {
         @Override
         public void run() {
           if (!focusedFieldId.isEmpty()) {
             switch (focusedFieldId) {
               case "zss_field_title":
                 updateFormatBarEnabledState(false);
                 break;
               case "zss_field_content":
                 updateFormatBarEnabledState(true);
                 break;
             }
           }
         }
       });
 }
Ejemplo n.º 5
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   if (item.getItemId() == BUTTON_ID_LOG_HTML) {
     if (mDebugModeEnabled) {
       // Log the raw html
       mWebView.post(
           new Runnable() {
             @Override
             public void run() {
               mWebView.execJavaScriptFromString("console.log(document.body.innerHTML);");
             }
           });
     } else {
       AppLog.d(AppLog.T.EDITOR, "Could not execute JavaScript - debug mode not enabled");
     }
     return true;
   } else {
     return super.onOptionsItemSelected(item);
   }
 }
Ejemplo n.º 6
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);
          }
        }
      }
    }
  }