How to override Mage_Tax renderer in Magento - overriding

I want to override the getShippingIncludeTax() method in the class Mage_Tax_Block_Checkout_Shipping , this block is defined as a renderer in the config;
<sales>
<quote>
<totals>
<shipping>
<renderer>tax/checkout_shipping</renderer>
</shipping>
</totals>
</quote>
</sales>
I can override a block if needed, but this class doesn't have any Block definition. How do I override this?
NOTE: This is not a typical Block override.

You can just create a module that overrides Mage_Tax_Block_Checkout_Shipping...
<global>
<blocks>
<tax>
<rewrite>
<checkout_shipping>Test_TestModule_Block_Tax_Checkout_Shipping</checkout_shipping>
</rewrite>
</tax>
</blocks>
</global>

Related

Why doesn't my TemplateBinding to my custom TemplatedView's BindableProperty work

Here's my XAML:
<?xml version="1.0" encoding="UTF-8"?>
<TemplatedView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:control="clr-namespace:Core.View.Control"
x:Class="Core.View.Control.MyButton">
<TemplatedView.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="MyButtonTemplate">
<Grid BackgroundColor="Teal">
<!-- other irrelevant stuff. Trust me, it's irrelevant. -->
<Grid x:Name="MyGrid" Grid.Row="1" ColumnSpacing="0" BackgroundColor="{TemplateBinding Parent.BGCol}"> <!-- Can't get this TemplateBinding to work -->
<!-- If I change the above to something static, like BackgroundColor="Orange", it works. -->
</ControlTemplate>
<Style TargetType="TemplatedView" x:Key="MyButtonStyle">
<Setter Property="ControlTemplate" Value="{StaticResource MyButtonTemplate}" />
</Style>
And my code behind:
namespace Core.View.Control
{
public partial class MyButton : TemplatedView
{
public static readonly BindableProperty BGColProperty =
BindableProperty.Create("BGCol", typeof(Color), typeof(MyButton), Color.Orange);
public Color BGCol
{
get
{
return (Color)GetValue(BGColProperty);
}
set
{
SetValue(BGColProperty, value);
}
}
public MyButton()
{
InitializeComponent();
Style = (Style)this.Resources["MyButtonStyle"];
}
// ...
If I change BGColproperty to be of type string and use "Orange" instead of Color.Orange everywhere...it still doesn't work.
How do I bind the background property of the Grid control in my ControlTemplate to BGCol?
[ignore]
Irrelevant text because SO is still not happy, saying too much code.
Sometimes code with inline comments (as I've done) pretty much explains it better than any amount of text can, and you'd think that a site like SO would understand this, but nah.
More blabber.
More still.
Oh here we go, this seems enough.
[/ignore]
<Grid x:Name="MyGrid" BackgroundColor="{TemplateBinding BGCol}" >
Template Bindings go to the control, so the Parent is just confusing it.

gwt 2.7.0 background-image for body

I'd like my login page to have a background image in the body. Here's what I have so far:
public interface MyResources extends ClientBundle {
public static final MyResources INSTANCE = GWT.create(MyResources.class);
#Source("css/login.css")
public MyLoginCssResource loginCss();
#Source("css/GWT_App.css")
public CommonCss commonCss();
#Source("img/logo.png")
#ImageOptions(repeatStyle = RepeatStyle.Both)
ImageResource backgroundImage();
}
public interface CommonCss extends CssResource {
String body();
}
.body {
background-color: white;
gwt-image: 'backgroundImage';
}
How do I reference the commonCSS in my ui.xml-file if I already have the loginCss referenced?
<ui:with field='res' type='client.resources.MyResources' />
<g:HTMLPanel addStyleNames="{res.loginCss.maindiv}">
</g:HTMLPanel>
</ui:UIBinder>
and also, how can I set a style for the body tag in a ui.xml-file?
How do I reference the commonCSS in my ui.xml-file if I already have the loginCss referenced?
<g:HTMLPanel addStyleNames="{res.loginCss.maindiv} {res.commonCss.body}"/>
and also, how can I set a style for the body tag in a ui.xml-file?
As far as i know you can't access body from ui.xml file.
There're a few ways to have this background ONLY in the login page.
The simplest one is to wrap all the page in a container block
<g:FlowPanel addStyleNames="{res.commonCss.body}">
<g:HTMLPanel addStyleNames="{res.loginCss.maindiv} "/>
</g:FlowPanel>
So on the navigation from the login page - the background won't stay there.
And in case you want a permanent effect - you can just add css in your index.html file, as a regular css for body tag

android-tv Changing text color and font of browse fragment rows header

How to change text color and font of rows header in browse fragment?.
The text not in menu but the text that appears above the rows.
I am assuming you are using the provided android.support.v17.leanback.widget.RowHeaderPresenter as the presenter for the HeaderFragment in your BrowseFragment.
The RowHeaderPresenter inflates the layout from R.layout.lb_row_header which looks like this:
<android.support.v17.leanback.widget.RowHeaderView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/row_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?rowHeaderStyle" />
As you can see, this uses a style attribute called rowHeaderStyle, which is normally pointing to #style/Widget.Leanback.Row.Header. You can override this by putting the following in your styles.xml:
<style name="MyCustomRowHeaderStyle" parent="Widget.Leanback.Row.Header">
<item name="android:textColor">#color/red</item>
</style>
<style name="MyCustomBrowseStyle" parent="Theme.Leanback.Browse">
<item name="rowHeaderStyle">#style/MyCustomRowHeaderStyle</item>
</style>
And then use MyCustomBrowseStyle for the Activity containing the BrowseFragment by declaring it in your AndroidManifest.xml.
In addition to David's answer.
rowHeaderStyle applies the style both to menu items in HeaderFragment and row titles in RowFragment (these two fragments compose your BrowseFragment).
If you want their styles (font colors in particular) to be different, you can override BrowseFragment::onCreateHeadersFragment() and apply specific theme at that point.
1) Add these styles to styles.xml:
<style name="AppTheme.Leanback.Browse.Row" parent="#style/Theme.Leanback.Browse">
<item name="rowHeaderStyle">#style/AppTheme.Leanback.Row</item>
</style>
<style name="AppTheme.Leanback.Browse.Header" parent="#style/AppTheme.Leanback.Browse.Row">
<item name="rowHeaderStyle">#style/AppTheme.Leanback.Header</item>
</style>
<style name="AppTheme.Leanback.Row" parent="Widget.Leanback.Row.Header">
<item name="android:textColor">#color/font_row</item>
</style>
<style name="AppTheme.Leanback.Header" parent="Widget.Leanback.Row.Header">
<item name="android:textColor">#color/font_header</item>
</style>
2) Apply AppTheme.Leanback.Browse.Row theme to your activity in manifest.
3) Apply AppTheme.Leanback.Browse.Header theme to headers in your BrowseFragment:
// Kotlin snippet
override fun onCreateHeadersFragment() : HeadersFragment {
class CustomHeadersFragment : HeadersFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return super.onCreateView(
inflater.cloneInContext(ContextThemeWrapper(inflater.context, R.style.AppTheme_Leanback_Browse_Header)),
container,
savedInstanceState
)
}
}
return CustomHeadersFragment()
}
The answer by david.mihola helps with the color, however I still had problems with setting a custom font globally. For everybody who stumbles upon this question and is puzzled about this as well, here is my solution:
Thanks to the awesome work done by chrisjenx (Calligraphy), you can easily set a global (custom) font.
Simply add Calligraphy to your gradle.build and add the following snippet to your Application.onCreate():
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/MyCustomFont.ttf")
.setFontAttrId(R.attr.fontPath)
.build()
);
and in every Activity add the following:
#Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
This has done the font-trick for me on every single TextView, without modifying layouts. The documentation of Calligraphy also offers some more possibilities. Check it out.
I hope this helps other people who find this question and are trying to set (custom) fonts globally.

