Skip to content

Commit 0b3743d

Browse files
committed
1. Added new animation utils.
2. Added new listener for time picker dialog. 3. Added new date time utils. 4. Added new methods in Shared Preferences Data. 5. Modified method for checking internet connection. 6. Added highlight search text method in text utils.
1 parent ca435d6 commit 0b3743d

File tree

8 files changed

+415
-44
lines changed

8 files changed

+415
-44
lines changed

.idea/caches/build_file_checksums.ser

-37 Bytes
Binary file not shown.

app/src/main/java/com/amit/anim/AnimUtil.java

Lines changed: 179 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.view.ViewGroup;
1212
import android.view.animation.Animation;
1313
import android.view.animation.AnimationUtils;
14+
import android.view.animation.Transformation;
1415

1516
import com.amit.R;
1617

@@ -47,7 +48,7 @@ public static void slideActivityFromRightToLeft(@NonNull Context context)
4748
* this activity will make the activity to slide in from left and slide out from right
4849
*
4950
* @param context - context of the activity
50-
**/
51+
**/
5152
public static void slideActivityFromLeftToRight(@NonNull Context context)
5253
{
5354
try
@@ -161,7 +162,7 @@ public static void slideActivityFromUpWithStay(@NonNull Context context)
161162
* this method will make the activity to slide from bottom to up.
162163
*
163164
* @param context - context of the activity
164-
**/
165+
**/
165166
public static void slideActivityFromBottomToUp(@NonNull Context context)
166167
{
167168
try
@@ -180,7 +181,7 @@ public static void slideActivityFromBottomToUp(@NonNull Context context)
180181
* this method will make the activity to slide from up to bottom.
181182
*
182183
* @param context - context of the activity
183-
**/
184+
**/
184185
public static void slideActivityFromUpToBottom(@NonNull Context context)
185186
{
186187
try
@@ -207,9 +208,7 @@ public static void slideActivityFromUpToBottom(@NonNull Context context)
207208
* @param duration - duration of the transition
208209
**/
209210
@TargetApi(21)
210-
public static void explodeTransition(@NonNull Context context,
211-
ViewGroup viewGroup,
212-
int duration)
211+
public static void explodeTransition(@NonNull Context context, ViewGroup viewGroup, int duration)
213212
{
214213
try
215214
{
@@ -238,9 +237,7 @@ public static void explodeTransition(@NonNull Context context,
238237
* @param view - view to animate
239238
* @param duration - duration of animation
240239
**/
241-
public static void slideAnimFromRight(@NonNull Context context,
242-
@NonNull View view,
243-
int duration)
240+
public static void slideAnimFromRight(@NonNull Context context, @NonNull View view, int duration)
244241
{
245242
try
246243
{
@@ -265,9 +262,7 @@ public static void slideAnimFromRight(@NonNull Context context,
265262
* @param view - view to animate
266263
* @param duration - duration of animation
267264
**/
268-
public static void slideAnimFromLeft(@NonNull Context context,
269-
@NonNull View view,
270-
int duration)
265+
public static void slideAnimFromLeft(@NonNull Context context, @NonNull View view, int duration)
271266
{
272267
try
273268
{
@@ -293,10 +288,7 @@ public static void slideAnimFromLeft(@NonNull Context context,
293288
* @param duration - duration of the animation
294289
* @param animResId - anim resouce for animation
295290
**/
296-
public static void slideAnim(@NonNull Context context,
297-
@NonNull View view,
298-
int duration,
299-
@AnimRes int animResId)
291+
public static void slideAnim(@NonNull Context context, @NonNull View view, int duration, @AnimRes int animResId)
300292
{
301293
try
302294
{
@@ -319,7 +311,7 @@ public static void slideAnim(@NonNull Context context,
319311
*
320312
* @param context - context of the application
321313
* @param view - view to animate
322-
**/
314+
**/
323315
public static void bounceAnim(Context context, View view)
324316
{
325317
try
@@ -335,4 +327,174 @@ public static void bounceAnim(Context context, View view)
335327
e.printStackTrace();
336328
}
337329
}
330+
331+
/**
332+
* 2019 July 22 - Monday - 12:30 PM
333+
* expand view method
334+
*
335+
* this method is used to expand the view to its content's height
336+
*
337+
* @param v - View that needs to be expanded
338+
**/
339+
public static void expandView(final View v)
340+
{
341+
int matchParentMeasureSpec = View.MeasureSpec.makeMeasureSpec(((View) v.getParent()).getWidth(), View.MeasureSpec.EXACTLY);
342+
int wrapContentMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
343+
344+
v.measure(matchParentMeasureSpec, wrapContentMeasureSpec);
345+
final int targetHeight = v.getMeasuredHeight();
346+
347+
// Older versions of android (pre API 21) cancel animations for views with a height of 0.
348+
v.getLayoutParams().height = 1;
349+
v.setVisibility(View.VISIBLE);
350+
351+
Animation a = new Animation()
352+
{
353+
@Override
354+
protected void applyTransformation(float interpolatedTime, Transformation t)
355+
{
356+
v.getLayoutParams().height = interpolatedTime == 1
357+
? ViewGroup.LayoutParams.WRAP_CONTENT
358+
: (int) (targetHeight * interpolatedTime);
359+
360+
v.requestLayout();
361+
}
362+
363+
@Override
364+
public boolean willChangeBounds()
365+
{
366+
return true;
367+
}
368+
};
369+
370+
// Expansion speed of 1dp/ms
371+
a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
372+
v.startAnimation(a);
373+
}
374+
375+
/**
376+
* 2019 July 22 - Monday - 12:30 PM
377+
* collapse view method
378+
*
379+
* this method is used to collapse the view to its content's height
380+
*
381+
* @param v - View that needs to be collapsed
382+
**/
383+
public static void collapseView(final View v)
384+
{
385+
final int initialHeight = v.getMeasuredHeight();
386+
387+
Animation a = new Animation()
388+
{
389+
@Override
390+
protected void applyTransformation(float interpolatedTime, Transformation t)
391+
{
392+
if (interpolatedTime == 1)
393+
{
394+
v.setVisibility(View.GONE);
395+
}
396+
else
397+
{
398+
v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
399+
v.requestLayout();
400+
}
401+
}
402+
403+
@Override
404+
public boolean willChangeBounds()
405+
{
406+
return true;
407+
}
408+
};
409+
410+
// Collapse speed of 1dp/ms
411+
a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
412+
v.startAnimation(a);
413+
}
414+
415+
/**
416+
* 2019 July 22 - Monday - 12:30 PM
417+
* expand view method
418+
*
419+
* this method is used to expand the view to its content's height
420+
*
421+
* @param v - View that needs to be expanded
422+
*
423+
* @param animDuration - duration of the animation for expanding the view
424+
**/
425+
public static void expandView(final View v, int animDuration)
426+
{
427+
int matchParentMeasureSpec = View.MeasureSpec.makeMeasureSpec(((View) v.getParent()).getWidth(), View.MeasureSpec.EXACTLY);
428+
int wrapContentMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
429+
430+
v.measure(matchParentMeasureSpec, wrapContentMeasureSpec);
431+
final int targetHeight = v.getMeasuredHeight();
432+
433+
// Older versions of android (pre API 21) cancel animations for views with a height of 0.
434+
v.getLayoutParams().height = 1;
435+
v.setVisibility(View.VISIBLE);
436+
437+
Animation a = new Animation()
438+
{
439+
@Override
440+
protected void applyTransformation(float interpolatedTime, Transformation t)
441+
{
442+
v.getLayoutParams().height = interpolatedTime == 1
443+
? ViewGroup.LayoutParams.WRAP_CONTENT
444+
: (int) (targetHeight * interpolatedTime);
445+
446+
v.requestLayout();
447+
}
448+
449+
@Override
450+
public boolean willChangeBounds()
451+
{
452+
return true;
453+
}
454+
};
455+
456+
a.setDuration(animDuration);
457+
v.startAnimation(a);
458+
}
459+
460+
/**
461+
* 2019 July 22 - Monday - 12:30 PM
462+
* collapse view method
463+
*
464+
* this method is used to collapse the view to its content's height
465+
*
466+
* @param v - View that needs to be collapsed
467+
*
468+
* @param animDuration - duration of the animation for collapsing the view
469+
**/
470+
public static void collapseView(final View v, int animDuration)
471+
{
472+
final int initialHeight = v.getMeasuredHeight();
473+
474+
Animation a = new Animation()
475+
{
476+
@Override
477+
protected void applyTransformation(float interpolatedTime, Transformation t)
478+
{
479+
if (interpolatedTime == 1)
480+
{
481+
v.setVisibility(View.GONE);
482+
}
483+
else
484+
{
485+
v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
486+
v.requestLayout();
487+
}
488+
}
489+
490+
@Override
491+
public boolean willChangeBounds()
492+
{
493+
return true;
494+
}
495+
};
496+
497+
a.setDuration(animDuration);
498+
v.startAnimation(a);
499+
}
338500
}

app/src/main/java/com/amit/utilities/DateTimeUtils.java

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.amit.utilities;
22

3+
import android.content.Context;
34
import android.text.format.DateFormat;
45
import android.util.Log;
56

67
import java.text.ParseException;
78
import java.text.SimpleDateFormat;
9+
import java.util.Calendar;
810
import java.util.Date;
911
import java.util.Locale;
1012

@@ -106,10 +108,8 @@ public static String formatMilliSecondsToTime(long milliseconds)
106108
int seconds = (int) (milliseconds / 1000) % 60;
107109
int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
108110
int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);
109-
110-
return twoDigitString(hours) + " : " +
111-
twoDigitString(minutes) + " : "
112-
+ twoDigitString(seconds);
111+
112+
return twoDigitString(hours) + ":" + twoDigitString(minutes) + ":" + twoDigitString(seconds);
113113
}
114114

115115
/**
@@ -150,4 +150,79 @@ public static long convertDaysInMillis(int days)
150150
{
151151
return days * 24 * 60 * 60 * 1000;
152152
}
153+
154+
/**
155+
* 2019 June 03 - Monday - 12:14 PM
156+
* get current fin year method
157+
*
158+
* this method will get current fin year in yy-yy format
159+
*
160+
* @param context - context of the application or activity
161+
*
162+
* @return it will return current fin year in yy-yy format
163+
**/
164+
public static String getCurrentFinYear(Context context)
165+
{
166+
try
167+
{
168+
String currentFinYear;
169+
170+
int currentYear = Integer.parseInt(DateTimeUtils.getCurrentDateTime("yy"));
171+
int currentMonth = Integer.parseInt(DateTimeUtils.getCurrentDateTime("MM"));
172+
173+
int nextYear = currentYear + 1;
174+
175+
if (currentMonth <= 3)
176+
{
177+
nextYear = currentYear;
178+
currentYear = currentYear - 1;
179+
}
180+
181+
currentFinYear = currentYear + "-" + nextYear;
182+
return currentFinYear;
183+
}
184+
catch (Exception e)
185+
{
186+
Log.e(TAG, "getCurrentFinYear: exception while getting current fin year:\n");
187+
e.printStackTrace();
188+
189+
return "";
190+
}
191+
}
192+
193+
/**
194+
* 2019 July 15 - Monday - 01:29 PM
195+
* convert to date time from milliseconds method
196+
*
197+
* this method will convert milliseconds to date time
198+
*
199+
* @param context - context of the application or activity
200+
*
201+
* @param milliseconds - milli seconds to be converted to date time
202+
*
203+
* @param inDateTimeFormat - format in which you want date time
204+
* Example: yyyy-MM-dd HH:mm:ss
205+
*
206+
* @return Date time in specified in inDateTimeFormat
207+
**/
208+
private static String convertToDateTimeFromMilliseconds(Context context, Long milliseconds, String inDateTimeFormat)
209+
{
210+
try
211+
{
212+
// Create a DateFormatter object for displaying date in specified format.
213+
SimpleDateFormat formatter = new SimpleDateFormat(inDateTimeFormat, Locale.US);
214+
215+
// Create a calendarIcon object that will convert the date and time value in milliseconds to date.
216+
Calendar calendar = Calendar.getInstance();
217+
calendar.setTimeInMillis(milliseconds);
218+
return formatter.format(calendar.getTime());
219+
}
220+
catch (Exception e)
221+
{
222+
Log.e(TAG, "exception while converting to date time from milliseconds:\n");
223+
e.printStackTrace();
224+
225+
return String.valueOf(milliseconds);
226+
}
227+
}
153228
}

app/src/main/java/com/amit/utilities/Internet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static boolean isInternetConnected(Context context)
3131
if (connectivityManager != null)
3232
{
3333
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
34-
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
34+
return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
3535
}
3636
else
3737
{

0 commit comments

Comments
 (0)