Java 类android.text.ClipboardManager 实例源码

项目:GitHub    文件:PubkeyListActivity.java   
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.act_pubkeylist);

    mListView = (RecyclerView) findViewById(R.id.list);
    mListView.setHasFixedSize(true);
    mListView.setLayoutManager(new LinearLayoutManager(this));
    mListView.addItemDecoration(new ListItemDecoration(this));

    mEmptyView = findViewById(R.id.empty);

    registerForContextMenu(mListView);

    clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
}
项目:MyFire    文件:CommentDialog.java   
@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, FormatUtil.checkValue(mCommentItem.getId()),commentPosition);
            }
            dismiss();
            break;
        default:
            break;
    }
}
项目:Hitalk    文件:CommentDialog.java   
@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 (bnItemOnClickListener != null && mCommentItem != null) {
            bnItemOnClickListener.deleteComment(mCirclePosition, mCommentItem.getId());
        }
        dismiss();
        break;
    default:
        break;
    }
}
项目:Hitalk    文件:CommentActionPopup.java   
@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.action_copy:
            if (mCommentItem != null) {
                ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                clipboard.setText(mCommentItem.getContent());
            }
            dismiss();
            break;
        case R.id.action_delete:
            if (mBnItemOnClickListener != null && mCommentItem != null) {
                mBnItemOnClickListener.deleteComment(mBnPosition, mCommentItem.getId());
            }
            dismiss();
            break;
    }
}
项目:PureNews    文件:WebUI.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.item_copy:
            ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            cm.setText(url);
            SnackBarUtil.showSnackBar(R.string.copy_msg, webView, this);
            break;
        case R.id.item_browser:
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
            break;
    }
    return super.onOptionsItemSelected(item);
}
项目:buildAPKsSamples    文件:UnitConverterActivity.java   
public void onClick(View view) {
    if (view == this.reverseUnits) {
        int inputUnitPosition = this.inputUnit.getSelectedItemPosition();
        this.inputUnit.setSelection(this.outputUnit
                .getSelectedItemPosition());
        this.outputUnit.setSelection(inputUnitPosition);
    } else if (view == this.clearInput) {
        this.inputAmount.setText("");
    } else if (view == this.copyResult) {
        CharSequence result = this.outputAmount.getText();
        if (result.length() > 0) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            clipboard.setText(result);
            Toast.makeText(this,
                    super.getString(R.string.copy_result_message, result),
                    Toast.LENGTH_SHORT).show();
        }
    } else {
        throw new AssertionError("Unexpected click on view: " + view);
    }
    this.recalculate();
}
项目:QRCodeScanner    文件:TextScanResultActivity.java   
@Override
public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.btn_copy) {
        ClipboardManager clipboarManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboarManager.setText(mEtText.getText().toString());
        Toast.makeText(this, R.string.added_to_clip_board, Toast.LENGTH_LONG).show();
    } else if (id == R.id.btn_search) {
        String url = String.format(
                "http://m.baidu.com/s?word=%s",
                URLEncoder.encode(mEtText.getText().toString()));

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        setResult(RESULT_OK);
        finish();
    }
}
项目:YalpStore    文件:Video.java   
@Override
public void draw() {
    if (TextUtils.isEmpty(app.getVideoUrl())) {
        return;
    }
    TextView videoLink = activity.findViewById(R.id.video);
    videoLink.setVisibility(View.VISIBLE);
    videoLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(app.getVideoUrl())));
            } catch (ActivityNotFoundException e) {
                ((ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE)).setText(app.getVideoUrl());
                ContextUtil.toast(v.getContext().getApplicationContext(), R.string.about_copied_to_clipboard);
            }
        }
    });
}
项目:TAG    文件:PasteEditText.java   
@SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    @Override
    public boolean onTextContextMenuItem(int id) {
        if(id == android.R.id.paste){
            ClipboardManager clip = (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            String text = clip.getText().toString();
            if(text.startsWith(ChatActivity.COPY_IMAGE)){
//                intent.setDataAndType(Uri.fromFile(new File("/sdcard/mn1.jpg")), "image/*");     
                text = text.replace(ChatActivity.COPY_IMAGE, "");
                Intent intent = new Intent(context,AlertDialog.class);
                intent.putExtra("title", "发送以下图片?");
                intent.putExtra("forwardImage", text);
                intent.putExtra("cancel", true);
                ((Activity)context).startActivityForResult(intent,ChatActivity.REQUEST_CODE_COPY_AND_PASTE);
//                clip.setText("");
            }
        }
        return super.onTextContextMenuItem(id);
    }
项目:BlueLightAPP    文件:ConsoleActivity.java   
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    if(item.getItemId() == CLEAR_CODE)
    {
        currentLog=new SpannableStringBuilder();
        label_log.setText("");
        return true;
    }
    else if(item.getItemId() == COPY_CODE)
    {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        clipboard.setText(currentLog);
        Toast.makeText(this,R.string.message_copied,Toast.LENGTH_SHORT).show();
    }
    return false;
}
项目:info_demo    文件:PasteEditText.java   
@SuppressLint("NewApi")
    @Override
    public boolean onTextContextMenuItem(int id) {
        if(id == android.R.id.paste){
            ClipboardManager clip = (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            if (clip == null || clip.getText() == null) {
                return false;
            }
            String text = clip.getText().toString();
            if(text.startsWith(ChatActivity.COPY_IMAGE)){
//                intent.setDataAndType(Uri.fromFile(new File("/sdcard/mn1.jpg")), "image/*");     
                text = text.replace(ChatActivity.COPY_IMAGE, "");
                Intent intent = new Intent(context,AlertDialog.class);
                String str = context.getResources().getString(R.string.Send_the_following_pictures);
                intent.putExtra("title", str);
                intent.putExtra("forwardImage", text);
                intent.putExtra("cancel", true);
                ((Activity)context).startActivityForResult(intent,ChatActivity.REQUEST_CODE_COPY_AND_PASTE);
//                clip.setText("");
            }
        }
        return super.onTextContextMenuItem(id);
    }
项目:Koku    文件:WebViewActivity.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            break;
        case R.id.action_refresh:  //刷新
            mWebView.reload();
            break;
        case R.id.action_open_in_browser:  //在浏览器中打开
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);
            break;
        case R.id.action_copy:  //复制网址
            ClipboardManager clip = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            clip.setText(url); // 复制
            CommonUtil.showSnackbar(mWebView, R.string.copy_to_clipboard, getResources().getColor(R.color.Indigo_colorPrimary));
            break;
        default:
            break;
    }
    return super.onOptionsItemSelected(item);
}
项目:school_shop    文件:PasteEditText.java   
@SuppressLint("NewApi")
    @Override
    public boolean onTextContextMenuItem(int id) {
        if(id == android.R.id.paste){
            ClipboardManager clip = (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            if (clip == null || clip.getText() == null) {
                return false;
            }
            String text = clip.getText().toString();
            if(text.startsWith(ChatActivity.COPY_IMAGE)){
//                intent.setDataAndType(Uri.fromFile(new File("/sdcard/mn1.jpg")), "image/*");     
                text = text.replace(ChatActivity.COPY_IMAGE, "");
                Intent intent = new Intent(context,AlertDialog.class);
                String str = context.getResources().getString(R.string.Send_the_following_pictures);
                intent.putExtra("title", str);
                intent.putExtra("forwardImage", text);
                intent.putExtra("cancel", true);
                ((Activity)context).startActivityForResult(intent,ChatActivity.REQUEST_CODE_COPY_AND_PASTE);
//                clip.setText("");
            }
        }
        return super.onTextContextMenuItem(id);
    }
项目:bVnc    文件:RemoteCanvas.java   
/**
 * Constructor used by the inflation apparatus
 * 
 * @param context
 */
public RemoteCanvas(final Context context, AttributeSet attrs) {
    super(context, attrs);

    clipboard = (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);

    decoder = new Decoder (this);

    isRdp   = getContext().getPackageName().contains("RDP");
    isSpice = getContext().getPackageName().contains("SPICE");

    final Display display = ((Activity)context).getWindow().getWindowManager().getDefaultDisplay();
    displayWidth  = display.getWidth();
    displayHeight = display.getHeight();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    displayDensity = metrics.density;

    if (android.os.Build.MODEL.contains("BlackBerry") ||
        android.os.Build.BRAND.contains("BlackBerry") || 
        android.os.Build.MANUFACTURER.contains("BlackBerry")) {
        bb = true;
    }
}
项目:here    文件:PasteEditText.java   
@SuppressLint("NewApi")
    @Override
    public boolean onTextContextMenuItem(int id) {
        if(id == android.R.id.paste){
            ClipboardManager clip = (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            if (clip == null || clip.getText() == null) {
                return false;
            }
            String text = clip.getText().toString();
            if(text.startsWith(ChatActivity.COPY_IMAGE)){
//                intent.setDataAndType(Uri.fromFile(new File("/sdcard/mn1.jpg")), "image/*");     
                text = text.replace(ChatActivity.COPY_IMAGE, "");
                Intent intent = new Intent(context,AlertDialog.class);
                String str = context.getResources().getString(R.string.Send_the_following_pictures);
                intent.putExtra("title", str);
                intent.putExtra("forwardImage", text);
                intent.putExtra("cancel", true);
                ((Activity)context).startActivityForResult(intent,ChatActivity.REQUEST_CODE_COPY_AND_PASTE);
//                clip.setText("");
            }
        }
        return super.onTextContextMenuItem(id);
    }
项目:here    文件:PasteEditText.java   
@SuppressLint("NewApi")
    @Override
    public boolean onTextContextMenuItem(int id) {
        if(id == android.R.id.paste){
            ClipboardManager clip = (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            if (clip == null || clip.getText() == null) {
                return false;
            }
            String text = clip.getText().toString();
            if(text.startsWith(ChatActivity.COPY_IMAGE)){
//                intent.setDataAndType(Uri.fromFile(new File("/sdcard/mn1.jpg")), "image/*");     
                text = text.replace(ChatActivity.COPY_IMAGE, "");
                Intent intent = new Intent(context,AlertDialog.class);
                String str = context.getResources().getString(R.string.Send_the_following_pictures);
                intent.putExtra("title", str);
                intent.putExtra("forwardImage", text);
                intent.putExtra("cancel", true);
                ((Activity)context).startActivityForResult(intent,ChatActivity.REQUEST_CODE_COPY_AND_PASTE);
//                clip.setText("");
            }
        }
        return super.onTextContextMenuItem(id);
    }
项目:android_chat    文件:MessageAdapter.java   
public View getView(int position, View convertView, ViewGroup parent) {
     View vi = convertView;
     final Discussion entry = data.get(position);

     if (entry.getMe()) vi = inflater.inflate(R.layout.message_list_out, null);
     else vi = inflater.inflate(R.layout.message_list_in, null);

     LinearLayout list = (LinearLayout)vi.findViewById(R.id.messageList);
     TextView time = (TextView)vi.findViewById(R.id.time);
     TextView message = (TextView)vi.findViewById(R.id.message);

     list.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
    ClipboardManager cm = (ClipboardManager) activity
        .getSystemService(Context.CLIPBOARD_SERVICE);
       cm.setText(entry.getMessage());
       th.sendNotification(activity, "Copied to clipboard");
    return true;
}
     });
     message.setText(entry.getMessage());
     Timestamp timestamp = entry.getTimestamp();
     time.setText(timestamp.getHours()+":"+timestamp.getMinutes());
     return vi;
 }
