Skip to content

Commit

Permalink
Added multiple utils classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hariharan Eswaran authored and Hariharan committed Nov 17, 2021
1 parent 1d58956 commit 201ca1d
Show file tree
Hide file tree
Showing 56 changed files with 2,936 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.iml
.gradle
.idea
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# app-utils
Provides common utility methods
# App Utils

# Description

Library provides commonly used sources in Android development.


# Getting Started

To add this library to your project, please follow below steps

Add this in your root `build.gradle` file (project level gradle file):

```gradle
allprojects {
repositories {
maven { url "https://www.jitpack.io" }
}
}
buildscript {
repositories {
maven { url "https://www.jitpack.io" }
}
}
```

Then, Add this in your root `build.gradle` file (app level gradle file):

add implementation 'implementation 'com.github.braver-tool:app-utils:1.0.0' to your build.gradle dependencies block.

for example:

```
dependencies {
implementation 'com.github.braver-tool:app-utils:1.0.0'
}
```

You can find demo project code [here](https://github.com/braver-tool/app-utils)
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
54 changes: 54 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
*
* * Created by https://github.com/braver-tool on 16/11/21, 10:30 AM
* * Copyright (c) 2021 . All rights reserved.
* * Last modified 17/11/21, 03:10 PM
*
*/

plugins {
id 'com.android.application'
id 'kotlin-android'
}

android {
compileSdkVersion 30

defaultConfig {
applicationId "com.braver.app.utils"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation project(':utils')
//implementation 'com.github.braver-tool:app-utils:1.0.0'

}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
*
* * Created by https://github.com/braver-tool on 16/11/21, 10:30 AM
* * Copyright (c) 2021 . All rights reserved.
* * Last modified 17/11/21, 03:10 PM
*
*/

package com.braver.app.utils

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.braver.app.utils", appContext.packageName)
}
}
30 changes: 30 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ /*
~ * Created by https://github.com/braver-tool on 16/11/21, 10:30 AM
~ * Copyright (c) 2021 . All rights reserved.
~ * Last modified 17/11/21, 03:10 PM
~ */
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.braver.app.utils">

<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="@mipmap/app_logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/app_logo"
android:supportsRtl="true"
android:theme="@style/Theme.Apputils">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
155 changes: 155 additions & 0 deletions app/src/main/java/com/braver/app/utils/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
*
* * Created by https://github.com/braver-tool on 16/11/21, 10:30 AM
* * Copyright (c) 2021 . All rights reserved.
* * Last modified 17/11/21, 03:10 PM
*
*/

package com.braver.app.utils

import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import com.braver.utils.*
import java.util.*

class MainActivity : AppCompatActivity(), DialogUtils.OnDialogWidgetClick {
private lateinit var prefManager: PreferencesManager


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
prefManager = PreferencesManager.getInstance(this@MainActivity)
usageOfUtils()

}

override fun onPositiveClick() {
Log.d("##", "onPositiveClick------->")
}

override fun onNegativeClick() {
Log.d("##", "onNegativeClick------->")
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
// Inflate the main; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_permission -> {
checkSamplePermission()
}
R.id.action_alert_dialog_1 -> {
DialogUtils.showAlertMsgDialogWithSingleWidget(
"Lorem ipsum dolor sit amet, consectetur adipisicing elit. At autem culpa dignissimos eaque eos facilis impedit inventore laudantium modi, molestias neque numquam obcaecati officiis porro quisquam vel veritatis, vitae! Aut culpa cumque dolorum magni perspiciatis, recusandae ut voluptatibus. Consequuntur doloribus ducimus expedita minus ratione tempore voluptate? A harum nulla ratione?",
this@MainActivity,
this
)
}
R.id.action_alert_dialog_2 -> {
DialogUtils.showAlertMsgDialogWithTwoWidget(
"Lorem ipsum dolor sit amet, consectetur adipisicing elit. At autem culpa dignissimos eaque eos facilis impedit inventore laudantium modi, molestias neque numquam obcaecati officiis porro quisquam vel veritatis, vitae! Aut culpa cumque dolorum magni perspiciatis, recusandae ut voluptatibus. Consequuntur doloribus ducimus expedita minus ratione tempore voluptate? A harum nulla ratione?",
this@MainActivity,
this
)
}
}
return super.onOptionsItemSelected(item)
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
if (requestCode == 3646) {
var isCameraPermission = true
for (grantResult in grantResults) {
isCameraPermission =
isCameraPermission and (grantResult == PackageManager.PERMISSION_GRANTED)
}
Log.d("##", "isCameraPermission------->$isCameraPermission")
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}

