2 * ownCloud Android client application
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com
.owncloud
.android
.ui
.activity
;
23 import com
.owncloud
.android
.R
;
25 import android
.app
.Activity
;
26 import android
.content
.ClipData
;
27 import android
.content
.Intent
;
28 import android
.os
.Bundle
;
29 import android
.text
.ClipboardManager
;
30 import android
.widget
.Toast
;
33 * Activity copying the text of the received Intent into the system clibpoard.
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();