Esempio n. 1
0
 private void Accessory_Click(object sender, EventArgs e)
 {
     if (!Pair.RaiseEvent(nameof(AccessorySelected), EventArgs.Empty))
     {
         DroidFactory.Navigate(AccessoryLink, Parent);
     }
 }
Esempio n. 2
0
        public static void Activated(object sender, EventArgs eventArgs)
        {
            var menu = sender as IMenu;

            if (menu == null)
            {
                var popover = PaneManager.Instance.FromNavContext(Pane.Popover)?.CurrentView;
                menu = (popover as IListView)?.Menu ??
                       (popover as IGridView)?.Menu ??
                       (popover as IBrowserView)?.Menu ??
                       (popover as BaseFragment)?.Menu;
            }
            if (menu == null || menu.ButtonCount <= 0)
            {
                return;
            }
            var items = new string[menu.ButtonCount];

            for (var i = 0; i < menu.ButtonCount; i++)
            {
                items[i] = menu.GetButton(i).Title;
            }
            var builder = new AlertDialog.Builder(DroidFactory.MainActivity)
                          .SetItems(items, DroidFactory.GetNativeObject <Menu>(menu, nameof(menu)));

            builder.Create().Show();
        }
Esempio n. 3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle)
        {
            var view = inflater.Inflate(Resource.Layout.popover, null);

            view.FindViewById <Button>(Resource.Id.action).Click += (o, e) =>
            {
                var menu = GetMenu();
                if (menu == null || menu.ButtonCount <= 0)
                {
                    return;
                }
                var button = menu.GetButton(0);
                if (!button.RaiseEvent(nameof(button.Clicked), EventArgs.Empty))
                {
                    DroidFactory.Navigate(button.NavigationLink, _stack.CurrentView);
                }
            };
            view.FindViewById <ImageButton>(Resource.Id.options).Click += Menu.Activated;
            var homeAction = view.FindViewById <ImageButton>(Resource.Id.home);

            homeAction.SetImageDrawable(Resources.GetDrawable(Activity.ApplicationInfo.Icon));
            homeAction.Click += (o, e) => Activity.OnBackPressed();
            UpdateTitle(view);
            return(view);
        }
Esempio n. 4
0
        public static void Stop()
        {
            _recordingDialog?.Dismiss();
            _recordingDialog = null;

            // stop recording
            try
            {
                _mic.Stop();
            }
            catch (Exception e)
            {
                Device.Log.Warn(e);
            }

            // prepare object for GC by calling dispose
            _mic.Release();
            _mic.Dispose();
            _mic = null;

            if (_callback != null)
            {
                DroidFactory.Navigate(new Link(_callback, new Dictionary <string, string>
                {
                    { CallbackParam, _callbackId },
                }));
            }
        }
Esempio n. 5
0
 public void Focus()
 {
     try
     {
         if (CurrentFocus != this)
         {
             CurrentFocus?.Blur(false);
             CurrentFocus = this;
             if (!IsFocused)
             {
                 _isFocused = true;
                 this.RaiseEvent(nameof(GotFocus), EventArgs.Empty);
                 this.OnPropertyChanged(nameof(IsFocused));
             }
         }
         Device.Thread.ExecuteOnMainThread(() =>
         {
             Focusable            = true;
             FocusableInTouchMode = true;
             DroidFactory.ShowKeyboard(this);
         });
     }
     catch (ObjectDisposedException)
     {
         _isFocused = false;
         /*GULLPPPP!!*/
     }
 }
Esempio n. 6
0
        /// <summary>
        /// This hook is called whenever an item in the options menu is selected. The default implementation
        /// simply returns false to have the normal processing happen (calling the item's Runnable or sending
        /// a message to its Handler as appropriate). You can use this method for any items for which you would
        /// like to do processing without those other facilities.<br/>
        /// Derived classes should call through to the base class for it to perform the default menu handling.
        /// </summary>
        /// <param name="item">The menu item that was selected.</param>
        /// <returns><c>false</c> to allow normal menu processing to proceed, <c>true</c> to consume it here.</returns>
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            if (item.ItemId != Android.Resource.Id.Home)
            {
                return(base.OnOptionsItemSelected(item));
            }

            var previousView = Stack.Views.ElementAtOrDefault(Stack.Views.Count() - 2);
            var viewAtt      = previousView == null ? null : Device.Reflector.GetCustomAttribute <StackBehaviorAttribute>(previousView.GetType(), true);

            var backLink = (Stack.CurrentView as IHistoryEntry)?.BackLink;

            if ((ActionBar.DisplayOptions & ActionBarDisplayOptions.HomeAsUp) == ActionBarDisplayOptions.HomeAsUp)
            {
                DroidFactory.HideKeyboard(false);
                Stack.HandleBackLink(backLink, Pane.Popover);
            }
            else if (Stack.CanGoBack() ||
                     backLink == null && (previousView == null || viewAtt != null && (viewAtt.Options & StackBehaviorOptions.HistoryShy) == StackBehaviorOptions.HistoryShy))
            {
                DroidFactory.HideKeyboard(false);
                Close(false);
            }
            return(true);
        }
