Tweaks - A customizable debug screen to view and edit flags that can be used for development

Overview

A customizable debug screen to view and edit flags that can be used for development in Jetpack Compose applications

To include the library add to your app's build.gradle:

implementation 'com.telefonica:tweaks:{version}'

Or, in case you want to don't add the library in release builds:

debugImplementation 'com.telefonica:tweaks:{version}'
releaseImplementation 'com.telefonica:tweaks-no-op:{version}'

Then initialize the library in your app's onCreate:

override fun onCreate() {
    super.onCreate()
    Tweaks.init(this@TweakDemoApplication, demoTweakGraph())
}

where demoTweakGraph is the structure you want to be rendered:

private fun demoTweakGraph() = tweaksGraph {
    cover("Tweaks Demo") {
        label("cover-key", "Current user ID:") { flowOf("1") }
    }
    category("Screen 1") {
        group("Group 1") {
            label(
                key = "timestamp",
                name = "Current timestamp",
            ) {
                timestampState
            }
            editableString(
                key = "value1",
                name = "Value 1",
            )
            editableBoolean(
                key = "value2",
                name = "Value 2",
                defaultValue = true,
            )
            editableLong(
                key = "value4",
                name = "Value 4",
                defaultValue = 42L,
            )
            button(
                key = "button1",
                name = "Demo button"
            ) {
                Toast.makeText(this@TweakDemoApplication, "Demo button", Toast.LENGTH_LONG)
                    .show()
            }

            routeButton(
                key = "button2",
                name = "Custom screen button",
                route = "custom-screen"
            )
        }
    }
}

And then, in your NavHost setup, use the extension function NavGraphBuilder.addTweakGraph to fill the navigation graph with the tweak components:

@Composable
    private fun DemoNavHost(
        navController: NavHostController,
        initialScreen: String,
        modifier: Modifier = Modifier,
    ) {
        NavHost(
            navController = navController,
            startDestination = initialScreen,
            modifier = modifier,
        ) {
            addTweakGraph(
                navController = navController,
            )
        }
    }

How to build the TweaksGraph

You can use the DSL to create your own graph. Please note that a graph is composed by:

  • A main group of tweaks (Optional)
  • A list of categories

The categories are separate screens and are composed of groups of tweaks. You can use each category to separate debug elements of your app by feature or key components, for example: (chat, webviews, login, stats, etc...)

The group of tweaks are a shown inside each category screen, they are composed of tweaks and can represent configuration settings that can be grouped together, for example: endpoints of your API.

And finally, the tweaks are the configurable elements. Currently we support these ones:

button(
    key: String,
    name: String,
    action: () -> Unit
)

Used to display a button that performs an action

fun routeButton(
    key: String,
    name: String,
    route: String,
)

Similar, but this button navigates directly to a route of the NavHost, check custom screens section for more info

fun label(
    key: String,
    name: String,
    value: () -> Flow<String>,
)

A non editable text

fun editableString(
    key: String,
    name: String,
    defaultValue: Flow<String>? = null,
)
fun editableString(
    key: String,
    name: String,
    defaultValue: String,
)

An editable text

fun editableBoolean(
    key: String,
    name: String,
    defaultValue: Flow<Boolean>? = null,
)
fun editableBoolean(
    key: String,
    name: String,
    defaultValue: Boolean,
)

An editable boolean

fun editableInt(
    key: String,
    name: String,
    defaultValue: Flow<Int>? = null,
)
fun editableInt(
    key: String,
    name: String,
    defaultValue: Int,
) 

An editable Int

fun editableLong(
    key: String,
    name: String,
    defaultValue: Flow<Long>? = null,
)
fun editableLong(
    key: String,
    name: String,
    defaultValue: Long,
)

An editable Long

Please review the app module for configuration examples.

Custom screens:

You can add your custom screens to the TweaksGraph by using the customComposableScreens parameter of addTweakGraph function, for example:

