-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ANDR][Example] Add config settings page (#88)
* [ANDR][Example] Add config settings page * Use api and url settings to init bitdrift logger * fmt * reshuffle * add license * Fix test
- Loading branch information
Showing
9 changed files
with
104 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
.../gradle-test-app/src/main/java/io/bitdrift/gradletestapp/ConfigurationSettingsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// capture-sdk - bitdrift's client SDK | ||
// Copyright Bitdrift, Inc. All rights reserved. | ||
// | ||
// Use of this source code is governed by a source available license that can be found in the | ||
// LICENSE file or at: | ||
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt | ||
|
||
package io.bitdrift.gradletestapp | ||
|
||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.os.Bundle | ||
import androidx.preference.EditTextPreference | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceCategory | ||
import androidx.preference.PreferenceFragmentCompat | ||
import kotlin.system.exitProcess | ||
|
||
class ConfigurationSettingsFragment : PreferenceFragmentCompat() { | ||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
val context = preferenceManager.context | ||
val screen = preferenceManager.createPreferenceScreen(context) | ||
|
||
val backendCategory = PreferenceCategory(context) | ||
backendCategory.key = "control_plane_category" | ||
backendCategory.title = "Control Plane Configuration" | ||
|
||
screen.addPreference(backendCategory) | ||
|
||
val apiUrlPref = EditTextPreference(context) | ||
apiUrlPref.key = "apiUrl" | ||
apiUrlPref.title = "API URL" | ||
apiUrlPref.summary = "App needs to be restarted for changes to take effect" | ||
|
||
backendCategory.addPreference(apiUrlPref) | ||
|
||
val apiKeyPref = EditTextPreference(context) | ||
apiKeyPref.key = "apiKey" | ||
apiKeyPref.title = "API Key" | ||
apiKeyPref.summary = "App needs to be restarted for changes to take effect" | ||
|
||
backendCategory.addPreference(apiKeyPref) | ||
|
||
val restartPreference = Preference(context) | ||
restartPreference.key = "restart" | ||
restartPreference.title = "Restart the App" | ||
restartPreference.setOnPreferenceClickListener { | ||
val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName) | ||
val restartIntent = Intent.makeRestartActivityTask(launchIntent!!.component) | ||
// Required for API 34 and later | ||
// Ref: https://developer.android.com/about/versions/14/behavior-changes-14#safer-intents | ||
restartIntent.setPackage(context.packageName); | ||
context.startActivity(restartIntent) | ||
exitProcess(0) | ||
} | ||
|
||
screen.addPreference(restartPreference) | ||
|
||
preferenceScreen = screen | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters