Skip to content

Commit

Permalink
1. Added new animation utils.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amitjangid80 committed Jul 26, 2019
1 parent ca435d6 commit 0b3743d
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 44 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
196 changes: 179 additions & 17 deletions app/src/main/java/com/amit/anim/AnimUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Transformation;

import com.amit.R;

Expand Down Expand Up @@ -47,7 +48,7 @@ public static void slideActivityFromRightToLeft(@NonNull Context context)
* this activity will make the activity to slide in from left and slide out from right
*
* @param context - context of the activity
**/
**/
public static void slideActivityFromLeftToRight(@NonNull Context context)
{
try
Expand Down Expand Up @@ -161,7 +162,7 @@ public static void slideActivityFromUpWithStay(@NonNull Context context)
* this method will make the activity to slide from bottom to up.
*
* @param context - context of the activity
**/
**/
public static void slideActivityFromBottomToUp(@NonNull Context context)
{
try
Expand All @@ -180,7 +181,7 @@ public static void slideActivityFromBottomToUp(@NonNull Context context)
* this method will make the activity to slide from up to bottom.
*
* @param context - context of the activity
**/
**/
public static void slideActivityFromUpToBottom(@NonNull Context context)
{
try
Expand All @@ -207,9 +208,7 @@ public static void slideActivityFromUpToBottom(@NonNull Context context)
* @param duration - duration of the transition
**/
@TargetApi(21)
public static void explodeTransition(@NonNull Context context,
ViewGroup viewGroup,
int duration)
public static void explodeTransition(@NonNull Context context, ViewGroup viewGroup, int duration)
{
try
{
Expand Down Expand Up @@ -238,9 +237,7 @@ public static void explodeTransition(@NonNull Context context,
* @param view - view to animate
* @param duration - duration of animation
**/
public static void slideAnimFromRight(@NonNull Context context,
@NonNull View view,
int duration)
public static void slideAnimFromRight(@NonNull Context context, @NonNull View view, int duration)
{
try
{
Expand All @@ -265,9 +262,7 @@ public static void slideAnimFromRight(@NonNull Context context,
* @param view - view to animate
* @param duration - duration of animation
**/
public static void slideAnimFromLeft(@NonNull Context context,
@NonNull View view,
int duration)
public static void slideAnimFromLeft(@NonNull Context context, @NonNull View view, int duration)
{
try
{
Expand All @@ -293,10 +288,7 @@ public static void slideAnimFromLeft(@NonNull Context context,
* @param duration - duration of the animation
* @param animResId - anim resouce for animation
**/
public static void slideAnim(@NonNull Context context,
@NonNull View view,
int duration,
@AnimRes int animResId)
public static void slideAnim(@NonNull Context context, @NonNull View view, int duration, @AnimRes int animResId)
{
try
{
Expand All @@ -319,7 +311,7 @@ public static void slideAnim(@NonNull Context context,
*
* @param context - context of the application
* @param view - view to animate
**/
**/
public static void bounceAnim(Context context, View view)
{
try
Expand All @@ -335,4 +327,174 @@ public static void bounceAnim(Context context, View view)
e.printStackTrace();
}
}

/**
* 2019 July 22 - Monday - 12:30 PM
* expand view method
*
* this method is used to expand the view to its content's height
*
* @param v - View that needs to be expanded
**/
public static void expandView(final View v)
{
int matchParentMeasureSpec = View.MeasureSpec.makeMeasureSpec(((View) v.getParent()).getWidth(), View.MeasureSpec.EXACTLY);
int wrapContentMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);

v.measure(matchParentMeasureSpec, wrapContentMeasureSpec);
final int targetHeight = v.getMeasuredHeight();

// Older versions of android (pre API 21) cancel animations for views with a height of 0.
v.getLayoutParams().height = 1;
v.setVisibility(View.VISIBLE);

Animation a = new Animation()
{
@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
v.getLayoutParams().height = interpolatedTime == 1
? ViewGroup.LayoutParams.WRAP_CONTENT
: (int) (targetHeight * interpolatedTime);

v.requestLayout();
}

@Override
public boolean willChangeBounds()
{
return true;
}
};

// Expansion speed of 1dp/ms
a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}

/**
* 2019 July 22 - Monday - 12:30 PM
* collapse view method
*
* this method is used to collapse the view to its content's height
*
* @param v - View that needs to be collapsed
**/
public static void collapseView(final View v)
{
final int initialHeight = v.getMeasuredHeight();

Animation a = new Animation()
{
@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
if (interpolatedTime == 1)
{
v.setVisibility(View.GONE);
}
else
{
v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
v.requestLayout();
}
}

@Override
public boolean willChangeBounds()
{
return true;
}
};

// Collapse speed of 1dp/ms
a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}

/**
* 2019 July 22 - Monday - 12:30 PM
* expand view method
*
* this method is used to expand the view to its content's height
*
* @param v - View that needs to be expanded
*
* @param animDuration - duration of the animation for expanding the view
**/
public static void expandView(final View v, int animDuration)
{
int matchParentMeasureSpec = View.MeasureSpec.makeMeasureSpec(((View) v.getParent()).getWidth(), View.MeasureSpec.EXACTLY);
int wrapContentMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);

v.measure(matchParentMeasureSpec, wrapContentMeasureSpec);
final int targetHeight = v.getMeasuredHeight();

// Older versions of android (pre API 21) cancel animations for views with a height of 0.
v.getLayoutParams().height = 1;
v.setVisibility(View.VISIBLE);

Animation a = new Animation()
{
@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
v.getLayoutParams().height = interpolatedTime == 1
? ViewGroup.LayoutParams.WRAP_CONTENT
: (int) (targetHeight * interpolatedTime);

v.requestLayout();
}

@Override
public boolean willChangeBounds()
{
return true;
}
};

a.setDuration(animDuration);
v.startAnimation(a);
}

/**
* 2019 July 22 - Monday - 12:30 PM
* collapse view method
*
* this method is used to collapse the view to its content's height
*
* @param v - View that needs to be collapsed
*
* @param animDuration - duration of the animation for collapsing the view
**/
public static void collapseView(final View v, int animDuration)
{
final int initialHeight = v.getMeasuredHeight();

Animation a = new Animation()
{
@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
if (interpolatedTime == 1)
{
v.setVisibility(View.GONE);
}
else
{
v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
v.requestLayout();
}
}

@Override
public boolean willChangeBounds()
{
return true;
}
};

a.setDuration(animDuration);
v.startAnimation(a);
}
}
83 changes: 79 additions & 4 deletions app/src/main/java/com/amit/utilities/DateTimeUtils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.amit.utilities;

import android.content.Context;
import android.text.format.DateFormat;
import android.util.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

Expand Down Expand Up @@ -106,10 +108,8 @@ public static String formatMilliSecondsToTime(long milliseconds)
int seconds = (int) (milliseconds / 1000) % 60;
int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);

return twoDigitString(hours) + " : " +
twoDigitString(minutes) + " : "
+ twoDigitString(seconds);

return twoDigitString(hours) + ":" + twoDigitString(minutes) + ":" + twoDigitString(seconds);
}

/**
Expand Down Expand Up @@ -150,4 +150,79 @@ public static long convertDaysInMillis(int days)
{
return days * 24 * 60 * 60 * 1000;
}

/**
* 2019 June 03 - Monday - 12:14 PM
* get current fin year method
*
* this method will get current fin year in yy-yy format
*
* @param context - context of the application or activity
*
* @return it will return current fin year in yy-yy format
**/
public static String getCurrentFinYear(Context context)
{
try
{
String currentFinYear;

int currentYear = Integer.parseInt(DateTimeUtils.getCurrentDateTime("yy"));
int currentMonth = Integer.parseInt(DateTimeUtils.getCurrentDateTime("MM"));

int nextYear = currentYear + 1;

if (currentMonth <= 3)
{
nextYear = currentYear;
currentYear = currentYear - 1;
}

currentFinYear = currentYear + "-" + nextYear;
return currentFinYear;
}
catch (Exception e)
{
Log.e(TAG, "getCurrentFinYear: exception while getting current fin year:\n");
e.printStackTrace();

return "";
}
}

/**
* 2019 July 15 - Monday - 01:29 PM
* convert to date time from milliseconds method
*
* this method will convert milliseconds to date time
*
* @param context - context of the application or activity
*
* @param milliseconds - milli seconds to be converted to date time
*
* @param inDateTimeFormat - format in which you want date time
* Example: yyyy-MM-dd HH:mm:ss
*
* @return Date time in specified in inDateTimeFormat
**/
private static String convertToDateTimeFromMilliseconds(Context context, Long milliseconds, String inDateTimeFormat)
{
try
{
// Create a DateFormatter object for displaying date in specified format.
SimpleDateFormat formatter = new SimpleDateFormat(inDateTimeFormat, Locale.US);

// Create a calendarIcon object that will convert the date and time value in milliseconds to date.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliseconds);
return formatter.format(calendar.getTime());
}
catch (Exception e)
{
Log.e(TAG, "exception while converting to date time from milliseconds:\n");
e.printStackTrace();

return String.valueOf(milliseconds);
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/amit/utilities/Internet.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static boolean isInternetConnected(Context context)
if (connectivityManager != null)
{
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}
else
{
Expand Down
Loading

0 comments on commit 0b3743d

Please sign in to comment.