Skip to content

Commit 23468ec

Browse files
committed
SettingIntent is ready for development.
1 parent 6b82632 commit 23468ec

File tree

6 files changed

+178
-244
lines changed

6 files changed

+178
-244
lines changed

Library/src/main/java/com/next/androidintentlibrary/ContactIntents.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
public class ContactIntents
1919
{
2020
public static final int REQUEST_SELECT_CONTACT = 5;
21+
public static final int REQUEST_SELECT_PHONE_NUMBER = 6;
2122
private Context context;
2223
private Intent intent;
2324

@@ -125,6 +126,18 @@ public ContactIntents pickContact()
125126
return this;
126127
}
127128

129+
// TODO: requires start activity for result, on activity result, should only be used with build not show
130+
public ContactIntents pickContact(String scope)
131+
{
132+
intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://com.android.contacts/contacts"));
133+
134+
if (!TextUtils.isEmpty(scope))
135+
{
136+
intent.setType(scope);
137+
}
138+
return this;
139+
}
140+
128141
public Intent build()
129142
{
130143
return intent;

Library/src/main/java/com/next/androidintentlibrary/MessagingIntents.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.net.Uri;
77
import android.os.Build;
88
import android.provider.Telephony;
9+
import android.text.TextUtils;
910

1011
import androidx.annotation.NonNull;
1112

@@ -102,6 +103,93 @@ public MessagingIntents sendSms(Context context, String to, String message)
102103
}
103104
}
104105

106+
public MessagingIntents newEmptySmsIntent()
107+
{
108+
return newSmsIntent(null, (String[]) null);
109+
}
110+
111+
public MessagingIntents newEmptySmsIntent(String phoneNumber)
112+
{
113+
return newSmsIntent(null, new String[]{phoneNumber});
114+
}
115+
116+
public MessagingIntents newEmptySmsIntent(String[] phoneNumbers)
117+
{
118+
return newSmsIntent(null, phoneNumbers);
119+
}
120+
121+
public MessagingIntents newSmsIntent(String body)
122+
{
123+
return newSmsIntent(body, (String[]) null);
124+
}
125+
126+
public MessagingIntents newSmsIntent(String body, String phoneNumber)
127+
{
128+
return newSmsIntent(body, new String[]{phoneNumber});
129+
}
130+
131+
public MessagingIntents newSmsIntent(String body, String[] phoneNumbers)
132+
{
133+
Uri smsUri;
134+
if (phoneNumbers == null || phoneNumbers.length == 0)
135+
{
136+
smsUri = Uri.parse("smsto:");
137+
} else
138+
{
139+
smsUri = Uri.parse("smsto:" + Uri.encode(TextUtils.join(",", phoneNumbers)));
140+
}
141+
142+
143+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
144+
{
145+
intent = new Intent(Intent.ACTION_SENDTO, smsUri);
146+
intent.setPackage(Telephony.Sms.getDefaultSmsPackage(context));
147+
} else
148+
{
149+
intent = new Intent(Intent.ACTION_VIEW, smsUri);
150+
}
151+
152+
if (body != null)
153+
{
154+
intent.putExtra("sms_body", body);
155+
}
156+
157+
return this;
158+
}
159+
160+
public MessagingIntents openEmptySmsIntent()
161+
{
162+
return newSmsIntent(null, (String[]) null);
163+
}
164+
165+
public MessagingIntents openSmsNumberIntent(String phoneNumber)
166+
{
167+
if (phoneNumber != null)
168+
return newSmsIntent(null, new String[]{phoneNumber});
169+
return null;
170+
}
171+
172+
public MessagingIntents openSmsNumbersIntent(String[] phoneNumbers)
173+
{
174+
return newSmsIntent(null, phoneNumbers);
175+
}
176+
177+
178+
public MessagingIntents openSmsBodyIntent(String body)
179+
{
180+
return newSmsIntent(body, (String[]) null);
181+
}
182+
183+
public MessagingIntents openSmsNumberBodyIntent(String body, String phoneNumber)
184+
{
185+
return newSmsIntent(body, new String[]{phoneNumber});
186+
}
187+
188+
public MessagingIntents openSmsNumbersBodyIntent(String body, String[] phoneNumbers)
189+
{
190+
return newSmsIntent(body, phoneNumbers);
191+
}
192+
105193
public Intent build()
106194
{
107195
return intent;

Library/src/main/java/com/next/androidintentlibrary/PhoneIntents.java

Lines changed: 6 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44
import android.content.Context;
55
import android.content.Intent;
66
import android.net.Uri;
7-
import android.os.Build;
8-
import android.provider.Telephony;
97

108
import androidx.annotation.NonNull;
119

12-
import android.text.TextUtils;
13-
14-
import static android.content.Intent.ACTION_DIAL;
15-
1610
public class PhoneIntents
1711
{
18-
public static final int REQUEST_SELECT_PHONE_NUMBER = 6;
1912
private Context context;
2013
private Intent intent;
2114

@@ -29,150 +22,21 @@ public static PhoneIntents from(@NonNull Context context)
2922
return new PhoneIntents(context);
3023
}
3124

32-
public PhoneIntents newEmptySmsIntent()
33-
{
34-
return newSmsIntent(null, (String[]) null);
35-
}
36-
37-
public PhoneIntents newEmptySmsIntent(String phoneNumber)
38-
{
39-
return newSmsIntent(null, new String[]{phoneNumber});
40-
}
41-
42-
public PhoneIntents newEmptySmsIntent(String[] phoneNumbers)
43-
{
44-
return newSmsIntent(null, phoneNumbers);
45-
}
46-
47-
public PhoneIntents newSmsIntent(String body)
25+
public PhoneIntents showDialNumber()
4826
{
49-
return newSmsIntent(body, (String[]) null);
50-
}
51-
52-
public PhoneIntents newSmsIntent(String body, String phoneNumber)
53-
{
54-
return newSmsIntent(body, new String[]{phoneNumber});
55-
}
56-
57-
public PhoneIntents newSmsIntent(String body, String[] phoneNumbers)
58-
{
59-
Uri smsUri;
60-
if (phoneNumbers == null || phoneNumbers.length == 0)
61-
{
62-
smsUri = Uri.parse("smsto:");
63-
} else
64-
{
65-
smsUri = Uri.parse("smsto:" + Uri.encode(TextUtils.join(",", phoneNumbers)));
66-
}
67-
68-
69-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
70-
{
71-
intent = new Intent(Intent.ACTION_SENDTO, smsUri);
72-
intent.setPackage(Telephony.Sms.getDefaultSmsPackage(context));
73-
} else
74-
{
75-
intent = new Intent(Intent.ACTION_VIEW, smsUri);
76-
}
77-
78-
if (body != null)
79-
{
80-
intent.putExtra("sms_body", body);
81-
}
82-
27+
intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"));
8328
return this;
8429
}
8530

86-
public PhoneIntents newDialNumberIntent(String phoneNumber)
31+
public PhoneIntents showDialNumber(String phoneNumber)
8732
{
88-
89-
if (phoneNumber == null || phoneNumber.trim().length() <= 0)
90-
{
91-
intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"));
92-
} else
93-
{
94-
intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber.replace(" ", "")));
95-
}
33+
intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber.replace(" ", "")));
9634
return this;
9735
}
9836

