Aug 31 | 8:50 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Aug 31 | 9:00 AM |
midas | has entered the room |
Mark M. |
hello, midas!
|
Mark M. |
how can I help you today?
|
midas |
Hey Mark
|
midas |
Best way to explain my question is by first explaining the background:
|
midas |
My company develops a platform for supermarket chains. Our customers are the chains. A recent change gave the individual stores of the chain the ability to adjust their branding. They choose a primaryColor and a secondaryColor. On app load I get the colors from the server.
|
midas |
Is there a way for me to use those colors as the Material Design theme for the app?
|
midas |
Even though its not defined in an xml
|
Mark M. |
why isn't it defined in a resource?
|
Aug 31 | 9:05 AM |
Mark M. |
I have to imagine that these apps are white-label custom builds
|
Mark M. |
so other resources (app name, icon, etc.) would vary
|
Mark M. |
oh, wait -- *individual stores* out of the chain?
|
midas |
Each individual store can define it on the fly in their management system.
|
midas |
yes
|
Mark M. |
I'm stunned that any chain would consider that to be a feature, rather than a bug
|
Mark M. |
but, that's just me
|
midas |
what do you mean?
|
midas |
oh I get you, the chain should control all the branding
|
midas |
yeah I agree
|
Mark M. |
right
|
midas |
but I just work here
|
Mark M. |
the app is by chain, though -- does the user somehow associate their copy of the app with a "favorite store", and that's where the color choice comes into play?
|
midas |
thats another terrible design choice if you ask me, the app is by chain (every chain has its own app) and the the user must choose a store before he can use the app
|
Mark M. |
"before he can use the app" -- yeah, that's bizarre
|
midas |
what can I say
|
midas |
above my pay grade
|
Mark M. |
are you using appcompat-v7 (AppCompatActivity, etc.), or are you using Theme.Material and kin directly with Activity/FragmentActivity
|
midas |
anyway, back to the issue at hand
|
midas |
I get the colors at runtime
|
midas |
can I use them for the theme?
|
Mark M. |
you can't use them for the theme directly, as that's a resource
|
Mark M. |
are you using appcompat-v7 (AppCompatActivity, etc.), or are you using Theme.Material and kin directly with Activity/FragmentActivity?
|
Aug 31 | 9:10 AM |
midas |
AppCompat
|
midas |
support down to API 16
|
Mark M. |
AFAIK, AppCompat's magic comes down to two things: their custom LayoutInflater, and a custom ContextThemeWrapper
|
Mark M. |
because the notion of primary/accent colors and tints and stuff did not exist in the platform prior to Android 5.0, they rely on the custom LayoutInflater to convert all your TextView, EditText, Button, etc. widgets into AppCompatTextView, AppCompatEditText, AppCompatButton, etc.
|
midas |
right, and I can insert myself into that process?
|
Mark M. |
AFAIK, they then get the primary and accent colors from the ContextThemeWrapper, which gets them from the custom attributes in the style resource
|
Mark M. |
AppCompatActivity does not have setters for things like the primary and accent colors
|
Mark M. |
so, if my understanding is correct, you would need to wrap their ContextThemeWrapper in your own, where you override their methods for getting those color values
|
Mark M. |
actually... see how Palette works
|
Mark M. |
Palette is the support library class that examines a Bitmap and synthesizes primary and accent colors based on the colors used in the image
|
midas |
hmmm
|
Mark M. |
that's all dynamic, as it is based on the image
|
midas |
that sounds very similar to what I want
|
Mark M. |
so, poke around the source code to Palette and see if you can reproduce its implementation
|
Aug 31 | 9:15 AM |
Mark M. |
it might get icky, as it might rely on internal implementation of the support libraries
|
midas |
yeah sounds like a good place to start. thanks
|
midas |
if I find anything do you want me to let you know?
|
Mark M. |
for educational background, I wouldn't mind knowing
|
midas |
np
|
midas |
thanks again
|
Mark M. |
you might also look at themeing engines on the Android Arsenal: https://android-arsenal.com/search?q=theme
|
midas | has left the room |
Aug 31 | 9:40 AM |
midas | has entered the room |
Mark M. |
hello, again!
|
Mark M. |
not sure if you caught my last comment before you headed off, but you might also look at themeing engines on the Android Arsenal: https://android-arsenal.com/search?q=theme
|
midas |
I didn't see that
|
midas |
glad I came back
|
midas |
I dont think that Palette is the way to go
|
midas |
heres a sample from the docs
|
midas |
View paste
|
midas |
as you can see
|
midas |
it doesn't generate or change primary or accent
|
Mark M. |
hmmm... I must have been mis-remembering or something
|
Mark M. |
could've sworn that in the demos it affected everything
|
midas |
anyway, Ill look into ContextThemeWrapper for a more manual implementation
|
midas |
and the theme generators
|
Mark M. |
sorry for the wild goose chase I led you down
|
midas |
np it was a good place to start
|
midas |
take care
|
Aug 31 | 9:45 AM |
Mark M. |
you too!
|
midas | has left the room |
Aug 31 | 9:55 AM |
Mark M. | turned off guest access |