|
0
|
1 |
package hh.dejsem;
|
|
|
2 |
|
|
|
3 |
import android.content.ClipData;
|
|
|
4 |
import android.content.ClipboardManager;
|
|
|
5 |
import android.content.Context;
|
|
|
6 |
import android.content.DialogInterface;
|
|
|
7 |
import android.content.Intent;
|
|
|
8 |
import android.net.Uri;
|
|
|
9 |
import android.support.v7.app.AlertDialog;
|
|
|
10 |
import android.telephony.SmsManager;
|
|
|
11 |
|
|
|
12 |
import java.util.List;
|
|
|
13 |
|
|
|
14 |
import hh.dejsem.fm.TransferAlert;
|
|
|
15 |
import hh.lib.D;
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* share http URL
|
|
|
19 |
* ● complete URL from URI path
|
|
|
20 |
* ● copy URL to clipboard
|
|
|
21 |
* ● optionally share URL
|
|
|
22 |
*/
|
|
|
23 |
public class SendUriNG implements DialogInterface.OnClickListener {
|
|
|
24 |
|
|
|
25 |
public static void decideSendUri(String uriPath) {
|
|
|
26 |
if(uriPath != null && uriPath.length() > 0)
|
|
|
27 |
K.app.startActivity(new Intent(K.app, TransferAlert.class)
|
|
|
28 |
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) /*Intent.FLAG_ACTIVITY_SINGLE_TOP)*/
|
|
|
29 |
.putExtra(K.ACTION_KEY, K.TRANSFER_SEND_URI)
|
|
|
30 |
.putExtra(K.TXT_KEY, uriPath)
|
|
|
31 |
);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
D d;
|
|
|
35 |
Context c;
|
|
|
36 |
AlertDialog alert;
|
|
|
37 |
public String uriStr;
|
|
|
38 |
|
|
|
39 |
public SendUriNG(D d, Context c, String uriPath) {
|
|
|
40 |
this.d = d.klon(this);
|
|
|
41 |
this.c = c;
|
|
|
42 |
uriStr = buildUri(uriPath).toString();
|
|
|
43 |
if(this.d.ll(4)) this.d.l("exposed as " + uriStr);
|
|
|
44 |
((ClipboardManager)(c.getSystemService(Context.CLIPBOARD_SERVICE))) // pin URL on clipboard
|
|
|
45 |
.setPrimaryClip(ClipData.newPlainText("exposed URL", uriStr));
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
@Override
|
|
|
49 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
50 |
d.l(4,"onClick");
|
|
|
51 |
if(which == DialogInterface.BUTTON_POSITIVE) send();
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
Uri buildUri(String uriPath) {
|
|
|
55 |
return new Uri.Builder().scheme("http").authority(Prefs.host).path(uriPath).build();
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
void send() {
|
|
|
59 |
Intent actionSEND = new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT, uriStr).setTypeAndNormalize("text/plain");
|
|
|
60 |
c.startActivity(Intent.createChooser(actionSEND, null));
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public void sendTestSMS(String url) {
|
|
|
64 |
if(d.ll(4)) d.l("sent by SMS: " + url);
|
|
|
65 |
SmsManager sms = SmsManager.getDefault();
|
|
|
66 |
List<String> messages = sms.divideMessage(url);
|
|
|
67 |
/*String recipient = recipientTextEdit.getText().toString();*/
|
|
|
68 |
/*String recipient = "601593811";*/
|
|
|
69 |
String recipient = "607677931";
|
|
|
70 |
for (String message : messages) {
|
|
|
71 |
if(d.ll(5)) d.l(String.format("sms.sendTextMessage(\"%s\", null, \"%s\", null, null)", recipient, message));
|
|
|
72 |
sms.sendTextMessage(recipient, null, message, null, null);
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
}
|