Skip to content

Commit f625c41

Browse files
Fix #418
1 parent 715c947 commit f625c41

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailImageDialogFragment.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package de.luhmer.owncloudnewsreader;
22

33
import android.annotation.TargetApi;
4+
import android.app.Activity;
45
import android.app.DownloadManager;
56
import android.content.BroadcastReceiver;
7+
import android.content.ClipData;
8+
import android.content.ClipboardManager;
69
import android.content.Context;
710
import android.content.Intent;
811
import android.content.IntentFilter;
@@ -110,6 +113,14 @@ public void execute() {
110113
openLinkInBrowser(mImageUrl);
111114
}
112115
});
116+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
117+
mMenuItems.put("Copy Link", new MenuAction() {
118+
@Override
119+
public void execute() {
120+
copyToCipboard(mDialogTitle, mImageUrl.toString());
121+
}
122+
});
123+
}
113124
break;
114125
case URL:
115126
mMenuItems.put("Share Link", new MenuAction() {
@@ -129,6 +140,14 @@ public void execute() {
129140
}
130141
}
131142
});
143+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
144+
mMenuItems.put("Copy Link", new MenuAction() {
145+
@Override
146+
public void execute() {
147+
copyToCipboard(mDialogTitle, mDialogText);
148+
}
149+
});
150+
}
132151
break;
133152
}
134153

@@ -181,6 +200,14 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
181200
return v;
182201
}
183202

203+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
204+
private void copyToCipboard(String label, String text) {
205+
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE);
206+
ClipData clip = ClipData.newPlainText(label, text);
207+
clipboard.setPrimaryClip(clip);
208+
Toast.makeText(getActivity(), "Copied to clipboard", Toast.LENGTH_SHORT).show();
209+
getDialog().dismiss();
210+
}
184211

185212
private void shareImage() {
186213
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);

0 commit comments

Comments
 (0)