private fun checkSamplePermission() {
val permissionList: MutableList<String> = ArrayList()
permissionList.add(Manifest.permission.CAMERA)
val isCameraPermission =
PermissionUtils.isSpecialPermissionGranted(this@MainActivity, permissionList)
if (isCameraPermission) {
Log.d("##", "isCameraPermission------->$isCameraPermission")
} else {
PermissionUtils.showSpecialPermissionRequestDialog(
this@MainActivity,
permissionList,
3646
)
}
}

private fun usageOfUtils() {
//SharedPreferences
prefManager.setStringValue("DATA", "SAMPLE")
//Check Network Availability
val isNetwork = AppUtils.isNetworkAvailable(this@MainActivity)
Log.d("##", "isNetwork------->$isNetwork")
//Check App State
val isAppFore = AppUtils.isAppOnForeground(this@MainActivity)
Log.d("##", "isAppFore------->$isAppFore")
//Check Valid Email Address
val isValidEmail = AppUtils.isValidEmailAddress("[email protected]")
Log.d("##", "isValidEmail------->$isValidEmail")
//Check Valid Password
val isValidPass = AppUtils.isValidPassword("tEst321@")
Log.d("##", "isValidPass------->$isValidPass")
//Check Valid URL
val isValidUrl = AppUtils.isValidUrl("https://www.androiddeveloper.co.in/")
Log.d("##", "isValidUrl------->$isValidUrl")
//Check Valid Phone
val isValidPhone = AppUtils.isValidPhoneNumber("9876543210")
Log.d("##", "isValidPhone------->$isValidPhone")
//Get Device's Screen Size
val deviceSizeInfo = AppUtils.getMeasurementDetail(this@MainActivity)
Log.d("##", "deviceSizeInfo~Width------->${deviceSizeInfo.x}")
Log.d("##", "deviceSizeInfo~Height------->${deviceSizeInfo.y}")
//Check is Tab
val isTab = AppUtils.isTablet(this@MainActivity)
Log.d("##", "isTab------->$isTab")
//Get Random UUID
val randomID = AppUtils.getRandomUUID()
Log.d("##", "randomID------->$randomID")
//Get App Version
val appVersion = AppUtils.getAppVersion(this@MainActivity)
Log.d("##", "appVersion------->$appVersion")
//Get DeviceID
val deviceID = AppUtils.getDeviceID(this@MainActivity)
Log.d("##", "deviceID------->$deviceID")
//Check device have finger prints
val isHaveFingerPrints = AppUtils.isDeviceHaveFingerPrints(this@MainActivity)
Log.d("##", "isHaveFingerPrints------->$isHaveFingerPrints")
//Check device have keyguard
val isHaveKeyguard = AppUtils.isDeviceHaveKeyguard(this@MainActivity)
Log.d("##", "isHaveKeyguard------->$isHaveKeyguard")
//Get IP Address
val ipAddress = AppUtils.getIPAddress(this@MainActivity)
Log.d("##", "ipAddress------->$ipAddress")
//Call AES Encryption
val encText = CryptoUtils.callEncryptMethod("Pass123", "Braver-Tool")
Log.d("##", "encText------->$encText")
//Call AES Decryption
val decryptText = CryptoUtils.callDecryptMethod("Pass123", encText)
Log.d("##", "decryptText------->$decryptText")
}
}
Loading

0 comments on commit 201ca1d

Please sign in to comment.