Skip to content

Commit 783548f

Browse files
Add files via upload
1 parent d517fa7 commit 783548f

16 files changed

+1481
-0
lines changed

CalculateAgeUtils.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package tech.appzilla.com.setmydate.Utils;
2+
3+
import java.text.ParseException;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Calendar;
6+
import java.util.Date;
7+
8+
public class CalculateAgeUtils {
9+
10+
public static String getAge(String dobString){
11+
12+
Date date = null;
13+
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
14+
try {
15+
date = sdf.parse(dobString);
16+
} catch (ParseException e) {
17+
e.printStackTrace();
18+
}
19+
20+
if(date == null) return String.valueOf(0);
21+
22+
Calendar dob = Calendar.getInstance();
23+
Calendar today = Calendar.getInstance();
24+
25+
dob.setTime(date);
26+
27+
int year = dob.get(Calendar.YEAR);
28+
int month = dob.get(Calendar.MONTH);
29+
int day = dob.get(Calendar.DAY_OF_MONTH);
30+
31+
dob.set(year, month+1, day);
32+
33+
int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
34+
35+
if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR)){
36+
age--;
37+
}
38+
39+
40+
41+
return String.valueOf(age);
42+
}
43+
44+
45+
}

ConvertTime.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package tech.appzilla.com.setmydate.Utils;
2+
3+
import android.content.Context;
4+
import android.text.format.DateFormat;
5+
6+
import java.text.SimpleDateFormat;
7+
import java.util.Calendar;
8+
import java.util.Date;
9+
10+
public class ConvertTime {
11+
12+
13+
14+
private static final int SECOND_MILLIS = 1000;
15+
private static final int MINUTE_MILLIS = 60 * SECOND_MILLIS;
16+
private static final int HOUR_MILLIS = 60 * MINUTE_MILLIS;
17+
private static final int DAY_MILLIS = 24 * HOUR_MILLIS;
18+
19+
20+
public static String getTimeAgo(long time) {
21+
if (time < 1000000000000L) {
22+
// if timestamp given in seconds, convert to millis
23+
time *= 1000;
24+
}
25+
26+
long now = System.currentTimeMillis();
27+
if (time > now || time <= 0) {
28+
return "just now";
29+
}
30+
31+
// TODO: localize
32+
final long diff = now - time;
33+
if (diff < MINUTE_MILLIS) {
34+
return "just now";
35+
} else if (diff < 2 * MINUTE_MILLIS) {
36+
return "a minute ago";
37+
} else if (diff < 50 * MINUTE_MILLIS) {
38+
return diff / MINUTE_MILLIS + " minutes ago";
39+
} else if (diff < 90 * MINUTE_MILLIS) {
40+
return "an hour ago";
41+
} else if (diff < 24 * HOUR_MILLIS) {
42+
return diff / HOUR_MILLIS + " hours ago";
43+
} else if (diff < 48 * HOUR_MILLIS) {
44+
return "yesterday";
45+
} else {
46+
return diff / DAY_MILLIS + " days ago";
47+
}
48+
}
49+
50+
public static String getDateAndTime(long time){
51+
SimpleDateFormat sfd = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
52+
53+
return sfd.format(new Date(time));
54+
}
55+
56+
public static String getMyPrettyDate(long neededTimeMilis) {
57+
Calendar nowTime = Calendar.getInstance();
58+
Calendar neededTime = Calendar.getInstance();
59+
neededTime.setTimeInMillis(neededTimeMilis);
60+
61+
if ((neededTime.get(Calendar.YEAR) == nowTime.get(Calendar.YEAR))) {
62+
63+
if ((neededTime.get(Calendar.MONTH) == nowTime.get(Calendar.MONTH))) {
64+
65+
if (neededTime.get(Calendar.DATE) - nowTime.get(Calendar.DATE) == 1) {
66+
//here return like "Tomorrow at 12:00"
67+
return "Tomorrow at " + DateFormat.format("hh:mm:aa", neededTime);
68+
69+
} else if (nowTime.get(Calendar.DATE) == neededTime.get(Calendar.DATE)) {
70+
//here return like "Today at 12:00"
71+
return "Today at " + DateFormat.format("hh:mm:aa", neededTime);
72+
73+
} else if (nowTime.get(Calendar.DATE) - neededTime.get(Calendar.DATE) == 1) {
74+
//here return like "Yesterday at 12:00"
75+
return "Yesterday at " + DateFormat.format("hh:mm:aa", neededTime);
76+
77+
} else {
78+
//here return like "May 31, 12:00"
79+
return DateFormat.format("MMMM d, hh:mm", neededTime).toString();
80+
}
81+
82+
} else {
83+
//here return like "May 31, 12:00"
84+
return DateFormat.format("MMMM d, hh:mm", neededTime).toString();
85+
}
86+
87+
} else {
88+
//here return like "May 31 2010, 12:00" - it's a different year we need to show it
89+
return DateFormat.format("MMMM dd yyyy, hh:mm", neededTime).toString();
90+
}
91+
}
92+
}

