01 – SitumWYF & Fragments (Android only)

Our Quickstart guide shows you how to load Situm WYF in an Android Activity. This is a common escenario, but it is also common to load it in a Fragment. Fortunately, Situm WYF provides the means to do it easily by using the method SitumMapsLibrary.loadInFragment, which accepts an androidx.fragment.app.Fragment where SitumWYF will load.

In this example, we will assume that you will load your Fragment from the MainActivity, but you can do it anywhere else. First, you need to define your MainActivity layout in “res/layout/activity_main.xml”. For instance:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <FrameLayout
        android:id="@+id/my_placeholder" 
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>
</LinearLayout>

Then, in our MainActivity.java, you need to start the Fragment (which will be loaded in the view element previously defined in the activity_main.xml):

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.my_placeholder, new MyFragment());
        ft.commit();

    }

}

Your Fragment will be composed of two elements. The first one will be the layout, created for example in “res/layout/my_fragment.xml”. It can be as simple as:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.basicwyfapp.MyFragment">

    <FrameLayout
        android:id="@+id/maps_library_target"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</RelativeLayout>

The second one will be the Fragment itself, that will load SitumWYF as usual, but using the loadInFragment method (instead of the regular load method). You will also be able to configure the static & dynamic UI settings if you want.

public class MyFragment extends Fragment {

    SitumMapsLibrary mapsLibrary = null;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
        //Create the view using "my_fragment.xml"
        View view = inflater.inflate(R.layout.my_fragment, parent, false);
        return view;
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);

        //Create LibrarySettings
        LibrarySettings librarySettings = new LibrarySettings();
        librarySettings.setApiKey("EMAIL", "APIKEY");

        //Configure dynamic UI settings (if you want)
        librarySettings.setMinZoom(15);
        ...


        //Prepares SitumMapsLibrary to load itself on "maps_library_target" view element
        //Note that the second parameter is "this.getActivity()", since it's an androidx.fragment.app.FragmentActivity
        //When called from an Activity, we would pass "this" as a second parameter instead
        mapsLibrary = new SitumMapsLibrary(R.id.maps_library_target, this.getActivity(), librarySettings);

        //Setup listener to configure dynamic UI settings (optional)
        mapsLibrary.setSitumMapsListener(mapsListener);

        //Load WYF in Fragment!
        mapsLibrary.loadInFragment(this);
    }

    private SitumMapsListener mapsListener = new SitumMapsListener() {
        @Override
        public void onSuccess() {
            //Configure dynamic UI settings after SitumWYF view loads correctly
            mapsLibrary.centerBuilding("12485", null);
            mapsLibrary.setFloorsListVisible(true);
            mapsLibrary.setInfoViewVisible(false);
            ...

        }

        @Override
        public void onError(int i) {
            //...
        }
    };
}

And voila! SitumWYF loads in a Fragment now!

Suscríbete a nuestro boletín

INFORMACIÓN BÁSICA SOBRE PROTECCIÓN DE DATOS

Responsable del tratamiento: SITUM TECHNOLOGIES, S.L.
Contacto: Responsable del tratamiento: situm@situm.es
Responsable de protección: dpo@situm.es
Finalidad y base legal: Gestionar el envío de newsletter de SITUM sólo con consentimiento.
Legitimación: Consentimiento expreso del interesado.
Destinatarios: Los datos no serán cedidos a terceros salvo obligación legal.
Plazo de conservación: Mientras la parte interesada permanezca suscrita al newsletter (en cada newsletter enviado por Situm estará disponible un link para darse de baja).
Derechos: El interesado podrá revocar en cualquier momento su consentimiento, así como ejercitar los derechos de oposición, acceso, conservación, rectificación, limitación, supresión de datos y no ser objeto de una decisión basada únicamente en el tratamiento automatizado de datos, dirigiéndose por escrito a SITUM en las direcciones indicadas.
Información Adicional: Puede consultar la información adicional y detallada sobre Protección de Datos en nuestra política de privacidad.

Por favor, descarga tu copia aquí.

Muchas gracias por descargar nuestro whitepaper. No dudes en contactar con nosotros si quieres saber más sobre cómo nuestras soluciones pueden ayudar a tu negocio.


Cerrar ventana