Skip to content

Commit

Permalink
Add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
koji-1009 committed Jun 22, 2019
1 parent bc923cc commit 9eaccf8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 10 deletions.
@@ -1,8 +1,10 @@
package com.app.dr1009.easysettingspaneldemo

import android.nfc.NfcAdapter
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.app.dr1009.easysettingspanel.EasySettingsPanel
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.content_main.*

Expand All @@ -14,13 +16,14 @@ class MainActivity : AppCompatActivity() {
setSupportActionBar(toolbar)

button_internet_connectivity.setOnClickListener {
EasySettingsPanel.openInternetConnectivityPanel(
this@MainActivity,
EasySettingsPanel.PreviousConnectivityMode.WIFI
)
EasySettingsPanel.openInternetConnectivityPanelBackportWifi(this@MainActivity)
}
button_nfc.setOnClickListener {
EasySettingsPanel.openNfcPanel(this@MainActivity)
if (NfcAdapter.getDefaultAdapter(this@MainActivity)?.isEnabled == true) {
EasySettingsPanel.openNfcPanel(this@MainActivity)
} else {
Snackbar.make(layout_top, "Sorry. This phone can not use NFC.", Snackbar.LENGTH_INDEFINITE).show()
}
}
button_volume.setOnClickListener {
EasySettingsPanel.openVolumePanel(this@MainActivity)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Expand Up @@ -2,6 +2,7 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
Expand Down
Expand Up @@ -20,27 +20,56 @@ import android.content.Intent
import android.os.Build
import android.provider.Settings

/**
* EasySettingsPanel is util class for Settings.Panel.
*/
object EasySettingsPanel {

enum class PreviousConnectivityMode {
// region internet connectivity panel
private enum class PreviousConnectivityMode {
WIFI,
MOBILE_DATA,
AIRPLANE_MODE
}

fun openInternetConnectivityPanelWifi(context: Context) {
/**
* If phone is over Android Q, open Internet Connectivity Panel.
* Otherwise, open UI that allows Wi-Fi to be turned on or off.
*
* @param context Context
* @throws RuntimePermission In some cases, a matching Activity may not exist, so ensure you safeguard against this.
*/
@Throws(RuntimeException::class)
fun openInternetConnectivityPanelBackportWifi(context: Context) {
openInternetConnectivityPanel(context, EasySettingsPanel.PreviousConnectivityMode.WIFI)
}

fun openInternetConnectivityPanelMobile(context: Context) {
/**
* If phone is over Android Q, open Internet Connectivity Panel.
* Otherwise, open UI that allows Mobile data to be turned on or off.
*
* @param context Context
* @throws RuntimePermission In some cases, a matching Activity may not exist, so ensure you safeguard against this.
*/
@Throws(RuntimeException::class)
fun openInternetConnectivityPanelBackportMobileData(context: Context) {
openInternetConnectivityPanel(context, EasySettingsPanel.PreviousConnectivityMode.MOBILE_DATA)
}

fun openInternetConnectivityPanelAirplane(context: Context) {
/**
* If phone is over Android Q, open Internet Connectivity Panel.
* Otherwise, open UI that allows Airplane mode to be turned on or off.
*
* @param context Context
* @throws RuntimePermission In some cases, a matching Activity may not exist, so ensure you safeguard against this.
*/
@Throws(RuntimeException::class)
fun openInternetConnectivityPanelBackportAirplane(context: Context) {
openInternetConnectivityPanel(context, EasySettingsPanel.PreviousConnectivityMode.AIRPLANE_MODE)
}

fun openInternetConnectivityPanel(context: Context, mode: PreviousConnectivityMode) {
@Throws(RuntimeException::class)
private fun openInternetConnectivityPanel(context: Context, mode: PreviousConnectivityMode) {
context.startActivity(
Intent(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Expand All @@ -55,7 +84,18 @@ object EasySettingsPanel {
)
)
}
// endregion

// region nfc panel
/**
* If phone is over Android Q, open NFC Panel.
* Otherwise, open UI that allows NFC to be turned on or off.
*
* This method
*
* @param context Context
* @throws RuntimePermission In some cases, a matching Activity may not exist, so ensure you safeguard against this.
*/
@Throws(RuntimeException::class)
fun openNfcPanel(context: Context) {
context.startActivity(
Expand All @@ -68,7 +108,19 @@ object EasySettingsPanel {
)
)
}
// endregion

// region volume panel
/**
* If phone is over Android Q, open Volume Panel.
* Otherwise, open UI that allows NFC to be turned on or off.
*
* This method
*
* @param context Context
* @throws RuntimePermission In some cases, a matching Activity may not exist, so ensure you safeguard against this.
*/
@Throws(RuntimeException::class)
fun openVolumePanel(context: Context) {
context.startActivity(
Intent(
Expand All @@ -80,7 +132,19 @@ object EasySettingsPanel {
)
)
}
// endregion

// region wifi panel
/**
* If phone is over Android Q, open Wi-Fi Panel.
* Otherwise, open UI that allows Wi-Fi to be turned on or off and select AccessPoint.
*
* This method
*
* @param context Context
* @throws RuntimePermission In some cases, a matching Activity may not exist, so ensure you safeguard against this.
*/
@Throws(RuntimeException::class)
fun openWifiPanel(context: Context) {
context.startActivity(
Intent(
Expand All @@ -92,4 +156,5 @@ object EasySettingsPanel {
)
)
}
// endregion
}

0 comments on commit 9eaccf8

Please sign in to comment.