FilePath.kt

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package tech.appzilla.com.setmydate.Utils
2+
3+
import android.content.ContentUris
4+
import android.content.Context
5+
import android.database.Cursor
6+
import android.net.Uri
7+
import android.os.Build
8+
import android.os.Environment
9+
import android.provider.DocumentsContract
10+
import android.provider.MediaStore
11+
12+
object FilePath {
13+
14+
15+
/**
16+
* Method for return file path of Gallery image
17+
*
18+
* @param context
19+
* @param uri
20+
* @return path of the selected image file from gallery
21+
*/
22+
23+
fun getPath(context: Context, uri: Uri): String? {
24+
//check here to KITKAT or new version
25+
val isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
26+
27+
// DocumentProvider
28+
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
29+
30+
// ExternalStorageProvider
31+
if (isExternalStorageDocument(uri)) {
32+
val docId = DocumentsContract.getDocumentId(uri)
33+
val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
34+
val type = split[0]
35+
36+
if ("primary".equals(type, ignoreCase = true)) {
37+
return Environment.getExternalStorageDirectory().toString() + "/" + split[1]
38+
}
39+
} else if (isDownloadsDocument(uri)) {
40+
41+
val id = DocumentsContract.getDocumentId(uri)
42+
val contentUri = ContentUris.withAppendedId(
43+
Uri.parse("content://downloads/public_downloads"), java.lang.Long.valueOf(id)
44+
)
45+
46+
return getDataColumn(context, contentUri, null, null)
47+
} else if (isMediaDocument(uri)) {
48+
val docId = DocumentsContract.getDocumentId(uri)
49+
val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
50+
val type = split[0]
51+
52+
var contentUri: Uri? = null
53+
if ("image" == type) {
54+
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
55+
} else if ("video" == type) {
56+
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
57+
} else if ("audio" == type) {
58+
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
59+
}
60+
61+
val selection = "_id=?"
62+
val selectionArgs = arrayOf(split[1])
63+
64+
return getDataColumn(context, contentUri, selection, selectionArgs)
65+
}// MediaProvider
66+
//DownloadsProvider
67+
} else if ("content".equals(uri.scheme, ignoreCase = true)) {
68+
69+
// Return the remote address
70+
return if (isGooglePhotosUri(uri)) uri.lastPathSegment else getDataColumn(context, uri, null, null)
71+
72+
} else if ("file".equals(uri.scheme, ignoreCase = true)) {
73+
return uri.path
74+
}// File
75+
// MediaStore (and general)
76+
77+
return null
78+
}
79+
80+
/**
81+
* Get the value of the data column for this Uri. This is useful for
82+
* MediaStore Uris, and other file-based ContentProviders.
83+
*
84+
* @param context The context.
85+
* @param uri The Uri to query.
86+
* @param selection (Optional) Filter used in the query.
87+
* @param selectionArgs (Optional) Selection arguments used in the query.
88+
* @return The value of the _data column, which is typically a file path.
89+
*/
90+
private fun getDataColumn(
91+
context: Context, uri: Uri?, selection: String?,
92+
selectionArgs: Array<String>?
93+
): String? {
94+
95+
var cursor: Cursor? = null
96+
val column = "_data"
97+
val projection = arrayOf(column)
98+
99+
try {
100+
cursor = context.contentResolver.query(uri!!, projection, selection, selectionArgs, null)
101+
if (cursor != null && cursor.moveToFirst()) {
102+
val index = cursor.getColumnIndexOrThrow(column)
103+
return cursor.getString(index)
104+
}
105+
} finally {
106+
cursor?.close()
107+
}
108+
return null
109+
}
110+
111+
/**
112+
* @param uri The Uri to check.
113+
* @return Whether the Uri authority is ExternalStorageProvider.
114+
*/
115+
private fun isExternalStorageDocument(uri: Uri): Boolean {
116+
return "com.android.externalstorage.documents" == uri.authority
117+
}
118+
119+
/**
120+
* @param uri The Uri to check.
121+
* @return Whether the Uri authority is DownloadsProvider.
122+
*/
123+
private fun isDownloadsDocument(uri: Uri): Boolean {
124+
return "com.android.providers.downloads.documents" == uri.authority
125+
}
126+
127+
/**
128+
* @param uri The Uri to check.
129+
* @return Whether the Uri authority is MediaProvider.
130+
*/
131+
private fun isMediaDocument(uri: Uri): Boolean {
132+
return "com.android.providers.media.documents" == uri.authority
133+
}
134+
135+
/**
136+
* @param uri The Uri to check.
137+
* @return Whether the Uri authority is Google Photos.
138+
*/
139+
private fun isGooglePhotosUri(uri: Uri): Boolean {
140+
141+
142+
if("com.google.android.apps.photos.contentprovider" == uri.authority)
143+
return true
144+
145+
return "com.google.android.apps.photos.contentprovider" == uri.authority
146+
}
147+
148+
}

