/* WP-Cache Config Sample File See wp-cache.php for author details. */ $wpsc_last_post_update = 1557541754; //Added by WP-Cache Manager $wpsc_save_headers = 0; //Added by WP-Cache Manager $wp_cache_home_path = '/'; //Added by WP-Cache Manager $cache_schedule_interval = 'daily'; //Added by WP-Cache Manager $cache_gc_email_me = 0; //Added by WP-Cache Manager $cache_scheduled_time = '00:00'; //Added by WP-Cache Manager $wp_cache_mobile_groups = ''; //Added by WP-Cache Manager $wp_cache_mobile_prefixes = 'w3c , w3c-, acs-, alav, alca, amoi, audi, avan, benq, bird, blac, blaz, brew, cell, cldc, cmd-, dang, doco, eric, hipt, htc_, inno, ipaq, ipod, jigs, kddi, keji, leno, lg-c, lg-d, lg-g, lge-, lg/u, maui, maxo, midp, mits, mmef, mobi, mot-, moto, mwbp, nec-, newt, noki, palm, pana, pant, phil, play, port, prox, qwap, sage, sams, sany, sch-, sec-, send, seri, sgh-, shar, sie-, siem, smal, smar, sony, sph-, symb, t-mo, teli, tim-, tosh, tsm-, upg1, upsi, vk-v, voda, wap-, wapa, wapi, wapp, wapr, webc, winw, winw, xda , xda-'; //Added by WP-Cache Manager $wp_cache_refresh_single_only = 0; //Added by WP-Cache Manager $wp_cache_make_known_anon = 0; //Added by WP-Cache Manager $wp_cache_mod_rewrite = 0; //Added by WP-Cache Manager $wp_cache_front_page_checks = 0; //Added by WP-Cache Manager $wp_cache_mfunc_enabled = 0; //Added by WP-Cache Manager $wp_supercache_304 = 0; //Added by WP-Cache Manager $wp_cache_no_cache_for_get = 0; //Added by WP-Cache Manager $wp_cache_disable_utf8 = 0; //Added by WP-Cache Manager $cache_time_interval = '600'; //Added by WP-Cache Manager $cache_schedule_type = 'time'; //Added by WP-Cache Manager $cache_page_secret = '5b9836c88039e7acde90683f929191c4'; //Added by WP-Cache Manager $wp_cache_slash_check = 1; //Added by WP-Cache Manager if ( ! defined('WPCACHEHOME') ) define( 'WPCACHEHOME', WP_CONTENT_DIR . "/plugins/wp-super-cache/" ); //Added by WP-Cache Manager $cache_compression = 1; //Added by WP-Cache Manager $cache_enabled = true; //Added by WP-Cache Manager $super_cache_enabled = true; //Added by WP-Cache Manager $cache_max_time = '1800'; //Added by WP-Cache Manager //$use_flock = true; // Set it true or false if you know what to use $cache_path = WP_CONTENT_DIR . '/cache/'; $file_prefix = 'wp-cache-'; $ossdlcdn = 0; // Array of files that have 'wp-' but should still be cached $cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', 'wp-locations.php' ); $cache_rejected_uri = array('wp-.*\\.php', 'index\\.php'); $cache_rejected_user_agent = array ( 0 => 'bot', 1 => 'ia_archive', 2 => 'slurp', 3 => 'crawl', 4 => 'spider', 5 => 'Yandex' ); $cache_rebuild_files = 1; //Added by WP-Cache Manager // Disable the file locking system. // If you are experiencing problems with clearing or creating cache files // uncommenting this may help. $wp_cache_mutex_disabled = 1; //Added by WP-Cache Manager // Just modify it if you have conflicts with semaphores $sem_id = 2046492738; //Added by WP-Cache Manager if ( '/' != substr($cache_path, -1)) { $cache_path .= '/'; } $wp_cache_mobile = 0; $wp_cache_mobile_whitelist = 'Stand Alone/QNws'; $wp_cache_mobile_browsers = '2.0 MMP, 240x320, 400X240, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, Googlebot-Mobile, hiptop, IEMobile, KYOCERA/WX310K, LG/U990, MIDP-2., MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, PlayStation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, SHG-i900, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, webOS, Windows CE, WinWAP, YahooSeeker/M1A1-R2D2, iPhone, iPod, Android, BlackBerry9530, LG-TU915 Obigo, LGE VX, webOS, Nokia5800'; //Added by WP-Cache Manager // change to relocate the supercache plugins directory $wp_cache_plugins_dir = WPCACHEHOME . 'plugins'; // set to 1 to do garbage collection during normal process shutdown instead of wp-cron $wp_cache_shutdown_gc = 0; $wp_super_cache_late_init = 0; //Added by WP-Cache Manager // uncomment the next line to enable advanced debugging features $wp_super_cache_advanced_debug = 0; $wp_super_cache_front_page_text = ''; $wp_super_cache_front_page_clear = 0; $wp_super_cache_front_page_check = 0; $wp_super_cache_front_page_notification = '0'; $wp_cache_object_cache = 0; //Added by WP-Cache Manager $wp_cache_anon_only = 0; $wp_supercache_cache_list = 0; //Added by WP-Cache Manager $wp_cache_debug_to_file = 0; $wp_super_cache_debug = 0; $wp_cache_debug_level = 5; $wp_cache_debug_ip = ''; $wp_cache_debug_log = ''; $wp_cache_debug_email = ''; $wp_cache_pages[ "search" ] = 0; $wp_cache_pages[ "feed" ] = 0; $wp_cache_pages[ "category" ] = 0; $wp_cache_pages[ "home" ] = 0; $wp_cache_pages[ "frontpage" ] = 0; $wp_cache_pages[ "tag" ] = 0; $wp_cache_pages[ "archives" ] = 0; $wp_cache_pages[ "pages" ] = 0; $wp_cache_pages[ "single" ] = 0; $wp_cache_pages[ "author" ] = 0; $wp_cache_hide_donation = 0; $wp_cache_not_logged_in = 0; //Added by WP-Cache Manager $wp_cache_clear_on_post_edit = 0; //Added by WP-Cache Manager $wp_cache_hello_world = 0; //Added by WP-Cache Manager $wp_cache_mobile_enabled = 1; //Added by WP-Cache Manager $wp_cache_cron_check = 1; //Added by WP-Cache Manager ?> /* WP-Cache Config Sample File See wp-cache.php for author details. */ $wpsc_last_post_update = 1557541754; //Added by WP-Cache Manager $wpsc_save_headers = 0; //Added by WP-Cache Manager $wp_cache_home_path = '/'; //Added by WP-Cache Manager $cache_schedule_interval = 'daily'; //Added by WP-Cache Manager $cache_gc_email_me = 0; //Added by WP-Cache Manager $cache_scheduled_time = '00:00'; //Added by WP-Cache Manager $wp_cache_mobile_groups = ''; //Added by WP-Cache Manager $wp_cache_mobile_prefixes = 'w3c , w3c-, acs-, alav, alca, amoi, audi, avan, benq, bird, blac, blaz, brew, cell, cldc, cmd-, dang, doco, eric, hipt, htc_, inno, ipaq, ipod, jigs, kddi, keji, leno, lg-c, lg-d, lg-g, lge-, lg/u, maui, maxo, midp, mits, mmef, mobi, mot-, moto, mwbp, nec-, newt, noki, palm, pana, pant, phil, play, port, prox, qwap, sage, sams, sany, sch-, sec-, send, seri, sgh-, shar, sie-, siem, smal, smar, sony, sph-, symb, t-mo, teli, tim-, tosh, tsm-, upg1, upsi, vk-v, voda, wap-, wapa, wapi, wapp, wapr, webc, winw, winw, xda , xda-'; //Added by WP-Cache Manager $wp_cache_refresh_single_only = 0; //Added by WP-Cache Manager $wp_cache_make_known_anon = 0; //Added by WP-Cache Manager $wp_cache_mod_rewrite = 0; //Added by WP-Cache Manager $wp_cache_front_page_checks = 0; //Added by WP-Cache Manager $wp_cache_mfunc_enabled = 0; //Added by WP-Cache Manager $wp_supercache_304 = 0; //Added by WP-Cache Manager $wp_cache_no_cache_for_get = 0; //Added by WP-Cache Manager $wp_cache_disable_utf8 = 0; //Added by WP-Cache Manager $cache_time_interval = '600'; //Added by WP-Cache Manager $cache_schedule_type = 'time'; //Added by WP-Cache Manager $cache_page_secret = '5b9836c88039e7acde90683f929191c4'; //Added by WP-Cache Manager $wp_cache_slash_check = 1; //Added by WP-Cache Manager if ( ! defined('WPCACHEHOME') ) define( 'WPCACHEHOME', WP_CONTENT_DIR . "/plugins/wp-super-cache/" ); //Added by WP-Cache Manager $cache_compression = 1; //Added by WP-Cache Manager $cache_enabled = true; //Added by WP-Cache Manager $super_cache_enabled = true; //Added by WP-Cache Manager $cache_max_time = '1800'; //Added by WP-Cache Manager //$use_flock = true; // Set it true or false if you know what to use $cache_path = WP_CONTENT_DIR . '/cache/'; $file_prefix = 'wp-cache-'; $ossdlcdn = 0; // Array of files that have 'wp-' but should still be cached $cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', 'wp-locations.php' ); $cache_rejected_uri = array('wp-.*\\.php', 'index\\.php'); $cache_rejected_user_agent = array ( 0 => 'bot', 1 => 'ia_archive', 2 => 'slurp', 3 => 'crawl', 4 => 'spider', 5 => 'Yandex' ); $cache_rebuild_files = 1; //Added by WP-Cache Manager // Disable the file locking system. // If you are experiencing problems with clearing or creating cache files // uncommenting this may help. $wp_cache_mutex_disabled = 1; //Added by WP-Cache Manager // Just modify it if you have conflicts with semaphores $sem_id = 2046492738; //Added by WP-Cache Manager if ( '/' != substr($cache_path, -1)) { $cache_path .= '/'; } $wp_cache_mobile = 0; $wp_cache_mobile_whitelist = 'Stand Alone/QNws'; $wp_cache_mobile_browsers = '2.0 MMP, 240x320, 400X240, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, Googlebot-Mobile, hiptop, IEMobile, KYOCERA/WX310K, LG/U990, MIDP-2., MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, PlayStation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, SHG-i900, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, webOS, Windows CE, WinWAP, YahooSeeker/M1A1-R2D2, iPhone, iPod, Android, BlackBerry9530, LG-TU915 Obigo, LGE VX, webOS, Nokia5800'; //Added by WP-Cache Manager // change to relocate the supercache plugins directory $wp_cache_plugins_dir = WPCACHEHOME . 'plugins'; // set to 1 to do garbage collection during normal process shutdown instead of wp-cron $wp_cache_shutdown_gc = 0; $wp_super_cache_late_init = 0; //Added by WP-Cache Manager // uncomment the next line to enable advanced debugging features $wp_super_cache_advanced_debug = 0; $wp_super_cache_front_page_text = ''; $wp_super_cache_front_page_clear = 0; $wp_super_cache_front_page_check = 0; $wp_super_cache_front_page_notification = '0'; $wp_cache_object_cache = 0; //Added by WP-Cache Manager $wp_cache_anon_only = 0; $wp_supercache_cache_list = 0; //Added by WP-Cache Manager $wp_cache_debug_to_file = 0; $wp_super_cache_debug = 0; $wp_cache_debug_level = 5; $wp_cache_debug_ip = ''; $wp_cache_debug_log = ''; $wp_cache_debug_email = ''; $wp_cache_pages[ "search" ] = 0; $wp_cache_pages[ "feed" ] = 0; $wp_cache_pages[ "category" ] = 0; $wp_cache_pages[ "home" ] = 0; $wp_cache_pages[ "frontpage" ] = 0; $wp_cache_pages[ "tag" ] = 0; $wp_cache_pages[ "archives" ] = 0; $wp_cache_pages[ "pages" ] = 0; $wp_cache_pages[ "single" ] = 0; $wp_cache_pages[ "author" ] = 0; $wp_cache_hide_donation = 0; $wp_cache_not_logged_in = 0; //Added by WP-Cache Manager $wp_cache_clear_on_post_edit = 0; //Added by WP-Cache Manager $wp_cache_hello_world = 0; //Added by WP-Cache Manager $wp_cache_mobile_enabled = 1; //Added by WP-Cache Manager $wp_cache_cron_check = 1; //Added by WP-Cache Manager ?> Mobile App Development with Xamarin and MvvmCross – Part 4: Android UI | Danis Blog Mobile App Development with Xamarin and MvvmCross – Part 4: Android UI – Danis Blog
11 Oct