addTweakGraph(
    navController = navController,
) {
    composable(route = "custom-screen") {
        Column(
            modifier = Modifier
                .fillMaxSize()
                .padding(16.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
        ) {
            Text("Custom screen")
        }
    }
}

Shake gesture support:

The tweaks can be opened when the user shakes the device, to do this you need to add to your navigation controller:

navController.navigateToTweaksOnShake()

And also, optionally

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

to your AndroidManifest.xml

Special thanks to contributors:

Comments
  • Extending theme

    Extending theme

    Providing custom attributes for the theme

    https://user-images.githubusercontent.com/4595241/203996965-e30ee36d-f21e-46af-8f25-7de6c95e0678.mp4

    That can be overridable when creating the tweaks:

         addTweakGraph(
                    navController = navController,
                    tweaksCustomTheme = { content ->
                        val tweaksColors = TweaksColors(
                            tweaksPrimary = Color.Cyan,
                            tweaksOnPrimary = Color.White,
                            tweaksPrimaryVariant = Color.Cyan,
                            tweaksSurface = Color.Magenta,
                            tweaksOnSurface = Color.White,
                            tweaksBackground = Color.Blue,
                            tweaksOnBackground = Color.White,
                            tweaksGroupBackground = Color.Cyan,
                            tweaksColorModified = Color.Cyan,
                        )
                        CompositionLocalProvider(LocalTweaksColors provides tweaksColors) {
                            content()
                        }
                    }
                ) {}
    

    image

    opened by gmerinojimenez 0
  • [Equinox] Revamp UI, models and some minor new functionalities

    [Equinox] Revamp UI, models and some minor new functionalities

    Several changes:

    • Added a default theme (overridable if wanted)
    • Fixed logic in the DSL: there were mandatory keys that didn't provide anything, like the ones in the buttons.
    • Full revamp of the models.
    • Minor UI improvements in the editable composable
    • Add a configurable button to reset a tweak group

    After: demo

    Before:

    opened by gmerinojimenez 0
  • Tweak button to allow custom navigations

    Tweak button to allow custom navigations

    Create a new CustomNavigationTweakEntry entry type and the corresponding DSL method customNavigationButton. It is just like RouteButtonTweakEntry but It receives a lambda of type (NavController) -> Unit) instead of a route: String so a more complex navigation can be performed.

    opened by yamal-alm 0
  • add copy to clipboard in readonly tweaks

    add copy to clipboard in readonly tweaks

    Copy to clipboard values

    I propose to make the readonly values allowed to be copied to clipboard on longPress.

    https://user-images.githubusercontent.com/944814/154074636-82c88839-ec27-40c0-8a67-ef0ef4e75c2e.mp4

    Bonus point

    I have the following aliases in my dotfiles:

    alias pbcopy='xclip -selection clipboard'
    alias pbpaste='xclip -selection clipboard -o'
    alias copyadbclipboard='adb shell am broadcast -n ch.pete.adbclipboard/.ReadReceiver | pbcopy'
    

    These alias allows me to move the clipboard content from my android device to my computer clipboard

    enhancement 
    opened by manolovn 0
  • make tweaks screen scrollable

    make tweaks screen scrollable

    Make TweaksScreen scrollable.

    When the elements in the screen exceeds the vertical space in the screen, it's necessary to make the Column scrollable:

    Before:

    https://user-images.githubusercontent.com/944814/154070180-c0a248a1-a783-400e-8334-369bbff93add.mp4

    After the fix: https://user-images.githubusercontent.com/944814/154069914-6bc2975b-f0c1-4d73-b967-7cd1c4668ce6.mp4

    enhancement 
    opened by manolovn 0
  • Include sources in release

    Include sources in release

    We were only publishing sources on release from main folder, we should publish whole source to ease developers debugging.

    However, I couldn't come to a solution where noop and enabled sources could be packed in separated jars and then include each one on each maven publication. What I've done is to only generate one jar with main and enabled source sets and include it only on enabled release.

    Tested with an snapshot in a client app

    enhancement 
    opened by yamal-alm 0
  • Initial PR

    Initial PR

    "Forked" from github.com/gmerinojimenez/tweaks and updated to use com.telefonica. I still need to fix some github actions, but I need to have this integrated to be able to test them

    opened by gmerinojimenez 0