How to properly use CSS in GWTP?

it's very difficult to find a complete step-by-step guidelines of How to properly use CSS in GWTP on internet.
I am using eclipse & GWTP to build my app & I want to set some simple Css styles for my widgets (button, textbox...).
Ok, here is what I got: a TestPresenter.java, TestView.java & TestView.ui.xml
-In TestView.ui.xml:
<ui:UiBinder .....>
<ui:style src='myStyle.css' />
<g:HTMLPanel>
<g:Button text="My But 1" addStyleNames="{style.myBut}" ui:field="myBut1"/>
<g:Button text="My But 2" ui:field="myBut2"/>
</g:HTMLPanel>
</ui:UiBinder>
myStyle.css is in the same folder that houses TestPresenter.java, TestView.java & TestView.ui.xml
-TestPresenter.java (has 2 buttons- myBut 1 & myBut 2): I added "myBut" for myBut2
getView().getMyBut2().addStyleName("myBut");
After running, it shows 2 buttons, the first myBut1 got the correct CSS but myBut2 still show the default Css. I changed to getView().getMyBut2().setStyleName("myBut"); but it still didn't work.
So i think probably i'm missing some classes here & that is why eClipse couldn't recognize "myBut" CSS so that it can apply for myBut2.
So, How to let myBut2 show the correct Css in eClipse?
the reason is that adding a CSS style sheet as a source to the uibinder causes the gwt compiler to generate a CssResource class for it, and therefore obfuscating the CSS class name to SHA1 hash.
That mean that in the final compiled version, instead of ".myBut" you actually end up with something like ".XYZXYZ".
this is purely GWT uibinder behavior that you can read about here
Specifically for GWTP, the textbook solution is:
in TestView.java add:
public TestView extends SomeGWTPViewClass implements TestPresenter.MyView
{
public interface MyStyle extends CssResource
{
String myBut();
}
#UiField MyStyle style;
#Override
MyStyle getStyle()
{
return style;
}
//rest of code here......
.....
...
}
in TestView.ui.xml change ui:style to:
<ui:style src='myStyle.css' type="fully.qualified.package.name.TestView.MyStyle"/>
in TestPresenter.MyView interface add:
MyStyle getStyle();
now you can access the myBut style in TestPresenter by:
getView().getMyBut2().addStyleName(getView().getStyle().myBut());

