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