Merge pull request #1048 from owncloud/shareWithYou_icon_in_fileList
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / CopyToClipboardActivity.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author David A. Velasco
5 * Copyright (C) 2015 ownCloud Inc.
6 *
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.
10 *
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.
15 *
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/>.
18 *
19 */
20
21 package com.owncloud.android.ui.activity;
22
23 import com.owncloud.android.R;
24
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;
31
32 /**
33 * Activity copying the text of the received Intent into the system clibpoard.
34 */
35 @SuppressWarnings("deprecation")
36 public class CopyToClipboardActivity extends Activity {
37
38 @Override
39 public void onCreate(Bundle savedInstanceState) {
40 super.onCreate(savedInstanceState);
41
42 // get the clipboard system service
43 ClipboardManager clipboardManager = (ClipboardManager) this.getSystemService(CLIPBOARD_SERVICE);
44
45 // get the text to copy into the clipboard
46 Intent intent = getIntent();
47 CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
48
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);
54
55 } else {
56 // API level >= 11 -> legacy Clipboard
57 clipboardManager.setText(text);
58 }
59
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();
62
63 finish();
64 }
65
66 }