Mobile App Development with Xamarin and MvvmCross – Part 4: Android UI

Android UI 

In this article we are going to create our first Android view. To do this, we will create an AXML file, which will hold the layout of the individual UI components. This AXML file will also create bindings to the ViewModel, so that the view is automatically updated when the data in the ViewModel changes. Additionally, we will create a backing C#-class, which will hold the view logic for our layout.

Android view layer

Android separates its view layer into two types of assets:

  • AXML-Files, which will define the layout, size and constraints of the individual UI components with an XML-based syntax
  • Activities, which load AXML-defined layouts, access the contained UI elements and connect them with the application code

AXML files

AXML is an XML dialect for files to define both whole views as well as individual, reusable UI components. Android comes with a set of ready-made standard components, which can be extended and combined in order to create new components. Traditionally, AXML files are of static nature, but the contained components can be programmatically changed at runtime e.g. by changing their size, adding or removing components or registering event listeners.

MvX introduces its own tags to include framework functionality such as two-way data binding already in the AXML-layout. However, currently VisualStudio does not support content assist for these tags. To use the tags, their namespace must be imported with an arbitrary name. The following example illustrates using the MvxItemTemplate-Tag by including the MvX-namespace under the local prefix.

The following table shows a selection of commonly used MvX-tags in AXML along with a usage example:

