Skip to content

Commit

Permalink
new extensions added
Browse files Browse the repository at this point in the history
  • Loading branch information
death14stroke committed Apr 4, 2020
1 parent cda15a6 commit 22d5412
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.0-beta01'
classpath 'com.android.tools.build:gradle:4.0.0-beta03'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"

Expand Down
26 changes: 23 additions & 3 deletions library/src/main/java/com/andruid/magic/eezetensions/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ fun Context.hasInternet(): Boolean {
*/
fun Context.getPackageVersion(): String? {
return try {
val pInfo = packageManager.getPackageInfo(applicationContext.packageName, 0)
pInfo.versionName
packageManager.getPackageInfo(applicationContext.packageName, 0).versionName
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
null
Expand Down Expand Up @@ -111,4 +110,25 @@ fun Context.toast(@StringRes msgRes: Int, duration: Int = Toast.LENGTH_SHORT, fr
* @receiver context of the calling component
*/
fun Context.getUserDeviceName(): String =
Settings.Global.getString(contentResolver, "device_name")
Settings.Global.getString(contentResolver, "device_name")

/**
* Get the application name
* @return application name
* @receiver context of the calling component
*/
fun Context.getApplicationName(): String {
val stringId = applicationInfo.labelRes
return if (stringId == 0)
applicationInfo.nonLocalizedLabel.toString()
else
getString(stringId)
}

/**
* Check whether mobile data is enabled
* @return true/false
* @receiver context of the calling component
*/
fun Context.isMobileDataEnabled() =
Settings.Global.getInt(contentResolver, "mobile_data", 1) == 1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.Intent
import android.widget.Toast
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.RequiresPermission
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment

Expand Down
11 changes: 11 additions & 0 deletions library/src/main/java/com/andruid/magic/eezetensions/Intent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ fun Context.buildSettingsIntent(): Intent {
val uri = Uri.fromParts("package", packageName, null)
return Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
.setData(uri)
}

/**
* Get intent to show hotspot settings screen
* @return intent to launch hotspot settings
* @receiver context of the calling component
*/
fun Context.buildHotspotSettingsIntent(): Intent {
return Intent()
.setClassName("com.android.settings", "com.android.settings.wifi.mobileap.WifiApSettings")
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
}

0 comments on commit 22d5412

Please sign in to comment.