Esempio n. 7
0
        public void AddChild(IElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }
            var concreteControl = DroidFactory.GetNativeObject <View>(element, nameof(element));

            if (concreteControl == null)
            {
                throw new ArgumentException("Element must provide a native Pair.", nameof(element));
            }
            if (concreteControl.Parent == this)
            {
                return;
            }
            var oldElement = string.IsNullOrEmpty(element.ID) ? null : Children.FirstOrDefault(c => c.ID == element.ID);

            if (oldElement != null)
            {
                RemoveChild(oldElement);
            }
            (concreteControl.Parent as ViewGroup)?.RemoveView(concreteControl);
            AddView(concreteControl);
        }
Esempio n. 8
0
        public override Android.Views.View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var parent = ((Android.Views.View)_canvas).Parent;

            if (parent != null)
            {
                ((ViewGroup)parent).RemoveView(_canvas);
            }
            _container = new LinearLayout(Activity)
            {
                Orientation = Orientation.Vertical,
            };
            _container.AddView(_canvas, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, 0)
            {
                Weight = 1,
            });

            var bar = DroidFactory.GetNativeObject <Android.Views.View>(_toolbar, "Toolbar");

            if (bar != null)
            {
                if (bar.Parent != _container && bar.Parent != null)
                {
                    ((ViewGroup)bar.Parent).RemoveView(bar);
                }
                _container.AddView(bar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent));
                ((Toolbar)bar).UpdateItems();
            }
            Render();

            return(_container);
        }
Esempio n. 9
0
        private void Alert_DismissEvent(object sender, EventArgs e)
        {
            if (Buttons == AlertButtons.YesNo)
            {
                _result += 2;
            }
            var handler = Dismissed;

            if (handler != null)
            {
                handler(this, new AlertResultEventArgs(_result));
            }
            else
            {
                switch (_result)
                {
                case AlertResult.OK:
                case AlertResult.Yes:
                    DroidFactory.Navigate(OKLink);
                    break;

                case AlertResult.Cancel:
                case AlertResult.No:
                    DroidFactory.Navigate(CancelLink);
                    break;
                }
            }
            Instance = null;
            _result  = AlertResult.Cancel;
        }
            public void OnSensorChanged(SensorEvent e)
            {
                for (int i = 0; i < 3; i++)
                {
                    data[i] += e.Values[i];
                }

                if (mCount++ <= 10)
                {
                    return;
                }
                mCount = 0;

                ((SensorManager)DroidFactory.MainActivity.GetSystemService(Context.SensorService)).
                UnregisterListener(this);
                if (locationGetter != null)
                {
                    locationGetter.Dismiss();
                    locationGetter = null;
                }

                if (_accel.CallbackUrl != null)
                {
                    DroidFactory.Navigate(_accel, new Dictionary <string, string>
                    {
                        { "X", (data[0] / 10).ToString(CultureInfo.InvariantCulture) },
                        { "Y", (data[1] / 10).ToString(CultureInfo.InvariantCulture) },
                        { "Z", (data[2] / 10).ToString(CultureInfo.InvariantCulture) },
                    });
                }

                _accel = null;
            }
Esempio n. 11
0
        public static void Start(string audioFilePath)
        {
            if (audioFilePath == null)
            {
                return;
            }

            // first stop any active audio on MediaPlayer instance
            if (_player != null)
            {
                Stop();
            }

            _player = new MediaPlayer();
            if (_player == null)
            {
                throw new Exception("Could not load MediaPlayer");
            }

            _player.SetDataSource(new Java.IO.FileInputStream(audioFilePath).FD);
            _player.Prepare();
            _player.Completion += (sender, args) =>
            {
                Stop();
                if (_callback == null)
                {
                    return;
                }
                DroidFactory.Navigate(_callback);
                _callback = null;
            };
            _player.Start();
        }