GalleryUtils.kt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package tech.appzilla.com.setmydate.Utils
2+
3+
import android.app.Activity
4+
import android.content.Context
5+
import android.content.Intent
6+
import android.net.Uri
7+
import android.os.Environment
8+
import android.provider.MediaStore
9+
import android.os.Environment.getExternalStorageDirectory
10+
import android.support.v4.content.FileProvider
11+
import android.util.Log
12+
import java.io.File
13+
import java.io.IOException
14+
import java.text.SimpleDateFormat
15+
import java.util.*
16+
17+
18+
class GalleryUtils(context: Context) {
19+
20+
var context: Context? = context
21+
22+
companion object {var mCurrentPhotoPath: String? = null}
23+
24+
25+
//open camera
26+
fun openCamera() {
27+
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
28+
// Ensure that there's a camera activity to handle the intent
29+
if (intent.resolveActivity(context!!.packageManager) != null) {
30+
// Create the File where the photo should go
31+
var photoFile : File ? = null;
32+
try {
33+
photoFile = createImageFile()
34+
} catch (ex: IOException) {
35+
ex.printStackTrace()
36+
}
37+
// Continue only if the File was successfully created
38+
if (photoFile != null) {
39+
val photoURI = FileProvider.getUriForFile(
40+
context!!,
41+
"com.example.android.fileprovider",
42+
photoFile
43+
);
44+
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
45+
(context as Activity).startActivityForResult(intent, AppConstants.CODE_PERMISSION_CAMERA)
46+
}
47+
48+
}
49+
50+
}
51+
52+
@Throws(IOException::class)
53+
fun createImageFile() : File {
54+
// Create an image file name
55+
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss").format( Date());
56+
val imageFileName = "JPEG_" + timeStamp + "_";
57+
val storageDir = context!!.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
58+
val image = File.createTempFile(
59+
imageFileName, /* prefix */
60+
".jpg", /* suffix */
61+
storageDir /* directory */
62+
);
63+
64+
// Save a file: path for use with ACTION_VIEW intents
65+
mCurrentPhotoPath = image.getAbsolutePath();
66+
67+
Log.d("CURRENT_PATH",mCurrentPhotoPath)
68+
69+
return image
70+
}
71+
72+
73+
//open gallery
74+
fun openGallery() {
75+
val intent = Intent()
76+
intent.type = "image/*"
77+
intent.action = Intent.ACTION_PICK
78+
(context as Activity).startActivityForResult(
79+
Intent.createChooser(intent, "Select Picture"),
80+
AppConstants.CODE_PERMISSION_GALLERY
81+
)
82+
83+
}
84+
85+
//open image and video gallery with multiple selection
86+
fun openMultipleSelectGallery(selectionType: String) {
87+
val pickIntent = Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
88+
pickIntent.type = selectionType
89+
pickIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
90+
(context as Activity).startActivityForResult(pickIntent, AppConstants.CODE_IMAGE_PICKER)
91+
}
92+
93+
}

GpsUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package tech.appzilla.com.setmydate.Utils;
2+
3+
import android.content.Context;
4+
import android.location.LocationManager;
5+
6+
/**
7+
* Created by Rohit Singh$ on 11/06/2019.
8+
*/
9+
public class GpsUtils {
10+
//Check GPS Status true/false
11+
public static boolean checkGPSStatus(Context context){
12+
LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE );
13+
return manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
14+
};
15+
}

0 commit comments

Comments
 (0)