Releases(2.2.0)
  • 2.2.0(Dec 20, 2022)

    What's Changed

    Other Changes

    • Tweaks.init() use Context class instead Application by @dagonco in https://github.com/Telefonica/tweaks/pull/23

    New Contributors

    • @dagonco made their first contribution in https://github.com/Telefonica/tweaks/pull/23

    Full Changelog: https://github.com/Telefonica/tweaks/compare/2.1.1...2.2.0

    Source code(tar.gz)
    Source code(zip)
  • 2.1.1(Dec 2, 2022)

    What's Changed

    Other Changes

    • Some color fixes by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/21

    Full Changelog: https://github.com/Telefonica/tweaks/compare/2.1.0...2.1.1

    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Nov 28, 2022)

    What's Changed

    Other Changes

    • Extending theme by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/20

    Full Changelog: https://github.com/Telefonica/tweaks/compare/2.0.2...2.1.0

    Source code(tar.gz)
    Source code(zip)
  • 2.0.2(Oct 28, 2022)

    What's Changed

    Other Changes

    • Fix background color by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/19

    Full Changelog: https://github.com/Telefonica/tweaks/compare/2.0.1...2.0.2

    Source code(tar.gz)
    Source code(zip)
  • 2.0.1(Oct 10, 2022)

    What's Changed

    Other Changes

    • Fixing addTweakGraph signature by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/18

    Full Changelog: https://github.com/Telefonica/tweaks/compare/2.0.0...2.0.1

    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(Oct 10, 2022)

    What's Changed

    Breaking changes

    • [Equinox] Revamp UI, models and some minor new functionalities by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/17

    Other Changes

    • ANDROID-10857 Update gradle.properties to use common by @jeslat in https://github.com/Telefonica/tweaks/pull/16

    New Contributors

    • @jeslat made their first contribution in https://github.com/Telefonica/tweaks/pull/16

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.3.0...2.0.0

    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(May 4, 2022)

    What's Changed

    Other Changes

    • Fix initial value in dropdown by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/13

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.2.0...1.3.0

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Apr 1, 2022)

    What's Changed

    New Features 馃帀

    • Adding dropdown menu by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/12

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.1.0...1.2.0

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Mar 17, 2022)

    What's Changed

    Other Changes

    • Tweak button to allow custom navigations by @yamal-alm in https://github.com/Telefonica/tweaks/pull/11

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.0.6...1.1.0

    Source code(tar.gz)
    Source code(zip)
  • 1.0.6(Mar 4, 2022)

    What's Changed

    Other Changes

    • Fix initialization by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/10

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.0.5...1.0.6

    Source code(tar.gz)
    Source code(zip)
  • 1.0.5(Feb 17, 2022)

    What's Changed

    Other Changes

    • make tweak category screen scrollable by @yamal-alm in https://github.com/Telefonica/tweaks/pull/9

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.0.4...1.0.5

    Source code(tar.gz)
    Source code(zip)
  • 1.0.4(Feb 15, 2022)

    What's Changed

    New Features 馃帀

    • make tweaks screen scrollable by @manolovn in https://github.com/Telefonica/tweaks/pull/7
    • add copy to clipboard in readonly tweaks by @manolovn in https://github.com/Telefonica/tweaks/pull/8

    New Contributors

    • @manolovn made their first contribution in https://github.com/Telefonica/tweaks/pull/7

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.0.3...1.0.4

    Source code(tar.gz)
    Source code(zip)
  • 1.0.3(Jan 31, 2022)

    What's Changed

    Other Changes

    • Fixing a bug when adding the cover items by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/6

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.0.2...1.0.3

    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Jan 28, 2022)

    What's Changed

    New Features 馃帀

    • Include sources in release by @yamal-alm in https://github.com/Telefonica/tweaks/pull/5

    New Contributors

    • @yamal-alm made their first contribution in https://github.com/Telefonica/tweaks/pull/5

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.0.1...1.0.2

    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Jan 20, 2022)

    What's Changed

    Other Changes

    • Fixing a bug when adding the cover items by @gmerinojimenez in https://github.com/Telefonica/tweaks/pull/4

    Full Changelog: https://github.com/Telefonica/tweaks/compare/1.0.0...1.0.1

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jan 17, 2022)

Owner
Telef贸nica
Telef贸nica official source code platform
Telef贸nica
Learn how to make an app designed for single-screen devices shine when running on foldable and dual-screen devices

dcberlin21-workshop Make your app shine om foldable devices with the samples we have here. Related links SDK open-source code SDK samples (Kotlin) App

