1 /* ownCloud Android client application 
   2  *   Copyright (C) 2012-2014 ownCloud Inc. 
   4  *   This program is free software: you can redistribute it and/or modify 
   5  *   it under the terms of the GNU General Public License version 2, 
   6  *   as published by the Free Software Foundation. 
   8  *   This program is distributed in the hope that it will be useful, 
   9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
  10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  11  *   GNU General Public License for more details. 
  13  *   You should have received a copy of the GNU General Public License 
  14  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  18 package com
.owncloud
.android
.ui
.activity
; 
  20 import com
.owncloud
.android
.R
; 
  22 import android
.app
.Activity
; 
  23 import android
.content
.ClipData
; 
  24 import android
.content
.Intent
; 
  25 import android
.os
.Bundle
; 
  26 import android
.text
.ClipboardManager
; 
  27 import android
.widget
.Toast
; 
  30  * Activity copying the text of the received Intent into the system clibpoard. 
  32  * @author David A. Velasco 
  34 @SuppressWarnings("deprecation") 
  35 public class CopyToClipboardActivity 
extends Activity 
{ 
  38     public void onCreate(Bundle savedInstanceState
) { 
  39         super.onCreate(savedInstanceState
); 
  41         // get the clipboard system service 
  42         ClipboardManager clipboardManager 
= (ClipboardManager
) this.getSystemService(CLIPBOARD_SERVICE
); 
  44         // get the text to copy into the clipboard  
  45         Intent intent 
= getIntent(); 
  46         CharSequence text 
= intent
.getCharSequenceExtra(Intent
.EXTRA_TEXT
); 
  48         // and put the text the clipboard 
  49         if (android
.os
.Build
.VERSION
.SDK_INT 
>= android
.os
.Build
.VERSION_CODES
.HONEYCOMB
) { 
  50             // API level >= 11 -> modern Clipboard 
  51             ClipData clip 
= ClipData
.newPlainText("ownCloud was here", text
); 
  52             ((android
.content
.ClipboardManager
)clipboardManager
).setPrimaryClip(clip
); 
  55             // API level >= 11 -> legacy Clipboard 
  56             clipboardManager
.setText(text
);     
  59         // alert the user that the text is in the clipboard and we're done 
  60         Toast
.makeText(this, R
.string
.clipboard_text_copied
, Toast
.LENGTH_SHORT
).show();