项目:CloudyPhone    文件:CopyClipboardReceiver.java   
@Override
public void execute(Context ctx, JSONObject data) {
    try {
        String string = data.getString("message");

        if (TextUtils.isEmpty(string)) {
            // No message, return
            return;
        }

        // Get clipboard manager and set the text to it
        ((ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE))
                .setText(string);
    } catch (JSONException e) {
    }
}
项目:number_converter    文件:ResultAdapter.java   
public ResultAdapter(Context context, String[] titles) {
    Log.d(TAG, "constructor");

    mContext = context;
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mVersionCode = android.os.Build.VERSION.SDK_INT;
    if (mVersionCode >= Build.VERSION_CODES.HONEYCOMB) {
        mClipboardManager = (android.content.ClipboardManager)
                context.getSystemService(Context.CLIPBOARD_SERVICE);
    }
    else {
        mClipboardManager = (android.text.ClipboardManager)
                context.getSystemService(Context.CLIPBOARD_SERVICE);
    }

    mResultTitles = titles;
    mResults = new ArrayList<String>(titles.length);
    String resultZero = getResString(R.string.result_zero);
    for (int i = 0; i < titles.length; ++i) {
        mResults.add(i, resultZero);
    }
}
项目:sms_DualCard    文件:MessageListView.java   
@Override
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_C:


         Log.v("MessageList", "�����ˣ�����");
        MessageListItem view = (MessageListItem)getSelectedView();
        if (view == null) {
            break;
        }
        MessageItem item = view.getMessageItem();

        if (item != null && item.isSms()) {
            ClipboardManager clip =
                (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            clip.setText(item.mBody);
            return true;
        }
        break;
    }

    return super.onKeyShortcut(keyCode, event);
}
项目:HashPass    文件:HashPassActivity.java   
@Override
protected String doInBackground(Integer... params) {

    //clear the clipboard after the specified interval
    try{   
        Thread.sleep(params[0]);
        ClipboardManager clipboard = 
                  (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
        clipboard.setText("");
        return "success";

    }catch(InterruptedException e) {
        e.printStackTrace();
    }


    return "failure";

}
项目:CatLog-Holo    文件:SenderAppAdapter.java   
public void respondToClick(int position, String subject, String body, SendLogDetails.AttachmentType attachmentType, File attachment) {

        ResolveInfo launchable = getItem(position);
        ActivityInfo activity=launchable.activityInfo;

        if (launchable instanceof DummyClipboardLaunchable) {
            ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); 

            clipboard.setText(body);
            Toast.makeText(mContext, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
        } else {

            ComponentName name= new ComponentName(activity.applicationInfo.packageName, activity.name);

            Intent actionSendIntent= createSendIntent(subject, body, attachmentType, attachment);
            actionSendIntent.setComponent(name);

            mContext.startActivity(actionSendIntent);   
        }
    }
项目:OpenTalkOn-Android-Chat-API    文件:OTRoomBase.java   
public void onLongClickMsgBody(){
    if(listElem.msg.isImgMsg()) return;
    AlertDialog.Builder ab = new Builder(OTRoomBase.this);
    ab.setTitle(getString(R.string.oto_select_recommend_task));
    ab.setItems(getResources().getStringArray(R.array.oto_chat_msg_menu),
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            CharSequence text = nowConvResource.body.getText();
            ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
            switch(which){
            case 0:
                cm.setText(text);
                break;
            }
        }
    });
    ab.show();
}
项目:BlockchainSearch    文件:TransactionActivity.java   
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId()) {
        case android.R.id.home:
            return MenuManager.back(this);
        case R.id.action_refresh:
            Toast.makeText(getApplicationContext(), getString(R.string.text_refreshing), Toast.LENGTH_SHORT).show();
            refresh();
            return true;
        case R.id.action_copy:
            ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            cm.setText(searchText);
            Toast.makeText(getApplicationContext(), getString(R.string.text_copied), Toast.LENGTH_SHORT).show();
            return true;
        case R.id.action_settings:
            return MenuManager.openSettings(this);

    }

    return super.onOptionsItemSelected(item);
}
项目:libpastelog    文件:SubmitLogFragment.java   
private TextView handleBuildSuccessTextView(final String logUrl) {
  TextView showText = new TextView(getActivity());

  showText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
  showText.setPadding(15, 30, 15, 30);
  showText.setText(getString(R.string.log_submit_activity__copy_this_url_and_add_it_to_your_issue, logUrl));
  showText.setAutoLinkMask(Activity.RESULT_OK);
  showText.setMovementMethod(LinkMovementMethod.getInstance());
  showText.setOnLongClickListener(new View.OnLongClickListener() {

    @Override
    public boolean onLongClick(View v) {
      @SuppressWarnings("deprecation")
      ClipboardManager manager =
          (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE);
      manager.setText(logUrl);
      Toast.makeText(getActivity(),
                     R.string.log_submit_activity__copied_to_clipboard,
                     Toast.LENGTH_SHORT).show();
      return true;
    }
  });

  Linkify.addLinks(showText, Linkify.WEB_URLS);
  return showText;
}
项目:allogy-legacy-android-app    文件:CommunityActivity.java   
/** Action Bar SMS Button */
public void onSmsClick() {

    if (mPhoneNum != null && mPhoneNum.compareTo("null") != 0) {
        Intent sendIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.parse("sms:" + mPhoneNum));
        sendIntent.putExtra("address", mPhoneNum);
        sendIntent.putExtra("sms_body", "@" + mUserName + " ");

        ClipboardManager CbM = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        CbM.setText("@" + mUserName + " ");
        startActivity(sendIntent);
    } else {
        startActivity(new Intent(this, SettingsActivity.class));
        Toast.makeText(this, "Enter Gateway Number", Toast.LENGTH_SHORT).show();
    }
}
项目:AcFun-Area63    文件:CommentsActivity.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    Object o = parent.getItemAtPosition(position);
    if(o == null || !(o instanceof Comment)) return false;
    Comment c = (Comment)o;
    ClipboardManager ma = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
        ClipData text = ClipData.newHtmlText(c.userName, c.content, c.content);
        ((android.content.ClipboardManager) ma).setPrimaryClip(text);
    }else{
        ma.setText(c.content);
    }
    Toast.makeText(this, "#"+c.count+"的内容已复制", 0).show();
    return true;
}
项目:ghostcommander-supath    文件:Panels.java   
public final void copyName() {
    try {
        CommanderAdapter ca = getListAdapter( true );
        if( ca == null )
            return;
        ClipboardManager clipboard = (ClipboardManager)c.getSystemService( Context.CLIPBOARD_SERVICE );
        int pos = getSelection( true );
        if( pos >= 0 ) {
            String in = ca.getItemName( pos, true );
            if( in != null ) {
                if( in.startsWith( RootAdapter.DEFAULT_LOC ) )
                    in = Uri.parse( in ).getPath();
                clipboard.setText( in );
            }
        }
    } catch( Exception e ) {
        e.printStackTrace();
    }
}
项目:ZShaolin    文件:Term.java   
private void doPaste() {
    ClipboardManager clip = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
    if(!clip.hasText()){
        Toast tt = Toast.makeText(this, "No text to Paste..", Toast.LENGTH_SHORT);
        tt.show();
        return;
    }

    CharSequence paste = clip.getText();
    byte[] utf8;
    try {
        utf8 = paste.toString().getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        Log.e(TermDebug.LOG_TAG, "UTF-8 encoding not found.");
        return;
    }

    getCurrentTermSession().write(paste.toString());
}
项目:supergenpass-android    文件:GeneratedPasswordView.java   
public void copyToClipboard(){
    final CharSequence genPw = getText();
    if (genPw == null) {
        return;
    }

    final ClipboardManager clipMan = (ClipboardManager)getContext().getSystemService(Application.CLIPBOARD_SERVICE);
    clipMan.setText(genPw);
    if (genPw.length() > 0){
        if (domain != null){
            Toast.makeText(getContext(), getResources().getString(R.string.toast_copied, domain),
                    Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(getContext(), getResources().getString(R.string.toast_copied_no_domain),
                    Toast.LENGTH_SHORT).show();
        }
    }
}
项目:jitsi-android    文件:ChatFragment.java   
/**
 * {@inheritDoc}
 */
@SuppressWarnings("deprecation")
@Override
public boolean onContextItemSelected(MenuItem item)
{
    if(item.getItemId() == R.id.copy_to_clipboard)
    {
        AdapterView.AdapterContextMenuInfo info
                = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        // Clicked position must be aligned to list headers count
        int position = info.position - chatListView.getHeaderViewsCount();
        // Gets clicked message
        ChatMessage clickedMsg = chatListAdapter.getMessage(position);
        // Copy message content to clipboard
        ClipboardManager clipboardManager
                = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboardManager.setText(clickedMsg.getContentForClipboard());
        return true;
    }
    return super.onContextItemSelected(item);
}
项目:android-aosp-mms    文件:MessageListView.java   
@Override
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_C:
        MessageListItem view = (MessageListItem)getSelectedView();
        if (view == null) {
            break;
        }
        MessageItem item = view.getMessageItem();
        if (item != null && item.isSms()) {
            ClipboardManager clip =
                (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            clip.setText(item.mBody);
            return true;
        }
        break;
    }

    return super.onKeyShortcut(keyCode, event);
}
项目:qsysinfo    文件:LogViewer.java   
@Override
public boolean onContextItemSelected( MenuItem item )
{
    int pos = ( (AdapterContextMenuInfo) item.getMenuInfo( ) ).position;
    LogItem log = (LogItem) getListView( ).getItemAtPosition( pos );

    if ( log != null && log.getMsg( ) != null )
    {
        ClipboardManager cm = (ClipboardManager) getSystemService( CLIPBOARD_SERVICE );

        if ( cm != null )
        {
            cm.setText( log.getMsg( ) );

            Util.shortToast( this, R.string.copied_hint );
        }
    }

    return true;
}
项目:CraftMeAPass    文件:ResultActivity.java   
@Override
   public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = null; 
    if (item.getItemId() == android.R.id.home) {
        finish();
        return true;
    } else if (item.getItemId() == R.id.menu_clear_clipboard) {
        ClipboardManager clipBoard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipBoard.setText("");
        return true;
    } else if (item.getItemId() == R.id.menu_settings) {
        intent = new Intent(getApplicationContext(), SettingsActivity.class);
        startActivity(intent);
        return true;
    } else if (item.getItemId() == R.id.menu_quit) {
        intent = new Intent(getApplicationContext(), MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("EXIT", true);
        startActivity(intent);
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}