What do you need help with?

Widget Bar Creation and Placement

Follow

Widget Bar Container is where we display the application widgets. The widget bar serves the purpose of giving user the access to control an app's widget when an app is active or running in the background. The difference with standard Android widget concept is that ReticleOS doesn't place any widget on the home screen. Instead, they will be placed in the widget bar. Also, by default, widget bar would not be displayed on the screen unless an application defines to have it side by side with it.

Basically, ODG has divided the whole Android phone window into three sections, "Status Bar", "Active App" and "Widget Bar". Currently, the height for the widget Bar is set to 70 density pixel, and the area for active app is shrank to fit the widget bar. By default, only "status bar" and "active app" sections will be displayed on the screen.

The widget bar is evenly divided into three sections, and each section is approximately 294 dip. However, developers should only keep the sizes of both width and height in mind when designing the look and feel of their widget(s). but they should not hardcode the width. Instead, they should use "match_parent" in the layout. Also, each section are reserved for different purpose. The left section is reserved for communication type of widget, and the right section is for entertainment/media only. Any other app widget should only be placed in the mid section.

The widget bar container takes on the widget creation request from xml manifest and displays them accordingly, and the idea is adopted from the Android Home Screen.

Our custom framework handles the actual widget creation and placement. Currently, ODG is not exposing any direct function calls for the widget creation and placement. Instead, developers are required to do it by defining ODG custom Tags and Attributes in the Android Manifest.

Displaying widget bar throughout the whole application:

As mentioned, widget bar is hidden by default unless an app is defined to display along side with it. To display the widget bar throughout the whole app, in your AndroidManifest.xml, put in a metadata.

Example:

<application ...>
   <meta-data android:name="display_widget_bar" android:value="true" />
   ...
</application>

Displaying widget bar for only certain activity:

Likewise, you put in a meta-data inside your Activity tag.

Example:

<activity ...>
   <meta-data android:name="display_widget_bar" android:value="true" />
   ...
</activity>

Define if an activity is associated with a widget:

When an activity is associated with a widget, during the activity launch, both activity and widget will be displayed in the active app area and widget bar respectively. For those activities that don't have any associated widget, previously launched widget will remain at where it is. The following attribute must be included application manifest if developer wants to place a widget onto widget bar.

Attribute Name:
hasWidget

Value:
true -- displays widget when launching an activity.
false -- not to display any widget. (by default)

Example:

<activity android:name="com.android.music.MusicBrowserActivity"
           ....
          widgetOnly="false"
          hasWidget="true">

Defining where widget will be placed:

Example:

<app-widget-position
          position="1" 
          widgetPackageName="com.osterhoutgroup.telephony.widget"
          widgetClassName="com.osterhoutgroup.telephony.widget.TelephonyWidget" />

app-widget-position --- this xml tag includes widget's package and class paths in order to create the actual widget in the widget bar.

Attribute name:
position -- defines app type and where to display the widget.

Value:

  • "1"  = communication type. It will be placed on the left hand side of the widget bar.
  • "2"  = generic type. It will be placed in the middle of the widget bar.
  • "3"  = media type. It will be placed on the right hand side of the widget bar.

Attribute name: widgetPackageName
Value: "widget's package path"

Attribute name: widgetClassName
Value:  "widget's class path"

 

Hiding activity while displaying a widget:

In case developer only want to display widget without displaying activity, the following attribute is needed in the Android manifest:

Attribute name:  widgetOnly
Value:
true -- launch widget, but hide the activity.
false -- launch both activity and widget (Developer doesn't have to define it since it is false by default.)

Example:

<activity android:name="com.android.music.MusicBrowserActivity"
...
widgetOnly="false">

 

Notice: you cannot display widget bar in full screen app. Full screen is full screen, and the app will take the whole screen.

Notice: widgets feature is deprecated in Marshmallow and higher ReticleOS / Android versions.

Have more questions? Submit a request

Comments

Powered by Zendesk