Device Setup Library - Remove Log Out Button For Two Legged Auth

Hi there,

I’m building a product using Two Legged Auth. I’ve got it all working with our server and the Android app with the ParticleDeviceSetupLibrary v0.5.3 and I’m setting the user’s access token on the ParticleCloudSDK library.

My issue is that the device setup activities have a ‘Log Out’ button which, if pressed, brings the user to a login screen that means nothing to them because they don’t actually have a particle login. Thus, I want to remove/hide this button.

I can’t get to the button because it’s buried in the library and I can’t extend the ParticleDeviceSetupLibrary class due to its restrictions. The only other thing I can think of at the moment is to fork the whole (daunting) repo to edit the activities, which seems like a lot of extra work for a relatively small gain as I’m fairly new to Android development and am still confused about DI stuff.

Does anyone have any suggestions on how to do this?

Cheers,
James

Hi James,

You don’t need to extend or fork the whole repo. You can bypass login/logout by using ParticleDeviceSetupLibrary.initWithSetupOnly instead of ParticleDeviceSetupLibrary.init (the recommended way) or create activity_discover_device.xml layout inside your project, there you can copy and modify our layout used inside setup library.

<LinearLayout
    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"
    android:orientation="vertical"
    android:paddingBottom="12dp"
    tools:context="io.particle.android.sdk.devicesetup.ui.DiscoverDeviceActivity">

    <include layout="@layout/brand_image_header"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:clipChildren="false"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="96dp"
            android:layout_height="96dp"
            android:layout_marginBottom="4dp"
            android:layout_marginTop="8dp"
            android:contentDescription="@null"
            android:src="@drawable/device_image_small"/>

        <TextView
            android:id="@+id/wifi_list_header"
            style="@style/SectionHeader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/wifi_list_header_text"/>

        <fragment
            android:id="@+id/wifi_list_fragment"
            android:name="io.particle.android.sdk.devicesetup.ui.WifiListFragment"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1"
            tools:layout="@layout/row_wifi_scan_result"/>

        <TextView
            android:id="@+id/msg_device_not_listed"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="4dp"
            android:gravity="center"
            android:padding="8dp"
            android:text="@string/msg_device_not_listed"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textSize="@dimen/text_size_nano"/>

        <TextView
            android:id="@+id/action_troubleshooting"
            style="@style/LinkText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="12dp"
            android:gravity="center"
            android:text="@string/troubleshooting"
            android:visibility="gone"/>

        <TextView
            android:id="@+id/logged_in_as"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:gravity="center"
            android:text="@string/you_are_logged_in_as"
            android:textColor="@color/normal_text_color"
            android:textSize="@dimen/text_size_micro"/>

        <Button
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:id="@+id/action_log_out"
            style="@style/SparkButton"
            android:layout_marginBottom="12dp"
            android:text="@string/log_out"/>

        <Button
            android:id="@+id/action_cancel"
            style="@style/SparkButton"
            android:layout_marginBottom="8dp"
            android:text="@string/cancel"/>

    </LinearLayout>

</LinearLayout>

Note I set action_log_out button width and height to 0dp.

1 Like

Thank you julius!

I was using initWithSetupOnly wrong, and I didn’t quite realise that overriding the layout in my project would work like that. Good to know for other things!

Changing the width and height to 0dp almost works…

but it leaves a drop shadow. Any idea of how to get rid of that?

Cheers,
James

You are right setting width and height leaves a shadow. You can do this instead then:

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone">

            <Button
                android:id="@+id/action_log_out"
                style="@style/SparkButton"
                android:layout_marginBottom="12dp"
                android:text="@string/log_out"/>
        </FrameLayout>
1 Like

Yep. That did it!

Thanks again, Julius.

@Raimis is there a good way to do this on iOS? I tried setting the initWithSetupOnly option by calling:

if let setupController = ParticleSetupMainController.init(setupOnly: true)
        {
            setupController.delegate = self //as! UIViewController & ParticleSetupMainControllerDelegate
            self.present(setupController, animated: true, completion: nil)
        }

Unfortunately, this still has the log out button showing on the device setup process. I’m new to swift programming… so it’s very possible I’m doing something wrong as well.

Try adding:
ParticleSetupCustomization.sharedInstance().disableLogOutOption = true

Yep that did the trick! Thanks! Had missed that option in the customization file.