Office Hours — Today, August 31

Tuesday, August 29

Aug 31
8:50 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:00 AM
midas
has entered the room
Mark M.
hello, midas!
how can I help you today?
midas
Hey Mark
Best way to explain my question is by first explaining the background:
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.
Is there a way for me to use those colors as the Material Design theme for the app?
Even though its not defined in an xml
Mark M.
why isn't it defined in a resource?
9:05 AM
Mark M.
I have to imagine that these apps are white-label custom builds
so other resources (app name, icon, etc.) would vary
oh, wait -- *individual stores* out of the chain?
midas
Each individual store can define it on the fly in their management system.
yes
Mark M.
I'm stunned that any chain would consider that to be a feature, rather than a bug
but, that's just me
midas
what do you mean?
oh I get you, the chain should control all the branding
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
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
I get the colors at runtime
can I use them for the theme?
Mark M.
you can't use them for the theme directly, as that's a resource
are you using appcompat-v7 (AppCompatActivity, etc.), or are you using Theme.Material and kin directly with Activity/FragmentActivity?
9:10 AM
midas
AppCompat
support down to API 16
Mark M.
AFAIK, AppCompat's magic comes down to two things: their custom LayoutInflater, and a custom ContextThemeWrapper
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
AppCompatActivity does not have setters for things like the primary and accent colors
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
actually... see how Palette works
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
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
if I find anything do you want me to let you know?
Mark M.
for educational background, I wouldn't mind knowing
midas
np
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
9:40 AM
midas
has entered the room
Mark M.
hello, again!
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
glad I came back
I dont think that Palette is the way to go
heres a sample from the docs
View paste
public void setToolbarColor(Bitmap bitmap) {
  // Generate the palette and get the vibrant swatch
  // See the createPaletteSync() and checkVibrantSwatch() methods
  // from the code snippets above
  Palette p = createPaletteSync(bitmap);
  Palette.Swatch vibrantSwatch = checkVibrantSwatch(p);
  
  // Set the toolbar background and text colors
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setBackgroundColor(vibrantSwatch.getRgb());
  toolbar.setTitleTextColor(vibrantSwatch.getTitleTextColor());
}
as you can see
it doesn't generate or change primary or accent
Mark M.
hmmm... I must have been mis-remembering or something
could've sworn that in the demos it affected everything
midas
anyway, Ill look into ContextThemeWrapper for a more manual implementation
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
take care
9:45 AM
Mark M.
you too!
midas
has left the room
9:55 AM
Mark M.
turned off guest access

Tuesday, August 29

 

Office Hours

People in this transcript

  • Mark Murphy
  • midas