Menu

Create the layout

This section describes how to create the app layout.

Create the buttons and Textview

This app contains 5 buttons.

  • ToggleAdminbtn – prompts the user to activate/deactivate device administrator for the app.
  • ActivateLicencebtn –activates the Knox ELM licence key.
  • GrantPermissionsbtn–Grants runtime permission to create shortcut to the Kiosk app...
  • ToggleDefaultKioskbtn – activates/deactivates default Kiosk mode.
  • ToggleCustomKioskbtn – activates/deactivates custom Kiosk mode.

Open activity_main.xml and insert the following xml mark up. This creates your screen layout.

NOTE – to resolve the @stringerrors, copy these 2 files from the sample app into your project.

  • background.xml:KnoxSdkSample\app\src\main\res\drawable\Background
  • strings.xml: KnoxSdkSample\app\src\main\res\values\strings
<?xml version="1.0" encoding="utf-8"?>
					<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
					xmlns:tools="http://schemas.android.com/tools"
					android:id="@+id/mainpage"
					android:layout_width="match_parent"
					android:layout_height="match_parent"
					tools:context="com.samsung.knox.example.kioskmode.MainActivity">
					<TextView
					android:id="@+id/logview_id"
					android:gravity="bottom"
					android:layout_width="320dp"
					android:layout_height="230dp"
					android:textColor="#3F51B5"
					android:background="@drawable/background"
					android:scrollbars="vertical"
					android:paddingLeft="10dp"
					android:layout_marginTop="22dp"
					android:layout_alignParentTop="true"
					android:layout_centerHorizontal="true" />
					<ScrollView
					android:id="@+id/scrollView"
					android:layout_marginTop="10dp"
					android:layout_below="@id/logview_id"
					android:layout_width="match_parent"
					android:layout_height="wrap_content">
					<RelativeLayout
					android:padding="10dp"
					android:layout_width="match_parent"
					android:layout_height="wrap_content">

        
					<Button
					android:id="@+id/ToggleAdminbtn"
					android:layout_width="200dp"
					android:layout_height="wrap_content"
					android:layout_centerHorizontal="true"
					android:text="@string/activate_admin" />

					<Button
					android:id="@+id/ActivateLicencebtn"
					android:layout_width="200dp"
					android:layout_height="wrap_content"
					android:layout_alignStart="@+id/ToggleAdminbtn"
					android:layout_below="@+id/ToggleAdminbtn"
					android:text="@string/activate_license" />

					<Button
					android:id="@+id/GrantPermissionsbtn"
					android:layout_width="200dp"
					android:layout_height="wrap_content"
					android:layout_alignStart="@id/ToggleAdminbtn"
					android:layout_below="@id/ActivateLicencebtn"
					android:text="@string/grant_permissions"/>

					<Button
					android:id="@+id/ToggleDefaultKioskbtn"
					android:layout_width="200dp"
					android:layout_height="wrap_content"
					android:layout_alignStart="@id/ToggleAdminbtn"
					android:layout_below="@id/GrantPermissionsbtn"
					android:text="@string/toggle_kiosk"/>

					<Button
					android:id="@+id/ToggleCustomKioskbtn"
					android:layout_width="200dp"
					android:layout_height="wrap_content"
					android:layout_alignStart="@id/ToggleAdminbtn"
					android:layout_below="@id/ToggleDefaultKioskbtn"
					android:text="@string/toggle_kiosk_settings" />
					</RelativeLayout>
					</ScrollView>
					</RelativeLayout>
				

You now see 5 buttons in the middle of the screen. ACTIVATE ADMIN, ACTIVATE LICENCE, GRANT PERMISSIONS ,TOGGLE DEFAULT KIOSK and TOGGLE CUSTOM KIOSK. You will later assign methods to these buttons to control their respective actions. There is also a TextView at the top of the screen that will display any log messages.

Create the Kiosk mode customization layout

Create checkboxes for enabling/disabling differerent policies in Kiosk mode. In the layout folder which is present in res folder in Android view, create new Layout resource file and named promt_kiosk_setting.xml.

Open promt_kiosk_setting.xml file and insert the following xml mark up. This creates your customization layout.

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingTop="20dp" android:paddingLeft="25dp" android:paddingRight="25dp" android:paddingBottom="10dp" android:id="@+id/kiosk_config_group" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/dtxtKioskSetting" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/kiosk_setting" android:textColor="@android:color/black" /> <CheckBox android:id="@+id/chkSettingsChange" android:layout_below="@id/dtxtKioskSetting" android:text="@string/allow_settings_changes" android:checked="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkAllowStatusBar" android:layout_below="@id/chkSettingsChange" android:text="@string/allow_status_bar" android:checked="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkStatusBarExpansion" android:layout_below="@id/chkAllowStatusBar" android:checked="true" android:text="@string/allow_status_bar_expansion" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkAllowSystemBar" android:layout_below="@id/chkStatusBarExpansion" android:text="@string/allow_system_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkAllowTaskManager" android:layout_below="@id/chkAllowSystemBar" android:text="@string/allow_task_manager" android:checked="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkAllowHomekey" android:layout_below="@id/chkAllowTaskManager" android:text="@string/allow_home_key" android:checked="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkAllowAirCommand" android:layout_below="@id/chkAllowHomekey" android:text="@string/allow_air_command" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkAllowAirview" android:layout_below="@id/chkAllowAirCommand" android:text="@string/allow_air_view" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkAllowMultiwindow" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/chkAllowAirview" android:checked="false" android:text="@string/allow_multiwindow" /> <CheckBox android:id="@+id/chkAllowSmartClip" android:layout_below="@id/chkAllowMultiwindow" android:text="@string/allow_smart_clip" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkAllowNavBar" android:layout_below="@id/chkAllowSmartClip" android:text="@string/allow_nav_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkWipeRecentTasks" android:layout_below="@id/chkAllowNavBar" android:text="@string/wipe_recent_tasks" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkClearNotifications" android:layout_below="@id/chkWipeRecentTasks" android:text="@string/clear_notifications" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>

You now see the following checkboxes on the screen. You can see some of the settings are already checked.

For detailed information on creating Android layouts, see Google's page on how to Build a Simple User Interface.

Tutorial Progress

You are 2/8 done! Go to the next step.