Esempio n. 12
0
 private void OnClick(object o, EventArgs e)
 {
     if (this.RaiseEvent(nameof(Clicked), EventArgs.Empty))
     {
         return;
     }
     DroidFactory.Navigate(NavigationLink, Parent);
 }
Esempio n. 13
0
 public void LaunchExternal(string url)
 {
     Parameter.CheckUrl(url);
     DroidFactory.HandleUrl(new UI.Link(url)
     {
         RequestType = UI.RequestType.NewWindow
     }, false, this);
 }
Esempio n. 14
0
        public void OnTabSelected(ActionBar.Tab actionTab, FragmentTransaction ft)
        {
            if (_inFlight)
            {
                return;
            }
            var itemPosition = actionTab.Position;
            var masterStack  = (FragmentHistoryStack)PaneManager.Instance.FromNavContext(Pane.Master, itemPosition);
            var tab          = TabItems.ElementAt(itemPosition);
            var nativeTab    = DroidFactory.GetNativeObject <TabItem>(tab, "tab");

            if (itemPosition != SelectedIndex && !PaneManager.Instance.ShouldNavigate(tab.NavigationLink, Pane.Tabs, NavigationType.Tab))
            {
                DroidFactory.MainActivity.ActionBar.GetTabAt(_selectedIndex).Select();
                return;
            }

            var navTabs = _model as NavigationTabs;

            if (masterStack.CurrentView != null && (navTabs == null || !navTabs.TabItems[itemPosition].RefreshOnFocus))
            {
                if (itemPosition != SelectedIndex)
                {
                    _selectedIndex = itemPosition;
                    this.OnPropertyChanged("SelectedIndex");
                    nativeTab.OnSelected();
                }
                iApp.SetNavigationContext(new iLayer.NavigationContext {
                    OutputOnPane = Pane.Tabs, NavigatedActiveTab = itemPosition,
                });
                masterStack.Align(NavigationType.Tab);
                return;
            }

            iLayer.NavigationContext context;
            if (masterStack.CurrentLayer != null && (context = masterStack.CurrentLayer.NavContext) != null)
            {
                //Fix layer context if it was modified in a different tab
                context.ClearPaneHistoryOnOutput = false;
                context.NavigatedActivePane      = Pane.Tabs;
                context.NavigatedActiveTab       = itemPosition;
                context.OutputOnPane             = Pane.Master;
            }

            if (itemPosition != iApp.CurrentNavContext.ActiveTab)
            {
                var masterView = (PaneManager.Instance.FromNavContext(Pane.Master, iApp.CurrentNavContext.ActiveTab) as FragmentHistoryStack)?.CurrentView as IView;
                iApp.SetNavigationContext(new iLayer.NavigationContext {
                    OutputOnPane = Pane.Tabs, NavigatedActiveTab = itemPosition,
                });
                masterView?.RaiseEvent("Deactivated", EventArgs.Empty);
            }

            _selectedIndex = itemPosition;
            this.OnPropertyChanged("SelectedIndex");
            nativeTab.Activate(this);
        }
Esempio n. 15
0
        public static void OnVideoResult(Uri result, bool deleteFile = false)
        {
            var loader = ProgressDialog.Show(DroidFactory.MainActivity, string.Empty, iApp.Factory.GetResourceString("SaveVideo") ?? "Saving video...", true);

            iApp.Thread.QueueWorker(o =>
            {
                string extension = null;
                var uriString    = result?.ToString().ToLowerInvariant() ?? string.Empty;
                if (uriString.StartsWith("content:"))
                {
                    extension = MimeTypeMap.Singleton.GetExtensionFromMimeType(DroidFactory.MainActivity.ContentResolver.GetType(result));
                }
                else if (uriString.StartsWith("file://"))
                {
                    extension = uriString.Substring(uriString.LastIndexOf('.') + 1);
                }

                if (extension == null)
                {
                    Toast.MakeText(DroidFactory.MainActivity, iApp.Factory.GetResourceString("InvalidFile") ?? "Invalid file", ToastLength.Short).Show();
                    return;
                }

                var mime = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
                if (mime == null || !mime.StartsWith("video"))
                {
                    Toast.MakeText(DroidFactory.MainActivity, iApp.Factory.GetResourceString("InvalidFile") ?? "Invalid file", ToastLength.Short).Show();
                    return;
                }

                string videoId = null;
                try
                {
                    videoId = DroidFactory.Instance.StoreImage(result, extension);
                    if (deleteFile)
                    {
                        DroidFactory.MainActivity.ContentResolver.Delete(result, null, null);
                    }
                }
                catch (IOException e)
                {
                    iApp.Log.Error(e);
                    Toast.MakeText(DroidFactory.MainActivity, iApp.Factory.GetResourceString("VideoError") ?? "There was a problem saving the video. Please check your disk usage.", ToastLength.Long).Show();
                }

                DroidFactory.MainActivity.RunOnUiThread(loader.Dismiss);

                if (_callback == null)
                {
                    return;
                }
                DroidFactory.Navigate(new Link(_callback, new Dictionary <string, string> {
                    { CallbackParam, videoId }
                }));
                _callback = null;
            });
        }
