touch4j 4.0 google map UIbinder change view

To change view:

add an abstract class for content:


public abstract class Content extends Composite
{
}

Inside the  TouchEntryPoint:

private static final HelloTouch INSTANCE = new HelloTouch();
    private Content content;

    public static HelloTouch getInstance(){
        return INSTANCE;
    }

    public void onLoad()
    {
        HelloTouch.getInstance().setContent(new MyGoogleMap());
    }

    public void setContent(Content content){
        this.content = content;
        ViewPort.get().clear();
        ViewPort.get().add(content);
    }

For UI binder, same way as we use in GWT.

Just add the touch4j namespace:

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
             xmlns:g='urn:import:com.google.gwt.user.client.ui'
             xmlns:touch="urn:import:com.emitrom.touch4j.client.ui">
   <touch:Panel ui:field="container"  >
      <touch:ToolBar docked="top" title="My ToolBar">
         <touch:Button text="Back"  ui="back" ui:field="backButton"  />
         <touch:Spacer />
         <touch:Button  ui="plain" iconMask="true" iconCls="info"  ui:field="infoButton" />
      </touch:ToolBar>
      <touch:GoogleMap useCurrentLocation="true" />
   </touch:Panel>
</ui:UiBinder>

The corresponding class could be:

interface xxx extends UiBinder<Panel, MyGoogleMap>
    {
    }

    private static xxxUiBinder ourUiBinder = GWT.create(xxxUiBinder.class);

    @UiField
    Button infoButton;
    @UiField
    Button backButton;

    public MyGoogleMap()
    {
        Panel rootElement = ourUiBinder.createAndBindUi(this);

        infoButton.addTapHandler(new TapHandler()
        {
            @Override
            public void onTap(Button button, EventObject event)
            {
                MessageBox.alert("Welcome Here");
            }
        });

        backButton.addTapHandler(new TapHandler()
        {
            @Override
            public void onTap(Button button, EventObject eventObject)
            {
                 HelloTouch.getInstance().setContent(new SecondView());
            }
        });

        initWidget(rootElement);
    }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s