Skip to content

Commit

Permalink
More extensions with demo added
Browse files Browse the repository at this point in the history
  • Loading branch information
death14stroke committed Apr 5, 2020
1 parent 22d5412 commit 6484d40
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 19 deletions.
18 changes: 18 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

Expand All @@ -20,6 +21,21 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

viewBinding {
enabled true
}
androidExtensions {
experimental true
}
}

dependencies {
Expand All @@ -29,4 +45,6 @@ dependencies {
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation project(path: ':library')
}
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.andruid.magic.sample">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="AllowBackup">
<activity android:name="com.andruid.magic.sample.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
26 changes: 25 additions & 1 deletion app/src/main/java/com/andruid/magic/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,34 @@ package com.andruid.magic.sample

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.andruid.magic.eezetensions.*
import com.andruid.magic.sample.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.apply {
packageVersionTV.text = getString(R.string.package_version, this@MainActivity.getPackageVersion())
deviceNameTV.text = getString(R.string.device_name, this@MainActivity.getUserDeviceName())
appNameTV.text = getString(R.string.application_name, this@MainActivity.getApplicationName())

hasInternetBtn.setOnClickListener {
toast("Has internet = ${this@MainActivity.hasInternet()}")
}
mobileDataBtn.setOnClickListener {
toast("Mobile data enabled = ${this@MainActivity.isMobileDataEnabled()}")
}
settingsBtn.setOnClickListener {
startActivity(this@MainActivity.buildSettingsIntent())
}
tetherSettingsBtn.setOnClickListener {
startActivity(buildTetherSettingsIntent())
}
}
}
}
68 changes: 64 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,72 @@
tools:context="com.andruid.magic.sample.MainActivity">

<TextView
android:id="@+id/packageVersionTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:text="Package version"
app:layout_constraintBottom_toTopOf="@id/deviceNameTV"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/deviceNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Device name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/packageVersionTV"
app:layout_constraintBottom_toTopOf="@id/appNameTV"/>

<TextView
android:id="@+id/appNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="App name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/deviceNameTV"
app:layout_constraintBottom_toTopOf="@id/hasInternetBtn" />

<Button
android:id="@+id/hasInternetBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check_connectivity"
app:layout_constraintBottom_toTopOf="@id/mobileDataBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/appNameTV" />

<Button
android:id="@+id/mobileDataBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check_mobile_data_connectivity"
app:layout_constraintBottom_toTopOf="@id/settingsBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/hasInternetBtn" />

<Button
android:id="@+id/settingsBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_settings"
app:layout_constraintTop_toBottomOf="@id/mobileDataBtn"
app:layout_constraintBottom_toTopOf="@id/tetherSettingsBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/tetherSettingsBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tether_settings"
app:layout_constraintTop_toBottomOf="@id/settingsBtn"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<resources>
<string name="app_name">My Application</string>

<string name="package_version">Package version: %1$s</string>
<string name="device_name">User device name: %1$s</string>
<string name="application_name">Application name: %1$s</string>
<string name="check_connectivity">Check connectivity</string>
<string name="check_mobile_data_connectivity">Check mobile data connectivity</string>
<string name="app_settings">App settings</string>
<string name="tether_settings">Tether settings</string>
</resources>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
kotlin_version = "1.3.70"
kotlin_version = "1.3.71"
dokka_version = "0.10.1"
splitties_version = "2.1.1"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("unused")

package com.andruid.magic.eezetensions

import android.Manifest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("unused")

package com.andruid.magic.eezetensions

import android.content.Intent
Expand Down
11 changes: 4 additions & 7 deletions library/src/main/java/com/andruid/magic/eezetensions/Intent.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("unused")

package com.andruid.magic.eezetensions

import android.content.Context
Expand All @@ -19,12 +17,11 @@ fun Context.buildSettingsIntent(): Intent {
}

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

0 comments on commit 6484d40

Please sign in to comment.