Building a preference screen with Android Jetpack Compose - android

i have to build a new Android app. Since Jetpack Compose is now stable i want to build the entire UI with that. Further i need also a Preference/Settings screen where the user can specify his preferences. According the doc it is still recommended doing this via Fragments.
https://developer.android.com/guide/topics/ui/settings
I found also an external library witch would provide this functionality in the compose way.
https://github.com/alorma/Compose-Settings
Has anybody done this before? Whats the "cleanest" way for doing that?
Thank you

I have implemented an app in compose and I created the settings screen using the tools available in Jetpack Compose, without fragments.
The way I did this is create a composable for each settings option, that contains a title, and optional subtitle, and a checkbox, which indicates if the option is enabled or not.
These options are then added to a column (or a grid, if you have a tablet, it's easy to support both in compose); you just have to hook the clicks on the checkbox to your viewmodel to change the setting and then refresh the UI.
If you have other kinds of settings entries you can define your own composables for those as well. In my case I have other settings options that open a dialog where the user can configure some parameters, I have another composable function for this kind of settings row as well.
This is personal opinion, but I prefer to stay away from 3rd party libraries unless a) they provide significant value and b) they're from a source that offers some kind of maintenance and bug fixes guarantees. I don't know about that library you mentioned, but if you include 3rd party libraries, you need to be aware you are relinquishing control over parts of your app so you need to balance the cost/benefit ratio.

Related

ANDROID - Jetpack Compose: how to implement theme settings?

I'm having hard times trying to implement a preference who switch the application theme.
Normally I would be able to do it with XML but with Jetpack Compose I saw that the best practice is to use DataStore (https://developer.android.com/topic/libraries/architecture/datastore)
Someone please, can explain me from scratch how to store a preference and change the whole application theme when the user click on a button for example?
Thank you
I believe that the DataStore documentation already explains in great detail how it works...
Talking about Compose we have the isSystemInDarkTheme function which brings up the current theme of the user's android system (which can be seen in Theme.kt inside the ui package that Android Studio automatically creates in a Compose project).
What needs to be done is whenever you open the app, check if the user has chosen to change the theme manually in your app through a function that accesses the DataStore, in other words, provide a Flow<Boolean?>, with a logic like if null the user has not changed the theme on your app, so you follow with the android system and if have the boolean, pass and apply to the MaterialTheme of Compose.
And you also need to create a function that sends a boolean to the DataStore regarding the theme change on the app.
Here is a repository with example code allowing the user to change the theme between dark and light and saving the option in the DataStore. And here is an article with theoretical and practical explanation about themes in Compose which I think may contribute to the clarification.

Kotlin How to create a template application

I have to create 2 application with almost the same design. But the backend i mean the way i receive data and i make request to my api is not the same. And there are also minor design such as color or bouton placement...
So i wanted to know if it's possible to create and app template i was thinking of creating a library module such as aar that would hold all the design then i would import it in both my application ?
But if i do that, is there a way to to update the design of the library within the app for exemple i assume that i want to change some color i could do it programmatically, but what happen if i want to change some button position or add rounder corner ? Do i have to provide methodes in my library to handle all those cases ? or is there a way to handle those within the app, meaning that the app could change some design of the library it self ?
In the end would like to have the logic in my app then give all information to the template library to render the design. So i would like to know if there is a way to implement such thing and what are the best practices to do it.
I have in my projects two ways.
Library, as you mention. I use it when there are routines that are common to several projects. It is possible to change color patterns and some style details. But it is often plastered.
Flavors - Build Variants https://developer.android.com/studio/build/build-variants
With build variants you can create one project/app with two versions, chandind only wat you need. This option is very good when you want to change color, endpoint, style, show or hide some system functionality. I use it and it's very good.

Changing iOS and Android app's name and icon on the fly

Okay, I know the title is a bit confusing so let me explain it a little bit more.
We have different groups of clients and they want to have their own app, meaning the app name, icon, splash screen and theme colour are customized. But the functionalities and features remain the same across the whole product line.
Of course, we can submit different app for different client. But the maintenance would be a nightmare to the development team - each new feature / bug fixes needed to be pushed to different branches and we need to do multiple app update. Furthermore, we need to do manual testing on all the variants. We do not want to go down this road.
As a developer, I want to have a generic app for app submission and update. But once the client signed up then we change the app name, icon and splash screen according to his settings. I know I can do the splash screen and theme color - just render a different image and RGB value from the server on login. But I do not know if there is way to changed the app name and icon after the app installation.
I have also done preliminary search on this question but the answer I got is a no. Since those answers are from 2011 so I wonder if the situation has changed or not.
Many Thanks!
P.S. I found a group of apps on App Store which cover the question I asked. It is called DropLocker. They have 14 variants but I guess they use the same code base. I wonder if there is an update, do they push it individually or there is a way to do a multiple app updates at one shot.
For iOS apps, you can create targets in the same app and for each target you can change the appicons, splash screen, theme color etc.
To create target, go to your Project, On Left side, under "TARGETS", you will see, two targets, one with your Project name, other with Test. Right click your project and click "Duplicate". Then you can rename the target. Also rename the target in "Manage Schemes", to avoid confusion later on. Then, you can change the app name seperately for all targets in "info" section. Similarly, you can create a different sets of Appicons and splash screens and use them for different targets. To change theme color, you can define a "Preprocessor Macro" in Build Settings and use it inside your code. You can set the macro's value for different targets.

Using `PreferenceActivity` for features only, not settings

I'm currently working on an Android app, and looking at the PreferenceActivity class and the corresponding layout elements (PreferenceScreen, etc.), it appears that it provides much of the functionality that I desire for a major component of the app. However, that component is not a Settings activity per se, and I'm not sure if using Preference stuff for things that aren't technically preferences is a good way to do things. On the other hand, I'd prefer not having to implement all the features that PreferenceActivity/etc. provides, so would it be fine to use that framework and just change the layout theme so it doesn't seem like a Settings menu?
You can definitely load/set up the preference layout using the android framework and then save the data using your own implementation of SharedPreferences. This class is a good example. Not sure why you would not make it look like a preference screen though. What's wrong with that look?

how to permanently override android soft keys behaviour and display through

I am relatively new to android and want to create an application that permanently overrides androids basic softkey behaviour and view (for devices with soft keys).
Some functionalities I want to implement are changing the size of the softkeys window at the bottom, change its images, and possibly change its functionality.
For example, the user can set the size to of the softkey to be "large", "medium" or "small". And I can change the functionality of the back button to open say a particular application instead of going "back".
I'm basically looking for a high level answer as to how to do this, a basic direction of what I should read/study in order to be able to accomplish this. I realise this may require root access.
Please note that I want this behaviour to change not only in my application but I want the effect to exist on all applications. If this requires the application to be running atleast at the backend, that is fine.
After doing some decent amount of search, it seems I will have to make changes in the systemUI.apk, or possibly get its source code and modify it. Is this correct?
Thanks in advance.
I don't think even root is going to be enough for the type of changes you are describing. You're going to need to edit the Android source code and build your own system image.
Well you can't override system resources because they are part of the system image.
What you are looking for is called Home Application which can be developed like any other android app no need for root , you can find an example for it in your sdk samples.
Home Sample Application.
your app would be responsible to have UI components to send the user to all of the phone functionalities which includes:
Place for wegits
Place for apps listing (menue)
Access telephony functionality (call, phone history ...)
Access settings.

Categories

Resources