Exemplo n.º 1
0
 @SuppressLint("NewApi")
 private void enableWebDebugging(boolean enable) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
     AppLog.i(T.EDITOR, "Enabling web debugging");
     WebView.setWebContentsDebuggingEnabled(enable);
   }
 }
Exemplo n.º 2
0
  /**
   * Returns the contents of the content field from the JavaScript editor. Should be called from a
   * background thread where possible.
   */
  @Override
  public CharSequence getContent() {
    if (!isAdded()) {
      return "";
    }

    if (mSourceView != null && mSourceView.getVisibility() == View.VISIBLE) {
      mContentHtml = mSourceViewContent.getText().toString();
      return StringUtils.notNullStr(mContentHtml);
    }

    if (Looper.myLooper() == Looper.getMainLooper()) {
      AppLog.d(T.EDITOR, "getContent() called from UI thread");
    }

    mGetContentCountDownLatch = new CountDownLatch(1);

    // All WebView methods must be called from the UI thread
    getActivity()
        .runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                mWebView.execJavaScriptFromString(
                    "ZSSEditor.getField('zss_field_content').getHTMLForCallback();");
              }
            });

    try {
      mGetContentCountDownLatch.await(1, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
      AppLog.e(T.EDITOR, e);
      Thread.currentThread().interrupt();
    }

    return StringUtils.notNullStr(mContentHtml);
  }
Exemplo n.º 3
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);
   }
 }
Exemplo n.º 4
0
  public boolean hasChanges(NoteDetail otherNote) {

    AppLog.i("title equals:" + !StringUtils.equals(title, otherNote.title));
    AppLog.i("content equals:" + !StringUtils.equals(content, otherNote.content));
    AppLog.i("notebookid equals:" + !StringUtils.equals(noteBookId, otherNote.noteBookId));
    AppLog.i("isMarkDown equal:" + (isMarkDown != otherNote.isMarkDown));
    AppLog.i("tags equals:" + !StringUtils.equals(tags, otherNote.tags));
    AppLog.i("isblog equals:" + (isPublicBlog != otherNote.isPublicBlog));

    return otherNote == null
        || !StringUtils.equals(title, otherNote.title)
        || !StringUtils.equals(content, otherNote.content)
        || !StringUtils.equals(noteBookId, otherNote.noteBookId)
        || isMarkDown != otherNote.isMarkDown
        || !StringUtils.equals(tags, otherNote.tags)
        || isPublicBlog != otherNote.isPublicBlog;
  }
Exemplo n.º 5
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);
      }
    }
  }
Exemplo n.º 6
0
 @Override
 public void onImageLoaded(String localFileId) {
   AppLog.i("download, reload webview...");
   mWebView.reload();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_share_note);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
      actionBar.setElevation(0.0f);
      actionBar.setDisplayHomeAsUpEnabled(true);
      actionBar.setHomeButtonEnabled(true);
    }

    FragmentManager fragmentManager = getFragmentManager();
    Bundle extras = getIntent().getExtras();
    String action = getIntent().getAction();

    if (savedInstanceState == null) {
      if (extras != null) {
        // Load post from the postId passed in extras
        long localNoteId = extras.getLong(EXTRA_NOTEID, 0L);

        mNote = Leanote.leaDB.getLocalNoteById(localNoteId);
        AppLog.i("mnote:" + mNote);
      } else {
        // A postId extra must be passed to this activity
        showErrorAndFinish(R.string.note_not_found);
        return;
      }
    }

    // Ensure we have a valid post
    if (mNote == null) {
      showErrorAndFinish(R.string.note_not_found);
      return;
    }

    setTitle(StringUtils.unescapeHTML("Share Notes"));

    publishToLeaBlog = (Button) findViewById(R.id.share_note_blog_btn);
    publishToLeaBlog.setOnClickListener(
        new Button.OnClickListener() {
          @Override
          public void onClick(View v) {
            mNote.setIsPublicBlog(true);
            Leanote.leaDB.updateNote(mNote);
            Toast.makeText(getApplicationContext(), "Publish to Lea++ Blog", Toast.LENGTH_LONG)
                .show();
          }
        });

    sendMailBtn = (Button) findViewById(R.id.share_note_mail_btn);
    //        mailAddrEditText = (EditText) findViewById(R.id.sourceview_mail_addr);
    //        pwdEditText = (EditText) findViewById(R.id.sourceview_mail_pwd);
    sendMailBtn.setOnClickListener(
        new Button.OnClickListener() {
          @Override
          public void onClick(View v) {
            //                if( mailAddrEditText.getText().length() == 0 ) {
            //                    Toast.makeText(getApplicationContext(), "Please input you e-mail
            // address", Toast.LENGTH_LONG).show();
            //                }
            //
            //                if( pwdEditText.getText().length() == 0 ) {
            //                    Toast.makeText(getApplicationContext(), "Please input you e-mail
            // password", Toast.LENGTH_LONG).show();
            //                }

            Intent data = new Intent(Intent.ACTION_SENDTO);
            data.setData(Uri.parse("mailto:"));
            data.putExtra(Intent.EXTRA_SUBJECT, mNote.getTitle());
            data.putExtra(Intent.EXTRA_TEXT, mNote.getContent());
            startActivity(data);
          }
        });
  }