Esempio n. 16
0
        public static void RequestResize(this IElement element, bool condition = true)
        {
            var gridBase = DroidFactory.GetNativeObject <GridBase>(element.Parent, nameof(element.Parent));

            if (gridBase != null && condition)
            {
                gridBase.ResizeRequested = true;
            }
        }
Esempio n. 17
0
 public static void OnVideoPlaybackResult()
 {
     if (_callback == null)
     {
         return;
     }
     DroidFactory.Navigate(_callback);
     _callback = null;
 }
Esempio n. 18
0
        public void OnTabReselected(ActionBar.Tab tab, FragmentTransaction ft)
        {
            if (_inFlight)
            {
                return;
            }
            var actionTab = DroidFactory.GetNativeObject <TabItem>(TabItems.ElementAt(tab.Position), "actionTab");

            actionTab.Activate(this);
        }
Esempio n. 19
0
        public void Deselect()
        {
            SetBackgroundColor(BackgroundColor.ToColor());
            var labels = Children.OfType <ILabel>().Select(f => DroidFactory.GetNativeObject <Label>(f, "label"));

            foreach (var label in labels)
            {
                label.SetTextColor(label.ForegroundColor.ToColor());
            }
        }
Esempio n. 20
0
        private void OnClick(object o, EventArgs e)
        {
            TextBase.CurrentFocus?.Blur(true);
            if (this.RaiseEvent(nameof(Clicked), EventArgs.Empty))
            {
                return;
            }
            var view = Parent as GridBase;

            DroidFactory.Navigate(NavigationLink, view?.Parent);
        }
Esempio n. 21
0
        private void OnScrollStateChanged(object o, AbsListView.ScrollStateChangedEventArgs e)
        {
            DescendantFocusability = DescendantFocusability.BeforeDescendants;
            DroidFactory.HideKeyboard();
            var fragment = Parent as BaseFragment;

            if (fragment != null)
            {
                fragment.RequestFocusHomeUp = false;
            }
        }
Esempio n. 22
0
        private void OnClick(object sender, EventArgs e)
        {
            if (this.RaiseEvent("Clicked", EventArgs.Empty))
            {
                return;
            }
            var toolContainer = Parent as LinearLayout;
            var view          = toolContainer?.Parent as Toolbar;

            DroidFactory.Navigate(NavigationLink, view?.Parent);
        }
Esempio n. 23
0
        public void Select()
        {
            if (Parent is ListViewFragment listViewFragment)
            {
                listViewFragment.SelectedIndex = Metadata.Get <int>("Index");
            }

            if (!this.RaiseEvent(nameof(Selected), EventArgs.Empty))
            {
                DroidFactory.Navigate(NavigationLink, Parent);
            }
        }
Esempio n. 24
0
            public override bool ShouldOverrideUrlLoading(WebView view, string url)
            {
                url = url.Replace(Device.ApplicationPath, string.Empty);
                var links = Items?.OfType <UI.Link>();
                var link  = links?.FirstOrDefault(l => l.Address == url) ?? new UI.Link(url);

                if (DroidFactory.HandleUrl(link, _newBrowser, _parentView))
                {
                    return(true);
                }
                iApp.Factory.BeginBlockingUserInput();
                return(false);
            }
Esempio n. 25
0
        public static Size MeasureView(this IElement view, Size constraints)
        {
            var nativeView = DroidFactory.GetNativeObject <View>(view, nameof(view));

            if (nativeView == null)
            {
                return(new Size());
            }
            nativeView.Measure(View.MeasureSpec.MakeMeasureSpec(GetMeasureSpec(constraints.Width),
                                                                view.HorizontalAlignment == HorizontalAlignment.Stretch ? MeasureSpecMode.Exactly : MeasureSpecMode.AtMost),
                               View.MeasureSpec.MakeMeasureSpec(GetMeasureSpec(constraints.Height), MeasureSpecMode.Unspecified));
            return(new Size(nativeView.MeasuredWidth, nativeView.MeasuredHeight));
        }
