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