Tooleap and B4A – Part 6 : Other considerations

There are some additional important things to note when using Tooleap.

  • If you are using view positions in %x,%y your view positions can be a bit off. Also affects popup menus. Make sure you adjust your layout for miniApp mode and normal mode if you need to use it in both.
  • Do not use Dialogs. This means MsgBox/InputList/CustomDialogs/BetterDialogs etc.
  • MiniApp icon should be atleast 30dip x 30dip
  • If you call StartActivity from the miniApp it will close the miniApp/sidebar.
  • When the application runs the miniApp, it gets cleared from recent tasks menu.
  • After the HOME button is pressed, it takes longer to load the miniApp (5 seconds). This is Android’s security feature.

 

Multiple instances of same activity

You can use the same activity for multiple purposes (for instance different conversations in a chat app etc). This can be done, as whenever you launch an activity for one type you can use the appID to distinguish between different instances, and load different data accordingly.

Tooleap and B4A Part 5: Launching a MiniApp

You can launch your miniApp from another activity or service. To manage your miniApps you will need to use the MSTooleapManager object. This object allows you to add/remove or find your miniApps.

To create and set up a particular miniApp you will need to use the MSTooleapMiniApp object.

Lets see how to create and start an activity in miniApp mode and also to set up its notification object.

We start off by creating an intent to our activity. This is in the format of “<packagename>/.<activityname>”. (There were probably easier ways to do this but I chose this to remain flexible)

 Dim i1 As Intent
i1.Initialize("","")
i1.SetComponent("com.maximussoft.tooleap/.test")

Then we set up our miniApp object:

TooleapMiniApp1.Initialize(i1,TooleapMiniApp1.TYPE_POPOUT_MINIAPP)
TooleapMiniApp1.ContentTitle = "A sample Title"
TooleapMiniApp1.ContentText = "content TExt"
TooleapMiniApp1.NotificationText = "Notification Text!"
TooleapMiniApp1.NotificationBadgeNumber = 3
TooleapMiniApp1.bubbleBackgroundColor = Colors.Transparent

Simple stuff, just setting up the Header/Titles.

Now to actually start the floating notification we need to add the miniApp using the manager.

appID = TooleapManager1.addMiniApp(TooleapMiniApp1)

That is it! That will start a notification, and when you click on the notification, it will launch your activity in miniApp mode.
You can customise the miniApp more using the object, and can manage them using the manager object. You can remove all miniApps or remove particular ones, and list them all etc.

Tooleap and B4A Part 4: Creating a Tooleap Activity in B4A

Once you create a Tooleap Activity, it can be used in normal mode or in miniApp mode (but only one at a time).

To set up your activity as a Tooleap Activity, you need to follow some steps. Firstly, we will change the activity type by using the following activity attribute (in your activity attributes section).

#extends: com.tooleap.sdk.TooleapActivities.Activity

Then in your manifest, you need to add the following lines (remember to replace with your activity name):

AddActivityText(test,
<intent-filter>
<action android:name="com.tooleap.sdk.TOOLEAP_SHOW"/>
</intent-filter>
)
SetActivityAttribute(test, android:theme, "@android:style/Theme.Translucent")
SetActivityAttribute(test, android:launchMode, "singleInstance")
SetActivityAttribute(test, android:taskAffinity, ".tooleap")

That is all the preparation that is required.

Now remember in miniApp mode the size of the Activity will be different (80%x, 100%y-105dip). In order to find out if the activity is in normal or miniApp mode you can use the MSTooleapActivityHelper object:

Dim TA As MSTooleapActivityHelper

If TA.isStartedByTooleap Then
    lbl.Text = "Started by Tooleap"
Else
    lbl.Text = "Started in normal mode"
End If

To get the current activity’s app id (each miniApp must have its own ID)

Dim appID As Long = TA.getCurrentActivityTooleapAppId 

 

Tooleap and B4A Part 3: Installation of Tooleap library and Application setup

The following library files need to be in your AdditionalLibs folder (these are all available in the B4A forum post here):

  • TooleapHelper (both jar/xml)
  • the latest tooleap sdk jar (current is tooleap-sdk-0.9.4.jar)

Before we start we need to make some manifest changes to the Application level.

These lines need to be added to your manifest editor:

For permissions:

AddManifestText(
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.GET_TASKS" />)

For Tooleap’s internal services:

AddApplicationText(
<service android:name="com.tooleap.sdk.TooleapAppService"/>
<service android:name="com.tooleap.sdk.TooleapUIService"
         android:process=":UIService"
         android:exported="true">
         <intent-filter>
                <action android:name="com.tooleap.sdk.BIND_UI_SERVICE" />
         </intent-filter>
</service>
<receiver android:name="com.tooleap.sdk.TooleapReceiver">
         <intent-filter>
               <action android:name="android.intent.action.PACKAGE_REPLACED"/>
               <data android:scheme="package"/>
         </intent-filter>
         <intent-filter>
               <action android:name="com.tooleap.sdk.TOOLEAP_ACTION"/>
         </intent-filter>
</receiver>)

Once you add these you are ready to start writing your Tooleap Activity/MiniApp.

Tooleap and B4A Part 1: Introduction

I came across a pretty cool SDK called Tooleap. In their words:

Tooleap is an Android SDK which brings your app to the forefront
of a user’s device screen with a floating (always-on-top) UI,
thus creating a unique multitasking experience and increasing
your app’s availability and usability.

From what I understand Tooleap functionality consists of two parts.

1. A rich floating notification. This can notify the user of new data, or just be available to interact with from anywhere.

2. MiniApps, which are a slide-out window providing the same functionality of a usual activity, without losing context of the previous activity.

After reading their SDK I didnt think we would be able to use it in B4A since it required us to subclass Activity which we never had been able to do before, but Erel gave us a lifeline and now we are able to subclass Activity, thus being able to use this SDK.

I wrote some thin Java wrappers to get the functionality into B4A.


Dim TooleapManager1 As MSTooleapManager
Dim TooleapMiniApp1 As MSTooleapMiniApp
Dim TooleapActHlper As MSTooleapActivityHelper