How to declare dependent style names with UiBinder

I have a simple UiBinder widget containing a TextArea:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:TextArea visibleLines="3" />
</ui:UiBinder>
I want to control the background color of this textarea for writeable and read only states. GWT uses the "-readonly" style name decorator to achieve this. So I try this:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.textBoxStyle {
background-color:yellow;
}
.textBoxStyle-readonly {
background-color:lightgray;
}
</ui:style>
<g:TextArea styleName="{style.textBoxStyle}" visibleLines="3" />
</ui:UiBinder>
Obviously this won't work because style names are obfuscated for CssResources resulting in something like this:
.G1x26wpeN {
background-color:yellow
}
.G1x26wpeO {
background-color: lightgray;
}
The result HTML for writeable textarea looks like this:
<textarea tabindex="0" class="G1x26wpeN" rows="3"/>
The read only textarea looks like this:
<textarea tabindex="0" class="G1x26wpeN G1x26wpeN-readonly" readonly="" rows="3"/>
How do I declare the style so GWT will obfuscate the primary part but not the "-readonly" decdorator?
I know that I can disable the obfuscation for the entire style name. But I'd like to keep the obfuscation while making use of the decorators.
At this moment (GWT 2.4) it is not supported, and it's not clear if/when it will be supported, see issue 4746 in the GWT issue tracker.
The workaround is to add #external, which disables obfuscation for those styles. In this case that would be:
#external textBoxStyle, textBoxStyle-readonly;
If you want to use this style for all your read-only TextAreas then I'd suggest just modifying the .gwt-TextArea-readonly style in your GWT theme CSS file.
Otherwise, I can only think of adding your custom style programmatically when you set the TextArea read-only.
PS: from the docs:
<set-configuration-property name="CssResource.obfuscationPrefix" value="empty" />` can be used for minimal-length selector names, but this is only recommended when the GWT module has total control over the page.
I recommend using this (with "empty" or "X" or other unused prefix) for much shorter class names - because at default settings you don't gain that much through obfuscation (textBoxStyle - 12chars, G1x26wpeN - 9chars, X0 - 2 chars ;)).
Why don't you try sth like this
public class MyFoo extends Widget {
interface MyStyle extends CssResource {
String normal();
String readonly();
}
#UiField MyStyle style;
/* ... */
void setEnabled(boolean enabled) {
getElement().addStyle(enabled ? style.normal() : style.readonly());
getElement().removeStyle(enabled ? style.readonly() : style.normal());
}
}
this would allow you change style if a text box is "normal" or readonly...
And off course, in the UiBinder you should have sth like
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>
<ui:style type='com.my.app.MyFoo.MyStyle'>
.redBox { background-color:pink; border: 1px solid red; }
.normal { color:black; }
.readonly { color:gray; }
</ui:style>
<div class='{style.redBox} {style.normal}'>I'm a red box widget.</div>
</ui:UiBinder>
Try Now This One I Hope You will get it.
With the <ui:style> element, you can define the CSS for your UI right where you need it
Note: <ui:style> elements must be direct children of the root element
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:TextArea visibleLines="3" />
</ui:UiBinder>
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style field='MyStyle'>
.textBoxStyle {
background-color:yellow;
}
.textBoxStyle-readonly {
background-color:lightgray;
}
</ui:style>
<g:TextArea name="myText" styleName="{MyStyle.textBoxStyle}" visibleLines="3" />
</ui:UiBinder>
Isn't there a typo in your UIBinder?
You have:
<g:TextArea styleName="{style.textBoxStyle}" visibleLines="3" />
.. but I think you need to be using "stylePrimaryName", ie.
<g:TextArea stylePrimaryName="{style.textBoxStyle}" visibleLines="3" />
But I guess this question has been answered really already..
Here's something valuable I figured out by putting together info from other posts in this thread especially...
If you use #external, you can override gwt styles. The problem is that is this change gets applied globally! It is possible, however, to extend & override select attributes without effecting every instance of a widget type. (This like the programmatic styling method of creating a css class with a gwt class name + a suffix and using addStyleDependantName().)
Here is an example of using UIBinder + a CssResource to extend a gwt style. I left out the CssResource part, but you'll get the idea...
In your xxxx.ui.xml file, expose the gwt style, but don't mess with it!
<ui:style>
#external .gwt-Button; .gwt-Button {}
</ui:style>
Then, style a widget it by specifying 2 (or more) styles in the styleName attribute. I.e. the gwt style, and the one (or more) from your resource.
<g:Button ui:field="submitButton_" text="Submit" styleName="{style.gwt-Button} {res.loginStyles.submitButtonStyle}" />
Here's the css class:
.submitButtonStyle{
margin: 3px 5px 5px 0px;
}
In this case, I defined a button that is styled in the standard method (easily changed via module inheritance) but with a specific margin that will remain fixed. This didn't mess up the global style, it didn't require defining all the attributes manually, and allowed for swapping the global styling at will with clean.css, dark.css, etc.

Resources