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
.Build
;
26 import android
.os
.Bundle
;
27 import android
.text
.ClipboardManager
;
28 import android
.widget
.Toast
;
31 * Activity copying the text of the received Intent into the system clibpoard.
33 * @author David A. Velasco
35 @SuppressWarnings("deprecation")
36 public class CopyToClipboardActivity
extends Activity
{
39 public void onCreate(Bundle savedInstanceState
) {
40 super.onCreate(savedInstanceState
);
42 // get the clipboard system service
43 ClipboardManager clipboardManager
= (ClipboardManager
) this.getSystemService(CLIPBOARD_SERVICE
);
45 // get the text to copy into the clipboard
46 Intent intent
= getIntent();
47 CharSequence text
= intent
.getCharSequenceExtra(Intent
.EXTRA_TEXT
);
49 // and put the text the clipboard
50 if (android
.os
.Build
.VERSION
.SDK_INT
>= android
.os
.Build
.VERSION_CODES
.HONEYCOMB
) {
51 // API level >= 11 -> modern Clipboard
52 ClipData clip
= ClipData
.newPlainText("ownCloud was here", text
);
53 ((android
.content
.ClipboardManager
)clipboardManager
).setPrimaryClip(clip
);
56 // API level >= 11 -> legacy Clipboard
57 clipboardManager
.setText(text
);
60 // alert the user that the text is in the clipboard and we're done
61 Toast
.makeText(this, R
.string
.clipboard_text_copied
, Toast
.LENGTH_SHORT
).show();