TagusageCode example
local:MvxItemTemplateWithin a list this tag can be used to load the referenced AXML file to render a single list element.Will load Resource/layout/my_item.axml to render a list element:

local:MvxItemTemplate="@layout/my_item"
local:MvxBindWithin some UI components this tag can be used to create an automated data binding between the ViewModel and the UI component. The UI component will be refreshed when the data in the ViewModel changes and changes in the UI component (e.g. a TextInput element) will be reflected in the ViewModel data.Will use the Items-property on the ViewModel as data source for list elements in a List defined in AXML:
local:MvxBind="ItemsSource Items"

Will connect a click on a UI element with the ShowDetail-Property (must be of type System.Windows.Input.ICommand) on the ViewModel:
local:MvxBind="ItemsClick ShowDetail"

Will bind the Text-property on a label with the Title-Property of the underlying element in a list item:
local:MvxBind="Text Title"

Creating the Activity

In order to use the newly defined AXML-layout we need to create an Activity, which is any class that extends Android.App.Activity. The Activity represents the UI logic of the layout and can be used for example to register event handlers. When using MvX, every Activity must be extended from Cirrious.MvvmCross.Droid.Views.MvxActivity (which extends Android.App.Activity) and follow a strict naming convention to be loaded by MvX when navigating to a ViewModel. MvX will load the Android activity based on its class name. That’s why a class must be named like the corresponding ViewModel, without the …Model-suffix (e.g. for MyViewModel.cs the corresponding Android activity must be named MyView.cs).

