Skip to content

Instantly share code, notes, and snippets.

View zmdominguez's full-sized avatar

Zarah Dominguez zmdominguez

View GitHub Profile

This gist provides a more flexible version of adb that exposes the functionality to select a device and then use that device's serial number in one or more adb commands. It expands on the initial implementation of the deeplinks.sh gist.

Companion blog post for usage is 🔗 here.

Companion posts for earlier versions of the script: Extending an Interactive ADB

import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
buildTypes{
getByName("debug") {
...
configure<CrashlyticsExtension> {
mappingFileUploadEnabled = false
}
}
}
<androidx.preference.Preference app:title="Bag Reminders">
<intent android:action="android.intent.action.VIEW"
android:targetClass="[REDACTED].NotificationSettingsActivity"
android:targetPackage="com.woolworths.debug" />
</androidx.preference.Preference>
fun showThemeSwitcher(activity: Activity, prefs: SharedPreferences) {
val builder = AlertDialog.Builder(activity)
val names = mutableListOf<String>()
var selectedTheme = getSelectedTheme(activity, prefs).ordinal
builder.setTitle("Choose theme to apply")
builder.setSingleChoiceItems(SwitchableThemes.values().mapTo(names) {
it.label
}.toTypedArray(), selectedTheme) { _, which ->
selectedTheme = which
}.setPositiveButton(R.string.ok) { dialog, which ->
fun Context.showDebugToast(message: String, settingsInteractor: SettingsInteractor) {
if (settingsInteractor.shouldShowDebugToasts()) {
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
}
}
fun saveLogs() {
val debugDirectory = getStorageDirectory(this)
val logFile = File(debugDirectory, "logcat" + System.currentTimeMillis() + ".txt")
try {
var process = Runtime.getRuntime().exec("logcat -c")
process = Runtime.getRuntime().exec("logcat -f $logFile")
} catch (e: IOException) {
Timber.d(e)
}
}
@zmdominguez
zmdominguez / README.md
Last active July 1, 2019 08:42
Inspecting and Resetting preferences

This is a helper function for an app's debug or development drawer and is designed to be pasted into an Activity. It retrieves all files from shared_prefs and allows the user to choose which files to inspect or reset to default values. It is extremely helpful when testing one-shot scenarios such as for hints or onboarding, etc.

It assumes that the files are named in a consistent and predictable way -- more specifically by prefixing them with the application ID as mentioned here. For maximum consistency, this assumes that files are named similar to how the system names the default SharedPreferences file (MY.PACKAGE.ID_my_preferences).

All the application-specific preferences files are displayed in an AlertDialog. For readability, the application ID is stripped out.

enum class Feature(val remoteConfigKey: String, val defaultValue: Boolean) {
FEATURE_1("feature_1_key", false),
FEATURE_2("feature_2_key", true),
FEATURE_3("feature_3_key", true)
}
<shortcut …>
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.zdominguez.sdksandbox"
android:targetClass="com.zdominguez.sdksandbox.MainActivity">
<extra android:name="target_tab" android:value="settings" />
</intent>
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.zdominguez.sdksandbox"