Skip to content

Commit

Permalink
add: some important function
Browse files Browse the repository at this point in the history
  • Loading branch information
amirisback committed Mar 6, 2022
1 parent 5056e2d commit af247e8
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 24 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true">
android:exported="true"
android:theme="@style/AppTheme.HideStatusBarUI"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/com/frogobox/appsdk/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.frogobox.appsdk

import android.os.Bundle
import com.frogobox.appsdk.databinding.ActivityMainBinding
import com.frogobox.sdk.view.FrogoAboutUsActivity

class MainActivity : BaseActivity<ActivityMainBinding>() {

Expand All @@ -14,11 +13,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}

override fun setupOnCreate(savedInstanceState: Bundle?) {
setupHideSystemUI()
binding.apply {
tv.text = "Frogo Android SDK"
tv.text = if (isNetworkConnected()) {
"Internet Connected"
} else {
"Disconnet from the Internet"
}
tv.setOnClickListener {
baseStartActivity<FrogoAboutUsActivity>()
shareApp(packageName, getString(R.string.app_name))
}
}
}

}
6 changes: 4 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@android:color/white">

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="@android:color/black"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/res/values-v27/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Created by Faisal Amir
*
* Name : Muhammad Faisal Amir
* E-mail : [email protected]
* Github : github.com/amirisback
*
* Copyright (C) 2022 Frogobox Inc.
* All rights reserved
*
-->

<resources>

<style name="AppTheme.HideStatusBarUI" parent="AppTheme.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>

</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>

</resources>
8 changes: 5 additions & 3 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<style name="AppTheme.HideStatusBarUI" parent="AppTheme.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ object FrogoConstant {
const val CSV = ".csv"
}

object Url {
const val BASE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id="
}

}
60 changes: 54 additions & 6 deletions frogosdk/src/main/java/com/frogobox/sdk/FrogoActivity.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.frogobox.sdk

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.*
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.frogobox.coresdk.FrogoConstant.Url.BASE_PLAY_STORE_URL
import com.github.javiersantos.piracychecker.*
import com.github.javiersantos.piracychecker.enums.Display
import com.github.javiersantos.piracychecker.enums.InstallerID
Expand Down Expand Up @@ -123,7 +127,7 @@ abstract class FrogoActivity<VB : ViewBinding> : AppCompatActivity(), IFrogoActi
}

protected inline fun <reified ClassActivity> baseStartActivity() {
this.startActivity(Intent(this, ClassActivity::class.java))
startActivity(Intent(this, ClassActivity::class.java))
}

protected inline fun <reified ClassActivity, Model> baseStartActivity(
Expand All @@ -133,14 +137,58 @@ abstract class FrogoActivity<VB : ViewBinding> : AppCompatActivity(), IFrogoActi
val intent = Intent(this, ClassActivity::class.java)
val extraData = Gson().toJson(data)
intent.putExtra(extraKey, extraData)
this.startActivity(intent)
Log.d(TAG, "Base Start Activity Extra Data (${extraData::class.java.simpleName}) : $extraData")
startActivity(intent)
}

protected inline fun <reified Model> baseGetExtraData(extraKey: String): Model {
val extraIntent = intent.getStringExtra(extraKey)
return Gson().fromJson(extraIntent, Model::class.java)
}

override fun isNetworkConnected(): Boolean {
return FrogoFunc.isNetworkConnected(this)
}

override fun setupFullScreen() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val controller = window.insetsController
if (controller != null) {
controller.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
controller.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
}

override fun setupHideSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, window.decorView).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
Log.d(TAG, "Hide System UI a.k.a Status Bar Android CutOut")
}

override fun shareApp(packageName: String, appName: String) {
val messageShare = "Hi, let's play $appName. Download now on Google Play! $BASE_PLAY_STORE_URL$packageName"
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_SUBJECT, appName)
intent.putExtra(Intent.EXTRA_TEXT, messageShare)
Log.d(TAG, "Message Share App : $messageShare")
startActivity(Intent.createChooser(intent, "Share"))
}

