-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonUtility.java
More file actions
60 lines (45 loc) · 2.07 KB
/
CommonUtility.java
File metadata and controls
60 lines (45 loc) · 2.07 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.mrdheerajpurohit.utility;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Dheeraj Purohit CommonUtility for Android.
*/
public class CommonUtility {
public static void share(Context ctx, String sharingMsg, String emailSubject, String title) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, sharingMsg);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
ctx.startActivity(Intent.createChooser(sharingIntent, title));
}
public static void shareImage(Context context, Uri uri, String title) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/jpeg");
context.startActivity(Intent.createChooser(shareIntent, title));
}
public static boolean isValidEmail(String email) {
final String emailPattern = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
Matcher matcher;
Pattern pattern = Pattern.compile(emailPattern);
matcher = pattern.matcher(email);
if (matcher != null)
return matcher.matches();
else
return false;
}
public static boolean isLandscape(Context context) {
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}
public static boolean isPortrait(Context context) {
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
}