diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..8e15477 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + defaultConfig { + applicationId "com.ssw.utilsmanagerdemo" + minSdkVersion 17 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + implementation project(path: ':commonutilsmanager') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/ssw/utilsmanagerdemo/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/ssw/utilsmanagerdemo/ExampleInstrumentedTest.java new file mode 100644 index 0000000..fa9c1b1 --- /dev/null +++ b/app/src/androidTest/java/com/ssw/utilsmanagerdemo/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.ssw.utilsmanagerdemo; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.ssw.utilsmanagerdemo", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e953da0 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/ssw/utilsmanagerdemo/MainActivity.java b/app/src/main/java/com/ssw/utilsmanagerdemo/MainActivity.java new file mode 100644 index 0000000..1644d95 --- /dev/null +++ b/app/src/main/java/com/ssw/utilsmanagerdemo/MainActivity.java @@ -0,0 +1,230 @@ +package com.ssw.utilsmanagerdemo; + +import android.os.Bundle; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +import com.ssw.commonutilsmanager.app.AppManager; +import com.ssw.commonutilsmanager.calendar.CalendarUtilsManager; +import com.ssw.commonutilsmanager.credit_cards.CardNumberValidations; +import com.ssw.commonutilsmanager.currencyamounts.AmountManager; +import com.ssw.commonutilsmanager.device.DeviceManager; +import com.ssw.commonutilsmanager.email.EmailManager; +import com.ssw.commonutilsmanager.fingerprint.FingerPrintAuthenticationHandler; +import com.ssw.commonutilsmanager.mobile.MobileManager; +import com.ssw.commonutilsmanager.network.NetworkManager; +import com.ssw.commonutilsmanager.nic.NICManager; +import com.ssw.commonutilsmanager.toasts.ToastManager; +import com.ssw.commonutilsmanager.utils.Utilizer; + +public class MainActivity extends AppCompatActivity { + private static final String TAG = "MainActivity"; + + private TextView textView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + initComponents(); + } + + private void initComponents() { + textView = findViewById(R.id.textView); + } + + // + private void checkAppRunning() { + System.out.println(AppManager.getInstance().isAppRunning(this, getPackageName())); + } + + private void getAppVersion() { + System.out.println(AppManager.getInstance().getAppVersion(this)); + } + // + + // + private void verifyFingerPrints() { + if (DeviceManager.getInstance().isFingerPrintAvailable(this) && DeviceManager.getInstance().hasEnrolledFingerprints(this)) { + FingerPrintAuthenticationHandler fingerPrintAuthenticationHandler = new FingerPrintAuthenticationHandler(this, new FingerPrintAuthenticationHandler.FingerPrintAuthenticationHandlerEvents() { + @Override + public void onAuthenticationSuccess() { + ToastManager.getInstance().showTopToast(MainActivity.this, "Authentication Success", ToastManager.TOP_DURATION_LONG); + } + + @Override + public void onAuthenticationFailed() { + ToastManager.getInstance().showTopToast(MainActivity.this, "Authentication Failed", ToastManager.TOP_DURATION_LONG); + } + + @Override + public void onAuthenticationCancelled() { + ToastManager.getInstance().showTopToast(MainActivity.this, "Authentication Cancelled", ToastManager.TOP_DURATION_LONG); + } + }); + + fingerPrintAuthenticationHandler.startAuthentication("Title", "SubTitle", "Description", "BTNTEXT", R.mipmap.ic_launcher); + } else { + ToastManager.getInstance().showTopToast(this, "Fingerprint Not Support", ToastManager.TOAST_LENGTH_LONG); + } + } + // + + // + private void checkInternetOn() { + System.out.println(NetworkManager.getInstance().isInternetOn(this)); + } + + private void checkInternetAvailable() { + NetworkManager.getInstance().isInternetAvailable(new NetworkManager.NetworkCheckListener() { + @Override + public void onInternetAvailable() { + System.out.println("onInternetAvailable"); + } + + @Override + public void onError() { + System.out.println("onError"); + } + }); + } + // + + // + private void checkEmptyString() { + System.out.println(Utilizer.getInstance().isStringEmpty("")); + } + // + + // + private void validateCardNumber() { + System.out.println(CardNumberValidations.getInstance().validateCreditCardNumber("123456789123456789")); + } + + private void getFormattedCardNumber() { + System.out.println(CardNumberValidations.getInstance().getFormattedCardNumber("1234567898765432", 4)); + } + + private void getCardTypeFromNumber() { + if (CardNumberValidations.getInstance().getCardTypeFromCardNumber("123456789123456789") == CardNumberValidations.CARD_TYPE_VISA) { + + } + } + // + + // + private void getCurrentDateInCustomFormat() { + System.out.println(CalendarUtilsManager.getInstance().getCurrentDateCustomFormat("yyyy-MMM-dd HH:mm:ss")); + } + + private void getPreviousDate() { + System.out.println(CalendarUtilsManager.getInstance().getPreviousDate(3, "yyyy-MMM-dd HH:mm:ss")); + } + + private void convertDateStrings() { + System.out.println(CalendarUtilsManager.getInstance().convertDateString(CalendarUtilsManager.getInstance().getCurrentDateCustomFormat("yyyy-MMM-dd HH:mm:ss"), "dd-MM-yyyy HH:mm:ss", "yyyy-MMM-dd HH:mm:ss", "yyyy-MMM-dd HH:mm:ss")); + } + + private void getTimeAgo() { + System.out.println(CalendarUtilsManager.getInstance().getDuration(System.currentTimeMillis() - CalendarUtilsManager.getInstance().getPreviousDate(3).getTime())); + } + // + + // + private void isValidMobileNumber() { + //If career validation is true, number will validate with all the mobile number careers in Sri Lanka + //Mobile number formats - +94773606094, 0094773606094, 0773606094 + MobileManager.getInstance().isValidMobileNumber("+94773606094", true); + } + + private void getCareerFromMobileNumber() { + //Mobile number formats - +94773606094, 0094773606094, 0773606094 + if (MobileManager.getInstance().getCareerFromMobileNumber("+94773606094") == MobileManager.CAREER_DIALOG) { + + } + } + // + + // + private void showBasicSnackBar() { + ToastManager.getInstance().showSnackBar(this.textView, "Test Message"); + } + + private void showSnackBarWithAction() { + ToastManager.getInstance().showSnackBar(this.textView, "Test Message", "OK", new ToastManager.SnackBarButtonAction() { + @Override + public void buttonClick() { + Toast.makeText(getApplicationContext(), "Button Clicked", Toast.LENGTH_SHORT).show(); + } + }); + } + + private void showToast() { + ToastManager.getInstance().showToast(this, "Test Message", ToastManager.TOAST_LENGTH_LONG); + } + + private void showTopToastShort() { + ToastManager.getInstance().showTopToast(this, "Test Message", ToastManager.TOP_DURATION_SHORT); + } + + private void showTopToastLong() { + ToastManager.getInstance().showTopToast(this, "Test Message", ToastManager.TOP_DURATION_LONG); + } + + private void showTopToastIndefinite() { + ToastManager.getInstance().showTopToast(this, "Test Message", ToastManager.TOP_DURATION_INDEFINITE); + } + + private void showTopToastWithStyles() { + ToastManager.getInstance().showTopToast(this, "Test Message", ToastManager.TOP_DURATION_LONG, "#880000", "#880000", "#FFFFFF", 10); + } +// + + // + private void isValidNIC() { + System.out.println(NICManager.getInstance().isValidNICNumber("199410900877")); //New NIC + System.out.println(NICManager.getInstance().isValidNICNumber("942490259V")); // Old NIC + } + + private void getBirthYearFromNIC() { + System.out.println(NICManager.getInstance().getBirthYearFromNIC("199410900877")); //New NIC + System.out.println(NICManager.getInstance().getBirthYearFromNIC("942490259V")); // Old NIC + } + + private void getGenderFromNIC() { + //New NIC + if (NICManager.getInstance().getGenderFromNIC("199410900877") == NICManager.GENDER_FEMALE) { + + } + + // Old NIC + else if (NICManager.getInstance().getGenderFromNIC("942490259V") == NICManager.GENDER_MALE) { + + } + } + + private void getBirthdayFromNIC() { + System.out.println(NICManager.getInstance().getBirthdayFromNIC("199410900877")); //New NIC + System.out.println(NICManager.getInstance().getBirthdayFromNIC("942490259V")); //Old NIC + } + // + + // + private void isValidEmailAddress() { + System.out.println(EmailManager.getInstance().isValidEmailAddress("sumudusahanmax@gmail.com")); + } + // + + // + private void getFormattedAmount() { + System.out.println(AmountManager.getInstance().getFormattedAmount(15548.25)); + } + + private void getCleanAmount() { + System.out.println(AmountManager.getInstance().getDoubleValueOfAmount("15,753.14")); + } + // +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..6be01a7 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..898f3ed Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..dffca36 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..64ba76f Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..dae5e08 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..e5ed465 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..14ed0af Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..b0907ca Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..d8ae031 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..2c18de9 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..beed3cd Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..69b2233 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #008577 + #00574B + #D81B60 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..3968bca --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + UtilsManagerDemo + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..5885930 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/test/java/com/ssw/utilsmanagerdemo/ExampleUnitTest.java b/app/src/test/java/com/ssw/utilsmanagerdemo/ExampleUnitTest.java new file mode 100644 index 0000000..1e72f84 --- /dev/null +++ b/app/src/test/java/com/ssw/utilsmanagerdemo/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.ssw.utilsmanagerdemo; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..a5bb815 --- /dev/null +++ b/build.gradle @@ -0,0 +1,27 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + google() + jcenter() + + } + dependencies { + classpath 'com.android.tools.build:gradle:3.5.3' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/commonutilsmanager/build.gradle b/commonutilsmanager/build.gradle new file mode 100644 index 0000000..a7750d0 --- /dev/null +++ b/commonutilsmanager/build.gradle @@ -0,0 +1,41 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + + + defaultConfig { + minSdkVersion 17 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'androidx.appcompat:appcompat:1.1.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + implementation 'com.androidadvance:topsnackbar:1.1.1' + implementation 'androidx.biometric:biometric:1.0.0' + + //sdp ssdp + implementation 'com.intuit.ssp:ssp-android:1.0.6' + implementation 'com.intuit.sdp:sdp-android:1.0.6' +} diff --git a/commonutilsmanager/consumer-rules.pro b/commonutilsmanager/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/commonutilsmanager/proguard-rules.pro b/commonutilsmanager/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/commonutilsmanager/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/commonutilsmanager/src/androidTest/java/com/ssw/commonutilsmanager/ExampleInstrumentedTest.java b/commonutilsmanager/src/androidTest/java/com/ssw/commonutilsmanager/ExampleInstrumentedTest.java new file mode 100644 index 0000000..c84a403 --- /dev/null +++ b/commonutilsmanager/src/androidTest/java/com/ssw/commonutilsmanager/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.ssw.commonutilsmanager; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.ssw.commonutilsmanager.test", appContext.getPackageName()); + } +} diff --git a/commonutilsmanager/src/main/AndroidManifest.xml b/commonutilsmanager/src/main/AndroidManifest.xml new file mode 100644 index 0000000..34ae6e5 --- /dev/null +++ b/commonutilsmanager/src/main/AndroidManifest.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/app/AppManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/app/AppManager.java new file mode 100644 index 0000000..12f7104 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/app/AppManager.java @@ -0,0 +1,45 @@ +package com.ssw.commonutilsmanager.app; + +import android.app.ActivityManager; +import android.content.Context; + +import java.util.List; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; + +public class AppManager { + private static final String TAG = "AppManager"; + + private static AppManager appManager; + + public static synchronized AppManager getInstance() { + if (appManager == null) { + appManager = new AppManager(); + } + return appManager; + } + + public boolean isAppRunning(Context context, String packageName) { + final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + final List procInfos = activityManager.getRunningAppProcesses(); + if (procInfos != null) { + for (final ActivityManager.RunningAppProcessInfo processInfo : procInfos) { + if (processInfo.processName.equals(packageName)) { + return true; + } + } + } + return false; + } + + public String getAppVersion(Context context) { + try { + return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return "1.0"; + } + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/calendar/CalendarUtilsManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/calendar/CalendarUtilsManager.java new file mode 100644 index 0000000..5186771 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/calendar/CalendarUtilsManager.java @@ -0,0 +1,187 @@ +package com.ssw.commonutilsmanager.calendar; + +import com.ssw.commonutilsmanager.common.ConstantList; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; +import static com.ssw.commonutilsmanager.common.ConstantList.EMPTY_STRING; + +public class CalendarUtilsManager { + private static final String TAG = "CalendarUtilsManager"; + + private static final List times = Arrays.asList( + TimeUnit.DAYS.toMillis(365), + TimeUnit.DAYS.toMillis(30), + TimeUnit.DAYS.toMillis(1), + TimeUnit.HOURS.toMillis(1), + TimeUnit.MINUTES.toMillis(1), + TimeUnit.SECONDS.toMillis(1)); + + private static final List timesString = Arrays.asList("year", "month", "day", "hour", "minute", "second"); + + private static CalendarUtilsManager calendarUtilsManager; + + public static synchronized CalendarUtilsManager getInstance() { + if (calendarUtilsManager == null) { + calendarUtilsManager = new CalendarUtilsManager(); + } + return calendarUtilsManager; + } + + public String getDuration(long duration) { + StringBuilder res = new StringBuilder(); + for (int i = 0; i < times.size(); i++) { + Long current = times.get(i); + long temp = duration / current; + if (temp > 0) { + res.append(temp).append(" ").append(timesString.get(i)).append(temp > 1 ? "s" : "").append(" ago"); + break; + } + } + if (res.toString().equals("") || res.toString().trim().isEmpty()) + return "0 second ago"; + else if (res.toString().equalsIgnoreCase("null")) { + return "0 second ago"; + } else + return res.toString(); + } + + public Date getCurrentDate() { + return Calendar.getInstance().getTime(); + } + + public String getCurrentDateCustomFormat(String outputDateFormat) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(outputDateFormat); + return simpleDateFormat.format(Calendar.getInstance().getTime()); + } catch (Exception ex) { + if (DEV_MODE) { + ex.printStackTrace(); + } + return EMPTY_STRING; + } + } + + public String getDateInCustomFormat(Date date, String outputDateFormat) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(outputDateFormat); + return simpleDateFormat.format(date); + } catch (Exception ex) { + if (DEV_MODE) { + ex.printStackTrace(); + } + return EMPTY_STRING; + } + } + + public String getPreviousDate(int numberOfDays, String outputDateFormat) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(outputDateFormat); + long DAY_IN_MS = 1000 * 60 * 60 * 24; + return simpleDateFormat.format(new Date(System.currentTimeMillis() - (numberOfDays * DAY_IN_MS))); + } + + public Date getPreviousDate(int numberOfDays) { + long DAY_IN_MS = 1000 * 60 * 60 * 24; + return new Date(System.currentTimeMillis() - (numberOfDays * DAY_IN_MS)); + } + + public ArrayList getPreviousMonth(int numberOfMonths, String outputDateFormat) { + ArrayList returningDateList = new ArrayList<>(); + + Calendar aCalendar = Calendar.getInstance(); + aCalendar.add(Calendar.MONTH, -1 * numberOfMonths); + aCalendar.set(Calendar.DATE, 1); + returningDateList.add(convertDateToString(aCalendar.getTime(), outputDateFormat)); + + aCalendar.set(Calendar.DATE, aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH)); + returningDateList.add(convertDateToString(aCalendar.getTime(), outputDateFormat)); + + return returningDateList; + } + + public String convertDateToString(Date inputDate, String dateFormat) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); + return simpleDateFormat.format(inputDate); + } catch (Exception ex) { + ex.printStackTrace(); + return ""; + } + } + + public String getFormattedDateTime(String date, String oldFormat, String newFormat) { + String result = date; + try { + String newDateString; + + SimpleDateFormat sdf = new SimpleDateFormat(oldFormat); + Date d = sdf.parse(date); + sdf.applyPattern(newFormat); + newDateString = sdf.format(d); + result = newDateString; + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + public String getDefaultFormattedDate(String date, String oldFormat) { + String result = date; + try { + String newDateString; + + SimpleDateFormat sdf = new SimpleDateFormat(oldFormat); + Date d = sdf.parse(date); + sdf.applyPattern(ConstantList.DEFAULT_DATE_FORMAT_NEW); + newDateString = sdf.format(d); + result = newDateString; + } catch (Exception e) { + e.printStackTrace(); + return "N/A"; + } + return result; + } + + public String convertDateString(String dateAsString, String newFormat, String oldFormat, String alterOldFormat) { + try { + SimpleDateFormat sdf = new SimpleDateFormat(oldFormat); + SimpleDateFormat sdf2 = new SimpleDateFormat(alterOldFormat); + Date date; + try { + date = sdf.parse(dateAsString); + sdf.applyPattern(newFormat); + return sdf.format(date); + } catch (Exception e) { + date = sdf2.parse(dateAsString); + sdf2.applyPattern(newFormat); + return sdf2.format(date); + } + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + + public String getServerFormattedDate(String date, String oldFormat) { + String result; + try { + String newDateString; + + SimpleDateFormat sdf = new SimpleDateFormat(oldFormat); + Date d = sdf.parse(date); + sdf.applyPattern(ConstantList.SERVER_DATE_FORMAT); + newDateString = sdf.format(d); + result = newDateString; + } catch (Exception e) { + result = ""; + } + return result; + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/common/ConstantList.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/common/ConstantList.java new file mode 100644 index 0000000..ca61164 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/common/ConstantList.java @@ -0,0 +1,21 @@ +package com.ssw.commonutilsmanager.common; + +public class ConstantList { + private static final String TAG = "ConstantList"; + + public static final boolean DEV_MODE = false; + + public static final String EMPTY_STRING = ""; + public static final String SPACE_STRING = " "; + public static final String STRING_ZERO = "0"; + + //Date Formats + public static final String SERVER_DATE_FORMAT = "yyyy-MM-dd"; + public static final String DEFAULT_DATE_FORMAT_NEW = "MMM dd, yyyy"; + + //Currency Formats + public static final String AMOUNT_FORMAT = "###,###,###,###,##0.00"; + + //Internet Checker + public static final int DEFAULT_CONNECTION_TIMEOUT = 60000; +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/credit_cards/CardNumberValidations.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/credit_cards/CardNumberValidations.java new file mode 100644 index 0000000..2fcbcb2 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/credit_cards/CardNumberValidations.java @@ -0,0 +1,102 @@ +package com.ssw.commonutilsmanager.credit_cards; + +import java.util.regex.Pattern; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; +import static com.ssw.commonutilsmanager.common.ConstantList.SPACE_STRING; + +public class CardNumberValidations { + private static final String TAG = "CardNumberValidations"; + + private static final String PATTERN_VISA = "^4[0-9]{12}(?:[0-9]{3}){0,2}$"; + private static final String PATTERN_MASTERCARD = "^(?:5[1-5]|2(?!2([01]|20)|7(2[1-9]|3))[2-7])\\d{14}$"; + private static final String PATTERN_AMERICAN_EXPRESS = "^3[47][0-9]{13}$"; + private static final String PATTERN_DINERS_CLUB = "^3(?:0[0-5]\\d|095|6\\d{0,2}|[89]\\d{2})\\d{12,15}$"; + private static final String PATTERN_DISCOVER = "^6(?:011|[45][0-9]{2})[0-9]{12}$"; + private static final String PATTERN_JCB = "^(?:2131|1800|35\\d{3})\\d{11}$"; + private static final String PATTERN_CHINA_UNION_PAY = "^62[0-9]{14,17}$"; + + public static final int CARD_TYPE_VISA = 1; + public static final int CARD_TYPE_MASTERCARD = 2; + public static final int CARD_TYPE_AMERICAN_EXPRESS = 3; + public static final int CARD_TYPE_DINERS_CLUB = 4; + public static final int CARD_TYPE_DISCOVER = 5; + public static final int CARD_TYPE_JCB = 6; + public static final int CARD_TYPE_CHINA_UNION_PAY = 7; + public static final int CARD_TYPE_UNKNOWN = 0; + + private static CardNumberValidations cardNumberValidations; + + public static synchronized CardNumberValidations getInstance() { + if (cardNumberValidations == null) { + cardNumberValidations = new CardNumberValidations(); + } + return cardNumberValidations; + } + + public String getFormattedCardNumber(String plainCardNumber, int interval) { + char[] chars = plainCardNumber.toCharArray(); + StringBuilder stringBuilder = new StringBuilder(); + for (int count = 0; count < chars.length; count++) { + stringBuilder.append(chars[count]); + if ((count + 1) % interval == 0) { + stringBuilder.append(SPACE_STRING); + } + } + + return stringBuilder.toString(); + } + + public int getCardTypeFromCardNumber(String cardNumber) { + if (validateCreditCardNumber(cardNumber)) { + if (Pattern.matches(PATTERN_VISA, cardNumber)) { + return CARD_TYPE_VISA; + } else if (Pattern.matches(PATTERN_MASTERCARD, cardNumber)) { + return CARD_TYPE_MASTERCARD; + } else if (Pattern.matches(PATTERN_AMERICAN_EXPRESS, cardNumber)) { + return CARD_TYPE_AMERICAN_EXPRESS; + } else if (Pattern.matches(PATTERN_DINERS_CLUB, cardNumber)) { + return CARD_TYPE_DINERS_CLUB; + } else if (Pattern.matches(PATTERN_DISCOVER, cardNumber)) { + return CARD_TYPE_DISCOVER; + } else if (Pattern.matches(PATTERN_JCB, cardNumber)) { + return CARD_TYPE_JCB; + } else if (Pattern.matches(PATTERN_CHINA_UNION_PAY, cardNumber)) { + return CARD_TYPE_CHINA_UNION_PAY; + } else return CARD_TYPE_UNKNOWN; + } else { + return CARD_TYPE_UNKNOWN; + } + } + + public boolean validateCreditCardNumber(String cardNumberString) { + try { + if (cardNumberString.trim().length() == 0) { + return false; + } else { + int[] ints = new int[cardNumberString.trim().length()]; + for (int i = 0; i < cardNumberString.trim().length(); i++) { + ints[i] = Integer.parseInt(cardNumberString.trim().substring(i, i + 1)); + } + for (int i = ints.length - 2; i >= 0; i = i - 2) { + int j = ints[i]; + j = j * 2; + if (j > 9) { + j = j % 10 + 1; + } + ints[i] = j; + } + int sum = 0; + for (int anInt : ints) { + sum += anInt; + } + return sum % 10 == 0; + } + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/currencyamounts/AmountManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/currencyamounts/AmountManager.java new file mode 100644 index 0000000..0363888 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/currencyamounts/AmountManager.java @@ -0,0 +1,39 @@ +package com.ssw.commonutilsmanager.currencyamounts; + +import java.text.DecimalFormat; +import java.text.NumberFormat; + +import static com.ssw.commonutilsmanager.common.ConstantList.AMOUNT_FORMAT; +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; + +public class AmountManager { + private static final String TAG = "AmountManager"; + + private static AmountManager amountManager; + + public static synchronized AmountManager getInstance() { + if (amountManager == null) { + amountManager = new AmountManager(); + } + return amountManager; + } + + public String getFormattedAmount(double amount) { + DecimalFormat formatter = new DecimalFormat(AMOUNT_FORMAT); + return formatter.format(amount); + } + + public double getDoubleValueOfAmount(String formattedAmount) { + String replaceable = String.format("[%s,]", NumberFormat.getCurrencyInstance().getCurrency().getSymbol()); + String cleanString = formattedAmount.replaceAll(replaceable, "").replaceAll(" ", ""); + + try { + return Double.parseDouble(cleanString.trim()); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return 0.00; + } + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/device/DeviceManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/device/DeviceManager.java new file mode 100644 index 0000000..27756b5 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/device/DeviceManager.java @@ -0,0 +1,219 @@ +package com.ssw.commonutilsmanager.device; + +import android.Manifest; +import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.pm.PackageManager; +import android.content.res.Configuration; +import android.graphics.Point; +import android.hardware.fingerprint.FingerprintManager; +import android.location.LocationManager; +import android.os.Build; +import android.provider.Settings; +import android.util.DisplayMetrics; +import android.view.Display; +import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; + +import androidx.core.app.ActivityCompat; +import androidx.core.hardware.fingerprint.FingerprintManagerCompat; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; +import static com.ssw.commonutilsmanager.common.ConstantList.EMPTY_STRING; + +public class DeviceManager { + private static final String TAG = "DeviceManager"; + + private static DeviceManager deviceManager; + + public static synchronized DeviceManager getInstance() { + if (deviceManager == null) { + deviceManager = new DeviceManager(); + } + return deviceManager; + } + + public String getBrand() { + String brand = "B"; + try { + brand = Build.MANUFACTURER; + if (brand == null || brand.isEmpty()) { + brand = "B"; + } + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + } + return brand; + } + + public String getModel() { + String model = "M"; + try { + model = Build.MODEL; + if (model == null || model.isEmpty()) { + model = "M"; + } + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + } + return model; + } + + public void showSoftKeyboard(Context context) { + try { + InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + } + } + + public void hideKeyboard(Activity activity) { + try { + InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + } + } + + public void hideSoftKeyboard(Context context, EditText editText) { + try { + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + } + } + + public Point getScreenDimensions(Context context) { + try { + WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + Display display = wm.getDefaultDisplay(); + Point size = new Point(); + display.getSize(size); + return size; + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return null; + } + } + + public boolean isTablet(Context context) { + boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4); + boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE); + return (xlarge || large); + } + + public double getInches(Activity activity) { + DisplayMetrics metrics = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); + + int widthPixels = metrics.widthPixels; + int heightPixels = metrics.heightPixels; + + double widthDpi = metrics.xdpi; + double heightDpi = metrics.ydpi; + + double widthInches = widthPixels / widthDpi; + double heightInches = heightPixels / heightDpi; + + return Math.sqrt(Math.pow(widthInches, 2) + Math.pow(heightInches, 2)); + } + + public void copyToClipboard(Context context, String label, String text) { + try { + ClipboardManager cManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + ClipData cd = ClipData.newPlainText(label, text); + cManager.setPrimaryClip(cd); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + } + } + + public String getTextFromClipboard(Context context) { + try { + ClipboardManager cManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + if (cManager.getPrimaryClip().getItemCount() > 0) { + return cManager.getPrimaryClip().getItemAt(0).getText().toString(); + } else { + return EMPTY_STRING; + } + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return EMPTY_STRING; + } + } + + public String getAndroidID(Context context) { + return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); + } + + public boolean isFingerPrintAvailable(Context context) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + try { + FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE); + + return fingerprintManager != null && fingerprintManager.isHardwareDetected(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } else { + try { + FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(context); + return fingerprintManagerCompat.isHardwareDetected(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + } + + public boolean hasEnrolledFingerprints(Context context) { + try { + FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE); + + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED) { + return fingerprintManager.hasEnrolledFingerprints(); + } + } catch (Exception ex) { + if (DEV_MODE) { + ex.printStackTrace(); + } + } + return false; + } + + public boolean isGPSEnabled(Context context) { + LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + return manager.isProviderEnabled(LocationManager.GPS_PROVIDER); + } + + public Integer getApiLevel() { + return Build.VERSION.SDK_INT; + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/email/EmailManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/email/EmailManager.java new file mode 100644 index 0000000..83585aa --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/email/EmailManager.java @@ -0,0 +1,32 @@ +package com.ssw.commonutilsmanager.email; + +import android.util.Patterns; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; + +public class EmailManager { + private static final String TAG = "EmailManager"; + + private static EmailManager emailManager; + + public static synchronized EmailManager getInstance() { + if (emailManager == null) { + emailManager = new EmailManager(); + } + + return emailManager; + } + + public boolean isValidEmailAddress(String emailAddress) { + try { + if (emailAddress.trim().isEmpty()) { + return false; + } else return Patterns.EMAIL_ADDRESS.matcher(emailAddress).matches(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/fingerprint/FingerPrintAuthenticationHandler.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/fingerprint/FingerPrintAuthenticationHandler.java new file mode 100644 index 0000000..6d66f12 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/fingerprint/FingerPrintAuthenticationHandler.java @@ -0,0 +1,186 @@ +package com.ssw.commonutilsmanager.fingerprint; + + +import android.app.Dialog; +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Build; +import android.os.Handler; +import android.os.Vibrator; +import android.view.View; +import android.view.Window; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; +import androidx.appcompat.widget.AppCompatImageView; +import androidx.biometric.BiometricPrompt; +import androidx.cardview.widget.CardView; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.FragmentActivity; + +import com.ssw.commonutilsmanager.R; + +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +import static android.content.Context.VIBRATOR_SERVICE; + +public class FingerPrintAuthenticationHandler { + private static final String TAG = "FingerPrintAuthenticationHandler"; + + private FragmentActivity fragmentActivity; + private FingerPrintAuthenticationHandlerEvents fingerPrintAuthenticationHandlerEvents; + + //Old Android Versions + private FingerprintHandler fingerprintHandler; + private Dialog alertDialog; + private Vibrator vibrator; + + //Android 9.0+ + private Executor newExecutor; + private BiometricPrompt myBiometricPrompt; + private BiometricPrompt.PromptInfo promptInfo; + + public FingerPrintAuthenticationHandler(FragmentActivity fragmentActivity, FingerPrintAuthenticationHandlerEvents fingerPrintAuthenticationHandlerEvents) { + this.fragmentActivity = fragmentActivity; + this.fingerPrintAuthenticationHandlerEvents = fingerPrintAuthenticationHandlerEvents; + } + + public void startAuthentication(String title, String subtitle, String description, String negativeButtonText, int logo) { + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + authenticateWithNewAPI(title, subtitle, description, negativeButtonText); + } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + authenticateWithOldAPI(description, negativeButtonText, logo); + } + } + + @RequiresApi(api = Build.VERSION_CODES.M) + private void authenticateWithOldAPI(String description, String negativeButtonText, int logo) { + openDialog(description, negativeButtonText, logo); + } + + @RequiresApi(api = Build.VERSION_CODES.M) + private void openDialog(String description, String negativeButtonText, int logo) { + alertDialog = new Dialog(fragmentActivity); + alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + alertDialog.setContentView(R.layout.fp_dialog_layout); + alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); + alertDialog.setCancelable(false); + + TextView tvDescription = alertDialog.findViewById(R.id.tvDescription); + tvDescription.setText(description); + + TextView tvCancel = alertDialog.findViewById(R.id.tvCancel); + tvCancel.setText(negativeButtonText); + + CardView mcvCancel = alertDialog.findViewById(R.id.mcvCancel); + mcvCancel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + fingerPrintAuthenticationHandlerEvents.onAuthenticationCancelled(); + alertDialog.dismiss(); + } + }); + + vibrator = (Vibrator) fragmentActivity.getSystemService(VIBRATOR_SERVICE); + + final AppCompatImageView ivLogo = alertDialog.findViewById(R.id.ivLogo); + ivLogo.setImageResource(logo); + + final AppCompatImageView ivFingerPrint = alertDialog.findViewById(R.id.ivFingerPrint); + ivFingerPrint.setBackgroundTintList(ColorStateList.valueOf(Color.BLACK)); + + fingerprintHandler = new FingerprintHandler(fragmentActivity, new FingerprintHandler.FingerprintHandlerEvents() { + @Override + public void onAuthSuccess() { + ivFingerPrint.setColorFilter(ContextCompat.getColor(fragmentActivity, R.color.authentication_success), android.graphics.PorterDuff.Mode.MULTIPLY); + vibrator.vibrate(100); + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + fingerPrintAuthenticationHandlerEvents.onAuthenticationSuccess(); + alertDialog.dismiss(); + } + }, 500); + } + + @Override + public void onAuthFailed() { + ivFingerPrint.setColorFilter(ContextCompat.getColor(fragmentActivity, R.color.authentication_failed), android.graphics.PorterDuff.Mode.MULTIPLY); + vibrator.vibrate(100); + fingerPrintAuthenticationHandlerEvents.onAuthenticationFailed(); + } + + @Override + public void onAuthCancelled() { + + } + }); + fingerprintHandler.fingerPrintInit(); + alertDialog.show(); + } + + private void authenticateWithNewAPI(String title, String subtitle, String description, String negativeButtonText) { + newExecutor = Executors.newSingleThreadExecutor(); + myBiometricPrompt = new BiometricPrompt(fragmentActivity, newExecutor, new BiometricPrompt.AuthenticationCallback() { + public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) { + super.onAuthenticationError(errorCode, errString); + if (errorCode != BiometricPrompt.ERROR_NEGATIVE_BUTTON) { + fingerPrintAuthenticationHandlerEvents.onAuthenticationFailed(); + } + } + + @Override + public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) { + super.onAuthenticationSucceeded(result); + fragmentActivity.runOnUiThread(new Runnable() { + public void run() { + fingerPrintAuthenticationHandlerEvents.onAuthenticationSuccess(); + } + }); + } + + @Override + public void onAuthenticationFailed() { + super.onAuthenticationFailed(); + fingerPrintAuthenticationHandlerEvents.onAuthenticationFailed(); + } + }); + myBiometricPrompt.authenticate(getBiometricPrompt(title, subtitle, description, negativeButtonText)); + } + + private BiometricPrompt.PromptInfo getBiometricPrompt(String title, String subtitle, String description, String negativeButtonText) { + try { + if (promptInfo == null) { + promptInfo = new BiometricPrompt.PromptInfo.Builder() + .setTitle(title) + .setSubtitle(subtitle) + .setDescription(description) + .setNegativeButtonText(negativeButtonText) + .build(); + } + } catch (Exception e) { + e.printStackTrace(); + promptInfo = new BiometricPrompt.PromptInfo.Builder() + .setTitle(title) + .setSubtitle(subtitle) + .setDescription(description) + .setNegativeButtonText(negativeButtonText) + .build(); + } + + return promptInfo; + } + + + public interface FingerPrintAuthenticationHandlerEvents { + void onAuthenticationSuccess(); + + void onAuthenticationFailed(); + + void onAuthenticationCancelled(); + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/fingerprint/FingerprintHandler.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/fingerprint/FingerprintHandler.java new file mode 100644 index 0000000..44dd648 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/fingerprint/FingerprintHandler.java @@ -0,0 +1,169 @@ +package com.ssw.commonutilsmanager.fingerprint; + +import android.Manifest; +import android.annotation.TargetApi; +import android.app.KeyguardManager; +import android.content.pm.PackageManager; +import android.hardware.fingerprint.FingerprintManager; +import android.os.Build; +import android.os.CancellationSignal; +import android.security.keystore.KeyGenParameterSpec; +import android.security.keystore.KeyProperties; + +import androidx.annotation.RequiresApi; +import androidx.core.app.ActivityCompat; +import androidx.fragment.app.FragmentActivity; + +import java.security.KeyStore; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; + +import static android.content.Context.FINGERPRINT_SERVICE; +import static android.content.Context.KEYGUARD_SERVICE; +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; + +@RequiresApi(api = Build.VERSION_CODES.M) +public class FingerprintHandler extends FingerprintManager.AuthenticationCallback { + private static final String TAG = "FingerprintHandler"; + + private FragmentActivity fragmentActivity; + + private Cipher cipher; + private KeyStore keyStore; + private static final String KEY_NAME = "frimi"; + + private FingerprintHandlerEvents fingerprintHandlerEvents; + + public interface FingerprintHandlerEvents { + void onAuthSuccess(); + + void onAuthFailed(); + + void onAuthCancelled(); + } + + FingerprintHandler(FragmentActivity fragmentActivity, FingerprintHandlerEvents fingerprintHandlerEvents) { + this.fragmentActivity = fragmentActivity; + this.fingerprintHandlerEvents = fingerprintHandlerEvents; + } + + @RequiresApi(api = Build.VERSION_CODES.M) + void fingerPrintInit() { + KeyguardManager keyguardManager = (KeyguardManager) fragmentActivity.getSystemService(KEYGUARD_SERVICE); + FingerprintManager fingerprintManager = (FingerprintManager) fragmentActivity.getSystemService(FINGERPRINT_SERVICE); + + try { + if (!fingerprintManager.isHardwareDetected()) { + fingerprintHandlerEvents.onAuthFailed(); + } else { + if (ActivityCompat.checkSelfPermission(fragmentActivity, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { + fingerprintHandlerEvents.onAuthFailed(); + } else { + if (!fingerprintManager.hasEnrolledFingerprints()) { + fingerprintHandlerEvents.onAuthFailed(); + } else { + if (!keyguardManager.isKeyguardSecure()) { + fingerprintHandlerEvents.onAuthFailed(); + } else { + generateKey(); + if (cipherInit()) { + FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher); + startAuth(fingerprintManager, cryptoObject); + } + } + } + } + } + } catch (Exception e) { + fingerprintHandlerEvents.onAuthFailed(); + if (DEV_MODE) { + e.printStackTrace(); + } + } + } + + @TargetApi(Build.VERSION_CODES.M) + private void generateKey() { + try { + keyStore = KeyStore.getInstance("AndroidKeyStore"); + } catch (Exception e) { + e.printStackTrace(); + } + KeyGenerator keyGenerator; + try { + keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore"); + } catch (Exception e) { + throw new RuntimeException("Failed to get KeyGenerator instance", e); + } + + + try { + keyStore.load(null); + keyGenerator.init(new + KeyGenParameterSpec.Builder(KEY_NAME, + KeyProperties.PURPOSE_ENCRYPT | + KeyProperties.PURPOSE_DECRYPT) + .setBlockModes(KeyProperties.BLOCK_MODE_CBC) + .setUserAuthenticationRequired(true) + .setEncryptionPaddings( + KeyProperties.ENCRYPTION_PADDING_PKCS7) + .build()); + keyGenerator.generateKey(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @TargetApi(Build.VERSION_CODES.M) + private boolean cipherInit() { + try { + cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7); + } catch (Exception e) { + throw new RuntimeException("Failed to get Cipher", e); + } + + try { + keyStore.load(null); + SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null); + cipher.init(Cipher.ENCRYPT_MODE, key); + return true; + } catch (Exception e) { + return false; + } + } + + + @RequiresApi(api = Build.VERSION_CODES.M) + private void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) { + CancellationSignal cancellationSignal = new CancellationSignal(); + if (ActivityCompat.checkSelfPermission(fragmentActivity, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { + return; + } + manager.authenticate(cryptoObject, cancellationSignal, 0, this, null); + } + + @Override + public void onAuthenticationError(int errMsgId, CharSequence errString) { + fingerprintHandlerEvents.onAuthCancelled(); + } + + + @Override + public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { + fingerprintHandlerEvents.onAuthFailed(); + } + + @Override + public void onAuthenticationFailed() { + fingerprintHandlerEvents.onAuthFailed(); + } + + + @Override + public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { + fingerprintHandlerEvents.onAuthSuccess(); + } + +} \ No newline at end of file diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/mobile/MobileManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/mobile/MobileManager.java new file mode 100644 index 0000000..25407ab --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/mobile/MobileManager.java @@ -0,0 +1,113 @@ +package com.ssw.commonutilsmanager.mobile; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; + +public class MobileManager { + private static final String TAG = "MobileManager"; + + private static final String PREFIX_DIALOG1 = "077"; + private static final String PREFIX_DIALOG2 = "076"; + private static final String PREFIX_MOBITEL1 = "071"; + private static final String PREFIX_MOBITEL2 = "070"; + private static final String PREFIX_ETISALAT = "072"; + private static final String PREFIX_HUTCH = "078"; + private static final String PREFIX_AIRTEL = "075"; + + public static final int CAREER_DIALOG = 1; + public static final int CAREER_MOBITEL = 2; + public static final int CAREER_HUTCH = 3; + public static final int CAREER_AIRTEL = 4; + public static final int CAREER_INVALID = 0; + + private static MobileManager mobileManager; + + public static synchronized MobileManager getInstance() { + if (mobileManager == null) { + mobileManager = new MobileManager(); + } + return mobileManager; + } + + public int getCareerFromMobileNumber(String mobileNumber) { + if (isValidMobileNumber(mobileNumber.trim(), true)) { + String formattedNumber; + if (mobileNumber.startsWith("+94")) { + formattedNumber = mobileNumber.replace("+94", "0"); + } else if (mobileNumber.startsWith("0094")) { + formattedNumber = mobileNumber.replace("0094", "0"); + } else { + formattedNumber = mobileNumber; + } + if (formattedNumber.startsWith(PREFIX_DIALOG1) || formattedNumber.startsWith(PREFIX_DIALOG2)) { + return CAREER_DIALOG; + } else if (formattedNumber.startsWith(PREFIX_MOBITEL1) || formattedNumber.startsWith(PREFIX_MOBITEL2)) { + return CAREER_MOBITEL; + } else if (formattedNumber.startsWith(PREFIX_HUTCH) || formattedNumber.startsWith(PREFIX_ETISALAT)) { + return CAREER_HUTCH; + } else if (formattedNumber.startsWith(PREFIX_AIRTEL)) { + return CAREER_AIRTEL; + } else { + return CAREER_INVALID; + } + } else return CAREER_INVALID; + } + + public boolean isValidMobileNumber(String mobileNumber, boolean enableCareerValidation) { + try { + if (mobileNumber.trim().isEmpty()) { + return false; + } else { + if (mobileNumber.startsWith("+94")) { + String s = mobileNumber.replace("+94", "0"); + if (s.length() != 10) { + return false; + } else if (enableCareerValidation) { + return (s.trim().startsWith(PREFIX_DIALOG1) + || s.trim().startsWith(PREFIX_DIALOG2) + || s.trim().startsWith(PREFIX_MOBITEL1) + || s.trim().startsWith(PREFIX_MOBITEL2) + || s.trim().startsWith(PREFIX_ETISALAT) + || s.trim().startsWith(PREFIX_HUTCH) + || s.trim().startsWith(PREFIX_AIRTEL)); + } else { + return true; + } + } else if (mobileNumber.startsWith("0094")) { + String s = mobileNumber.replace("0094", "0"); + if (s.length() != 10) { + return false; + } else if (enableCareerValidation) { + return (s.trim().startsWith(PREFIX_DIALOG1) + || s.trim().startsWith(PREFIX_DIALOG2) + || s.trim().startsWith(PREFIX_MOBITEL1) + || s.trim().startsWith(PREFIX_MOBITEL2) + || s.trim().startsWith(PREFIX_ETISALAT) + || s.trim().startsWith(PREFIX_HUTCH) + || s.trim().startsWith(PREFIX_AIRTEL)); + } else { + return true; + } + } else { + if (mobileNumber.length() != 10) { + return false; + } else if (enableCareerValidation) { + return (mobileNumber.trim().startsWith(PREFIX_DIALOG1) + || mobileNumber.trim().startsWith(PREFIX_DIALOG2) + || mobileNumber.trim().startsWith(PREFIX_MOBITEL1) + || mobileNumber.trim().startsWith(PREFIX_MOBITEL2) + || mobileNumber.trim().startsWith(PREFIX_ETISALAT) + || mobileNumber.trim().startsWith(PREFIX_HUTCH) + || mobileNumber.trim().startsWith(PREFIX_AIRTEL)); + } else { + return true; + } + } + } + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/network/NetworkManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/network/NetworkManager.java new file mode 100644 index 0000000..7076ba3 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/network/NetworkManager.java @@ -0,0 +1,81 @@ +package com.ssw.commonutilsmanager.network; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.os.AsyncTask; + +import com.ssw.commonutilsmanager.common.ConstantList; + +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.net.ssl.HttpsURLConnection; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; + +public class NetworkManager { + private static final String TAG = "NetworkManager"; + + private static NetworkManager networkManager; + + public static synchronized NetworkManager getInstance() { + if (networkManager == null) { + networkManager = new NetworkManager(); + } + return networkManager; + } + + public boolean isInternetOn(Context context) { + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + assert cm != null; + NetworkInfo netInfo = cm.getActiveNetworkInfo(); + return netInfo != null && netInfo.isConnectedOrConnecting(); + } + + public void isInternetAvailable(NetworkCheckListener networkCheckListener) { + new NetworkChecker(networkCheckListener).execute(); + } + + + private class NetworkChecker extends AsyncTask { + private NetworkCheckListener networkCheckListener; + + public NetworkChecker(NetworkCheckListener networkCheckListener) { + this.networkCheckListener = networkCheckListener; + } + + @Override + protected Boolean doInBackground(String... strings) { + try { + URL url = new URL("https://www.google.com/"); + HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection(); + httpsURLConnection.setRequestProperty("User-Agent", "test"); + httpsURLConnection.setRequestProperty("Connection", "close"); + httpsURLConnection.setConnectTimeout(ConstantList.DEFAULT_CONNECTION_TIMEOUT); + httpsURLConnection.connect(); + + return (httpsURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK); + } catch (Exception e) { + if(DEV_MODE){ + e.printStackTrace(); + } + return false; + } + } + + @Override + protected void onPostExecute(Boolean result) { + if (result) { + networkCheckListener.onInternetAvailable(); + } else { + networkCheckListener.onError(); + } + } + } + + public interface NetworkCheckListener { + void onInternetAvailable(); + void onError(); + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/nic/NICManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/nic/NICManager.java new file mode 100644 index 0000000..bccea36 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/nic/NICManager.java @@ -0,0 +1,105 @@ +package com.ssw.commonutilsmanager.nic; + +import com.ssw.commonutilsmanager.utils.Utilizer; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; + +public class NICManager { + private static final String TAG = "NICManager"; + + public static final int GENDER_MALE = 1; + public static final int GENDER_FEMALE = 0; + + private static final int NEW_NIC_LENGTH = 12; + private static final int GENDER_CUTOFF_VALIDATOR = 500; + private static final int[] MONTH_LIST = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + private static NICManager nicManager; + + public static synchronized NICManager getInstance() { + if (nicManager == null) { + nicManager = new NICManager(); + } + + return nicManager; + } + + public boolean isValidNICNumber(String nicNumber) { + if (nicNumber.trim().length() == NEW_NIC_LENGTH) { + return true; + } else { + if (nicNumber.trim().length() == 10) { + return nicNumber.trim().toUpperCase().endsWith("V") || nicNumber.trim().toUpperCase().endsWith("X"); + } else return false; + } + } + + public int getBirthYearFromNIC(String nicNumber) { + if (nicNumber.trim().length() == NEW_NIC_LENGTH) { + return (Integer.parseInt(nicNumber.trim().substring(0, 4))); + } + return (1900 + Integer.parseInt(nicNumber.trim().substring(0, 2))); + } + + private int getNumberOfDaysFromNIC(String nicNumber) { + int d = 0; + try { + if (nicNumber.trim().length() == NEW_NIC_LENGTH) { + d = Integer.parseInt(nicNumber.trim().substring(4, 7)); + } else { + d = Integer.parseInt(nicNumber.trim().substring(2, 5)); + } + + if (d > GENDER_CUTOFF_VALIDATOR) { + return (d - GENDER_CUTOFF_VALIDATOR); + } else { + return d; + } + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return d; + } + } + + public String getBirthdayFromNIC(String nicNumber) { + String dob; + int mo = 0, da = 0; + int days = getNumberOfDaysFromNIC(nicNumber); + + for (int i = 0; i < MONTH_LIST.length; i++) { + if (days <= MONTH_LIST[i]) { + mo = i + 1; + da = days; + break; + } else { + days = days - MONTH_LIST[i]; + } + } + + dob = Utilizer.getInstance().zeroPad(String.valueOf(da), 2) + "/" + + Utilizer.getInstance().zeroPad(String.valueOf(mo), 2) + "/" + + getBirthYearFromNIC(nicNumber); + return dob; + } + + public int getGenderFromNIC(String nicNumber) { + try { + int date = Integer.parseInt(nicNumber.trim().substring(2, 5)); + if (nicNumber.trim().length() == NEW_NIC_LENGTH) { + date = Integer.parseInt(nicNumber.trim().substring(4, 7)); + } + if (date > 500) { + return GENDER_FEMALE; + } else { + return GENDER_MALE; + } + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return 0; + } + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/preference/SharedPreferenceManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/preference/SharedPreferenceManager.java new file mode 100644 index 0000000..fbd5638 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/preference/SharedPreferenceManager.java @@ -0,0 +1,226 @@ +package com.ssw.commonutilsmanager.preference; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; + +public class SharedPreferenceManager { + private static final String TAG = "SharedPreferenceManager"; + + private static SharedPreferenceManager sharedPreferenceManager; + + public static synchronized SharedPreferenceManager getInstance() { + if (sharedPreferenceManager == null) { + sharedPreferenceManager = new SharedPreferenceManager(); + } + return sharedPreferenceManager; + } + + public void removePrefefence(Context context, String preferenceName, String key) { + try { + SharedPreferences sharedPrefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.remove(key); + editor.apply(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + } + } + + public void removePrefefence(Context context, String key) { + try { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.remove(key); + editor.apply(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + } + } + + public boolean hasPreference(Context context, String preferenceName, String key) { + try { + SharedPreferences sharedPrefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); + return sharedPrefs.contains(key); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public boolean hasPreference(Context context, String key) { + try { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + return sharedPrefs.contains(key); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public boolean putStringPreference(Context context, String preferenceName, String key, String value) { + try { + SharedPreferences sharedPrefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putString(key, value); + return editor.commit(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public boolean putStringPreference(Context context, String key, String value) { + try { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putString(key, value); + return editor.commit(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public boolean putIntPreference(Context context, String preferenceName, String key, int value) { + try { + SharedPreferences sharedPrefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putInt(key, value); + return editor.commit(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public boolean putIntPreference(Context context, String key, int value) { + try { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putInt(key, value); + return editor.commit(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public boolean removeAllPreference(Context context, String preferenceName) { + try { + SharedPreferences sharedPrefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.clear(); + return editor.commit(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public boolean removeAllPreference(Context context) { + try { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.clear(); + return editor.commit(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public boolean putBooleanPreference(Context context, String preferenceName, String key, boolean value) { + try { + SharedPreferences sharedPrefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putBoolean(key, value); + return editor.commit(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public boolean putBooleanPreference(Context context, String key, boolean value) { + try { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putBoolean(key, value); + return editor.commit(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } + + public String getStringPreference(Context context, String preferenceName, String key, String defaultValue) { + SharedPreferences sharedPrefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); + return sharedPrefs.getString(key, defaultValue); + } + + public String getStringPreference(Context context, String key, String defaultValue) { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + return sharedPrefs.getString(key, defaultValue); + } + + public int getIntPreference(Context context, String preferenceName, String key, int defaultValue) { + SharedPreferences sharedPrefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); + return sharedPrefs.getInt(key, defaultValue); + } + + public int getIntPreference(Context context, String key, int defaultValue) { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + return sharedPrefs.getInt(key, defaultValue); + } + + public boolean getBooleanPref(Context context, String preferenceName, String key, boolean defaultValue) { + try { + SharedPreferences sharedPrefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE); + return sharedPrefs.getBoolean(key, defaultValue); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return defaultValue; + } + } + + public boolean getBooleanPref(Context context, String key, boolean defaultValue) { + try { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + return sharedPrefs.getBoolean(key, defaultValue); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return defaultValue; + } + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/rv_layoutmanager/RecyclerViewLayoutManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/rv_layoutmanager/RecyclerViewLayoutManager.java new file mode 100644 index 0000000..098ab7b --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/rv_layoutmanager/RecyclerViewLayoutManager.java @@ -0,0 +1,48 @@ +package com.ssw.commonutilsmanager.rv_layoutmanager; + +import android.content.Context; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; + +public class RecyclerViewLayoutManager { + private static final String TAG = "RecyclerViewLayoutManager"; + + private static RecyclerViewLayoutManager recyclerViewLayoutManager; + + public static final int ORIENTATION_VERTICAL = 0; + public static final int ORIENTATION_HORIZONTAL = 1; + + private LinearLayoutManager linearLayoutManager; + + public static synchronized RecyclerViewLayoutManager getInstance() { + if (recyclerViewLayoutManager == null) { + recyclerViewLayoutManager = new RecyclerViewLayoutManager(); + } + return recyclerViewLayoutManager; + } + + public boolean setLayoutManager(Context context, RecyclerView recyclerView, int orientation) { + try { + switch (orientation) { + case ORIENTATION_VERTICAL: + default: + linearLayoutManager = new LinearLayoutManager(context, RecyclerView.VERTICAL, false); + break; + + case ORIENTATION_HORIZONTAL: + linearLayoutManager = new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false); + break; + } + recyclerView.setLayoutManager(linearLayoutManager); + return true; + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return false; + } + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/serializer/ObjectSerializer.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/serializer/ObjectSerializer.java new file mode 100644 index 0000000..f6dbf7a --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/serializer/ObjectSerializer.java @@ -0,0 +1,56 @@ +package com.ssw.commonutilsmanager.serializer; + +import android.util.Base64; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; +import static com.ssw.commonutilsmanager.common.ConstantList.EMPTY_STRING; + +public class ObjectSerializer { + private static final String TAG = "ObjectSerializer"; + + private static ObjectSerializer objectSerializer; + + public static synchronized ObjectSerializer getInstance() { + if (objectSerializer == null) { + objectSerializer = new ObjectSerializer(); + } + return objectSerializer; + } + + public String serializeObject(Serializable object) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(object); + oos.close(); + return Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return EMPTY_STRING; + } + } + + public Object deserializeObject(String serializedData) { + try { + ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decode(serializedData, Base64.DEFAULT)); + ObjectInputStream ois = new ObjectInputStream(bais); + Object result; + result = ois.readObject(); + ois.close(); + return result; + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return null; + } + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/toasts/ToastManager.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/toasts/ToastManager.java new file mode 100644 index 0000000..9bf3af0 --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/toasts/ToastManager.java @@ -0,0 +1,78 @@ +package com.ssw.commonutilsmanager.toasts; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Color; +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; + +import com.androidadvance.topsnackbar.TSnackbar; +import com.google.android.material.snackbar.Snackbar; + +public class ToastManager { + private static final String TAG = "ToastManager"; + + public static final int TOAST_LENGTH_SHORT = 0; + public static final int TOAST_LENGTH_LONG = 1; + + public static final int TOP_DURATION_LONG = 0; + public static final int TOP_DURATION_INDEFINITE = -2; + public static final int TOP_DURATION_SHORT = -1; + + private static ToastManager toastManager; + + public static synchronized ToastManager getInstance() { + if (toastManager == null) { + toastManager = new ToastManager(); + } + return toastManager; + } + + public void showToast(Context context, String message, int duration) { + Toast.makeText(context, message, duration).show(); + } + + public void showTopToast(Activity activity, String message, int duration, String actionBarTextColor, String backgroundColor, String textColor, int padding) { + TSnackbar snackBar = TSnackbar.make(activity.findViewById(android.R.id.content), message, duration); + snackBar.setActionTextColor(Color.parseColor(actionBarTextColor)); + + View snackBarView = snackBar.getView(); + snackBarView.setBackgroundColor(Color.parseColor(backgroundColor)); + snackBarView.setPadding(0, padding, 0, 0); + + TextView textView = snackBarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text); + textView.setTextColor(Color.parseColor(textColor)); + textView.setPadding(padding, padding, padding, padding); + snackBar.show(); + } + + public void showTopToast(Activity activity, String message, int duration) { + TSnackbar snackBar = TSnackbar.make(activity.findViewById(android.R.id.content), message, duration); + snackBar.show(); + } + + public void showSnackBar(View view, String message, String buttonText, final SnackBarButtonAction snackBarButtonAction) { + Snackbar snackbar = Snackbar + .make(view, message, Snackbar.LENGTH_LONG) + .setAction(buttonText, new View.OnClickListener() { + @Override + public void onClick(View view) { + snackBarButtonAction.buttonClick(); + } + }); + + snackbar.show(); + } + + public void showSnackBar(View view, String message) { + Snackbar snackbar = Snackbar + .make(view, message, Snackbar.LENGTH_LONG); + + snackbar.show(); + } + + public interface SnackBarButtonAction { + void buttonClick(); + } +} diff --git a/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/utils/Utilizer.java b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/utils/Utilizer.java new file mode 100644 index 0000000..32ecf7a --- /dev/null +++ b/commonutilsmanager/src/main/java/com/ssw/commonutilsmanager/utils/Utilizer.java @@ -0,0 +1,46 @@ +package com.ssw.commonutilsmanager.utils; + +import static com.ssw.commonutilsmanager.common.ConstantList.DEV_MODE; +import static com.ssw.commonutilsmanager.common.ConstantList.EMPTY_STRING; +import static com.ssw.commonutilsmanager.common.ConstantList.STRING_ZERO; + +public class Utilizer { + private static final String TAG = "Utilizer"; + + private static Utilizer utilizer; + + public static synchronized Utilizer getInstance() { + if (utilizer == null) { + utilizer = new Utilizer(); + } + return utilizer; + } + + public String zeroPad(String message, int length) { + try { + StringBuilder stringBuilder = new StringBuilder(); + + for (int i = 0; i < (length - message.length()); i++) { + stringBuilder.append(STRING_ZERO); + } + + return (stringBuilder + message); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return EMPTY_STRING; + } + } + + public boolean isStringEmpty(String input) { + try { + return input.trim().isEmpty(); + } catch (Exception e) { + if (DEV_MODE) { + e.printStackTrace(); + } + return true; + } + } +} diff --git a/commonutilsmanager/src/main/res/layout/fp_dialog_layout.xml b/commonutilsmanager/src/main/res/layout/fp_dialog_layout.xml new file mode 100644 index 0000000..aac91d6 --- /dev/null +++ b/commonutilsmanager/src/main/res/layout/fp_dialog_layout.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/commonutilsmanager/src/main/res/mipmap-hdpi/ic_fingerprint.png b/commonutilsmanager/src/main/res/mipmap-hdpi/ic_fingerprint.png new file mode 100644 index 0000000..28e18fb Binary files /dev/null and b/commonutilsmanager/src/main/res/mipmap-hdpi/ic_fingerprint.png differ diff --git a/commonutilsmanager/src/main/res/mipmap-mdpi/ic_fingerprint.png b/commonutilsmanager/src/main/res/mipmap-mdpi/ic_fingerprint.png new file mode 100644 index 0000000..053c388 Binary files /dev/null and b/commonutilsmanager/src/main/res/mipmap-mdpi/ic_fingerprint.png differ diff --git a/commonutilsmanager/src/main/res/mipmap-xhdpi/ic_fingerprint.png b/commonutilsmanager/src/main/res/mipmap-xhdpi/ic_fingerprint.png new file mode 100644 index 0000000..675e9ba Binary files /dev/null and b/commonutilsmanager/src/main/res/mipmap-xhdpi/ic_fingerprint.png differ diff --git a/commonutilsmanager/src/main/res/mipmap-xxhdpi/ic_fingerprint.png b/commonutilsmanager/src/main/res/mipmap-xxhdpi/ic_fingerprint.png new file mode 100644 index 0000000..39c2870 Binary files /dev/null and b/commonutilsmanager/src/main/res/mipmap-xxhdpi/ic_fingerprint.png differ diff --git a/commonutilsmanager/src/main/res/mipmap-xxxhdpi/ic_fingerprint.png b/commonutilsmanager/src/main/res/mipmap-xxxhdpi/ic_fingerprint.png new file mode 100644 index 0000000..1a3fc81 Binary files /dev/null and b/commonutilsmanager/src/main/res/mipmap-xxxhdpi/ic_fingerprint.png differ diff --git a/commonutilsmanager/src/main/res/values/colors.xml b/commonutilsmanager/src/main/res/values/colors.xml new file mode 100644 index 0000000..420e200 --- /dev/null +++ b/commonutilsmanager/src/main/res/values/colors.xml @@ -0,0 +1,8 @@ + + + #aa0000 + #00aa00 + + #FFFFFF + #000000 + diff --git a/commonutilsmanager/src/main/res/values/strings.xml b/commonutilsmanager/src/main/res/values/strings.xml new file mode 100644 index 0000000..6c3885b --- /dev/null +++ b/commonutilsmanager/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + CommonUtilsManager + diff --git a/commonutilsmanager/src/test/java/com/ssw/commonutilsmanager/ExampleUnitTest.java b/commonutilsmanager/src/test/java/com/ssw/commonutilsmanager/ExampleUnitTest.java new file mode 100644 index 0000000..27cbd53 --- /dev/null +++ b/commonutilsmanager/src/test/java/com/ssw/commonutilsmanager/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.ssw.commonutilsmanager; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..199d16e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,20 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f6b961f Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9f9e361 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Dec 09 12:41:51 IST 2019 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..7c1b313 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +include ':app', ':commonutilsmanager' +rootProject.name='UtilsManagerDemo'