Example #1
0
        public static void SetToolbarItems(Action <MenuItemInfo> onActivated, IEnumerable <MenuItemInfo> rawMenuItems)
        {
            var menuItems = rawMenuItems.ToList();

            Action <string> rawtoolbarItemActivated = webItemIdUriEncoded => {
                var webItemId     = Window.DecodeURIComponent(webItemIdUriEncoded);
                var maybeMenuItem = menuItems.FirstOrDefault(x => x.webMenuItemId == webItemId);

                Logger.Debug(typeof(IawAppApi), "androidPostToolbarItemActivated({0}) found?={1} allItems={2}", webItemId, maybeMenuItem, menuItems.PrettyToString(y => y.webMenuItemId));

                if (maybeMenuItem != null)
                {
                    onActivated(maybeMenuItem);
                }
            };

            BridgeObjectUtil.SetFieldValue(Window.Instance, "androidPostToolbarItemActivated", rawtoolbarItemActivated);

            var impl = GetImpl();

            var mi = JsonConvert.SerializeObject(menuItems.ToArray());

            if (impl != null)
            {
                impl.setToolbarItems(mi);
                Logger.Debug(typeof(IawAppApi), "IAWApp setToolbarItems() called");
            }
            else
            {
                BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setToolbarItems", mi);
                Logger.Debug(typeof(IawAppApi), "fake setToolbarItems() called");
            }
        }
Example #2
0
        public static void SetToolbarSearchState(Action <bool, string> onUpdateOrNull = null)
        {
            Action <bool, string> searchUsed = (committed, queryUriEncoded) => {
                var query = Window.DecodeURIComponent(queryUriEncoded);
                Logger.Debug(typeof(IawAppApi), "androidPostToolbarSearchUpdate({0}, {1})", committed, query);
                onUpdateOrNull(committed, query);
            };

            if (onUpdateOrNull == null)
            {
                Logger.Debug(typeof(IawAppApi), "setToolbarSearchState() deactivation");
                BridgeObjectUtil.SetFieldValue(Window.Instance, "androidPostToolbarSearchUpdate", null);
            }
            else
            {
                Logger.Debug(typeof(IawAppApi), "setToolbarSearchState() deactivation");
                BridgeObjectUtil.SetFieldValue(Window.Instance, "androidPostToolbarSearchUpdate", searchUsed);
            }

            var impl = GetImpl();

            if (impl != null)
            {
                impl.setToolbarSearchState(onUpdateOrNull != null);
                Logger.Debug(typeof(IawAppApi), "IAWApp setToolbarSearchState() called");
            }
            else
            {
                BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setToolbarSearchState", onUpdateOrNull != null);
                Logger.Debug(typeof(IawAppApi), "fake setToolbarItems() called");
            }
        }
Example #3
0
        public static void SetToolbarBackButtonState(bool enabled)
        {
            var impl = GetImpl();

            if (impl != null)
            {
                impl.setToolbarBackButtonState(enabled);
                Logger.Debug(typeof(IawAppApi), "IAWApp SetToolbarBackButtonState() called");
            }
            else
            {
                BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setToolbarBackButtonState", enabled);
                Logger.Debug(typeof(IawAppApi), "fake SetToolbarBackButtonState() called");
            }
        }
Example #4
0
        public static bool SetPausedScanOverlayImage(string mediaIdentifierId)
        {
            var impl = GetImpl();

            if (impl != null)
            {
                var res = impl.setPausedScanOverlayImage(mediaIdentifierId);
                Logger.Debug(typeof(IawAppApi), "IAWApp setPausedScanOverlayImage() called");
                return(res);
            }

            BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setPausedScanOverlayImage", mediaIdentifierId);
            Logger.Debug(typeof(IawAppApi), "fake setPausedScanOverlayImage() called");
            return(true);
        }
Example #5
0
        public static void SetToolbarColors(string backgroundColor, string foregroundColor)
        {
            var impl = GetImpl();

            if (impl != null)
            {
                impl.setToolbarColors(backgroundColor, foregroundColor);
                Logger.Debug(typeof(IawAppApi), "IAWApp SetToolbarColors() called");
            }
            else
            {
                var v = backgroundColor + "_" + foregroundColor;
                BridgeObjectUtil.SetFieldValue(Window.Instance, "_iawapp_setToolbarColors", v);
                Logger.Debug(typeof(IawAppApi), "fake SetToolbarColors() called");
            }
        }
Example #6
0
        public static void RegisterPostScanQrReplyHandler(string requestId, Action <IAWAppScanReply> action)
        {
            Logger.Debug(typeof(IAWAppHostApi), "RegisterPostScanQrReplyHandler {0}", requestId);
            var handler = BridgeObjectUtil.GetFieldValue(Window.Instance, nameof(androidPostScanQrReply));

            if (handler == null)
            {
                Logger.Debug(typeof(IAWAppHostApi), "setup handler");
                BridgeObjectUtil.SetFieldValue(Window.Instance, nameof(androidPostScanQrReply), (Action <string>)androidPostScanQrReply);
            }
            else
            {
                Logger.Debug(typeof(IAWAppHostApi), "handler already installed");
            }

            _scanQrCallbacks.Add(requestId, action);
        }
Example #7
0
        public static void RegisterPostMediaAssetReady(string requestId, Action <string> action)
        {
            Logger.Debug(typeof(IAWAppHostApi), "RegisterPostMediaAssetReady {0}", requestId);
            var handler = BridgeObjectUtil.GetFieldValue(Window.Instance, "androidPostMediaAssetReady");

            if (handler == null)
            {
                Logger.Debug(typeof(IAWAppHostApi), "setup handler");
                BridgeObjectUtil.SetFieldValue(Window.Instance, nameof(androidPostMediaAssetReady), (Action <string, string>)androidPostMediaAssetReady);
            }
            else
            {
                Logger.Debug(typeof(IAWAppHostApi), "handler already installed");
            }

            _mediaReadyCallbacks.Add(requestId, action);
        }
Example #8
0
 /// <param name="callback">return true if webapp consumed event. false if it didn't</param>
 public static void SetOnBackPressed(Func <bool> callback) =>
 BridgeObjectUtil.SetFieldValue(Window.Instance, "androidBackConsumed", callback);