Java Code Examples for android.text.ClipboardManager

The following are top voted examples for showing how to use android.text.ClipboardManager. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: PubkeyListActivity.java   View source code 6 votes vote down vote up
@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);
}
 
Example 2
Project: MyFire   File: CommentDialog.java   View source code 6 votes vote down vote up
@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;
    }
}
 
Example 3
Project: Hitalk   File: CommentDialog.java   View source code 6 votes vote down vote up
@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;
	}
}
 
Example 4
Project: Hitalk   File: CommentActionPopup.java   View source code 6 votes vote down vote up
@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;
    }
}
 
Example 5
Project: PureNews   File: WebUI.java   View source code 6 votes vote down vote up
@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);
}
 
Example 6
Project: buildAPKsSamples   File: UnitConverterActivity.java   View source code 6 votes vote down vote up
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();
}
 
Example 7
Project: QRCodeScanner   File: TextScanResultActivity.java   View source code 6 votes vote down vote up
@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();
    }
}
 
Example 8
Project: YalpStore   File: Video.java   View source code 6 votes vote down vote up
@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);
            }
        }
    });
}
 
Example 9
Project: TAG   File: PasteEditText.java   View source code 6 votes vote down vote up
@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);
    }
 
Example 10
Project: BlueLightAPP   File: ConsoleActivity.java   View source code 6 votes vote down vote up
@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;
}
 
Example 11
Project: info_demo   File: PasteEditText.java   View source code 6 votes vote down vote up
@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);
    }
 
Example 12
Project: Koku   File: WebViewActivity.java   View source code 6 votes vote down vote up
@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);
}
 
Example 13
Project: authenticator   File: AuthenticatorActivityTest.java   View source code 6 votes vote down vote up
public void testContextMenuCopyToClipboard() throws Exception {
  // use HOTP to avoid any timing issues when "current" pin is compared with clip board text.
  mAccountDb.update(
      "[email protected]", "7777777777777777", "[email protected]", OtpType.HOTP, null);
  ListView userList = (ListView) getActivity().findViewById(R.id.user_list);
  // find and click next otp button.
  View buttonView = getActivity().findViewById(R.id.next_otp);
  TestUtilities.clickView(getInstrumentation(), buttonView);
  // get the pin being displayed
  View listEntry0 = userList.getChildAt(0);
  String pin = ((TextView) listEntry0.findViewById(R.id.pin_value)).getText().toString();
  TestUtilities.openContextMenuAndInvokeItem(
      getInstrumentation(),
      getActivity(),
      listEntry0,
      AuthenticatorActivity.COPY_TO_CLIPBOARD_ID);
  // check clip board value.
  Context context = getInstrumentation().getTargetContext();
  ClipboardManager clipboard =
      (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
  assertEquals(pin, clipboard.getText());
}
 
Example 14
Project: school_shop   File: PasteEditText.java   View source code 6 votes vote down vote up
@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);
    }
 
Example 15
Project: bVnc   File: RemoteCanvas.java   View source code 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example 16
Project: here   File: PasteEditText.java   View source code 6 votes vote down vote up
@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);
    }
 
Example 17
Project: here   File: PasteEditText.java   View source code 6 votes vote down vote up
@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);
    }
 
Example 18
Project: android_chat   File: MessageAdapter.java   View source code 6 votes vote down vote up
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;
 }
 
Example 19
Project: CloudyPhone   File: CopyClipboardReceiver.java   View source code 6 votes vote down vote up
@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) {
	}
}
 
Example 20
Project: google-authenticator-android   File: AuthenticatorActivityTest.java   View source code 6 votes vote down vote up
public void testContextMenuCopyToClipboard() throws Exception {
  // use HOTP to avoid any timing issues when "current" pin is compared with clip board text.
  mAccountDb.update(
      "[email protected]", "7777777777777777", "[email protected]", OtpType.HOTP, null);
  ListView userList = (ListView) getActivity().findViewById(R.id.user_list);
  // find and click next otp button.
  View buttonView = getActivity().findViewById(R.id.next_otp);
  TestUtilities.clickView(getInstrumentation(), buttonView);
  // get the pin being displayed
  View listEntry0 = userList.getChildAt(0);
  String pin = ((TextView) listEntry0.findViewById(R.id.pin_value)).getText().toString();
  TestUtilities.openContextMenuAndInvokeItem(
      getInstrumentation(),
      getActivity(),
      listEntry0,
      AuthenticatorActivity.COPY_TO_CLIPBOARD_ID);
  // check clip board value.
  Context context = getInstrumentation().getTargetContext();
  ClipboardManager clipboard =
      (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
  assertEquals(pin, clipboard.getText());
}
 
Example 21
Project: number_converter   File: ResultAdapter.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 22
Project: sms_DualCard   File: MessageListView.java   View source code 6 votes vote down vote up
@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);
}
 
Example 23
Project: HashPass   File: HashPassActivity.java   View source code 6 votes vote down vote up
@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";
	
}
 
Example 24
Project: CatLog-Holo   File: SenderAppAdapter.java   View source code 6 votes vote down vote up
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);	
		}
	}
 
Example 25
Project: OpenTalkOn-Android-Chat-API   File: OTRoomBase.java   View source code 6 votes vote down vote up
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();
}
 
Example 26
Project: BlockchainSearch   File: TransactionActivity.java   View source code 6 votes vote down vote up
@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);
}
 
Example 27
Project: libpastelog   File: SubmitLogFragment.java   View source code 6 votes vote down vote up
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;
}
 
