Search in sources :

Example 6 with ClipboardManager

use of android.text.ClipboardManager in project cw-advandroid by commonsguy.

the class IPClipper method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    try {
        String addr = getLocalIPAddress();
        if (addr == null) {
            Toast.makeText(this, "IP address not available -- are you online?", Toast.LENGTH_LONG).show();
        } else {
            ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            cm.setText(addr);
            Toast.makeText(this, "IP Address clipped!", Toast.LENGTH_SHORT).show();
        }
    } catch (Exception e) {
        Log.e("IPClipper", "Exception getting IP address", e);
        Toast.makeText(this, "Could not obtain IP address", Toast.LENGTH_LONG).show();
    }
}
Also used : ClipboardManager(android.text.ClipboardManager) SocketException(java.net.SocketException)

Example 7 with ClipboardManager

use of android.text.ClipboardManager in project cw-omnibus by commonsguy.

the class IPClipper method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        String addr = getLocalIPAddress();
        if (addr == null) {
            Toast.makeText(this, "IP address not available -- are you online?", Toast.LENGTH_LONG).show();
        } else {
            ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            try {
                cm.setText(addr);
                Toast.makeText(this, "IP Address clipped!", Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                Log.e(getClass().getSimpleName(), "Exception clipping IP", e);
                Toast.makeText(this, "Exception: " + e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    } catch (Exception e) {
        Log.e("IPClipper", "Exception getting IP address", e);
        Toast.makeText(this, "Could not obtain IP address", Toast.LENGTH_LONG).show();
    }
    finish();
}
Also used : ClipboardManager(android.text.ClipboardManager) SocketException(java.net.SocketException)

Example 8 with ClipboardManager

use of android.text.ClipboardManager in project JustAndroid by chinaltz.

the class CommentDialog method onClick.

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.copyTv:
            if (mCommentItem != null) {
                ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                clipboard.setText(mCommentItem.getContent());
            }
            dismiss();
            break;
        case R.id.deleteTv:
            //			if (mPresenter != null && mCommentItem != null) {
            //				mPresenter.deleteComment(mCirclePosition, mCommentItem.getId());
            //			}
            dismiss();
            break;
        default:
            break;
    }
}
Also used : ClipboardManager(android.text.ClipboardManager)

Example 9 with ClipboardManager

use of android.text.ClipboardManager in project Jota-Text-Editor-old by jiro-aqua.

the class TextView method onTextContextMenuItem.

/**
     * Called when a context menu option for the text view is selected.  Currently
     * this will be one of: {@link android.R.id#selectAll},
     * {@link android.R.id#startSelectingText},
     * {@link android.R.id#cut}, {@link android.R.id#copy},
     * {@link android.R.id#paste}, {@link android.R.id#copyUrl},
     * or {@link android.R.id#switchInputMethod}.
     */
