Skip to content

Commit

Permalink
Refactor utils package to util
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpandey committed Aug 7, 2021
1 parent cbebb40 commit b3e7841
Show file tree
Hide file tree
Showing 38 changed files with 283 additions and 129 deletions.
2 changes: 1 addition & 1 deletion dynamic-utils/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pranavpandey.android.dynamic.utils">
package="com.pranavpandey.android.dynamic.util">

<!-- Query intents on API 30 and above. -->
<queries>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.pranavpandey.android.dynamic.utils;
package com.pranavpandey.android.dynamic.util;

import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.pranavpandey.android.dynamic.utils;
package com.pranavpandey.android.dynamic.util;

import android.annotation.TargetApi;
import android.content.Context;
Expand Down Expand Up @@ -45,12 +45,12 @@
public class DynamicBitmapUtils {

/**
* Retrieve the bitmap from the supplied uri.
* Retrieve the bitmap from the supplied URI.
*
* @param context The context to get the content resolver.
* @param uri The uri to retrieve the bitmap.
* @param uri The URI to retrieve the bitmap.
*
* @return The bitmap from the supplied uri.
* @return The bitmap from the supplied URI.
*
* @see Context#getContentResolver()
*/
Expand Down Expand Up @@ -156,11 +156,14 @@ public class DynamicBitmapUtils {
*
* @return The resized bitmap with new width and height.
*/
public static @NonNull Bitmap resizeBitmap(@NonNull Bitmap bitmap,
public static @Nullable Bitmap resizeBitmap(@Nullable Bitmap bitmap,
int newWidth, int newHeight) {
if (bitmap == null) {
return null;
}

Bitmap resizedBitmap = Bitmap.createBitmap(
newWidth, newHeight, Bitmap.Config.ARGB_8888);

float scaleX = newWidth / (float) bitmap.getWidth();
float scaleY = newHeight / (float) bitmap.getHeight();
float pivotX = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.pranavpandey.android.dynamic.utils;
package com.pranavpandey.android.dynamic.util;

import android.graphics.Color;

Expand All @@ -25,7 +25,7 @@
import androidx.annotation.Size;
import androidx.core.graphics.ColorUtils;

import com.pranavpandey.android.dynamic.utils.cache.IntegerLruCache;
import com.pranavpandey.android.dynamic.util.cache.IntegerLruCache;

import java.util.Random;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.pranavpandey.android.dynamic.utils;
package com.pranavpandey.android.dynamic.util;

import android.Manifest;
import android.annotation.TargetApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.pranavpandey.android.dynamic.utils;
package com.pranavpandey.android.dynamic.util;

import android.annotation.TargetApi;
import android.graphics.Color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.pranavpandey.android.dynamic.utils;
package com.pranavpandey.android.dynamic.util;

import android.annotation.TargetApi;
import android.app.Activity;
Expand Down Expand Up @@ -72,12 +72,12 @@ public class DynamicFileUtils {
public static final String FILE_PROVIDER = ".FileProvider";

/**
* Constant to match the content uri.
* Constant to match the content URI.
*/
public static final String URI_MATCHER_CONTENT = "content:";

/**
* Constant to match the file uri.
* Constant to match the file URI.
*/
public static final String URI_MATCHER_FILE = "file:";

Expand Down Expand Up @@ -346,13 +346,13 @@ public static void unzip(@NonNull File zip, @NonNull File extractTo)
}

/**
* Returns uri from the file.
* Returns URI from the file.
* <p>It will automatically use the @link FileProvider} on API 24 and above.
*
* @param context The context to get the file provider.
* @param file The file to get the uri.
* @param file The file to get the URI.
*
* @return The uri from the file.
* @return The URI from the file.
*
* @see Uri
*/
Expand All @@ -370,12 +370,12 @@ public static void unzip(@NonNull File zip, @NonNull File extractTo)
}

/**
* Returns file name from the uri.
* Returns file name from the URI.
*
* @param context The context to get content resolver.
* @param uri The uri to get the file name.
* @param uri The URI to get the file name.
*
* @return The file name from the uri.
* @return The file name from the URI.
*
* @see Context#getContentResolver()
*/
Expand Down Expand Up @@ -456,11 +456,11 @@ public static boolean writeToFile(@NonNull File source,
}

/**
* Writes a file uri from the source to destination.
* Writes a file URI from the source to destination.
*
* @param context The context to get content resolver.
* @param sourceUri The source file uri.
* @param destinationUri The destination file uri.
* @param sourceUri The source file URI.
* @param destinationUri The destination file URI.
* @param mode Mode for the destination file.
* <p>May be "w", "wa", "rw", or "rwt".
*
Expand Down Expand Up @@ -506,12 +506,12 @@ public static boolean writeToFile(@NonNull Context context,
}

/**
* Writes a file uri from the source to destination in "rwt" mode which truncates all the
* previous content if the destination uri already exists.
* Writes a file URI from the source to destination in "rwt" mode which truncates all the
* previous content if the destination URI already exists.
*
* @param context The context to get content resolver.
* @param sourceUri The source file uri.
* @param destinationUri The destination file uri.
* @param sourceUri The source file URI.
* @param destinationUri The destination file URI.
*
* @return {@code true} if the file has been written successfully.
*
Expand All @@ -523,12 +523,12 @@ public static boolean writeToFile(@NonNull Context context,
}

/**
* Writes a string data to file uri from the source to destination.
* Writes a string data to file URI from the source to destination.
*
* @param context The context to get content resolver.
* @param data The string data to be written.
* @param sourceUri The source file uri.
* @param destinationUri The destination file uri.
* @param sourceUri The source file URI.
* @param destinationUri The destination file URI.
* @param mode Mode for the destination file.
* <p>May be "w", "wa", "rw", or "rwt".
*
Expand Down Expand Up @@ -573,13 +573,13 @@ public static boolean writeStringToFile(@NonNull Context context, @Nullable Stri
}

/**
* Writes a string data to file uri from the source to destination in "rwt" mode which
* truncates all the previous content if the destination uri already exists.
* Writes a string data to file URI from the source to destination in "rwt" mode which
* truncates all the previous content if the destination URI already exists.
*
* @param context The context to get content resolver.
* @param data The string data to be written.
* @param sourceUri The source file uri.
* @param destinationUri The destination file uri.
* @param sourceUri The source file URI.
* @param destinationUri The destination file URI.
*
* @return {@code true} if the file has been written successfully.
*
Expand All @@ -591,11 +591,11 @@ public static boolean writeStringToFile(@NonNull Context context,
}

/**
* Writes a string data to file uri.
* Writes a string data to file URI.
*
* @param context The context to get content resolver.
* @param data The string data to be written.
* @param sourceUri The source file uri.
* @param sourceUri The source file URI.
*
* @return {@code true} if the file has been written successfully.
*
Expand All @@ -607,10 +607,10 @@ public static boolean writeStringToFile(@NonNull Context context,
}

/**
* Reads a string data from the file uri.
* Reads a string data from the file URI.
*
* @param context The context to get content resolver.
* @param fileUri The source file uri.
* @param fileUri The source file URI.
*
* @return The string data after reading the file.
*/
Expand Down Expand Up @@ -645,18 +645,18 @@ public static boolean writeStringToFile(@NonNull Context context,
}

/**
* Save and returns uri from the bitmap.
* Save and returns URI from the bitmap.
* <p>It will automatically use the @link FileProvider} on API 24 and above.
*
* <p>It requires {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission on
* API 18 and below.
*
* @param context The context to get the file provider.
* @param bitmap The bitmap to get the uri.
* @param bitmap The bitmap to get the URI.
* @param name The name for the file.
* @param extension The extension for the file.
*
* @return The uri from the bitmap.
* @return The URI from the bitmap.
*
* @see Uri
*/
Expand Down Expand Up @@ -688,17 +688,17 @@ public static boolean writeStringToFile(@NonNull Context context,
}

/**
* Save and returns uri from the bitmap.
* Save and returns URI from the bitmap.
* <p>It will automatically use the @link FileProvider} on API 24 and above.
*
* <p>It requires {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission on
* API 18 and below.
*
* @param context The context to get the file provider.
* @param bitmap The bitmap to get the uri.
* @param bitmap The bitmap to get the URI.
* @param name The name for the file.
*
* @return The uri from the bitmap.
* @return The URI from the bitmap.
*
* @see Uri
*/
Expand Down Expand Up @@ -742,13 +742,13 @@ public static boolean isValidExtension(@Nullable Context context,
}

/**
* Checks whether the extension is valid for a uri.
* Checks whether the extension is valid for a URI.
*
* @param context The context to retrieve the resources.
* @param uri The uri to get the extension.
* @param uri The URI to get the extension.
* @param extension The extension to be validated.
*
* @return {@code true} if the extension is valid for the uri.
* @return {@code true} if the extension is valid for the URI.
*/
public static boolean isValidExtension(@Nullable Context context,
@Nullable Uri uri, @Nullable String extension) {
Expand Down Expand Up @@ -782,7 +782,7 @@ public static boolean isValidExtension(@Nullable Context context,
/**
* Checks whether the mime type is valid for an intent data.
*
* @param context The context to match the uri mime type.
* @param context The context to match the URI mime type.
* @param intent The intent to get the data.
* @param mimeType The mime type to be validated.
* @param extension The optional extension to be validated if mime type is invalid.
Expand Down Expand Up @@ -815,10 +815,10 @@ && isValidExtension(context,
}

/**
* Checks whether the mime type is valid for a uri.
* Checks whether the mime type is valid for a URI.
*
* @param context The context to get the content resolver.
* @param uri The uri to get the type.
* @param uri The URI to get the type.
* @param mimeType The mime type to be validated.
* @param extension The optional extension to be validated if mime type is invalid.
*
Expand Down Expand Up @@ -847,7 +847,7 @@ public static boolean isValidMimeType(@Nullable Context context,
* Checks whether the mime type is valid for a file.
*
* @param context The context to get the content resolver.
* @param file The file to get the uri.
* @param file The file to get the URI.
* @param mimeType The mime type to be validated.
* @param extension The optional extension to be validated if mime type is invalid.
*
Expand Down Expand Up @@ -917,8 +917,8 @@ public static void shareFiles(@NonNull Activity activity, @Nullable String title
/**
* Returns an intent to request a storage location for the supplied file.
*
* @param context The context to get the file uri.
* @param file The file uri to request the storage location.
* @param context The context to get the file URI.
* @param file The file URI to request the storage location.
* @param mimeType The mime type of the file.
*
* @return The intent to request a storage location for the supplied file.
Expand Down Expand Up @@ -949,7 +949,7 @@ public static void shareFiles(@NonNull Activity activity, @Nullable String title
/**
* Returns an intent to request a storage location for the supplied file.
*
* @param context The context to get the file uri.
* @param context The context to get the file URI.
* @param file The file to request the storage location.
* @param mimeType The mime type of the file.
*
Expand Down
Loading

0 comments on commit b3e7841

Please sign in to comment.