Widget viewer

Widgets are commonly used in applications like home screen (launcher) or lock screen. Widget is a simple component based on NUI View designed to show personalized set of information.

Figure: Widget Viewer

Widget Viewer

NUI Framework provides API to use and view widgets in your application. To read more about widget application you can check:

Platform applications preinstalled in the Tizen image provides few simple widgets such as Gallery, Music Player, and Contacts. To check installed widgets application in your Tizen image, you can use SDB tool and pkginfo command line interface.

To open device/emulator shell use the SDB tool:

shell
Copy
sdb shell

Then list installed widgets:

shell
Copy
pkginfo --listpkg | grep widget

Prerequisites

To view a widget, the application has to request permission by adding the following privilege to the tizen-manifest.xml file:

xml
Copy
<ui-application appid="org.tizen.example.NUIWidgetViewer"> <!-- application description --> </ui-application> <privileges> <privilege>http://tizen.org/privilege/widget.viewer</privilege> </privileges>

Create widget viewer

To use the methods and properties of the WidgetViewManager class, include the Tizen.NUI namespace in your application:

C#
Copy
using Tizen.NUI; using Tizen.NUI.BaseComponents;

Commonly the OnCreate() callback is implemented to initialize UI of an application:

C#
Copy
namespace NUIWidgetViewer { class Program : NUIApplication { protected override void OnCreate() { base.OnCreate(); Initialize(); } } //...

In this case, the Initialize() function called from the OnCreate() callback:

  • Creates the widgetsList View instance and:
    • Set its size using WidthResizePolicy and HeightResizePolicy to screen size.
    • Setup horizontal Layout with padding and margin.
  • Creates the widgetViewManager instance and register current application as a viewer for installed widgets using Application ID
  • Creates instances of two widgets. The galleryWidget and contactsWidget are created using widgetViewManager object.
  • Inserts created widgets into created widgetsList and add widgetsList to the default layer of the application window.
C#
Copy
void Initialize() { View widgetsList = new View() { WidthResizePolicy = ResizePolicyType.FillToParent, HeightResizePolicy = ResizePolicyType.FillToParent, Layout = new LinearLayout() { LinearAlignment = LinearLayout.Alignment.CenterVertical, LinearOrientation = LinearLayout.Orientation.Horizontal, CellPadding = new Size2D(20, 20), Padding = new Extents(30, 30, 30, 30) } }; WidgetViewManager widgetViewManager = new WidgetViewManager(this, this.ApplicationInfo.ApplicationId); var galleryWidget = widgetViewManager.AddWidget("org.tizen.gallery.widget", "", Window.Instance.WindowSize.Width / 2 - 40, Window.Instance.WindowSize.Height, 0); var contactsWidget = widgetViewManager.AddWidget("org.tizen.contacts.widget", "", Window.Instance.WindowSize.Width / 2 - 40, Window.Instance.WindowSize.Height, 0); widgetsList.Add(galleryWidget); widgetsList.Add(contactsWidget); Window.Instance.GetDefaultLayer().Add(widgetsList); }

Handling back button press events:

C#
Copy
public void OnKeyEvent(object sender, Window.KeyEventArgs e) { if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape")) { Exit(); } }

Main code of the application:

C#
Copy
static void Main(string[] args) { var app = new Program(); app.Run(args); }

For full source code of the example, see here.

  • Dependencies
    • Tizen 4.0 and Higher
Widget Control
Next Connectivity and Wireless
Submit your feedback to GitHub