Change colorPrimary and colorAccent programmatically for use in ContextThemeWrapper - android-view

I'm working on a live event app for a client. There are about 20 view containers that make heavy use of colorPrimary and colorAccent for coloring the views.
The client has just now decided that those colors should be different for each event.
Is there any way for me to use ContextThemeWrapper to simply inject the colorAccent and colorPrimary received from the backend? That way, when I start EventActivity, I can just put in the correct colors, and those would propagate all the way down to the activity's View, Fragment, and Dialog children.
If that's not possible, I guess I will have to go through each View one by one in Java and set the appropriate colors. That's tedious but easy. What's not easy are my shapes defined in XML. For instance, I have a drawable that I use as a button background which is simply a 1dp stroke on a rectangle with rounded corners. The color of the stroke is colorAccent. How would I go about changing that at runtime?

Related

iOS How to get size of chart grid?

I have used Charts library to make my chart. It really has ton of options, but I have been struggling to implement background for grid. I want to have gradient background, but just for grid part. I have done this by putting my view behind the chart view. I have printed _viewPortHandler.contentRect, and from there i positioned my view. Now, while this works, it is not most ideal solution. I would like to somehow at runtime have option to get gridview size, but since _viewPortHandler is internal, I see no option to do this:
Is there any better way to do this?

How to prevent a firemonkey form to draw itself (for calling an own drawing function)?

I try to convert an existing OpenGL-Application from VCL-based forms to FMX-based forms in C++ Builder XE3.
For this purpose I use the handle of a Firemonkey-form to create the OpenGL device context and make this form a child of another form to mimic the panel inside the form which I had in my VCL-based application.
The problem is now that after a resize-event or in general after calling Invalidate() the form is rendered with its background. This causes a flickering or even worse: sometimes the background is shown instead of my OpenGL rendered scene.
How can I prevent the repaint of the region at the position of my Firemonkey-OpenGL-form. Alternatively, can I define an Ownerdraw-function or something else?
Please note, that it is no option for me to use a Firemonkey-3d-Form.
Have tried giving the form a transparent background? Then you can paint whatever you want 'over the top'.
The quick way is to set the forms Transparent property to True, but this creates issues with ComboBoxes.
Another way is to place a TRectangle on the form. Set it's StyleName to 'backgroundstyle'. Set it's Fill.Color to claNull. Set Stroke.Thickness to 0. This will replace the default background styling for the form.
If you want to paint your own borders too you'll need to investigate non-client area styling but I don't have a pointer to a good resource at present.
After hours of experimenting I found the solution: The "TCommonCustomForm" has the needed properties: (1) it does not draw itself, (2) it has a handle which can be used for OpenGL initialization.
I hope this information will help others.

How to hide border around TRadioGroup

I have two radiobuttons in a TRadioGroup. All the logic behind how they are supposed to work is fine. But the TRadioGroup controler has a frame around it that I thought I would be able to delete using a border property or something like that. But the control doesn't seem to have any property that bears any resemblance to a border/frame. How do I set the controler to not include a frame?
TRadioGroup does not support what you are looking for. Place two TRadioButton components onto a TPanel instead. Then you can make it look how you want.
I don't think you can hide the border on a standard radio group box. It looks like you could create a custom descendant and override the painting if drawing normally, but that approach could be a bit more involved with theme support. Overall it sounds like a lot of work to go that route.
The next most obvious approach is to replace the radio group with a number of individual radio buttons on a container such as a panel. That would work and would be simple code but it could get messy. It seems a lot of busy work for little gain and I am lazy enough to look for another option.
There is a kludge you can use. If you put the radio group on a panel rather than directly onto the form (or other background) you can make the panel under-sized compared to the radio group. You want the panel to be as big as the interior of the radio group but not as big as the border. Then set the top and left of the radio group to negative numbers so that the border falls outside the parent panel. The border is not visible this way.
I know it's not best practice but I had a similar issue and couldn't redesign everything. So I did this to simply hide the border (and works great so far).
HANDLE Region = CreateRectRgn(3, 3, RadioGroup->Width-3, RadioGroup->Height-3) ;
SetWindowRgn(RadioGroup->Handle, Region, true);

What UI element might this be? (Custom tab-bar?)

http://www.flickr.com/photos/fraserspeirs/4329430635/in/set-72157623224262135/
The above is a link basically showing the form fill view of the numbers app on the iPad. Any idea as to how to achieve such a functionality which sort of looks like our vanilla tabs on Chrome?
You could do it with just buttons set to Custom type and using an image for the background. Then when they are clicked, bring the specific UIView to the front.
To create the tabs from a single image use UIImage's stretchableImageWithLeftCapWidth: topCapHeight:
http://tcninja.blogspot.com/2010/09/ios-adding-stretchable-uiimage-as.html
This will let you dynamically set the image's width in a way that will use the middle of it to fill the new area rather than stretching (and warping) the outer edges.
I would have implemented this with simple UIButtons. All you need to do is to style them (pngs or whatever), and track which one is the current.

Avoid painting over nested controls

I am writing a toolbar-style control and use the ThemeServices unit to paint the background required by the toolbar. Like so:
ThemeServices.DrawElement(Canvas.Handle,
ThemeServices.GetElementDetails(trRebarRoot), ARect);
I then drop child controls onto the toolbar and voila - instant toolbar. Except that every now and again I notice that the nested (child) controls don't repaint as well. So my control paints its background and the child controls disappear until you move the mouse over them.
Some of the edit controls show their client area (no border) and some of them are just gone altogether.
This happens mostly when I place a window from another application over the toolbar and move it away.
I keep thinking this has to be very easy to cure, that perhaps I'm somehow preventing the paint message from reaching the child controls, or missing an override but I have been unable to figure it out.
For this to work properly so you do not end up over-painting the child controls from the WM_NCPaint, you can use the Window's GDI Region functions to create a clipping region which excludes the areas you do not want to paint.
You can do this by creating a Region using the CreateRectRgn (or similar) function with the size of your background.
Select this region in to the DC you are using via the SelectClipRgn function.
Next, loop through the top level child windows on your toolbar / panel and calling ExcludeClipRect with the appropriate coords for each child.
Finally when you paint, only the area's that have not been excluded will be painted.
Also be aware you might need to clear up your region (best check the GDI help).
That's normal for a canvas to have to repaint when covered by another windows control.
You should draw your tool bar in the OnPaint event of the container control.
OK, I found the problem myself. I was drawing the background in WM_NCPAINT because it is a gradiated background that cannot really be drawn bit by bit. I didn't realize that WM_NCPAINT is often called without the client controls being repainted. So I still paint the background in WM_NCPAINT but also in WM_PAINT. The latter is already clipped to exclude the border and to get the former to clip the client area, I called ExcludeClipRect.
This works like a treat.

Resources