In Xamarin/MvX, every displayed view in Android can be created by following three simple steps:

  1. Define the view’s layout by creating an AXML file. The AXML file syntax is identical with the one of a standard Android application written in Java with the exception of the special MvX tags.
  2. Create an Activity class extending MvxActivity which is annotated with [Activity]. If the view serves as entry point when the app starts, the MainLauncher-attribute must be set to true. This is the case if the view belongs to the ViewModel that was registered with the AppStart (see previous article).
  3. Override the onCreate() function to load the layout when the activity is created.

The following code snipped shows a very basic implementation of MyView.cs, which can be used as view in the Android UI project for the MyViewModel-ViewModel.

Additional Views

Any other Android view can be created just the way it was described above. Any activity can have the MainLauncher attribute set to true, whether its ViewModel is registered as main ViewModel upon app start or not. The MainLauncher attribute simply defines that the activity can serve as an entry point (for example when launching from another app via Intent).

Navigating between views (activities)

As stated before, navigation in MvX happens over ViewModels, not views. This is to ensure the navigation logic has to be implemented only once and is consistent across platforms. A view can be changed by calling ShowView<ViewModel>(View) on the ViewModel. Because the method is protected, it must be wrapped in an ICommand-property which is made public. This ICommand property can be used for data binding with MvX (for example upon a click on a UI element) and will be triggered by MvX when the bound event occurs.

MvX uses reflection also for command binding. The ICommand property name must end in …Command and the bound property in the AXML file must match the name exactly (without the Command-suffix). The following example illustrates binding a navigation from MyViewModel.cs to OtherViewModel.cs upon click on a button in MyViewLayout.axml.

What we have done so far

In this chapter we have defined an Android view by defining its layout in AXML and creating the corresponding Activity as a C# class. We have connected some of the displayed data with the data in the ViewModel by using MvX-tags in the layout.

Series Navigation<< Mobile App Development with Xamarin and MvvmCross – Part 3: Core projectMobile App Development with Xamarin and MvvmCross – Part 6: iOS UI with Storyboard >>

Leave a Reply

Your email address will not be published. Required fields are marked *