public void onInsertImage(int resID) { if (DBG) { Log.d(LOG_TAG, "--- onInsertImage by resID"); } insertImageSpan(new ImageSpan(mEST.getContext(), resID)); mEST.notifyStateChanged(mMode, mState); }
public void onInsertImage(Uri uri) { if (DBG) { Log.d(LOG_TAG, "--- onInsertImage by URI: " + uri.getPath() + "," + uri.toString()); } insertImageSpan(new ImageSpan(mEST.getContext(), uri)); mEST.notifyStateChanged(mMode, mState); }
private void handleSelect() { if (DBG) { Log.d(LOG_TAG, "--- handleSelect:" + mEditFlag + "," + mState); } if (!mEditFlag) { return; } if (mState == STATE_SELECT_OFF) { if (isTextSelected()) { Log.e(LOG_TAG, "Selection is off, but selected"); } setSelectStartPos(); blockSoftKey(); mEST.setHintMessage(HINT_MSG_SELECT_END); } else if (mState == STATE_SELECT_ON) { if (isTextSelected()) { Log.e(LOG_TAG, "Selection now start, but selected"); } setSelectedEndPos(); mEST.setHintMessage(HINT_MSG_PUSH_COMPETE); doNextHandle(); } else if (mState == STATE_SELECTED) { if (!isTextSelected()) { Log.e(LOG_TAG, "Selection is done, but not selected"); } setSelectedEndPos(); doNextHandle(); } }
private void setSelection() { if (DBG) { Log.d(LOG_TAG, "--- onSelect:" + mCurStart + "," + mCurEnd); } if (mCurStart >= 0 && mCurStart <= mEST.getText().length() && mCurEnd >= 0 && mCurEnd <= mEST.getText().length()) { if (mCurStart < mCurEnd) { mEST.setSelection(mCurStart, mCurEnd); } else { mEST.setSelection(mCurEnd, mCurStart); } mState = STATE_SELECTED; } else { Log.e( LOG_TAG, "Select is on, but cursor positions are illigal.:" + mEST.getText().length() + "," + mCurStart + "," + mCurEnd); } }
public void onStartBackgroundColor() { if (DBG) { Log.d(LOG_TAG, "--- onClickColor"); } mEST.onShowBackgroundColorAlert(); mEST.notifyStateChanged(mMode, mState); }
private void unsetSelect() { if (DBG) { Log.d(LOG_TAG, "--- offSelect"); } int currpos = mEST.getSelectionStart(); mEST.setSelection(currpos, currpos); mState = STATE_SELECT_OFF; }
private void changeAlign(Layout.Alignment align) { if (DBG) { Log.d(LOG_TAG, "--- changeAlign:" + align); } setStyledTextSpan( new AlignmentSpan.Standard(align), findLineStart(mEST.getText(), mCurStart), findLineEnd(mEST.getText(), mCurEnd)); }
private void setSelectedEndPos() { if (DBG) { Log.d(LOG_TAG, "--- setSelectEndPos:"); } if (mEST.getSelectionStart() == mCurStart) { setSelectedEndPos(mEST.getSelectionEnd()); } else { setSelectedEndPos(mEST.getSelectionStart()); } }
private void setStyledTextSpan(Object span, int start, int end) { if (DBG) { Log.d(LOG_TAG, "--- setStyledTextSpan:" + mMode + "," + start + "," + end); } if (start < end) { mEST.getText().setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { mEST.getText().setSpan(span, end, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }
public void onEndEdit() { if (DBG) { Log.d(LOG_TAG, "--- onEndEdit"); } handleCancel(); mEST.notifyStateChanged(mMode, mState); }
public void onStartColor() { if (DBG) { Log.d(LOG_TAG, "--- onClickColor"); } handleColor(); mEST.notifyStateChanged(mMode, mState); }
public void onFixSelectedItem() { if (DBG) { Log.d(LOG_TAG, "--- onClickComplete"); } handleComplete(); mEST.notifyStateChanged(mMode, mState); }
public void onStartSize() { if (DBG) { Log.d(LOG_TAG, "--- onStartSize"); } handleSize(); mEST.notifyStateChanged(mMode, mState); }
private void blockSoftKey() { if (DBG) { Log.d(LOG_TAG, "--- blockSoftKey:"); } InputMethodManager imm = (InputMethodManager) mEST.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mEST.getWindowToken(), 0); mEST.setOnClickListener( new OnClickListener() { public void onClick(View v) { Log.d(LOG_TAG, "--- ontrackballclick:"); onFixSelectedItem(); } }); mSoftKeyBlockFlag = true; }
private void setSelectStartPos() { if (DBG) { Log.d(LOG_TAG, "--- setSelectStartPos"); } mCurStart = mEST.getSelectionStart(); mState = STATE_SELECT_ON; }
public void onStartSelectAll() { if (DBG) { Log.d(LOG_TAG, "--- onClickSelectAll"); } handleSelectAll(); mEST.notifyStateChanged(mMode, mState); }
public void onInsertHorizontalLine() { if (DBG) { Log.d(LOG_TAG, "--- onInsertHorizontalLine:"); } insertImageSpan(new HorizontalLineSpan(0xFF000000, mEST)); mEST.notifyStateChanged(mMode, mState); }
public void onStartAlign() { if (DBG) { Log.d(LOG_TAG, "--- onStartAlignRight"); } handleAlign(); mEST.notifyStateChanged(mMode, mState); }
public String getHtml() { String htmlBody = Html.toHtml(mEST.getText()); if (DBG) { Log.d(LOG_TAG, "--- getConvertedBody:" + htmlBody); } return htmlBody; }
public void SetHtml(String html) { final Spanned spanned = Html.fromHtml( html, new Html.ImageGetter() { public Drawable getDrawable(String src) { Log.d(LOG_TAG, "--- sethtml: src=" + src); if (src.startsWith("content://")) { Uri uri = Uri.parse(src); try { InputStream is = mEST.getContext().getContentResolver().openInputStream(uri); Bitmap bitmap = BitmapFactory.decodeStream(is); Drawable drawable = new BitmapDrawable(getContext().getResources(), bitmap); drawable.setBounds( 0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); is.close(); return drawable; } catch (Exception e) { Log.e(LOG_TAG, "--- set html: Failed to loaded content " + uri, e); return null; } } Log.d(LOG_TAG, " unknown src=" + src); return null; } }, null); mEST.setText(spanned); }
private void unblockSoftKey() { if (DBG) { Log.d(LOG_TAG, "--- unblockSoftKey:"); } mEST.setOnClickListener(null); mSoftKeyBlockFlag = false; }
public void onStartEdit() { if (DBG) { Log.d(LOG_TAG, "--- onStartEdit"); } Log.d(LOG_TAG, "--- onstartedit:"); handleResetEdit(); mEST.notifyStateChanged(mMode, mState); }
private void handlePaste() { if (DBG) { Log.d(LOG_TAG, "--- handlePaste"); } if (!mEditFlag) { return; } mEST.onTextContextMenuItem(android.R.id.paste); }
public void onCursorMoved() { if (DBG) { Log.d(LOG_TAG, "--- onClickView"); } if (mState == STATE_SELECT_ON || mState == STATE_SELECTED) { handleSelect(); mEST.notifyStateChanged(mMode, mState); } }
private void handleResetEdit() { if (DBG) { Log.d(LOG_TAG, "Reset Editor"); } blockSoftKey(); handleCancel(); mEditFlag = true; mEST.setHintMessage(HINT_MSG_SELECT_START); }
private void handleSelectAll() { if (DBG) { Log.d(LOG_TAG, "--- handleSelectAll"); } if (!mEditFlag) { return; } mEST.selectAll(); mState = STATE_SELECTED; }
private void handleSetSpan(int mode) { if (DBG) { Log.d(LOG_TAG, "--- handleSetSpan:" + mEditFlag + "," + mState + ',' + mMode); } if (!mEditFlag) { Log.e(LOG_TAG, "--- handleSetSpan: Editing is not started."); return; } if (mMode == MODE_NOTHING || mMode == MODE_SELECT) { mMode = mode; if (mState == STATE_SELECTED) { mState = STATE_SELECT_FIX; handleSetSpan(mode); } else { handleSelect(); } } else if (mMode != mode) { handleCancel(); mMode = mode; handleSetSpan(mode); } else { if (mState == STATE_SELECT_FIX) { mEST.setHintMessage(HINT_MSG_NULL); switch (mode) { case MODE_COLOR: mEST.onShowForegroundColorAlert(); break; case MODE_SIZE: mEST.onShowSizeAlert(); break; case MODE_ALIGN: mEST.onShowAlignAlert(); break; default: Log.e(LOG_TAG, "--- handleSetSpan: invalid mode."); break; } } else { Log.d(LOG_TAG, "--- handleSetSpan: do nothing."); } } }
/* If the style of the span is added, add check case for that style */ public boolean isStyledText() { Editable txt = mEST.getText(); int len = txt.length(); if (txt.getSpans(0, len - 1, ParagraphStyle.class).length > 0 || txt.getSpans(0, len - 1, QuoteSpan.class).length > 0 || txt.getSpans(0, len - 1, CharacterStyle.class).length > 0 || mEST.mBackgroundColor != DEFAULT_BACKGROUND_COLOR) { return true; } return false; }
private void handleCancel() { if (DBG) { Log.d(LOG_TAG, "--- handleCancel"); } mMode = MODE_NOTHING; mState = STATE_SELECT_OFF; mEditFlag = false; Log.d(LOG_TAG, "--- handleCancel:" + mEST.getInputType()); unblockSoftKey(); unsetSelect(); }
private void insertImageSpan(ImageSpan span) { if (DBG) { Log.d(LOG_TAG, "--- insertImageSpan"); } if (span != null) { Log.d( LOG_TAG, "--- insertimagespan:" + span.getDrawable().getIntrinsicHeight() + "," + span.getDrawable().getIntrinsicWidth()); Log.d(LOG_TAG, "--- insertimagespan:" + span.getDrawable().getClass()); int curpos = mEST.getSelectionStart(); mEST.getText().insert(curpos, "\uFFFC"); mEST.getText().setSpan(span, curpos, curpos + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mEST.notifyStateChanged(mMode, mState); } else { Log.e(LOG_TAG, "--- insertImageSpan: null span was inserted"); } }