public boolean onTextContextMenuItem(int id) {
    // Jota Text Editor
    int min = 0;
    int max = mText.length();
    if (isFocused()) {
        final int selStart = getSelectionStart();
        final int selEnd = getSelectionEnd();
        min = Math.max(0, Math.min(selStart, selEnd));
        max = Math.max(0, Math.max(selStart, selEnd));
    }
    ClipboardManager clip = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    switch(id) {
        case ID_SELECT_ALL:
            Selection.setSelection((Spannable) mText, 0, mText.length());
            startTextSelectionMode();
            getSelectionController().show();
            return true;
        case ID_START_SELECTING_TEXT:
            if (mHasNavigationDevice) {
                MetaKeyKeyListener.startSelecting(this, (Spannable) mText);
            } else {
                int start = Selection.getSelectionStart((Spannable) mText);
                ArrowKeyMovementMethod.selectWord((Spannable) mText, start);
                startTextSelectionMode();
            }
            //                getSelectionController().show();
            return true;
        case ID_STOP_SELECTING_TEXT:
            MetaKeyKeyListener.stopSelecting(this, (Spannable) mText);
            //                Selection.setSelection((Spannable) mText, getSelectionEnd()); // Jota Text Editor
            return true;
        // Jota Text Editor
        case ID_CANCEL_SELECTION:
            Selection.setSelection((Spannable) mText, getSelectionEnd());
            return true;
        // Jota Text Editor
        case ID_SHOW_IME:
            {
                showIme(true);
                return true;
            }
        case ID_UNDO:
            MetaKeyKeyListener.stopSelecting(this, (Spannable) mText);
            // UNDO
            {
                TextChange textchange = mUndoBuffer.pop();
                if (textchange != null) {
                    Editable text = (Editable) getText();
                    mUndoRedo = true;
                    text.replace(textchange.start, textchange.start + textchange.newtext.length(), textchange.oldtext);
                    Selection.setSelection(text, textchange.start + textchange.oldtext.length());
                    mRedoBuffer.push(textchange);
                }
            }
            return true;
        case ID_REDO:
            MetaKeyKeyListener.stopSelecting(this, (Spannable) mText);
            // REDO
            {
                TextChange textchange = mRedoBuffer.pop();
                if (textchange != null) {
                    Editable text = (Editable) getText();
                    mUndoRedo = true;
                    text.replace(textchange.start, textchange.start + textchange.oldtext.length(), textchange.newtext);
                    Selection.setSelection(text, textchange.start + textchange.newtext.length());
                    mUndoBuffer.push(textchange);
                }
            }
            return true;
        case ID_CUT:
            // Jota Text Editor
            if (max - min > MAX_PARCELABLE) {
                Toast.makeText(getContext(), R.string.toast_overflow_of_limit, Toast.LENGTH_LONG).show();
            } else {
                clip.setText(mTransformed.subSequence(min, max));
                ((Editable) mText).delete(min, max);
                stopTextSelectionMode();
                MetaKeyKeyListener.stopSelecting(this, (Spannable) mText);
            }
            return true;
        case ID_COPY:
            // Jota Text Editor
            if (max - min > MAX_PARCELABLE) {
                Toast.makeText(getContext(), R.string.toast_overflow_of_limit, Toast.LENGTH_LONG).show();
            } else {
                clip.setText(mTransformed.subSequence(min, max));
                stopTextSelectionMode();
                MetaKeyKeyListener.stopSelecting(this, (Spannable) mText);
            }
            return true;
        case ID_PASTE:
            CharSequence paste = clip.getText();
            if (paste != null && paste.length() > 0) {
                //                    long minMax = prepareSpacesAroundPaste(min, max, paste);
                //                    min = extractRangeStartFromLong(minMax);
                //                    max = extractRangeEndFromLong(minMax);
                //                    Selection.setSelection((Spannable) mText, max);
                ((Editable) mText).replace(min, max, paste);
                stopTextSelectionMode();
                MetaKeyKeyListener.stopSelecting(this, (Spannable) mText);
            }
            return true;
        case ID_COPY_URL:
            URLSpan[] urls = ((Spanned) mText).getSpans(min, max, URLSpan.class);
            if (urls.length == 1) {
                clip.setText(urls[0].getURL());
            }
            return true;
        case ID_SWITCH_INPUT_METHOD:
            {
                InputMethodManager imm = InputMethodManager.peekInstance();
                if (imm != null) {
                    imm.showInputMethodPicker();
                }
                return true;
            }
        case ID_DIRECTINTENT:
            MetaKeyKeyListener.stopSelecting(this, (Spannable) mText);
            if (min != max) {
                ((EditText) this).doShortcut(KeyEvent.KEYCODE_D);
            }
            return true;
    }
    return false;
}
Also used : ClipboardManager(android.text.ClipboardManager) TextChange(jp.sblo.pandora.jota.text.UndoBuffer.TextChange) Editable(android.text.Editable) InputMethodManager(android.view.inputmethod.InputMethodManager) URLSpan(jp.sblo.pandora.jota.text.style.URLSpan) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 10 with ClipboardManager

use of android.text.ClipboardManager in project FloatingStickies by MohammadAdib.

the class Window method getDropDownList.

public PopupWindow getDropDownList() {
    final List<DropDownListItem> items = new ArrayList<DropDownListItem>();
    items.add(new DropDownListItem("Copy", new Runnable() {

        @Override
        public void run() {
            ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(getText());
        }
    }));
    items.add(new DropDownListItem("Paste", new Runnable() {

        @Override
        public void run() {
            try {
                ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                setText(getText() + clipboard.getText().toString());
            } catch (Exception e) {
            }
        }
    }));
    items.add(new DropDownListItem("Share", new Runnable() {

        @Override
        public void run() {
            // Share
            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Floating Stickies");
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getText());
            mContext.startActivity(Intent.createChooser(sharingIntent, "Share Sticky").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    }));
    // turn item list into views in PopupWindow
    LinearLayout list = new LinearLayout(mContext);
    list.setOrientation(LinearLayout.VERTICAL);
    ScrollView scroller = new ScrollView(mContext);
    scroller.addView(list);
    final PopupWindow dropDown = new PopupWindow(scroller, StandOutLayoutParams.WRAP_CONTENT, StandOutLayoutParams.WRAP_CONTENT, true);
    for (final DropDownListItem item : items) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ViewGroup listItem = (ViewGroup) inflater.inflate(R.layout.drop_down_list_item, null);
        list.addView(listItem);
        TextView textView = (TextView) listItem.findViewById(R.id.text);
        textView.setText(item.text);
        listItem.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                dropDown.dismiss();
                item.action.run();
            }
        });
    }
    return dropDown;
}
Also used : ClipboardManager(android.text.ClipboardManager) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) PopupWindow(android.widget.PopupWindow) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ScrollView(android.widget.ScrollView) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

ClipboardManager (android.text.ClipboardManager)15 Intent (android.content.Intent)5 View (android.view.View)2 ImageView (android.widget.ImageView)2 SocketException (java.net.SocketException)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 Editable (android.text.Editable)1 Spanned (android.text.Spanned)1 TextPaint (android.text.TextPaint)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AdapterView (android.widget.AdapterView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 PopupWindow (android.widget.PopupWindow)1 ScrollView (android.widget.ScrollView)1