Cesar Valiente 3 Oct 26, 2021
Fully customizable, built from scratch NumberPicker for android. Created as an alternative to non-customizable native android NumberPicker

GoodNumberPicker GoodPicker is an Android library that provides a picker with customizable UI. It was developed as alternative to the default NumberPi

null 3 Nov 30, 2022
A single screen app learn in google basic Android Development course.

Project: Lemonade App - Starter Code Starter code for the first independent project for Android Basics in Kotlin Introduction This is the starter code

Kaushal Raj 0 Dec 19, 2022
A tip app which the user can use a screen bar to choose a tip based on the service, the total is then displayed.

Tip Calculator Spencer Damon Tippy Total computes the tip and total amount for a bill. The app uses the base amount and tip percentage to calculate th

Spencer Damon 0 Jan 3, 2022
A library that extends the existing JDBC API so that data objects can be used as input (to set parameters) and output (from ResultSet's rows).

SqlObjectMapper This is a library that extends the existing JDBC API so that data objects can be used as input (to set parameters) and output (from Re

Qualified Cactus 2 Nov 7, 2022
An introductory dynamics to Test Driven Development (TDD)An introductory dynamics to Test Driven Development (TDD)

tdd-demo Nesse hands-on teremos uma din芒mica introdut贸ria a Test Driven Development (TDD), ou desenvolvimento orientado por testes. instru莽玫es 1 - Clo

Plataforma Impact 1 Jan 15, 2022
An open source app which can be used to do basic surveys

SurveyApp This is an open source app which can be used to do basic surveys. It supports multiple question types. For demo please check the releases pa

Dhiraj Uchil 0 Dec 9, 2021
This is a skeleton project for Zircon users that can be used to get started with Zircon.

Zircon Kotlin Skeleton Project This is a skeleton project for Zircon users that can be used to get started with Zircon. Getting started This project w

Vladislav Kashchey 0 May 3, 2022
Tool for exporting Old School RuneScape environments so they can be used in 3D modeling programs like Blender.

OSRS Environment Exporter Tool for exporting Old School RuneScape environments so that they can be used in 3D modeling programs like Blender. Download

Connor 21 Dec 29, 2022
A custom OTP view to enter a code usually used in authentication

A custom view to enter a code usually used in authentication. Different types of OTPViews. Easy to use and configure your own view and character of OTP using all the attributes.

Simform Solutions 48 Aug 30, 2022
The app is composed of 2 screens, first is the profile screen, it has the user_name and address pinned at the top and then it lists all of this user鈥檚 albums.

The app is composed of 2 screens, first is the profile screen, it has the user_name and address pinned at the top and then it lists all of this user鈥檚 albums. When you press on any album it navigates to the second screen which is an album details screen that contains list of the images in an recyclerview grid. Also you have search bar that you can filter within the photos album by the image title.

Mahmoud Ibrahim 4 Jul 10, 2022
An Android app where you can view and examine the details of fast food divided into categories.

?? FastFood An Android application where you can view and examine the details of fast food divided into categories. ?? Tech Stack & Open-Source Librar

Muhammed Esad C枚mert 3 Oct 7, 2022
Quick photo and video camera with a flash, customizable resolution and no ads.

Simple Camera A camera with flash, zoom and no ads. The camera is usable for both photo taking and video recording. You can switch between front and r

Simple Mobile Tools 644 Dec 26, 2022
The starter repository for the Android tech screen!

Nearside Android Code Screen - Starter Welcome to Nearside's Code Screen starter repository! Quickstart You'll need the following: Android Studio Arct

Hatch 1 Dec 6, 2021
Swarup 2 Feb 6, 2022
Quickly rotate screen on Android devices without second thought

Useful uitlity for ONYX BOOX Eink devices. It provides several quick actions to be added in top system panel

Daniel Kao 21 Jan 3, 2023
A simple calendar with events, customizable widgets and no ads.

Simple Calendar A simple calendar with events and a customizable widget. A simple calendar with optional CalDAV synchronization. You can easily create

Simple Mobile Tools 3k Jan 8, 2023
MemoryGame - An Android memory game with customizable options

MemoryGame An Android memory game with customizable options Open source librarie

null 1 Feb 3, 2022