99-
public PhoneIntents newCallNumberIntent(String phoneNumber)
37+
public PhoneIntents callNumber(String phoneNumber)
10038
{
101-
102-
if (phoneNumber == null || phoneNumber.trim().length() <= 0)
103-
{
104-
intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"));
105-
} else
106-
{
107-
intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber.replace(" ", "")));
108-
}
109-
110-
return this;
111-
}
112-
113-
public PhoneIntents newPickContactIntent()
114-
{
115-
return newPickContactIntent(null);
116-
}
117-
118-
public PhoneIntents openEmptySmsIntent()
119-
{
120-
return newSmsIntent(null, (String[]) null);
121-
}
122-
123-
public PhoneIntents openSmsNumberIntent(String phoneNumber)
124-
{
125-
if (phoneNumber != null)
126-
return newSmsIntent(null, new String[]{phoneNumber});
127-
return null;
128-
}
129-
130-
public PhoneIntents openSmsNumbersIntent(String[] phoneNumbers)
131-
{
132-
return newSmsIntent(null, phoneNumbers);
133-
}
134-
135-
136-
public PhoneIntents openSmsBodyIntent(String body)
137-
{
138-
return newSmsIntent(body, (String[]) null);
139-
}
140-
141-
public PhoneIntents openSmsNumberBodyIntent(String body, String phoneNumber)
142-
{
143-
return newSmsIntent(body, new String[]{phoneNumber});
144-
}
145-
146-
public PhoneIntents openSmsNumbersBodyIntent(String body, String[] phoneNumbers)
147-
{
148-
return newSmsIntent(body, phoneNumbers);
149-
}
150-
151-
@SuppressWarnings("deprecation")
152-
public PhoneIntents newPickContactIntent(String scope)
153-
{
154-
intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://com.android.contacts/contacts"));
155-
156-
if (!TextUtils.isEmpty(scope))
157-
{
158-
intent.setType(scope);
159-
}
160-
return this;
161-
}
162-
163-
public PhoneIntents callPhone(String phoneNumber)
164-
{
165-
intent = new Intent();
166-
intent.setAction(Intent.ACTION_CALL);
167-
intent.setData(Uri.parse("tel:" + phoneNumber));
168-
return this;
169-
}
170-
171-
public PhoneIntents dialPhone(String phoneNumber)
172-
{
173-
intent = new Intent();
174-
intent.setAction(Intent.ACTION_DIAL);
175-
intent.setData(Uri.parse("tel:" + phoneNumber));
39+
intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber.replace(" ", "")));
17640
return this;
17741
}
17842

@@ -194,33 +58,4 @@ public void show()
19458
{
19559
startActivity(build());
19660
}
197-
198-
public PhoneIntents openDialNumberIntent(String phoneNumber)
199-
{
200-
if (phoneNumber == null || phoneNumber.trim().length() <= 0)
201-
{//b te
202-
intent = new Intent(ACTION_DIAL, Uri.parse("tel:"));
203-
} else
204-
{
205-
intent = new Intent(ACTION_DIAL, Uri.parse("tel:" + phoneNumber.replace(" ", "")));
206-
}
207-
return this;
208-
}
209-
210-
// TODO: 8/30/2017 Needed To see The main Page Remember.
211-
public PhoneIntents InitiatePhoneDial(String phoneNumber)
212-
{
213-
intent = new Intent(Intent.ACTION_DIAL);
214-
intent.setData(Uri.parse("tel:" + phoneNumber));
215-
return this;
216-
}
217-
218-
// TODO: 8/30/2017 Need Permission : <uses-permission android:name="android.permission.CALL_PHONE" />
219-
// TODO: 8/30/2017 Needed To see The main Page Remember.
220-
public PhoneIntents InitiatePhoneCall(String phoneNumber)
221-
{
222-
intent = new Intent(Intent.ACTION_CALL);
223-
intent.setData(Uri.parse("tel:" + phoneNumber));
224-
return this;
225-
}
22661
}

0 commit comments

Comments
 (0)