override fun rateApp(packageName: String) {
val url = "$BASE_PLAY_STORE_URL$packageName"
Log.d(TAG, "Url Play Store : $url")
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}

// ---------------------------------------------------------------------------------------------

override fun verifySignature() {
Expand Down Expand Up @@ -219,7 +267,7 @@ abstract class FrogoActivity<VB : ViewBinding> : AppCompatActivity(), IFrogoActi
}

override fun showApkSignatures() {
apkSignatures.forEach { Log.d(TAG,"Signature This Apps : $it") }
apkSignatures.forEach { Log.d(TAG, "Signature This Apps : $it") }
}

}
47 changes: 39 additions & 8 deletions frogosdk/src/main/java/com/frogobox/sdk/FrogoFunc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.frogobox.sdk
import android.app.AlertDialog
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkInfo
import android.net.NetworkCapabilities
import android.os.Build
import android.os.Environment
import android.os.Handler
import com.frogobox.coresdk.FrogoConstant
Expand Down Expand Up @@ -86,13 +87,43 @@ object FrogoFunc : IFrogoFunc {
return false
}

override fun isNetworkAvailable(context: Context): Boolean? {
var isConnected: Boolean? = false // Initial Value
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork: NetworkInfo? = connectivityManager.activeNetworkInfo
if (activeNetwork != null && activeNetwork.isConnected) isConnected = true
return isConnected
override fun isNetworkConnected(context: Context): Boolean {

// register activity with the connectivity manager service
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

// if the android version is equal to M
// or greater we need to use the
// NetworkCapabilities to check what type of
// network has the internet connection
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

// Returns a Network object corresponding to
// the currently active default data network.
val network = connectivityManager.activeNetwork ?: return false

// Representation of the capabilities of an active network.
val activeNetwork = connectivityManager.getNetworkCapabilities(network) ?: return false

return when {
// Indicates this network uses a Wi-Fi transport,
// or WiFi has network connectivity
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true

// Indicates this network uses a Cellular transport. or
// Cellular has network connectivity
activeNetwork.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true

// else return false
else -> false
}
} else {
// if the android version is below M
@Suppress("DEPRECATION") val networkInfo =
connectivityManager.activeNetworkInfo ?: return false
@Suppress("DEPRECATION")
return networkInfo.isConnected
}
}

override fun <T> fetchRawData(mContext: Context, sourceRaw: Int): ArrayList<T> {
Expand Down
11 changes: 11 additions & 0 deletions frogosdk/src/main/java/com/frogobox/sdk/IFrogoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.frogobox.sdk

import android.view.View
import androidx.fragment.app.Fragment

/*
* Created by faisalamir on 28/07/21
* FrogoSDK
Expand Down Expand Up @@ -34,6 +35,16 @@ interface IFrogoActivity {
extraDataResult: Model
)

fun isNetworkConnected(): Boolean

fun setupFullScreen()

fun setupHideSystemUI()

fun shareApp(packageName: String, appName: String)

fun rateApp(packageName: String)

fun verifySignature()

fun readSignature()
Expand Down
2 changes: 1 addition & 1 deletion frogosdk/src/main/java/com/frogobox/sdk/IFrogoFunc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface IFrogoFunc {

fun randomNumber(start: Int, end: Int): Int

fun isNetworkAvailable(context: Context): Boolean?
fun isNetworkConnected(context: Context): Boolean

fun <T> fetchRawData(mContext: Context, sourceRaw: Int): ArrayList<T>

Expand Down
21 changes: 21 additions & 0 deletions frogosdk/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<resources>
<!-- Base application theme. -->
<style name="FrogoAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="FrogoAppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>

</resources>
10 changes: 10 additions & 0 deletions frogosdk/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="FrogoAppTheme.HideStatusBarUI" parent="FrogoAppTheme.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges</item>
</style>

</resources>

0 comments on commit af247e8

Please sign in to comment.