Merge pull request #437 from owncloud/check_server_certificates_in_SSO_webview
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / CopyToClipboardActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2014 ownCloud Inc.
3 *
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.
7 *
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.
12 *
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/>.
15 *
16 */
17
18 package com.owncloud.android.ui.activity;
19
20 import com.owncloud.android.R;
21
22 import android.app.Activity;
23 import android.content.ClipData;
24 import android.content.Intent;
25 import android.os.Bundle;
26 import android.text.ClipboardManager;
27 import android.widget.Toast;
28
29 /**
30 * Activity copying the text of the received Intent into the system clibpoard.
31 *
32 * @author David A. Velasco
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 }