Implemented option to copy shared link in clipboard instead of trusting in external...
[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.Build;
26 import android.os.Bundle;
27 import android.text.ClipboardManager;
28 import android.widget.Toast;
29
30 /**
31 * Activity copying the text of the received Intent into the system clibpoard.
32 *
33 * @author David A. Velasco
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 }