-
Notifications
You must be signed in to change notification settings - Fork 1
/
CodeSharer.java
37 lines (31 loc) · 935 Bytes
/
CodeSharer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class CodeSharer {
Context context;
public CodeSharer(Context cxt)
{
context=ctx;
}
public void share(String text) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy_HH:mm:ss");
Date date = new Date();
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "code_generated_"+dateFormat.format(date));
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, codeForString(text));
context.startActivity(sharingIntent);
}
private String codeForString(String str) {
String newString="\"";
int charsInLine=0;
for(int i=0;i<str.length();i++)
{
newString+=str.charAt(i);
charsInLine+=1;
if(charsInLine>=80)
{
newString+="\"+\n\"";
charsInLine=0;
}
}
return newString+"\"";
}
}