Esempio n. 26
0
        public static void OnClick(IMenu menu, int index, IMXView view)
        {
            if (menu.ButtonCount <= 0)
            {
                return;
            }
            var button = menu.GetButton(index);

            if (!button.RaiseEvent("Clicked", EventArgs.Empty) && (button.Pair == null || !button.Pair.RaiseEvent("Clicked", EventArgs.Empty)))
            {
                DroidFactory.Navigate(button.NavigationLink, view);
            }
            Device.Log.Platform($"Clicked menu item \"{button.Title}\"");
        }
Esempio n. 27
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var layout = new LinearLayout(Activity)
            {
                Orientation = Orientation.Vertical,
            };
            var search = DroidFactory.GetNativeObject <SearchBox>(SearchBox, nameof(SearchBox));

            AttachSearchView(search, layout);

            List = MXContainer.Resolve <ListView>(Activity) ?? new ListView(Activity);
            List.OnItemSelectedListener  = this;
            List.OnItemClickListener     = this;
            List.OnItemLongClickListener = this;
            List.DescendantFocusability  = DescendantFocusability.BeforeDescendants;
            List.ScrollingCacheEnabled   = false;
            List.Adapter             = new CellAdapter(this);
            List.ScrollStateChanged += (o, e) =>
            {
                if (e.ScrollState == ScrollState.Idle)
                {
                    var cell = List.GetChildAt(0);
                    _index = List.FirstVisiblePosition;
                    _top   = cell?.Top ?? 0;
                }
                List.DescendantFocusability = DescendantFocusability.BeforeDescendants;
                if (_touchScroll)
                {
                    DroidFactory.HideKeyboard(true);
                }
                if (e.ScrollState == ScrollState.Idle)
                {
                    _touchScroll = true;
                }
                RequestFocusHomeUp = false;
            };
            List.SetRecyclerListener(this);
            SeparatorColor = _separatorColor;
            layout.AddView(List, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent));
            if (search == null || search.FocusRequested)
            {
                layout.RequestFocus();
            }
            else
            {
                List.RequestFocus();
            }

            return(layout);
        }
Esempio n. 28
0
        public void Highlight()
        {
            if (SelectionColor.IsDefaultColor)
            {
                Deselect();
                return;
            }

            SetBackgroundColor(SelectionColor.ToColor());
            var labels = Children.OfType <ILabel>().Select(f => DroidFactory.GetNativeObject <Label>(f, "label"));

            foreach (var label in labels)
            {
                label.SetTextColor(label.HighlightColor.ToColor());
            }
        }
Esempio n. 29
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (_browser == null)
            {
                _browser = new RichText
                {
                    Parent = this,
                };
                _browser.Load();
            }

            var viewParent = ((View)_browser).Parent as ViewGroup;

            if (viewParent != null)
            {
                _browser.Browser.LoadFinished -= ClientLoadFinished;
                viewParent.RemoveView(_browser);
            }

            _browser.Browser.AttachToView(this);
            _browser.Browser.LoadFinished += ClientLoadFinished;

            UserAgent = _agent;

            if (_url != null)
            {
                Load(_url);
                _url = null;
            }
            else if (_doc != null)
            {
                LoadFromString(_doc);
                _doc = null;
            }

            var control = DroidFactory.GetNativeObject <View>(_toolbar, "value");

            if (control != null)
            {
                ((ViewGroup)control.Parent)?.RemoveView(control);
                _browser.AddView(control, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent));
            }

            return(_browser);
        }
Esempio n. 30
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var style = iApp.Instance == null ? new Style() : iApp.Instance.Style;

            UpdateHeader(style.HeaderColor);
            base.OnCreate(savedInstanceState);
            ActionBar?.SetHomeButtonEnabled(true);
            var or = Resources.Configuration.Orientation;

            if (or != CurrentOrientation)
            {
                CurrentOrientation = or;
                DroidFactory.OrientationChanged(CurrentOrientation == Orientation.Portrait ? iApp.Orientation.Portrait : iApp.Orientation.LandscapeLeft);
            }
            if (Alert.Instance != null)
            {
                Alert.Instance.Show();
            }
        }