Esempio n. 1
0
 public void onInsertImage(int resID) {
   if (DBG) {
     Log.d(LOG_TAG, "--- onInsertImage by resID");
   }
   insertImageSpan(new ImageSpan(mEST.getContext(), resID));
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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();
   }
 }
Esempio n. 4
0
 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);
   }
 }
Esempio n. 5
0
 public void onStartBackgroundColor() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onClickColor");
   }
   mEST.onShowBackgroundColorAlert();
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 6
0
 private void unsetSelect() {
   if (DBG) {
     Log.d(LOG_TAG, "--- offSelect");
   }
   int currpos = mEST.getSelectionStart();
   mEST.setSelection(currpos, currpos);
   mState = STATE_SELECT_OFF;
 }
Esempio n. 7
0
 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));
 }
Esempio n. 8
0
 private void setSelectedEndPos() {
   if (DBG) {
     Log.d(LOG_TAG, "--- setSelectEndPos:");
   }
   if (mEST.getSelectionStart() == mCurStart) {
     setSelectedEndPos(mEST.getSelectionEnd());
   } else {
     setSelectedEndPos(mEST.getSelectionStart());
   }
 }
Esempio n. 9
0
 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);
   }
 }
Esempio n. 10
0
 public void onEndEdit() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onEndEdit");
   }
   handleCancel();
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 11
0
 public void onStartColor() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onClickColor");
   }
   handleColor();
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 12
0
 public void onFixSelectedItem() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onClickComplete");
   }
   handleComplete();
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 13
0
 public void onStartSize() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onStartSize");
   }
   handleSize();
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 14
0
 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;
 }
Esempio n. 15
0
 private void setSelectStartPos() {
   if (DBG) {
     Log.d(LOG_TAG, "--- setSelectStartPos");
   }
   mCurStart = mEST.getSelectionStart();
   mState = STATE_SELECT_ON;
 }
Esempio n. 16
0
 public void onStartSelectAll() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onClickSelectAll");
   }
   handleSelectAll();
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 17
0
 public void onInsertHorizontalLine() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onInsertHorizontalLine:");
   }
   insertImageSpan(new HorizontalLineSpan(0xFF000000, mEST));
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 18
0
 public void onStartAlign() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onStartAlignRight");
   }
   handleAlign();
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 19
0
 public String getHtml() {
   String htmlBody = Html.toHtml(mEST.getText());
   if (DBG) {
     Log.d(LOG_TAG, "--- getConvertedBody:" + htmlBody);
   }
   return htmlBody;
 }
Esempio n. 20
0
 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);
 }
Esempio n. 21
0
 private void unblockSoftKey() {
   if (DBG) {
     Log.d(LOG_TAG, "--- unblockSoftKey:");
   }
   mEST.setOnClickListener(null);
   mSoftKeyBlockFlag = false;
 }
Esempio n. 22
0
 public void onStartEdit() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onStartEdit");
   }
   Log.d(LOG_TAG, "--- onstartedit:");
   handleResetEdit();
   mEST.notifyStateChanged(mMode, mState);
 }
Esempio n. 23
0
 private void handlePaste() {
   if (DBG) {
     Log.d(LOG_TAG, "--- handlePaste");
   }
   if (!mEditFlag) {
     return;
   }
   mEST.onTextContextMenuItem(android.R.id.paste);
 }
Esempio n. 24
0
 public void onCursorMoved() {
   if (DBG) {
     Log.d(LOG_TAG, "--- onClickView");
   }
   if (mState == STATE_SELECT_ON || mState == STATE_SELECTED) {
     handleSelect();
     mEST.notifyStateChanged(mMode, mState);
   }
 }
Esempio n. 25
0
 private void handleResetEdit() {
   if (DBG) {
     Log.d(LOG_TAG, "Reset Editor");
   }
   blockSoftKey();
   handleCancel();
   mEditFlag = true;
   mEST.setHintMessage(HINT_MSG_SELECT_START);
 }
Esempio n. 26
0
 private void handleSelectAll() {
   if (DBG) {
     Log.d(LOG_TAG, "--- handleSelectAll");
   }
   if (!mEditFlag) {
     return;
   }
   mEST.selectAll();
   mState = STATE_SELECTED;
 }
Esempio n. 27
0
 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.");
     }
   }
 }
Esempio n. 28
0
 /* 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;
 }
Esempio n. 29
0
 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();
 }
Esempio n. 30
0
 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");
   }
 }