Example 28
Project: google-authenticator-android-pebble   File: AuthenticatorActivityTest.java   View source code 6 votes vote down vote up
public void testContextMenuCopyToClipboard() throws Exception {
  // use HOTP to avoid any timing issues when "current" pin is compared with clip board text.
  mAccountDb.update(
      "[email protected]", "7777777777777777", "[email protected]", OtpType.HOTP, null);
  ListView userList = (ListView) getActivity().findViewById(R.id.user_list);
  // find and click next otp button.
  View buttonView = getActivity().findViewById(R.id.next_otp);
  TestUtilities.clickView(getInstrumentation(), buttonView);
  // get the pin being displayed
  View listEntry0 = userList.getChildAt(0);
  String pin = ((TextView) listEntry0.findViewById(R.id.pin_value)).getText().toString();
  TestUtilities.openContextMenuAndInvokeItem(
      getInstrumentation(),
      getActivity(),
      listEntry0,
      AuthenticatorActivity.COPY_TO_CLIPBOARD_ID);
  // check clip board value.
  Context context = getInstrumentation().getTargetContext();
  ClipboardManager clipboard =
      (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
  assertEquals(pin, clipboard.getText());
}
 
Example 29
Project: allogy-legacy-android-app   File: CommunityActivity.java   View source code 6 votes vote down vote up
/** 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();
	}
}
 
Example 30
Project: google-authenticator.android   File: AuthenticatorActivityTest.java   View source code 6 votes vote down vote up
public void testContextMenuCopyToClipboard() throws Exception {
  // use HOTP to avoid any timing issues when "current" pin is compared with clip board text.
  mAccountDb.update(
      "[email protected]", "7777777777777777", "[email protected]", OtpType.HOTP, null);
  ListView userList = (ListView) getActivity().findViewById(R.id.user_list);
  // find and click next otp button.
  View buttonView = getActivity().findViewById(R.id.next_otp);
  TestUtilities.clickView(getInstrumentation(), buttonView);
  // get the pin being displayed
  View listEntry0 = userList.getChildAt(0);
  String pin = ((TextView) listEntry0.findViewById(R.id.pin_value)).getText().toString();
  TestUtilities.openContextMenuAndInvokeItem(
      getInstrumentation(),
      getActivity(),
      listEntry0,
      AuthenticatorActivity.COPY_TO_CLIPBOARD_ID);
  // check clip board value.
  Context context = getInstrumentation().getTargetContext();
  ClipboardManager clipboard =
      (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
  assertEquals(pin, clipboard.getText());
}
 
Example 31
Project: AcFun-Area63   File: CommentsActivity.java   View source code 6 votes vote down vote up
@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;
}
 
Example 32
Project: ghostcommander-supath   File: Panels.java   View source code 6 votes vote down vote up
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();
    }
}
 
Example 33
Project: ZShaolin   File: Term.java   View source code 6 votes vote down vote up
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());
}
 
Example 34
Project: supergenpass-android   File: GeneratedPasswordView.java   View source code 6 votes vote down vote up
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();
        }
    }
}
 
Example 35
Project: jitsi-android   File: ChatFragment.java   View source code 6 votes vote down vote up
/**
 * {@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);
}
 
Example 36
Project: glassauth   File: AuthenticatorActivityTest.java   View source code 6 votes vote down vote up
public void testContextMenuCopyToClipboard() throws Exception {
  // use HOTP to avoid any timing issues when "current" pin is compared with clip board text.
  mAccountDb.update(
      "[email protected]", "7777777777777777", "[email protected]", OtpType.HOTP, null);
  ListView userList = (ListView) getActivity().findViewById(R.id.user_list);
  // find and click next otp button.
  View buttonView = getActivity().findViewById(R.id.next_otp);
  TestUtilities.clickView(getInstrumentation(), buttonView);
  // get the pin being displayed
  View listEntry0 = userList.getChildAt(0);
  String pin = ((TextView) listEntry0.findViewById(R.id.pin_value)).getText().toString();
  TestUtilities.openContextMenuAndInvokeItem(
      getInstrumentation(),
      getActivity(),
      listEntry0,
      AuthenticatorActivity.COPY_TO_CLIPBOARD_ID);
  // check clip board value.
  Context context = getInstrumentation().getTargetContext();
  ClipboardManager clipboard =
      (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
  assertEquals(pin, clipboard.getText());
}
 
Example 37
Project: android-aosp-mms   File: MessageListView.java   View source code 6 votes vote down vote up
@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);
}
 
Example 38
Project: qsysinfo   File: LogViewer.java   View source code 6 votes vote down vote up
@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;
}
 
Example 39
Project: otp-authenticator-android   File: AuthenticatorActivityTest.java   View source code 6 votes vote down vote up
public void testContextMenuCopyToClipboard() throws Exception {
  // use HOTP to avoid any timing issues when "current" pin is compared with clip board text.
  mAccountDb.update(
      "[email protected]", "7777777777777777", "[email protected]", OtpType.HOTP, null);
  ListView userList = (ListView) getActivity().findViewById(R.id.user_list);
  // find and click next otp button.
  View buttonView = getActivity().findViewById(R.id.next_otp);
  TestUtilities.clickView(getInstrumentation(), buttonView);
  // get the pin being displayed
  View listEntry0 = userList.getChildAt(0);
  String pin = ((TextView) listEntry0.findViewById(R.id.pin_value)).getText().toString();
  TestUtilities.openContextMenuAndInvokeItem(
      getInstrumentation(),
      getActivity(),
      listEntry0,
      AuthenticatorActivity.COPY_TO_CLIPBOARD_ID);
  // check clip board value.
  Context context = getInstrumentation().getTargetContext();
  ClipboardManager clipboard =
      (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
  assertEquals(pin, clipboard.getText());
}
 
Example 40
Project: CraftMeAPass   File: ResultActivity.java   View source code 6 votes vote down vote up
@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);
	}
}